-
Notifications
You must be signed in to change notification settings - Fork 13k
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 |
#111076 marked all dependencies of libstd as private except for those that are actually part of the public interface of libstd to fix a similar diagnostic issue. This wasn't done for liballoc and other sysroot crates however. Should probably be fixed. |
@@ -876,6 +876,11 @@ impl<'tcx> TyCtxt<'tcx> { | |||
/// [public]: TyCtxt::is_private_dep | |||
/// [direct]: rustc_session::cstore::ExternCrate::is_direct | |||
pub fn is_user_visible_dep(self, key: CrateNum) -> bool { | |||
// `#![rustc_private]` overrides defaults to make private dependencies usable. | |||
if self.features().enabled(sym::rustc_private) { |
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.
However, this is a very internal feature, so it doesn't seem worth doing any additional filtering here.
Not really. There are a lot of external custom drivers that need to enable this feature.
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.
Are you suggesting that it is worth filtering here to only expose crates that are dependencies of std
? Or just that the message is inaccurate.
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 override for rustc_private should be removed. Even with rustc_private enabled you generally shouldn't do something like extern crate libc;
from the sysroot.
☀️ Test successful - checks-actions |
I was not aware of this history but that makes sense, I will update the others. In that case, do you think it makes sense to also revert ed63539? Assuming yes, since it would no longer be needed. |
If the Cargo.toml changes are enough, then yes. It would make sense to me to revert that commit. |
Opened #135501 as an experiment, but I have been unsuccessful keeping the test fixed just by setting |
Finished benchmarking commit (8c39ce5): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)Results (primary -1.6%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResults (primary 2.6%, secondary -3.4%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 763.379s -> 762.502s (-0.11%) |
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 [1]: rust-lang/rust#135278
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
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
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
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
Update `compiler-builtins` to 0.1.144 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
Update `compiler-builtins` to 0.1.144 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
Update `compiler-builtins` to 0.1.144 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
Update `compiler-builtins` to 0.1.144 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
Update `compiler-builtins` to 0.1.144 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
Update `compiler-builtins` to 0.1.144 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 try-job: test-various
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