Skip to content

Commit d9d6921

Browse files
Fix diagnostic suggests adding type [type error]
Fixes #79040 Unresolved questions: Why does this change output the diagnostic twice? Why does the CI fail when the errors are pointed out (UI tests)?
1 parent 1279b3b commit d9d6921

File tree

5 files changed

+27
-21
lines changed

5 files changed

+27
-21
lines changed

compiler/rustc_typeck/src/collect/type_of.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ fn infer_placeholder_type(
659659
format!("{}: {}", item_ident, ty),
660660
Applicability::MachineApplicable,
661661
)
662-
.emit();
662+
.emit_unless(matches!(ty.kind(), ty::Error(_)));
663663
}
664664
None => {
665665
let mut diag = bad_placeholder_type(tcx, vec![span]);

src/test/ui/79040.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn main() {
2+
const FOO = "hello" + 1;
3+
//^~ ERROR cannot add `{integer}` to `&str`
4+
println!("{}", FOO);
5+
}

src/test/ui/79040.stderr

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0369]: cannot add `{integer}` to `&str`
2+
--> $DIR/79040.rs:2:25
3+
|
4+
LL | const FOO = "hello" + 1;
5+
| ------- ^ - {integer}
6+
| |
7+
| &str
8+
9+
error[E0369]: cannot add `{integer}` to `&str`
10+
--> $DIR/79040.rs:2:25
11+
|
12+
LL | const FOO = "hello" + 1;
13+
| ------- ^ - {integer}
14+
| |
15+
| &str
16+
17+
error: aborting due to 2 previous errors
18+
19+
For more information about this error, try `rustc --explain E0369`.

src/test/ui/parser/item-free-const-no-body-semantic-fail.stderr

+1-7
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,5 @@ LL | const B;
1414
| |
1515
| help: provide a definition for the constant: `= <expr>;`
1616

17-
error: missing type for `const` item
18-
--> $DIR/item-free-const-no-body-semantic-fail.rs:6:7
19-
|
20-
LL | const B;
21-
| ^ help: provide a type for the item: `B: [type error]`
22-
23-
error: aborting due to 3 previous errors
17+
error: aborting due to 2 previous errors
2418

src/test/ui/parser/item-free-static-no-body-semantic-fail.stderr

+1-13
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,5 @@ LL | static mut D;
3030
| |
3131
| help: provide a definition for the static: `= <expr>;`
3232

33-
error: missing type for `static` item
34-
--> $DIR/item-free-static-no-body-semantic-fail.rs:6:8
35-
|
36-
LL | static B;
37-
| ^ help: provide a type for the item: `B: [type error]`
38-
39-
error: missing type for `static mut` item
40-
--> $DIR/item-free-static-no-body-semantic-fail.rs:10:12
41-
|
42-
LL | static mut D;
43-
| ^ help: provide a type for the item: `D: [type error]`
44-
45-
error: aborting due to 6 previous errors
33+
error: aborting due to 4 previous errors
4634

0 commit comments

Comments
 (0)