Comments (2)
The problem occurs because the code tries to look up the definition of the item in HIR, but that item comes from a foreign crate.
When the TraitRef
's ItemId
is created here
The type of the ID that is transmuted into
ItemId
is rustc_span::def_id::DefId
. But when the ctx.ast().item()
is called the ItemId
is converted into rustc_hir::hir::ItemId
. You may notice that the method in the snippet below doesn't use the layout.krate
field at all. I guess it assumes that this method is always called with local items (of the current crate).marker/marker_rustc_driver/src/conversion/rustc/common.rs
Lines 73 to 82 in 73835de
So this results in an invalid rustc_hir::hir::ItemId
. You'll get a panic even if you try to debug-print this ID.
I'm not sure what the best solution here should be. Maybe the to_item_id(ItemId) -> hir::ItemId
method should check if layout.krate
is not a local crate. I suppose there is a special sentinel value for krate
that identifies it as the current crate. Then if the given item is not from the current crate it should return None
.
But how could users query the info about which trait is implemented? Maybe if there was at least the path to the implemented trait in the TraitRef
that would allow to check the syntactic path to the trait.
from marker.
Ahh, I think the actual problem is the type. TraitRef
should hold a TyDefId
instead, and Marker should probably have a function to convert the TyDefId
into an ItemId
if the item is available.
Thinking about it, this will not resolve all issues though 🤔 Users can still retrieve ItemId
s when AstPath
s are resolved. So this case definitely need to be handled on Marker's side.
Rustc splits these IDs into a general DefId
which can be used across crate boundaries, but is not guaranteed to have an ast item, and a LocalDefId
which is only defined for items from the current crate, where an ast representation exists. I wonder if it would make sense to adapt a similar model 🤔
from marker.
Related Issues (20)
- [Feat]: Provide a way to automatically fix lints with `--fix` flag HOT 2
- Use consistent naming `fn pat()` vs `fn pattern()`
- [Bug]: `marker_uitest` doesn't work in a workspace with rust-toolchain.toml file that uses `1.71` HOT 1
- [Bug]: Marker panics when the item identifier from macro expansion is debug-printed.
- `FnItem::ident()` should return `Ident` instead of `Option<Ident>`
- [Feat]: Make `cargo test --doc` work with the lint crates to doc test examples HOT 2
- [Feat]: Add a method to check if type implements a trait HOT 2
- Chore: Bump nightly -> 2023-12-28
- [Bug]: `cargo marker setup --auto-install-toolchain` fails with E0554 `#[feature]` on stable channel HOT 14
- [Bug]: `cargo uitest` fails with `[E0463]: can't find crate for std` HOT 11
- [Panic]: broken on_unimplemented "{float}{_Self}{crate_local}{Trait}{ItemContext}" for <() as Baz>: no argument matching "crate_local
- [Panic]: `&MarkerConverterInner::lang_item_map` doesn't contain `TryTraitFromOutput
- [Panic]: assertion failed: 4 == 3
- [Panic]: unimplemented: type aliases / assoc type bounds
- [Panic]: not implemented: lifetimes?
- [Panic]: `this should be a literal expression Expr {`
- [Panic]: None / expected fulfillment errors
- [Panic]: no type for local variable
- [Panic]: unreachable HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from marker.