-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Exclude dependencies of std
for diagnostics
#135278
Conversation
r? @SparrowLii rustbot has assigned @SparrowLii. Use |
Unsure whether adding a query is okay or if this should just be a filtering method on @rustbot author |
Another option is to drop Open to suggestions here. |
6a3e3c6
to
a04ed09
Compare
Okay, I think I have something workable here. I dropped @rustbot ready |
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 change makes sense, but I'm not sure it is the best for diagnostics' design.
@compiler-errors Could you help have a review?
pub fn all_traits(self) -> impl Iterator<Item = DefId> + 'tcx { | ||
iter::once(LOCAL_CRATE) | ||
.chain(self.crates(()).iter().copied()) | ||
.chain(self.visible_crates(()).iter().copied()) |
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.
Do we have to change this? It makes sense to analyze trait candidates from private dependencies IMO, we just need to exclude it from diagnostics
And if we not change it here, we can avoid to add a new query since visible_crates
only be used in the query all_diagnostic_items
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.
yeah, this seems wrong. all_traits
is also used by things like SMIR and rustdoc in ways that are not just diagnostics. if you want to distinguish "all visible traits" from "all traits", and then use the former in diagnostics, then it should be more explicit.
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.
I wasn't sure about this one, but yeah that makes sense. I guess there are a couple questions - should the query be kept or should it just filter as-needed? My original thought was that there could be other existing or new places where crates
is used but visible_crates
would be more correct, but maybe this isn't very true.
Then either way, should all_traits
be split into visible_traits
, or is filtering in all_diagnostic_items
sufficient to cover this case? (I didn't realize that would affect the output here, so didn't actually test that on its own)
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.
I think the filtering should be done as needed. if we expose visible_traits
as just a function, it doesn't matter if the filtering is expensive b/c we only call it on the diagnostic codepath (i.e. failed compilation).
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.
Then either way, should all_traits be split into visible_traits, or is filtering in all_diagnostic_items sufficient to cover this case? (I didn't realize that would affect the output here, so didn't actually test that on its own)
probably worth just testing yourself, idk off the top of my head lol
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.
Just tested, seems like all_diagnostic_items
doesn't have any effect on the relevant output here so it has to filter somewhere else too.
So I got rid of the query and split all_traits
into all_traits
and visible_traits
that does the filtering on the fly. I also replaced all_traits
in a few other places that deal with errors that seem reasonable (?), still waiting for my tests to finish and see if that affects much.
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Exclude dependencies of `std` for diagnostics Currently crates in the sysroot can show up in diagnostic suggestions, such as in rust-lang#135232. To prevent this, introduce a query `visible_crates` that excludes crates marked `is_private_dep` and use this query in user-facing areas of code. Setting `#![feature(rustc_private)]` overrides this to just use all crates, since `rustc_private` enables use of `std`'s private dependencies. Notably, this changes `all_traits` to use `.visible_crates(())` rather than `.crates(())`. This is not strictly required and filtering could happen later as-needed; however, I cannot think of any cases where traits from private dependencies should be relevant in trait selection or diagnostics, so filtering at this earlier point seems more likely to avoid similar issues in the future. This may be reviewed per-commit. Fixes: rust-lang#135232
a04ed09
to
871d75a
Compare
HIR ty lowering was modified cc @fmease |
compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs
Outdated
Show resolved
Hide resolved
35ad309
to
c0eb4af
Compare
This comment has been minimized.
This comment has been minimized.
(^ spurious CI failure) |
@bors try @rust-timer queue |
The change between 0.1.143 and 0.1.144 includes refactoring that was in compiler-builtins before, but had to be reverted before landing in rust-lang/rust because the traits were leaking into diagnostics [1]. Recently a fix for this issue was merged [2] so the cleanup is reapplied here. This also acts as a regression test for [2]. [1]: rust-lang#128691 (comment) [2]: rust-lang#135278
`compiler_builtins` is always available as an injected dependency, introduced in AST as `extern crate compiler_builtins as _`. This makes it indistinguishable from any other user-specified `extern crate`, meaning `is_private_dep` does not see it as a dependency that should be marked private; this is the reason that `compiler_builtins` sometimes leaks into diagnostics, and has slightly different behavior from other stdlib dependencies tested in [1]. There is no easy way to know that an instance of `extern crate compiler_builtins` was the injected version; however, `compiler_builtins` To get around this, always mark `compiler_builtins` private. The items in this crate are never used directly, and this is the most [1]: rust-lang#135278
The change between 0.1.143 and 0.1.144 includes refactoring that was in compiler-builtins before, but had to be reverted before landing in rust-lang/rust because the traits were leaking into diagnostics [1]. Recently a fix for this issue was merged [2] so the cleanup is reapplied here. This also acts as a regression test for [2]. [1]: rust-lang#128691 (comment) [2]: rust-lang#135278
The change between 0.1.143 and 0.1.144 includes refactoring that was in compiler-builtins before, but had to be reverted before landing in rust-lang/rust because the traits were leaking into diagnostics [1]. Recently a fix for this issue was merged [2] so the cleanup is reapplied here. This also acts as a regression test for [2]. [1]: rust-lang#128691 (comment) [2]: rust-lang#135278
The change between 0.1.143 and 0.1.144 includes refactoring that was in compiler-builtins before, but had to be reverted before landing in rust-lang/rust because the traits were leaking into diagnostics [1]. Recently a fix for this issue was merged [2] so the cleanup is reapplied here. This also acts as a regression test for [2]. [1]: rust-lang#128691 (comment) [2]: rust-lang#135278
The change between 0.1.143 and 0.1.144 includes refactoring that was in compiler-builtins before, but had to be reverted before landing in rust-lang/rust because the traits were leaking into diagnostics [1]. Recently a fix for this issue was merged [2] so the cleanup is reapplied here. This also acts as a regression test for [2]. [1]: rust-lang#128691 (comment) [2]: rust-lang#135278
The change between 0.1.143 and 0.1.144 includes refactoring that was in compiler-builtins before, but had to be reverted before landing in rust-lang/rust because the traits were leaking into diagnostics [1]. Recently a fix for this issue was merged [2] so the cleanup is reapplied here. This also acts as a regression test for [2]. [1]: rust-lang#128691 (comment) [2]: rust-lang#135278
The change between 0.1.143 and 0.1.144 includes refactoring that was in compiler-builtins before, but had to be reverted before landing in rust-lang/rust because the traits were leaking into diagnostics [1]. Recently a fix for this issue was merged [2] so the cleanup is reapplied here. This also acts as a regression test for [2]. [1]: rust-lang#128691 (comment) [2]: rust-lang#135278
…, r=<try> Resolve `compiler_builtins` not being treated as private; clean up rust-lang#135278 Follow up of rust-lang#135278 Do the following (one per commit): * Do not make dependencies of `std` private by default * Update remaining sysroot crates to use `public-dependencies` * Force `compiler_builtins` to be private, since it is an injected `extern crate` * Ensure that marking a dependency private makes its dependents private by default as well * Do the `compiler_builtins` update that has been blocked on this Based on top of rust-lang#136226 so there are a few preceding commits. try-job: test-various try-job: x86_64-msvc-1
The change between 0.1.143 and 0.1.144 includes refactoring that was in compiler-builtins before, but had to be reverted before landing in rust-lang/rust because the traits were leaking into diagnostics [1]. Recently a fix for this issue was merged [2] so the cleanup is reapplied here. This also acts as a regression test for [2]. [1]: rust-lang#128691 (comment) [2]: rust-lang#135278
…, r=<try> Resolve `compiler_builtins` not being treated as private; clean up rust-lang#135278 Follow up of rust-lang#135278 Do the following (one per commit): * Do not make dependencies of `std` private by default * Update remaining sysroot crates to use `public-dependencies` * Ensure that marking a dependency private makes its dependents private by default as well * Do the `compiler_builtins` update that has been blocked on this Based on top of rust-lang#136226 so there are a few preceding commits. try-job: test-various try-job: x86_64-msvc-1
Replace `public_test_dep!` by placing optionally public items into new modules, then controlling what is exported with the `public-test-deps` feature. This is nicer for automatic formatting and diagnostics. This is a reland of 2e2a925 ("Eliminate the use of `public_test_dep!`"), which was reverted in 47e50fd ('Revert "Eliminate the use of..."') due to a bug exposed at [1]. This was fixed in [2], so the cleanup should be able to be applied again. [1]: rust-lang/rust#128691 [2]: rust-lang/rust#135278 (cherry picked from commit d4abaf4)
…, r=<try> Inject `compiler_builtins` during postprocessing and ensure it is made private Follow up of rust-lang#135278 Do the following: * Inject `compiler_builtins` during postprocessing, rather than injecting `extern crate compiler_builtins as _` into the AST * Do not make dependencies of `std` private by default (this was added in rust-lang#135278) * Make sure sysroot crates correctly mark their dependencies private/public * Ensure that marking a dependency private makes its dependents private by default as well, unless otherwise specified * Do the `compiler_builtins` update that has been blocked on this There is more detail in the commit messages. This includes the changes I was working on in rust-lang#136226. try-job: test-various try-job: x86_64-msvc-1 try-job: x86_64-msvc-2 try-job: i686-mingw
…, r=<try> Inject `compiler_builtins` during postprocessing and ensure it is made private Follow up of rust-lang#135278 Do the following: * Inject `compiler_builtins` during postprocessing, rather than injecting `extern crate compiler_builtins as _` into the AST * Do not make dependencies of `std` private by default (this was added in rust-lang#135278) * Make sure sysroot crates correctly mark their dependencies private/public * Ensure that marking a dependency private makes its dependents private by default as well, unless otherwise specified * Do the `compiler_builtins` update that has been blocked on this There is more detail in the commit messages. This includes the changes I was working on in rust-lang#136226. try-job: test-various try-job: x86_64-msvc-1 try-job: x86_64-msvc-2 try-job: i686-mingw-1 try-job: i686-mingw-2 try-job: i686-mingw-3
…, r=<try> Inject `compiler_builtins` during postprocessing and ensure it is made private Follow up of rust-lang#135278 Do the following: * Inject `compiler_builtins` during postprocessing, rather than injecting `extern crate compiler_builtins as _` into the AST * Do not make dependencies of `std` private by default (this was added in rust-lang#135278) * Make sure sysroot crates correctly mark their dependencies private/public * Ensure that marking a dependency private makes its dependents private by default as well, unless otherwise specified * Do the `compiler_builtins` update that has been blocked on this There is more detail in the commit messages. This includes the changes I was working on in rust-lang#136226. try-job: test-various try-job: x86_64-msvc-1 try-job: x86_64-msvc-2 try-job: i686-mingw-1 try-job: i686-mingw-2
Replace `public_test_dep!` by placing optionally public items into new modules, then controlling what is exported with the `public-test-deps` feature. This is nicer for automatic formatting and diagnostics. This is a reland of 2e2a925 ("Eliminate the use of `public_test_dep!`"), which was reverted in 47e50fd ('Revert "Eliminate the use of..."') due to a bug exposed at [1]. This was fixed in [2], so the cleanup should be able to be applied again. [1]: rust-lang/rust#128691 [2]: rust-lang/rust#135278 (cherry picked from commit d4abaf4)
…, r=<try> Inject `compiler_builtins` during postprocessing and ensure it is made private Follow up of rust-lang#135278 Do the following: * Inject `compiler_builtins` during postprocessing, rather than injecting `extern crate compiler_builtins as _` into the AST * Do not make dependencies of `std` private by default (this was added in rust-lang#135278) * Make sure sysroot crates correctly mark their dependencies private/public * Ensure that marking a dependency private makes its dependents private by default as well, unless otherwise specified * Do the `compiler_builtins` update that has been blocked on this There is more detail in the commit messages. This includes the changes I was working on in rust-lang#136226. try-job: test-various try-job: x86_64-msvc-1 try-job: x86_64-msvc-2 try-job: i686-mingw-1 try-job: i686-mingw-2
…te, r=bjorn3 Inject `compiler_builtins` during postprocessing and ensure it is made private Follow up of rust-lang#135278 Do the following: * Inject `compiler_builtins` during postprocessing, rather than injecting `extern crate compiler_builtins as _` into the AST * Do not make dependencies of `std` private by default (this was added in rust-lang#135278) * Make sure sysroot crates correctly mark their dependencies private/public * Ensure that marking a dependency private makes its dependents private by default as well, unless otherwise specified * Do the `compiler_builtins` update that has been blocked on this There is more detail in the commit messages. This includes the changes I was working on in rust-lang#136226. try-job: test-various try-job: x86_64-msvc-1 try-job: x86_64-msvc-2 try-job: i686-mingw-1 try-job: i686-mingw-2
…te, r=bjorn3 Inject `compiler_builtins` during postprocessing and ensure it is made private Follow up of rust-lang#135278 Do the following: * Inject `compiler_builtins` during postprocessing, rather than injecting `extern crate compiler_builtins as _` into the AST * Do not make dependencies of `std` private by default (this was added in rust-lang#135278) * Make sure sysroot crates correctly mark their dependencies private/public * Ensure that marking a dependency private makes its dependents private by default as well, unless otherwise specified * Do the `compiler_builtins` update that has been blocked on this There is more detail in the commit messages. This includes the changes I was working on in rust-lang#136226. try-job: test-various try-job: x86_64-msvc-1 try-job: x86_64-msvc-2 try-job: i686-mingw-1 try-job: i686-mingw-2
…te, r=bjorn3 Inject `compiler_builtins` during postprocessing and ensure it is made private Follow up of rust-lang#135278 Do the following: * Inject `compiler_builtins` during postprocessing, rather than injecting `extern crate compiler_builtins as _` into the AST * Do not make dependencies of `std` private by default (this was added in rust-lang#135278) * Make sure sysroot crates correctly mark their dependencies private/public * Ensure that marking a dependency private makes its dependents private by default as well, unless otherwise specified * Do the `compiler_builtins` update that has been blocked on this There is more detail in the commit messages. This includes the changes I was working on in rust-lang#136226. try-job: test-various try-job: x86_64-msvc-1 try-job: x86_64-msvc-2 try-job: i686-mingw-1 try-job: i686-mingw-2
…te, r=bjorn3 Inject `compiler_builtins` during postprocessing and ensure it is made private Follow up of rust-lang#135278 Do the following: * Inject `compiler_builtins` during postprocessing, rather than injecting `extern crate compiler_builtins as _` into the AST * Do not make dependencies of `std` private by default (this was added in rust-lang#135278) * Make sure sysroot crates correctly mark their dependencies private/public * Ensure that marking a dependency private makes its dependents private by default as well, unless otherwise specified * Do the `compiler_builtins` update that has been blocked on this There is more detail in the commit messages. This includes the changes I was working on in rust-lang#136226. try-job: test-various try-job: x86_64-msvc-1 try-job: x86_64-msvc-2 try-job: i686-mingw-1 try-job: i686-mingw-2
Rollup merge of rust-lang#135501 - tgross35:stdlib-dependencies-private, r=bjorn3 Inject `compiler_builtins` during postprocessing and ensure it is made private Follow up of rust-lang#135278 Do the following: * Inject `compiler_builtins` during postprocessing, rather than injecting `extern crate compiler_builtins as _` into the AST * Do not make dependencies of `std` private by default (this was added in rust-lang#135278) * Make sure sysroot crates correctly mark their dependencies private/public * Ensure that marking a dependency private makes its dependents private by default as well, unless otherwise specified * Do the `compiler_builtins` update that has been blocked on this There is more detail in the commit messages. This includes the changes I was working on in rust-lang#136226. try-job: test-various try-job: x86_64-msvc-1 try-job: x86_64-msvc-2 try-job: i686-mingw-1 try-job: i686-mingw-2
Replace `public_test_dep!` by placing optionally public items into new modules, then controlling what is exported with the `public-test-deps` feature. This is nicer for automatic formatting and diagnostics. This is a reland of 2e2a925 ("Eliminate the use of `public_test_dep!`"), which was reverted in 47e50fd ('Revert "Eliminate the use of..."') due to a bug exposed at [1], reapplied in d4abaf4 because the issue should have been fixed in [2], then reverted again in f6eef07 because [2] did not actually fix the issue. [3] has landed in rust-lang/rust since then, which should resolve the last problem remaining after [2]. So, apply this change for what is hopefully the final time. [1]: rust-lang/rust#128691 [2]: rust-lang/rust#135278 [3]: rust-lang/rust#135501
Replace `public_test_dep!` by placing optionally public items into new modules, then controlling what is exported with the `public-test-deps` feature. This is nicer for automatic formatting and diagnostics. This is a reland of 2e2a925 ("Eliminate the use of `public_test_dep!`"), which was reverted in 47e50fd ('Revert "Eliminate the use of..."') due to a bug exposed at [1], reapplied in d4abaf4 because the issue should have been fixed in [2], then reverted again in f6eef07 because [2] did not actually fix the issue. [3] has landed in rust-lang/rust since then, which should resolve the last problem remaining after [2]. So, apply this change for what is hopefully the final time. [1]: rust-lang/rust#128691 [2]: rust-lang/rust#135278 [3]: rust-lang/rust#135501
Inject `compiler_builtins` during postprocessing and ensure it is made private Follow up of rust-lang/rust#135278 Do the following: * Inject `compiler_builtins` during postprocessing, rather than injecting `extern crate compiler_builtins as _` into the AST * Do not make dependencies of `std` private by default (this was added in #135278) * Make sure sysroot crates correctly mark their dependencies private/public * Ensure that marking a dependency private makes its dependents private by default as well, unless otherwise specified * Do the `compiler_builtins` update that has been blocked on this There is more detail in the commit messages. This includes the changes I was working on in rust-lang/rust#136226. try-job: test-various try-job: x86_64-msvc-1 try-job: x86_64-msvc-2 try-job: i686-mingw-1 try-job: i686-mingw-2
Inject `compiler_builtins` during postprocessing and ensure it is made private Follow up of rust-lang/rust#135278 Do the following: * Inject `compiler_builtins` during postprocessing, rather than injecting `extern crate compiler_builtins as _` into the AST * Do not make dependencies of `std` private by default (this was added in #135278) * Make sure sysroot crates correctly mark their dependencies private/public * Ensure that marking a dependency private makes its dependents private by default as well, unless otherwise specified * Do the `compiler_builtins` update that has been blocked on this There is more detail in the commit messages. This includes the changes I was working on in rust-lang/rust#136226. try-job: test-various try-job: x86_64-msvc-1 try-job: x86_64-msvc-2 try-job: i686-mingw-1 try-job: i686-mingw-2
Inject `compiler_builtins` during postprocessing and ensure it is made private Follow up of rust-lang/rust#135278 Do the following: * Inject `compiler_builtins` during postprocessing, rather than injecting `extern crate compiler_builtins as _` into the AST * Do not make dependencies of `std` private by default (this was added in #135278) * Make sure sysroot crates correctly mark their dependencies private/public * Ensure that marking a dependency private makes its dependents private by default as well, unless otherwise specified * Do the `compiler_builtins` update that has been blocked on this There is more detail in the commit messages. This includes the changes I was working on in rust-lang/rust#136226. try-job: test-various try-job: x86_64-msvc-1 try-job: x86_64-msvc-2 try-job: i686-mingw-1 try-job: i686-mingw-2
…te, r=bjorn3 Inject `compiler_builtins` during postprocessing and ensure it is made private Follow up of rust-lang#135278 Do the following: * Inject `compiler_builtins` during postprocessing, rather than injecting `extern crate compiler_builtins as _` into the AST * Do not make dependencies of `std` private by default (this was added in rust-lang#135278) * Make sure sysroot crates correctly mark their dependencies private/public * Ensure that marking a dependency private makes its dependents private by default as well, unless otherwise specified * Do the `compiler_builtins` update that has been blocked on this There is more detail in the commit messages. This includes the changes I was working on in rust-lang#136226. try-job: test-various try-job: x86_64-msvc-1 try-job: x86_64-msvc-2 try-job: i686-mingw-1 try-job: i686-mingw-2
…te, r=bjorn3 Inject `compiler_builtins` during postprocessing and ensure it is made private Follow up of rust-lang#135278 Do the following: * Inject `compiler_builtins` during postprocessing, rather than injecting `extern crate compiler_builtins as _` into the AST * Do not make dependencies of `std` private by default (this was added in rust-lang#135278) * Make sure sysroot crates correctly mark their dependencies private/public * Ensure that marking a dependency private makes its dependents private by default as well, unless otherwise specified * Do the `compiler_builtins` update that has been blocked on this There is more detail in the commit messages. This includes the changes I was working on in rust-lang#136226. try-job: test-various try-job: x86_64-msvc-1 try-job: x86_64-msvc-2 try-job: i686-mingw-1 try-job: i686-mingw-2
Currently crates in the sysroot can show up in diagnostic suggestions, such as in #135232. To prevent this, duplicate
all_traits
intovisible_traits
which only shows traits in non-private crates.Setting
#![feature(rustc_private)]
overrides this and makes items in private crates visible as well, sincerustc_private
enables use ofstd
's private dependencies.This may be reviewed per-commit.
Fixes: #135232