Skip to content

Commit 15c74d5

Browse files
committed
Do not skip "type annotation needed"/Sized error
1 parent 660480a commit 15c74d5

File tree

47 files changed

+267
-169
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+267
-169
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,11 +1503,8 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
15031503
// avoid inundating the user with unnecessary errors, but we now
15041504
// check upstream for type errors and don't add the obligations to
15051505
// begin with in those cases.
1506-
if self.tcx.lang_items().sized_trait() == Some(data.trait_ref.def_id) {
1507-
self.emit_inference_failure_err(body_id, span, subst, ErrorCode::E0282, &[])
1508-
.delay_as_bug();
1509-
return;
1510-
}
1506+
let is_sized = self.tcx.lang_items().sized_trait() == Some(data.trait_ref.def_id);
1507+
15111508
// Try to find possible types that would satisfy the bounds in the type param to
15121509
// give an appropriate turbofish suggestion.
15131510
let turbofish_suggestions =
@@ -1516,11 +1513,12 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
15161513
body_id,
15171514
span,
15181515
subst,
1519-
ErrorCode::E0283,
1516+
if is_sized { ErrorCode::E0282 } else { ErrorCode::E0283 },
15201517
&turbofish_suggestions,
15211518
);
1522-
err.note(&format!("cannot satisfy `{}`", predicate));
1523-
1519+
if !is_sized {
1520+
err.note(&format!("cannot satisfy `{}`", predicate));
1521+
}
15241522
if let ObligationCauseCode::ItemObligation(def_id) = obligation.cause.code {
15251523
self.suggest_fully_qualified_path(
15261524
&mut err,
@@ -1600,6 +1598,10 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
16001598
}
16011599
}
16021600
}
1601+
if is_sized {
1602+
err.emit();
1603+
return;
1604+
}
16031605
err
16041606
}
16051607

src/test/ui/async-await/issues/issue-65159.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
async fn copy() -> Result<()> //~ ERROR wrong number of type arguments
66
{
77
Ok(())
8+
//~^ ERROR type annotations needed
89
}
910

1011
fn main() { }

src/test/ui/async-await/issues/issue-65159.stderr

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ error[E0107]: wrong number of type arguments: expected 2, found 1
44
LL | async fn copy() -> Result<()>
55
| ^^^^^^^^^^ expected 2 type arguments
66

7-
error: aborting due to previous error
7+
error[E0282]: type annotations needed
8+
--> $DIR/issue-65159.rs:7:5
9+
|
10+
LL | Ok(())
11+
| ^^ cannot infer type for type parameter `E` declared on the enum `Result`
12+
13+
error: aborting due to 2 previous errors
814

9-
For more information about this error, try `rustc --explain E0107`.
15+
Some errors have detailed explanations: E0107, E0282.
16+
For more information about an error, try `rustc --explain E0107`.

src/test/ui/closures/issue-52437.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
fn main() {
22
[(); &(&'static: loop { |x| {}; }) as *const _ as usize]
33
//~^ ERROR: invalid label name `'static`
4+
//~| ERROR: type annotations needed
45
//~| ERROR mismatched types
56
}

src/test/ui/closures/issue-52437.stderr

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ error: invalid label name `'static`
44
LL | [(); &(&'static: loop { |x| {}; }) as *const _ as usize]
55
| ^^^^^^^
66

7+
error[E0282]: type annotations needed
8+
--> $DIR/issue-52437.rs:2:30
9+
|
10+
LL | [(); &(&'static: loop { |x| {}; }) as *const _ as usize]
11+
| ^ consider giving this closure parameter a type
12+
713
error[E0308]: mismatched types
814
--> $DIR/issue-52437.rs:2:5
915
|
@@ -12,6 +18,7 @@ LL | fn main() {
1218
LL | [(); &(&'static: loop { |x| {}; }) as *const _ as usize]
1319
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found array `[(); _]`
1420

15-
error: aborting due to 2 previous errors
21+
error: aborting due to 3 previous errors
1622

17-
For more information about this error, try `rustc --explain E0308`.
23+
Some errors have detailed explanations: E0282, E0308.
24+
For more information about an error, try `rustc --explain E0282`.

src/test/ui/consts/issue-52432.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
fn main() {
44
[(); &(static |x| {}) as *const _ as usize];
55
//~^ ERROR: closures cannot be static
6+
//~| ERROR: type annotations needed
67
[(); &(static || {}) as *const _ as usize];
78
//~^ ERROR: closures cannot be static
89
//~| ERROR evaluation of constant value failed

src/test/ui/consts/issue-52432.stderr

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,24 @@ LL | [(); &(static |x| {}) as *const _ as usize];
55
| ^^^^^^^^^^
66

77
error[E0697]: closures cannot be static
8-
--> $DIR/issue-52432.rs:6:12
8+
--> $DIR/issue-52432.rs:7:12
99
|
1010
LL | [(); &(static || {}) as *const _ as usize];
1111
| ^^^^^^^^^
1212

13+
error[E0282]: type annotations needed
14+
--> $DIR/issue-52432.rs:4:20
15+
|
16+
LL | [(); &(static |x| {}) as *const _ as usize];
17+
| ^ consider giving this closure parameter a type
18+
1319
error[E0080]: evaluation of constant value failed
14-
--> $DIR/issue-52432.rs:6:10
20+
--> $DIR/issue-52432.rs:7:10
1521
|
1622
LL | [(); &(static || {}) as *const _ as usize];
1723
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "pointer-to-integer cast" needs an rfc before being allowed inside constants
1824

19-
error: aborting due to 3 previous errors
25+
error: aborting due to 4 previous errors
2026

21-
Some errors have detailed explanations: E0080, E0697.
27+
Some errors have detailed explanations: E0080, E0282, E0697.
2228
For more information about an error, try `rustc --explain E0080`.

src/test/ui/consts/issue-64662.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
enum Foo {
22
A = foo(), //~ ERROR: type annotations needed
3-
B = foo(), // We don't emit an error here, but if the one above is fixed, we will.
3+
B = foo(), //~ ERROR: type annotations needed
44
}
55

66
const fn foo<T>() -> isize {

src/test/ui/consts/issue-64662.stderr

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,23 @@ error[E0282]: type annotations needed
33
|
44
LL | A = foo(),
55
| ^^^ cannot infer type for type parameter `T` declared on the function `foo`
6+
|
7+
help: consider specifying the type argument in the function call
8+
|
9+
LL | A = foo::<T>(),
10+
| ^^^^^
11+
12+
error[E0282]: type annotations needed
13+
--> $DIR/issue-64662.rs:3:9
14+
|
15+
LL | B = foo(),
16+
| ^^^ cannot infer type for type parameter `T` declared on the function `foo`
17+
|
18+
help: consider specifying the type argument in the function call
19+
|
20+
LL | B = foo::<T>(),
21+
| ^^^^^
622

7-
error: aborting due to previous error
23+
error: aborting due to 2 previous errors
824

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

src/test/ui/error-codes/E0401.stderr

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,18 @@ LL | fn helper(sel: &Self) -> u8 {
3232
| use of generic parameter from outer function
3333
| use a type here instead
3434

35-
error[E0283]: type annotations needed
35+
error[E0282]: type annotations needed
3636
--> $DIR/E0401.rs:11:5
3737
|
38-
LL | fn bfnr<U, V: Baz<U>, W: Fn()>(y: T) {
39-
| ------ required by this bound in `bfnr`
40-
...
4138
LL | bfnr(x);
42-
| ^^^^ cannot infer type for type parameter `V` declared on the function `bfnr`
39+
| ^^^^ cannot infer type for type parameter `U` declared on the function `bfnr`
4340
|
44-
= note: cannot satisfy `_: Baz<_>`
4541
help: consider specifying the type arguments in the function call
4642
|
4743
LL | bfnr::<U, V, W>(x);
4844
| ^^^^^^^^^^^
4945

5046
error: aborting due to 4 previous errors
5147

52-
Some errors have detailed explanations: E0283, E0401.
53-
For more information about an error, try `rustc --explain E0283`.
48+
Some errors have detailed explanations: E0282, E0401.
49+
For more information about an error, try `rustc --explain E0282`.

0 commit comments

Comments
 (0)