Skip to content

Diagnostic suggests adding type [type error] #79040

Closed
@camelid

Description

@camelid

I think the suggestion is trying to suggest a type, but gets a TyKind::Error due to the type error in the body of the const. Ideally we would just not suggest a type, but there are probably a lot of other places that this issue occurs.

const FOO = "hello" + 1;

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error[E0369]: cannot add `{integer}` to `&str`
 --> src/lib.rs:1:21
  |
1 | const FOO = "hello" + 1;
  |             ------- ^ - {integer}
  |             |
  |             &str

error: missing type for `const` item
 --> src/lib.rs:1:7
  |
1 | const FOO = "hello" + 1;
  |       ^^^ help: provide a type for the item: `FOO: [type error]`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0369`.
error: could not compile `playground`.

To learn more, run the command again with --verbose.

Metadata

Metadata

Labels

A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.D-papercutDiagnostics: An error or lint that needs small tweaks.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.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