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

Fix diagnostic suggests adding type [type error] #82720

Merged
merged 2 commits into from
Mar 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions compiler/rustc_typeck/src/collect/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,18 +659,20 @@ fn infer_placeholder_type(
format!("{}: {}", item_ident, ty),
Applicability::MachineApplicable,
)
.emit();
.emit_unless(ty.references_error());
}
None => {
let mut diag = bad_placeholder_type(tcx, vec![span]);
if !matches!(ty.kind(), ty::Error(_)) {

if !ty.references_error() {
diag.span_suggestion(
span,
"replace `_` with the correct type",
ty.to_string(),
Applicability::MaybeIncorrect,
);
}

diag.emit();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ fn main() {}

const A: u8; //~ ERROR free constant item without body
const B; //~ ERROR free constant item without body
henryboisdequin marked this conversation as resolved.
Show resolved Hide resolved
//~^ ERROR missing type for `const` item
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,5 @@ LL | const B;
| |
| help: provide a definition for the constant: `= <expr>;`

error: missing type for `const` item
--> $DIR/item-free-const-no-body-semantic-fail.rs:6:7
|
LL | const B;
| ^ help: provide a type for the item: `B: [type error]`

error: aborting due to 3 previous errors
error: aborting due to 2 previous errors

2 changes: 0 additions & 2 deletions src/test/ui/parser/item-free-static-no-body-semantic-fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ fn main() {}

static A: u8; //~ ERROR free static item without body
static B; //~ ERROR free static item without body
//~^ ERROR missing type for `static` item

static mut C: u8; //~ ERROR free static item without body
static mut D; //~ ERROR free static item without body
oli-obk marked this conversation as resolved.
Show resolved Hide resolved
//~^ ERROR missing type for `static mut` item
18 changes: 3 additions & 15 deletions src/test/ui/parser/item-free-static-no-body-semantic-fail.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,20 @@ LL | static B;
| help: provide a definition for the static: `= <expr>;`

error: free static item without body
--> $DIR/item-free-static-no-body-semantic-fail.rs:9:1
--> $DIR/item-free-static-no-body-semantic-fail.rs:8:1
|
LL | static mut C: u8;
| ^^^^^^^^^^^^^^^^-
| |
| help: provide a definition for the static: `= <expr>;`

error: free static item without body
--> $DIR/item-free-static-no-body-semantic-fail.rs:10:1
--> $DIR/item-free-static-no-body-semantic-fail.rs:9:1
|
LL | static mut D;
| ^^^^^^^^^^^^-
| |
| help: provide a definition for the static: `= <expr>;`

error: missing type for `static` item
--> $DIR/item-free-static-no-body-semantic-fail.rs:6:8
|
LL | static B;
| ^ help: provide a type for the item: `B: [type error]`

error: missing type for `static mut` item
--> $DIR/item-free-static-no-body-semantic-fail.rs:10:12
|
LL | static mut D;
| ^ help: provide a type for the item: `D: [type error]`

error: aborting due to 6 previous errors
error: aborting due to 4 previous errors

5 changes: 5 additions & 0 deletions src/test/ui/typeck/issue-79040.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fn main() {
const FOO = "hello" + 1; //~ ERROR cannot add `{integer}` to `&str`
//~^ ERROR cannot add `{integer}` to `&str`
println!("{}", FOO);
}
19 changes: 19 additions & 0 deletions src/test/ui/typeck/issue-79040.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0369]: cannot add `{integer}` to `&str`
--> $DIR/issue-79040.rs:2:25
|
LL | const FOO = "hello" + 1;
| ------- ^ - {integer}
| |
| &str

error[E0369]: cannot add `{integer}` to `&str`
--> $DIR/issue-79040.rs:2:25
|
LL | const FOO = "hello" + 1;
| ------- ^ - {integer}
| |
| &str

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0369`.