Skip to content

Commit a5a825e

Browse files
authored
Rollup merge of rust-lang#82720 - henryboisdequin:fix-79040, r=oli-obk
Fix diagnostic suggests adding type `[type error]` Fixes rust-lang#79040 ### Unresolved questions: <del>Why does this change output the diagnostic twice (`src/test/ui/79040.rs`)?</del> Thanks `````@oli-obk`````
2 parents f3218df + 7d3a6f1 commit a5a825e

7 files changed

+32
-27
lines changed

compiler/rustc_typeck/src/collect/type_of.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -722,18 +722,20 @@ fn infer_placeholder_type(
722722
format!("{}: {}", item_ident, ty),
723723
Applicability::MachineApplicable,
724724
)
725-
.emit();
725+
.emit_unless(ty.references_error());
726726
}
727727
None => {
728728
let mut diag = bad_placeholder_type(tcx, vec![span]);
729-
if !matches!(ty.kind(), ty::Error(_)) {
729+
730+
if !ty.references_error() {
730731
diag.span_suggestion(
731732
span,
732733
"replace `_` with the correct type",
733734
ty.to_string(),
734735
Applicability::MaybeIncorrect,
735736
);
736737
}
738+
737739
diag.emit();
738740
}
739741
}

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

-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ fn main() {}
44

55
const A: u8; //~ ERROR free constant item without body
66
const B; //~ ERROR free constant item without body
7-
//~^ ERROR missing type for `const` item

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.rs

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ fn main() {}
44

55
static A: u8; //~ ERROR free static item without body
66
static B; //~ ERROR free static item without body
7-
//~^ ERROR missing type for `static` item
87

98
static mut C: u8; //~ ERROR free static item without body
109
static mut D; //~ ERROR free static item without body
11-
//~^ ERROR missing type for `static mut` item

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

+3-15
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,20 @@ LL | static B;
1515
| help: provide a definition for the static: `= <expr>;`
1616

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

2525
error: free static item without body
26-
--> $DIR/item-free-static-no-body-semantic-fail.rs:10:1
26+
--> $DIR/item-free-static-no-body-semantic-fail.rs:9:1
2727
|
2828
LL | static mut D;
2929
| ^^^^^^^^^^^^-
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

src/test/ui/typeck/issue-79040.rs

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

src/test/ui/typeck/issue-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/issue-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/issue-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`.

0 commit comments

Comments
 (0)