Skip to content

Improve diagnostics for const a: = expr; - #100168

Merged
bors merged 1 commit into
rust-lang:masterfrom
WaffleLapkin:improve_diagnostics_for_missing_type_in_a_const_item
Aug 5, 2022
Merged

Improve diagnostics for const a: = expr;#100168
bors merged 1 commit into
rust-lang:masterfrom
WaffleLapkin:improve_diagnostics_for_missing_type_in_a_const_item

Conversation

@WaffleLapkin

Copy link
Copy Markdown
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

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

@compiler-errorscompiler-errors left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

};
let mut err = self.struct_span_err(id.span, &format!("missing type for `{kind}` item"));

let colon = match colon_present {

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

@bors r+

@bors

bors commented Aug 5, 2022

Copy link
Copy Markdown
Collaborator

📌 Commit 743ad07 has been approved by compiler-errors

It is now in the queue for this repository.

@borsbors 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
|
LL | const A = "A".$fn();
| ^ help: provide a type for the constant: `A: usize`
| ^ help: provide a type for the constant: `: usize`

@klensyklensyAug 5, 2022

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
Contributor

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.

@Dylan-DPCDylan-DPC mentioned this pull request Aug 5, 2022
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:masterAug 5, 2022
@rustbotrustbot added this to the 1.64.0 milestone Aug 5, 2022
@ehussehuss modified the milestones: 1.64.0, 1.65.0Aug 31, 2022
@WaffleLapkin
WaffleLapkin deleted the improve_diagnostics_for_missing_type_in_a_const_item branch February 6, 2025 21:43
@GrigorenkoPV

Copy link
Copy Markdown
Contributor

There's a typo in the issue name of a test, it's #100146, not #100164.

@WaffleLapkin

Copy link
Copy Markdown
MemberAuthor

@GrigorenkoPV would you like to fix that up?.. Also, how did you stumble upon this on a >3 year old PR?

@GrigorenkoPV

GrigorenkoPV commented Dec 8, 2025

Copy link
Copy Markdown
Contributor

@GrigorenkoPV would you like to fix that up?..

Sure, I'll put up a PR.
UPD: done: #149770

Also, how did you stumble upon this on a >3 year old PR?

Had to update the test while working on #149738 and was trying to figure out what it was even supposed to be testing.

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Dec 11, 2025
…eLapkin
Rename some issue-* tests
Also fixes one incorrect issue number: rust-lang#100168 (comment)
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 11, 2025
…eLapkin
Rename some issue-* tests
Also fixes one incorrect issue number: rust-lang#100168 (comment)
rust-timer added a commit that referenced this pull request Dec 12, 2025
Rollup merge of #149770 - GrigorenkoPV:tests/consts, r=WaffleLapkin
Rename some issue-* tests
Also fixes one incorrect issue number: #100168 (comment)
github-actionsBot pushed a commit to rust-lang/miri that referenced this pull request Dec 13, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant 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

9 participants

@WaffleLapkin@compiler-errors@bors@GrigorenkoPV@chenyukang@klensy@ehuss@rust-highfive@rustbot