未验证 提交 a5a825e6 编写于 作者: Y Yuki Okushi 提交者: GitHub

Rollup merge of #82720 - henryboisdequin:fix-79040, r=oli-obk

Fix diagnostic suggests adding type `[type error]`

Fixes #79040

### Unresolved questions:

<del>Why does this change output the diagnostic twice (`src/test/ui/79040.rs`)?</del> Thanks `````@oli-obk`````
......@@ -722,11 +722,12 @@ 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",
......@@ -734,6 +735,7 @@ fn infer_placeholder_type(
Applicability::MaybeIncorrect,
);
}
diag.emit();
}
}
......
......@@ -4,4 +4,3 @@ fn main() {}
const A: u8; //~ ERROR free constant item without body
const B; //~ ERROR free constant item without body
//~^ ERROR missing type for `const` item
......@@ -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
......@@ -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
//~^ ERROR missing type for `static mut` item
......@@ -15,7 +15,7 @@ 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;
| ^^^^^^^^^^^^^^^^-
......@@ -23,24 +23,12 @@ 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
fn main() {
const FOO = "hello" + 1; //~ ERROR cannot add `{integer}` to `&str`
//~^ ERROR cannot add `{integer}` to `&str`
println!("{}", FOO);
}
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`.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册