Skip to content

Unusable path suggestion for item nested in function #146786

Description

@notriddle

Code

fnmain(){structError;// name must be non-unique in projectconstERROR = Error;}

Current output

error: missing typefor`const` item
--> test.rs:3:16
|
3 | const ERROR = Error;| ^ help: provide a typefor the constant: `: main::Error`
error: aborting due to 1 previous error

Desired output

error: missing typefor`const` item
--> test.rs:3:16
|
3 | const ERROR = Error;| ^ help: provide a typefor the constant: `: Error`
error: aborting due to 1 previous error

Rationale and extra context

If the suggestion is applied, it doesn't work, because main::Error isn't a real path.

error[E0433]: failed to resolve: function `main` is not a crate or module
--> test.rs:3:18
|
3 | const ERROR: main::Error = Error;
| ^^^^ function `main` is not a crate or module
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0433`.

Other cases

I figured out how to reproduce this problem with plain rustc while investigating rust-lang/rust-clippy#15221

Rust Version

rustc 1.89.0-nightly (be19eda0d 2025-06-22)
binary: rustc
commit-hash: be19eda0dc4c22c5cf5f1b48fd163acf9bd4b0a6
commit-date: 2025-06-22
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.7

Anything else?

Since this error and rust-lang/rust-clippy#15221 both produce similar problems, it seems like this should be fixed in the path-printer, not just the individual diagnostic found here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-diagnostic-infraDiagnostics: Issues that affect all diagnostics, or relate to the diagnostic machinery itself.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions