-
Notifications
You must be signed in to change notification settings - Fork 13.5k
avoid suggesting traits from private dependencies #143038
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
avoid suggesting traits from private dependencies #143038
Conversation
8dd63b7
to
2f3d599
Compare
Oh that's a wonderfully small fix. Were you able to reproduce this with something other than Just make sure it actually fails without the fix since I know this is a bit touchy. |
explain: bool, | ||
) -> bool { | ||
valid_out_of_scope_traits.retain(|id| !self.tcx.is_private_dep(id.krate)); |
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 it might be better to rename all_traits
to all_visible_traits
(and update its usage) here https://github.com/rust-lang/rust/blob/2f3d599989883d0be932df3dceed65a6ec3274f8/compiler/rustc_hir_typeck/src/method/suggest.rs#L4387C15-L4389, then have that function call visible_traits
rust/compiler/rustc_middle/src/ty/context.rs
Lines 2320 to 2335 in bc4376f
/// All traits in the crate graph, including those not visible to the user. | |
pub fn all_traits(self) -> impl Iterator<Item = DefId> { | |
iter::once(LOCAL_CRATE) | |
.chain(self.crates(()).iter().copied()) | |
.flat_map(move |cnum| self.traits(cnum).iter().copied()) | |
} | |
/// All traits that are visible within the crate graph (i.e. excluding private dependencies). | |
pub fn visible_traits(self) -> impl Iterator<Item = DefId> { | |
let visible_crates = | |
self.crates(()).iter().copied().filter(move |cnum| self.is_user_visible_dep(*cnum)); | |
iter::once(LOCAL_CRATE) | |
.chain(visible_crates) | |
.flat_map(move |cnum| self.traits(cnum).iter().copied()) | |
} |
suggest_valid_traits
.
@estebank any opinions here?
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.
Maybe renaming all_traits
to all_traits_inclusing_private
or something else verbose? visible_traits
is what most people want/need so it should have the shorter, more findable name.
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.
The actual tcx methods you mean? That seems reasonable to me to avoid the footgun. It's only named in ~10 places so @Qelxiros feel free to either do that in a second commit in this PR, or as a separate PR.
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'm happy to add it here. As a side note, visible_traits
above uses TyCtxt::is_user_visible_dep
, which allows imports from direct private dependencies. Using that instead of is_private_dep
still removes the erroneous suggestions, is more in line with my mental model of what I'm trying to do here, and aligns with the documentation of is_user_visible_dep
:
rust/compiler/rustc_middle/src/ty/util.rs
Lines 838 to 839 in bc4376f
/// dependency, or a [direct] private dependency. This is used to decide whether the crate can | |
/// be shown in `impl` suggestions. |
HIR ty lowering was modified cc @fmease |
I'm assuming that ping is due to the function rename, see #143038 (comment) for context |
This comment has been minimized.
This comment has been minimized.
1ac98c8
to
a9d5951
Compare
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.
LGTM as well, thank you for the changes!
One request if possible, are you able to adjust the history a bit? Split commits like:
- Add the tests and run+bless it so we have the current failures in history (this is purely nice to have, feel free to disregard this if it's tricky)
- Make
compiler-builtins
a private dep - Add the fix and update the test (everything else)
This is so we will be able to backport only the library changes (second commit) to beta, which should fix #143215.
0bd4396
to
92e5103
Compare
Awesome to see the failure reproduced in the first commit since I was having trouble getting it to work locally. Thank you for all the work here! @bors r+ |
@bors r- |
Rollup of 12 pull requests Successful merges: - #141847 (Explain `TOCTOU` on the top of `std::fs`, and reference it in functions) - #142138 (Add `Vec::into_chunks`) - #142321 (Expose elf abi on ppc64 targets) - #142886 (ci: aarch64-gnu: Stop skipping `panic_abort_doc_tests`) - #143038 (avoid suggesting traits from private dependencies) - #143194 (fix bitcast of single-element SIMD vectors) - #143206 (Align attr fixes) - #143231 (Suggest use another lifetime specifier instead of underscore lifetime) - #143232 ([COMPILETEST-UNTANGLE 3/N] Use "directives" consistently within compiletest) - #143258 (Don't recompute `DisambiguatorState` for every RPITIT in trait definition) - #143260 (Use the correct export kind for __rust_alloc_error_handler_should_panic) - #143274 (ci: support optional jobs) r? `@ghost` `@rustbot` modify labels: rollup
…-traits, r=tgross35 avoid suggesting traits from private dependencies fixes rust-lang#142676 fixes rust-lang#138191 r? ````@tgross35````
Rollup of 11 pull requests Successful merges: - #141847 (Explain `TOCTOU` on the top of `std::fs`, and reference it in functions) - #142138 (Add `Vec::into_chunks`) - #142321 (Expose elf abi on ppc64 targets) - #142886 (ci: aarch64-gnu: Stop skipping `panic_abort_doc_tests`) - #143038 (avoid suggesting traits from private dependencies) - #143194 (fix bitcast of single-element SIMD vectors) - #143231 (Suggest use another lifetime specifier instead of underscore lifetime) - #143232 ([COMPILETEST-UNTANGLE 3/N] Use "directives" consistently within compiletest) - #143258 (Don't recompute `DisambiguatorState` for every RPITIT in trait definition) - #143260 (Use the correct export kind for __rust_alloc_error_handler_should_panic) - #143274 (ci: support optional jobs) r? `@ghost` `@rustbot` modify labels: rollup
Since // By default, the `read` diagnostic suggests `std::os::unix::fs::FileExt::read_at`. Add
// something more likely to be recommended to make the diagnostic cross-platform.
trait DecoyRead {
fn read1(&self) {}
}
impl<T> DecoyRead for Vec<T> {} |
51aa76f
to
6b824e8
Compare
@bors2 try jobs=test-various |
…<try> avoid suggesting traits from private dependencies <!-- homu-ignore:start --> <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r? <reviewer name> --> <!-- homu-ignore:end --> fixes #142676 fixes #138191 r? `@tgross35` try-job: test-various
@bors r+ |
…-traits, r=tgross35 avoid suggesting traits from private dependencies fixes rust-lang#142676 fixes rust-lang#138191 r? `@tgross35`
Rollup of 6 pull requests Successful merges: - #134006 (setup typos check in CI) - #142876 (Port `#[target_feature]` to new attribute parsing infrastructure) - #143038 (avoid suggesting traits from private dependencies) - #143083 (Fix rustdoc not correctly showing attributes on re-exports) - #143283 (document optional jobs) - #143329 (minicore: use core's `diagnostic::on_unimplemented` messages) Failed merges: - #143237 (Port `#[no_implicit_prelude]` to the new attribute parsing infrastructure) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 6 pull requests Successful merges: - rust-lang/rust#134006 (setup typos check in CI) - rust-lang/rust#142876 (Port `#[target_feature]` to new attribute parsing infrastructure) - rust-lang/rust#143038 (avoid suggesting traits from private dependencies) - rust-lang/rust#143083 (Fix rustdoc not correctly showing attributes on re-exports) - rust-lang/rust#143283 (document optional jobs) - rust-lang/rust#143329 (minicore: use core's `diagnostic::on_unimplemented` messages) Failed merges: - rust-lang/rust#143237 (Port `#[no_implicit_prelude]` to the new attribute parsing infrastructure) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 6 pull requests Successful merges: - rust-lang/rust#134006 (setup typos check in CI) - rust-lang/rust#142876 (Port `#[target_feature]` to new attribute parsing infrastructure) - rust-lang/rust#143038 (avoid suggesting traits from private dependencies) - rust-lang/rust#143083 (Fix rustdoc not correctly showing attributes on re-exports) - rust-lang/rust#143283 (document optional jobs) - rust-lang/rust#143329 (minicore: use core's `diagnostic::on_unimplemented` messages) Failed merges: - rust-lang/rust#143237 (Port `#[no_implicit_prelude]` to the new attribute parsing infrastructure) r? `@ghost` `@rustbot` modify labels: rollup
fixes #142676
fixes #138191
r? @tgross35