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

Improve diagnostics for const a: = expr; #100168

Conversation

WaffleLapkin
Copy link
Member

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

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Aug 5, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 5, 2022
Copy link
Member

@compiler-errors compiler-errors left a 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 {
Copy link
Member

Choose a reason for hiding this comment

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

match bool 💀

@compiler-errors
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Aug 5, 2022

📌 Commit 743ad07 has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 5, 2022
| ^ help: provide a type for the constant: `A: usize`
| ^ help: provide a type for the constant: `: usize`
Copy link
Contributor

@klensy klensy Aug 5, 2022

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.

Copy link
Member

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.

Copy link
Member

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.

bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 5, 2022
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
@bors bors merged commit e7ed844 into rust-lang:master Aug 5, 2022
@rustbot rustbot added this to the 1.64.0 milestone Aug 5, 2022
@ehuss ehuss modified the milestones: 1.64.0, 1.65.0 Aug 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

For const variable declaration, if type is left dangling, also suggest type
8 participants