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 5 commits 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.

@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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed the output to be

error[E0433]: cannot find macro `bar` in enum `Foo`
  --> $DIR/extern-macro.rs:5:13
   |
LL |     let _ = Foo::bar!();
   |             ^^^^^^^^ a macro can't exist within an enum

Not perfect, but I feel it's more informative than we used to be.

@@ -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

This comment has been minimized.

@petrochenkov petrochenkov removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 15, 2025
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 298dec7 to 0b0bd12 Compare August 15, 2025 19:20
@estebank estebank force-pushed the resolve-error-wording-2 branch from 0b0bd12 to f6ce33d Compare August 15, 2025 19:28
Comment on lines +1 to +5
error[E0433]: cannot find derive macro `Anything` in trait `Foo`
--> $DIR/issue-46101.rs:2:10
|
LL | #[derive(Foo::Anything)]
| ^^^^^^^^^^^^^ partially resolved path in a derive macro
| ^^^^^^^^^^^^^ a derive macro can't exist within a trait
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me know if there's a wording you'd prefer for the label. I want to communicate the impossibility of the macro being in ADTs and traits in the first place.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-miri failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
tests/fail/tree_borrows/reserved/int-protected-write.rs ... ok
tests/fail/weak_memory/weak_uninit.rs ... ok

FAILED TEST: tests/fail/rustc-error2.rs
command: MIRI_ENV_VAR_TEST="0" MIRI_TEMP="/tmp/miri-uitest-VoPGws" RUST_BACKTRACE="1" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/miri" "--error-format=json" "--sysroot=/checkout/obj/build/x86_64-unknown-linux-gnu/miri-sysroot" "-Dwarnings" "-Dunused" "-Ainternal_features" "-Zui-testing" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/tmp/miri_ui/0/tests/fail" "tests/fail/rustc-error2.rs" "--edition" "2021"

error: actual output differed from expected
Execute `./miri test --bless` to update `tests/fail/rustc-error2.stderr` to the actual output
--- tests/fail/rustc-error2.stderr
+++ <stderr output>
---
Location:
   /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ui_test-0.30.2/src/lib.rs:365

  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   1: <color_eyre[5a00b443e1703d9a]::config::EyreHook>::into_eyre_hook::{closure#0}<unknown>
      at <unknown source file>:<unknown line>
   2: eyre[d9b0c1a323608d26]::private::format_err<unknown>
      at <unknown source file>:<unknown line>
   3: ui_test[ff0811f2fc4ba226]::run_tests_generic::<ui_test[ff0811f2fc4ba226]::default_file_filter, ui[ec7046a92c176db1]::run_tests::{closure#1}, alloc[3d295bdc4298664f]::boxed::Box<dyn ui_test[ff0811f2fc4ba226]::status_emitter::StatusEmitter>><unknown>
      at <unknown source file>:<unknown line>
   4: ui[ec7046a92c176db1]::ui<unknown>
      at <unknown source file>:<unknown line>
   5: ui[ec7046a92c176db1]::main<unknown>
      at <unknown source file>:<unknown line>
   6: std[b7b9f6e5c8de3bba]::sys::backtrace::__rust_begin_short_backtrace::<fn() -> core[69aab6a1f1fdf15a]::result::Result<(), eyre[d9b0c1a323608d26]::Report>, core[69aab6a1f1fdf15a]::result::Result<(), eyre[d9b0c1a323608d26]::Report>><unknown>
      at <unknown source file>:<unknown line>
   7: std[b7b9f6e5c8de3bba]::rt::lang_start::<core[69aab6a1f1fdf15a]::result::Result<(), eyre[d9b0c1a323608d26]::Report>>::{closure#0}<unknown>
      at <unknown source file>:<unknown line>
   8: std[b7b9f6e5c8de3bba]::rt::lang_start_internal<unknown>
      at <unknown source file>:<unknown line>
   9: main<unknown>
      at <unknown source file>:<unknown line>
  10: __libc_start_main<unknown>
      at <unknown source file>:<unknown line>
  11: _start<unknown>
      at <unknown source file>:<unknown line>

Run with COLORBT_SHOW_HIDDEN=1 environment variable to disable frame filtering.
Run with RUST_BACKTRACE=full to include source snippets.
error: test failed, to rerun pass `--test ui`

Caused by:
  process didn't exit successfully: `/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/ui-de637b1a885c82e4` (exit status: 1)
Command `/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo test --target x86_64-unknown-linux-gnu -Zbinary-dep-depinfo -j 4 -Zroot-dir=/checkout --locked --color always --release --manifest-path /checkout/src/tools/miri/Cargo.toml -- [workdir=/checkout]` failed with exit code 1
Created at: src/bootstrap/src/core/builder/cargo.rs:423:33
Executed at: src/bootstrap/src/core/build_steps/test.rs:644:19

Command has failed. Rerun with -v to see more details.
Build completed unsuccessfully in 0:39:59
  local time: Sat Aug 16 20:02:28 UTC 2025
  network time: Sat, 16 Aug 2025 20:02:28 GMT
##[error]Process completed with exit code 1.
Post job cleanup.

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