Skip to content

Unify wording of resolve error #145399

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

estebank
Copy link
Contributor

@estebank estebank commented Aug 14, 2025

Remove "failed to resolve" from the main error message and use the same format we use in other resolution errors "cannot find name":

error[E0433]: cannot find `nonexistent` in `existent`
  --> $DIR/custom_attr_multisegment_error.rs:5:13
   |
LL | #[existent::nonexistent]
   |             ^^^^^^^^^^^ could not find `nonexistent` in `existent`

The intent behind this is to end up with all resolve errors eventually be on the form of

error[ECODE]: cannot find `{NAME}` in {SCOPE}
  --> $DIR/file.rs:5:13
   |
LL | #[existent::nonexistent]
   |             ^^^^^^^^^^^ {SPECIFIC LABEL}

A category of errors that is interest are those that involve keywords. For example:

error[E0433]: cannot find `Self` in this scope
  --> $DIR/issue-97194.rs:2:35
   |
LL |     fn bget(&self, index: [usize; Self::DIM]) -> bool {
   |                                   ^^^^ `Self` is only available in impls, traits, and type definitions

and

error[E0433]: cannot find `super` in this scope
  --> $DIR/keyword-super.rs:2:9
   |
LL |     let super: isize;
   |         ^^^^^ there are too many leading `super` keywords

For these the label provides the actual help, while the message is less informative beyond telling you "couldn't find name".

This is an off-shoot of #126810 and #128086, a subset of the intended changes there with review comments applied.

r? @petrochenkov

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Aug 14, 2025
@rustbot
Copy link
Collaborator

rustbot commented Aug 14, 2025

This PR modifies tests/ui/issues/. If this PR is adding new tests to tests/ui/issues/,
please refrain from doing so, and instead add it to more descriptive subdirectories.

@rust-log-analyzer

This comment has been minimized.

Remove "failed to resolve" and use the same format we use in other resolution errors "cannot find `name`".

```
error[E0433]: cannot find `nonexistent` in `existent`
  --> $DIR/custom_attr_multisegment_error.rs:5:13
   |
LL | #[existent::nonexistent]
   |             ^^^^^^^^^^^ could not find `nonexistent` in `existent`
```
@estebank estebank force-pushed the resolve-error-wording-2 branch from fd49d2a to 298dec7 Compare August 14, 2025 16:32
@@ -1,4 +1,4 @@
error[E0433]: failed to resolve: partially resolved path in a macro
error[E0433]: cannot find `bar` in `Foo`
--> $DIR/extern-macro.rs:5:13
|
LL | let _ = Foo::bar!();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a diagnostic that needs improvement regardless: we need to explain that Foo is a type and that macros can't be in them. It would be particularly bad if Foo had an associated item bar as well.

@@ -41,7 +41,7 @@ LL - bar: st::cell::Cell<bool>
LL + bar: cell::Cell<bool>
|

error[E0433]: failed to resolve: function `bar` is not a crate or module
error[E0433]: cannot find `bar` in this scope
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I found I'd opened a separate PR already with some of these changes, and you had a comment about this change in particular

#128086 (comment)

I agree that this isn't an improvement, but the primary label does still mention the intended issue. I'll see over the weekend what I can do about this.

@estebank estebank added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Aug 14, 2025
@rust-log-analyzer
Copy link
Collaborator

The job aarch64-gnu-llvm-19-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
- error[E0433]: failed to resolve: could not find `bar` in the list of imported crates
+ error[E0433]: cannot find `bar` in the crate root
2   --> $DIR/visibility-indeterminate.rs:5:10
3    |
4 LL | pub(in ::bar) struct Baz {}


The actual stderr differed from the expected stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args resolve/visibility-indeterminate.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/resolve/visibility-indeterminate.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/resolve/visibility-indeterminate" "-A" "unused" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "--edition=2018"
stdout: none
--- stderr -------------------------------
error[E0433]: cannot find `bar` in the crate root
##[error]  --> /checkout/tests/ui/resolve/visibility-indeterminate.rs:5:10
   |
LL | pub(in ::bar) struct Baz {} //~ ERROR failed to resolve: could not find `bar` in the list of imported crates
   |          ^^^ could not find `bar` in the list of imported crates

error: cannot find macro `foo` in this scope
##[error]  --> /checkout/tests/ui/resolve/visibility-indeterminate.rs:3:1
   |
LL | foo!(); //~ ERROR cannot find macro `foo` in this scope
   | ^^^

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0433`.

@@ -7,6 +7,6 @@ macro_rules! cbor_map {
fn main() {
cbor_map! { #[test(test)] 4};
//~^ ERROR removing an expression is not supported in this position
//~| ERROR attribute must be of the form `#[test]`
//~| ERROR attribute must be of the form
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary change.

}
}
_ => format!("this scope"),
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is evaluated on a good path, and very often, but we don't actually need the result unless PathResult::failed is called with finalize == true.

PathResult::failed already takes a closure that is only evaluated when necessary, this logic can also be called from that closure.

@petrochenkov petrochenkov removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants