Skip to content
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

resolve: improve diagnostics for a single super at the crate root #39401

Open
jseyfried opened this issue Jan 30, 2017 · 4 comments
Open

resolve: improve diagnostics for a single super at the crate root #39401

jseyfried opened this issue Jan 30, 2017 · 4 comments
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name/path resolution done by `rustc_resolve` specifically C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jseyfried
Copy link
Contributor

jseyfried commented Jan 30, 2017

For example,

fn main() {
    let super = 0;
    //  ^^^^^ Ideally, the error here would be something like:
    // - "the root module has not parent"
    // - "`super` is not allowed in the crate root"
}
@jseyfried jseyfried added A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name/path resolution done by `rustc_resolve` specifically labels Jan 30, 2017
@jseyfried jseyfried self-assigned this Jan 30, 2017
@jseyfried
Copy link
Contributor Author

cc @petrochenkov

@petrochenkov petrochenkov self-assigned this Feb 19, 2017
@steveklabnik steveklabnik added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 9, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 26, 2017
@BGR360
Copy link
Contributor

BGR360 commented Dec 29, 2021

For reference, this is the message currently produced:

error[E0433]: failed to resolve: there are too many leading `super` keywords
 --> src/main.rs:2:9
  |
2 |     let super = 0;
  |         ^^^^^ there are too many leading `super` keywords

Ideally, the error here would be something like:

  • "the root module has not parent"
  • "super is not allowed in the crate root"

I'm not a Rust expert, but why should the error message say anything remotely related to path resolution? Is it valid to have a path after let? Here's what I would expect the message to be:

error: expected identifier, found keyword `super`
 --> src/main.rs:2:9
  |
2 |     let super = 0;
  |         ^^^^^ expected identifier, found keyword
  |
help: you can escape reserved keywords to use them as identifiers
  |
2 |     let r#super = 0;
  |         ~~~~~~~

@MolotovCherry
Copy link

MolotovCherry commented Sep 14, 2023

Turns out that super is not a valid raw identifier either (along with a small few others), so the help suggestion (if any) would need to say to rename it.

@kadiwa4
Copy link
Contributor

kadiwa4 commented Jan 10, 2024

@BGR360

I'm not a Rust expert, but why should the error message say anything remotely related to path resolution?

You can use patterns on the left side of let statements.

let bar = core::num::Wrapping(3);
let core::num::Wrapping(foo) = bar;

That pattern is also allowed to consist of a single constant, therefore Rust has to check if the thing on the left-hand side is a path.

const MY_CONST: () = ();
// does not define any new variables:
let MY_CONST = ();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name/path resolution done by `rustc_resolve` specifically C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants