-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Improve diagnostics for const a: = expr;
#100168
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Improve diagnostics for const a: = expr;
#100168
Conversation
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.
Thanks @WaffleLapkin
// Construct the error and stash it away with the hope | ||
// that typeck will later enrich the error with a type. | ||
let kind = match m { | ||
Some(Mutability::Mut) => "static mut", | ||
Some(Mutability::Not) => "static", | ||
None => "const", | ||
}; | ||
let mut err = self.struct_span_err(id.span, &format!("missing type for `{kind}` item")); | ||
|
||
let colon = match colon_present { |
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.
match bool 💀
@bors r+ |
| ^ help: provide a type for the constant: `A: usize` | ||
| ^ help: provide a type for the constant: `: usize` |
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.
Looks kinda off, IMHO: suggestion talks about type but suggest not var+type, not type, but something in between: colon+type.
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.
I think old style is better, and also seems more consistant with other suggestions in rustc.
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.
If anything this could be fixed by bumping to a verbose diagnostic, but I don't think this is necessarily a regression.
Rollup of 6 pull requests Successful merges: - rust-lang#99835 (Suggest adding/removing `ref` for binding patterns) - rust-lang#100155 (Use `node_type_opt` to skip over generics that were not expected) - rust-lang#100157 (rustdoc: use `collect()` instead of repeatedly pushing) - rust-lang#100158 (kmc-solid: Add a stub implementation of rust-lang#98246 (`File::set_times`)) - rust-lang#100166 (Remove more Clean trait implementations) - rust-lang#100168 (Improve diagnostics for `const a: = expr;`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Adds a suggestion to write a type when there is a colon, but the type is not present.
I've also shrunk spans a little, so the suggestions are a little nicer.
Resolves #100146
r? @compiler-errors