-
Notifications
You must be signed in to change notification settings - Fork 13.3k
For E0223, suggest associated functions that are similar to the path, even if the base type has multiple inherent impl blocks. #135865
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
For E0223, suggest associated functions that are similar to the path, even if the base type has multiple inherent impl blocks. #135865
Conversation
rustbot has assigned @compiler-errors. Use |
HIR ty lowering was modified cc @fmease |
(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
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.
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 |
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.
Want to give this test a better name as a drive-by improvement?
@bors delegate+ |
✌️ @zachs18, you can now approve this pull request! If @compiler-errors told you to " |
…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
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
…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
Currently, the "help: there is an associated function with a similar name
from_utf8
" suggestion forString::from::utf8
is only given ifString
has exactly one inherentimpl
item. This PR makes the suggestion be emitted even if the base type has multiple inherentimpl
items.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