For E0223, suggest associated functions that are similar to the path, even if the base type has multiple inherent impl blocks.#135865
Merged
bors merged 4 commits intorust-lang:masterfrom Jan 24, 2025
Conversation
Collaborator
|
rustbot has assigned @compiler-errors. Use |
Collaborator
|
HIR ty lowering was modified cc @fmease |
10 tasks
Contributor
Author
|
(Latest commit also works for primitives, but not |
This comment has been minimized.
This comment has been minimized.
… even if there are multiple inherent impls to check.
9f23011 to
7e1a8bd
Compare
compiler-errors
approved these changes
Jan 23, 2025
Contributor
compiler-errors
left a comment
There was a problem hiding this comment.
r=me with or without nit
| @@ -1,5 +1,5 @@ | |||
| error[E0223]: ambiguous associated type | |||
| --> $DIR/issue-109195.rs:2:5 | |||
| --> $DIR/issue-109195.rs:12:5 | |||
Contributor
There was a problem hiding this comment.
Want to give this test a better name as a drive-by improvement?
Contributor
|
@bors delegate+ |
Collaborator
|
✌️ @zachs18, you can now approve this pull request! If @compiler-errors told you to " |
Contributor
Author
Collaborator
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Jan 24, 2025
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#133605 (Add extensive set of drop order tests) - rust-lang#135489 (remove pointless allowed_through_unstable_modules on TryFromSliceError) - rust-lang#135757 (Add NuttX support for AArch64 and ARMv7-A targets) - rust-lang#135799 (rustdoc-json: Rename `Path::name` to `path`, and give it the path again.) - rust-lang#135865 (For E0223, suggest associated functions that are similar to the path, even if the base type has multiple inherent impl blocks.) - rust-lang#135890 (Implement `VecDeque::pop_front_if` & `VecDeque::pop_back_if`) - rust-lang#135914 (Remove usages of `QueryNormalizer` in the compiler) - rust-lang#135936 (fix reify-intrinsic test) r? `@ghost` `@rustbot` modify labels: rollup
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Jan 24, 2025
Rollup merge of rust-lang#135865 - zachs18:maybe_report_similar_assoc_fn_more, r=compiler-errors For E0223, suggest associated functions that are similar to the path, even if the base type has multiple inherent impl blocks. Currently, the "help: there is an associated function with a similar name `from_utf8`" suggestion for `String::from::utf8` is only given if `String` has exactly one inherent `impl` item. This PR makes the suggestion be emitted even if the base type has multiple inherent `impl` items. Example: ```rust struct Foo; impl Foo { fn bar_baz() {} } impl Foo {} // load-bearing fn main() { Foo::bar::baz; } ``` Nightly/stable output: ```rust error[E0223]: ambiguous associated type --> f.rs:7:5 | 7 | Foo::bar::baz; | ^^^^^^^^ | help: if there were a trait named `Example` with associated type `bar` implemented for `Foo`, you could use the fully-qualified path | 7 | <Foo as Example>::bar::baz; | ~~~~~~~~~~~~~~~~~~~~~ error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0223`. ``` Output with this PR, or without the load-bearing empty impl on nightly/stable: ```rust error[E0223]: ambiguous associated type --> f.rs:7:5 | 7 | Foo::bar::baz; | ^^^^^^^^ | help: there is an associated function with a similar name: `bar_baz` | 7 | Foo::bar_baz; | ~~~~~~~ error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0223`. ``` Ideally, this suggestion would also work for non-ADT types like ~~`str::char::indices`~~ (edit: latest commit makes this work with primitives) or `<dyn Any>::downcast::mut_unchecked`, but that seemed to be a harder change. `@rustbot` label +A-diagnostics
github-actions bot
pushed a commit
to tautschnig/verify-rust-std
that referenced
this pull request
Mar 11, 2025
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#133605 (Add extensive set of drop order tests) - rust-lang#135489 (remove pointless allowed_through_unstable_modules on TryFromSliceError) - rust-lang#135757 (Add NuttX support for AArch64 and ARMv7-A targets) - rust-lang#135799 (rustdoc-json: Rename `Path::name` to `path`, and give it the path again.) - rust-lang#135865 (For E0223, suggest associated functions that are similar to the path, even if the base type has multiple inherent impl blocks.) - rust-lang#135890 (Implement `VecDeque::pop_front_if` & `VecDeque::pop_back_if`) - rust-lang#135914 (Remove usages of `QueryNormalizer` in the compiler) - rust-lang#135936 (fix reify-intrinsic test) r? `@ghost` `@rustbot` modify labels: rollup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently, the "help: there is an associated function with a similar name
from_utf8" suggestion forString::from::utf8is only given ifStringhas exactly one inherentimplitem. This PR makes the suggestion be emitted even if the base type has multiple inherentimplitems.Example:
Nightly/stable output:
Output with this PR, or without the load-bearing empty impl on nightly/stable:
Ideally, this suggestion would also work for non-ADT types like
(edit: latest commit makes this work with primitives) orstr::char::indices<dyn Any>::downcast::mut_unchecked, but that seemed to be a harder change.@rustbot label +A-diagnostics