-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide more information on duplicate lang item error. #73449
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
This is somewhat hacky, as I'm not too familiar with the compiler code (I never know the proper ways to get information from one place to another). I'm not sure if this will actually be helpful to anyone besides myself, so I wanted to open this PR to see if anyone might see some use in it. cc @alexcrichton, you may or may not have an opinion on the usefulness here. |
👍 from a usefulness perspective, seems handy to have! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
crate_extern_paths
should be a query. I've left a couple of comments to give some explanation on how to do that.
I also have a nit about the error message.
src/librustc_passes/lang_items.rs
Outdated
paths.join(", ") | ||
}; | ||
err.note(&format!( | ||
"{} definition in `{}` loaded from {}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the local crate the note should be "{} definition in the local crate".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, tweaked the wording. I kept the crate name, since I find that can be useful at times.
@@ -513,4 +514,8 @@ impl CrateStore for CStore { | |||
fn allocator_kind(&self) -> Option<AllocatorKind> { | |||
self.allocator_kind() | |||
} | |||
|
|||
fn crate_extern_paths(&self, cnum: CrateNum) -> Vec<PathBuf> { | |||
self.get_crate_data(cnum).source().paths().cloned().collect() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this into the provide
macro above.
src/librustc_middle/ty/context.rs
Outdated
@@ -1207,6 +1208,14 @@ impl<'tcx> TyCtxt<'tcx> { | |||
if cnum == LOCAL_CRATE { false } else { self.cstore.crate_is_private_dep_untracked(cnum) } | |||
} | |||
|
|||
pub fn crate_extern_paths(&self, cnum: CrateNum) -> Vec<PathBuf> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a query: you can declare it be copying this example and updating the signature and description
rust/src/librustc_middle/query/mod.rs
Lines 1035 to 1038 in 7adbc0d
query extra_filename(_: CrateNum) -> String { | |
eval_always | |
desc { "looking up the extra filename for a crate" } | |
} |
@matthewjasper Thanks for taking a look! Is there some guidance on what should be a query and what should be a function? I assumed queries were mainly used for caching, and I assumed in this case that it wouldn't be useful since this only appears in an error. I'm also a bit confused on how to define the query. I'm getting all sorts of errors that I do not understand how to resolve. In particular:
The first error is very strange, since I am using The second one is completely opaque to me, perhaps it is a consequence of the first error? |
The I couldn't find an explanation of what should be a query. Queries are used both for caching and tracking dependencies for incremental: queries are expected to be depend only on their inputs and the results of any queries that they call. For data that exists prior to the query system, the current approach is to make make the public method to access the data an |
c2d8966
to
1b3ef66
Compare
Oh, thanks! In hindsight that was obvious, I'm not sure how I missed that. |
@bors r+ |
📌 Commit 1b3ef66 has been approved by |
…wjasper Provide more information on duplicate lang item error. This gives some notes on the location of the files where the lang items were loaded from. Some duplicate lang item errors can be a little confusing, and this might help in diagnosing what has happened. Here's an example when hitting a bug with Cargo's build-std: ``` error: duplicate lang item in crate `core` (which `rustc_std_workspace_core` depends on): `try`. | = note: the lang item is first defined in crate `core` (which `z10` depends on) = note: first definition in `core` loaded from /Users/eric/Proj/rust/cargo/scratch/z10/target/target/debug/deps/libcore-a764da499c7385f4.rmeta = note: second definition in `core` loaded from /Users/eric/Proj/rust/cargo/scratch/z10/target/target/debug/deps/libcore-5b082675aea34986.rmeta ```
…wjasper Provide more information on duplicate lang item error. This gives some notes on the location of the files where the lang items were loaded from. Some duplicate lang item errors can be a little confusing, and this might help in diagnosing what has happened. Here's an example when hitting a bug with Cargo's build-std: ``` error: duplicate lang item in crate `core` (which `rustc_std_workspace_core` depends on): `try`. | = note: the lang item is first defined in crate `core` (which `z10` depends on) = note: first definition in `core` loaded from /Users/eric/Proj/rust/cargo/scratch/z10/target/target/debug/deps/libcore-a764da499c7385f4.rmeta = note: second definition in `core` loaded from /Users/eric/Proj/rust/cargo/scratch/z10/target/target/debug/deps/libcore-5b082675aea34986.rmeta ```
…wjasper Provide more information on duplicate lang item error. This gives some notes on the location of the files where the lang items were loaded from. Some duplicate lang item errors can be a little confusing, and this might help in diagnosing what has happened. Here's an example when hitting a bug with Cargo's build-std: ``` error: duplicate lang item in crate `core` (which `rustc_std_workspace_core` depends on): `try`. | = note: the lang item is first defined in crate `core` (which `z10` depends on) = note: first definition in `core` loaded from /Users/eric/Proj/rust/cargo/scratch/z10/target/target/debug/deps/libcore-a764da499c7385f4.rmeta = note: second definition in `core` loaded from /Users/eric/Proj/rust/cargo/scratch/z10/target/target/debug/deps/libcore-5b082675aea34986.rmeta ```
…wjasper Provide more information on duplicate lang item error. This gives some notes on the location of the files where the lang items were loaded from. Some duplicate lang item errors can be a little confusing, and this might help in diagnosing what has happened. Here's an example when hitting a bug with Cargo's build-std: ``` error: duplicate lang item in crate `core` (which `rustc_std_workspace_core` depends on): `try`. | = note: the lang item is first defined in crate `core` (which `z10` depends on) = note: first definition in `core` loaded from /Users/eric/Proj/rust/cargo/scratch/z10/target/target/debug/deps/libcore-a764da499c7385f4.rmeta = note: second definition in `core` loaded from /Users/eric/Proj/rust/cargo/scratch/z10/target/target/debug/deps/libcore-5b082675aea34986.rmeta ```
…arth Rollup of 16 pull requests Successful merges: - rust-lang#72569 (Remove legacy InnoSetup GUI installer) - rust-lang#73306 (Don't implement Fn* traits for #[target_feature] functions) - rust-lang#73345 (expand: Stop using nonterminals for passing tokens to attribute and derive macros) - rust-lang#73449 (Provide more information on duplicate lang item error.) - rust-lang#73569 (Handle `macro_rules!` tokens consistently across crates) - rust-lang#73803 (Recover extra trailing angle brackets in struct definition) - rust-lang#73839 (Split and expand nonstandard-style lints unicode unit test.) - rust-lang#73841 (Remove defunct `-Z print-region-graph`) - rust-lang#73848 (Fix markdown rendering in librustc_lexer docs) - rust-lang#73865 (Fix Zulip topic format) - rust-lang#73892 (Clean up E0712 explanation) - rust-lang#73898 (remove duplicate test for rust-lang#61935) - rust-lang#73906 (Add missing backtick in `ty_error_with_message`) - rust-lang#73909 (`#[deny(unsafe_op_in_unsafe_fn)]` in libstd/fs.rs) - rust-lang#73910 (Rewrite a few manual index loops with while-let) - rust-lang#73929 (Fix comment typo) Failed merges: r? @ghost
This gives some notes on the location of the files where the lang items were loaded from. Some duplicate lang item errors can be a little confusing, and this might help in diagnosing what has happened.
Here's an example when hitting a bug with Cargo's build-std: