Skip to content

Commit 5960bc6

Browse files
committed
Taint infcx when reporting errors
1 parent a183989 commit 5960bc6

35 files changed

+468
-157
lines changed

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

+8-15
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
179179
for (error, suppressed) in iter::zip(&errors, &is_suppressed) {
180180
if !suppressed && error.obligation.cause.span.from_expansion() == from_expansion {
181181
let guar = self.report_fulfillment_error(error);
182+
self.infcx.set_tainted_by_errors(guar);
182183
reported = Some(guar);
183184
// We want to ignore desugarings here: spans are equivalent even
184185
// if one is the result of a desugaring and the other is not.
@@ -2686,22 +2687,14 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
26862687
}
26872688
}
26882689

2689-
// Given some `ConstArgHasType(?x, usize)`, we should not emit an error such as
2690-
// "type annotations needed: cannot satisfy the constant `_` has type `usize`"
2691-
// Instead we should emit a normal error suggesting the user to turbofish the
2692-
// const parameter that is currently being inferred. Unfortunately we cannot
2693-
// nicely emit such an error so we delay an ICE incase nobody else reports it
2694-
// for us.
2695-
ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, ty)) => {
2696-
return self.tcx.sess.dcx().span_delayed_bug(
2690+
ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, ..)) => self
2691+
.emit_inference_failure_err(
2692+
obligation.cause.body_id,
26972693
span,
2698-
format!(
2699-
"`ambiguous ConstArgHasType({:?}, {:?}) unaccompanied by inference error`",
2700-
ct, ty
2701-
),
2702-
);
2703-
}
2704-
2694+
ct.into(),
2695+
ErrorCode::E0284,
2696+
true,
2697+
),
27052698
ty::PredicateKind::NormalizesTo(ty::NormalizesTo { alias, term })
27062699
if term.is_infer() =>
27072700
{

tests/crashes/122044.rs

-38
This file was deleted.

tests/crashes/123255.rs

-13
This file was deleted.

tests/ui/const-generics/defaults/doesnt_infer.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ fn main() {
1212
let foo = Foo::<1>::foo();
1313
let foo = Foo::foo();
1414
//~^ ERROR type annotations needed for `Foo<_>`
15+
//~| ERROR type annotations needed
1516
}
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,37 @@
1-
error[E0282]: type annotations needed for `Foo<_>`
1+
error[E0284]: type annotations needed for `Foo<_>`
22
--> $DIR/doesnt_infer.rs:13:9
33
|
44
LL | let foo = Foo::foo();
5-
| ^^^
5+
| ^^^ ---------- type must be known at this point
66
|
7+
note: required by a bound in `Foo::<N>::foo`
8+
--> $DIR/doesnt_infer.rs:5:6
9+
|
10+
LL | impl<const N: u32> Foo<N> {
11+
| ^^^^^^^^^^^^ required by this bound in `Foo::<N>::foo`
12+
LL | fn foo() -> Self {
13+
| --- required by a bound in this associated function
14+
help: consider giving `foo` an explicit type, where the value of const parameter `N` is specified
15+
|
16+
LL | let foo: Foo<N> = Foo::foo();
17+
| ++++++++
18+
19+
error[E0284]: type annotations needed for `Foo<_>`
20+
--> $DIR/doesnt_infer.rs:13:9
21+
|
22+
LL | let foo = Foo::foo();
23+
| ^^^ --- type must be known at this point
24+
|
25+
note: required by a bound in `Foo`
26+
--> $DIR/doesnt_infer.rs:3:12
27+
|
28+
LL | struct Foo<const N: u32 = 2>;
29+
| ^^^^^^^^^^^^^^^^ required by this bound in `Foo`
730
help: consider giving `foo` an explicit type, where the value of const parameter `N` is specified
831
|
932
LL | let foo: Foo<N> = Foo::foo();
1033
| ++++++++
1134

12-
error: aborting due to 1 previous error
35+
error: aborting due to 2 previous errors
1336

14-
For more information about this error, try `rustc --explain E0282`.
37+
For more information about this error, try `rustc --explain E0284`.

tests/ui/const-generics/defaults/rp_impl_trait_fail.stderr

+7-2
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,23 @@ LL | 1_u64
3131
|
3232
= help: the trait `Traitor<1, 2>` is implemented for `u64`
3333

34-
error[E0282]: type annotations needed
34+
error[E0284]: type annotations needed
3535
--> $DIR/rp_impl_trait_fail.rs:28:5
3636
|
3737
LL | uwu();
3838
| ^^^ cannot infer the value of the const parameter `N` declared on the function `uwu`
3939
|
40+
note: required by a bound in `uwu`
41+
--> $DIR/rp_impl_trait_fail.rs:16:8
42+
|
43+
LL | fn uwu<const N: u8>() -> impl Traitor<N> {
44+
| ^^^^^^^^^^^ required by this bound in `uwu`
4045
help: consider specifying the generic argument
4146
|
4247
LL | uwu::<N>();
4348
| +++++
4449

4550
error: aborting due to 4 previous errors
4651

47-
Some errors have detailed explanations: E0277, E0282.
52+
Some errors have detailed explanations: E0277, E0284.
4853
For more information about an error, try `rustc --explain E0277`.

tests/ui/const-generics/generic_arg_infer/issue-91614.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ use std::simd::Mask;
55
fn main() {
66
let y = Mask::<_, _>::splat(false);
77
//~^ ERROR: type annotations needed
8+
//~| ERROR type annotations needed
89
}
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
1-
error[E0283]: type annotations needed for `Mask<_, _>`
1+
error[E0284]: type annotations needed for `Mask<_, _>`
22
--> $DIR/issue-91614.rs:6:9
33
|
44
LL | let y = Mask::<_, _>::splat(false);
55
| ^ -------------------------- type must be known at this point
66
|
7-
= note: cannot satisfy `_: MaskElement`
8-
= help: the following types implement trait `MaskElement`:
9-
i16
10-
i32
11-
i64
12-
i8
13-
isize
147
note: required by a bound in `Mask::<T, N>::splat`
158
--> $SRC_DIR/core/src/../../portable-simd/crates/core_simd/src/masks.rs:LL:COL
16-
help: consider giving `y` an explicit type, where the type for type parameter `T` is specified
9+
help: consider giving `y` an explicit type, where the value of const parameter `N` is specified
1710
|
1811
LL | let y: Mask<T, N> = Mask::<_, _>::splat(false);
1912
| ++++++++++++
2013

21-
error: aborting due to 1 previous error
14+
error[E0284]: type annotations needed for `Mask<_, _>`
15+
--> $DIR/issue-91614.rs:6:9
16+
|
17+
LL | let y = Mask::<_, _>::splat(false);
18+
| ^ ------------ type must be known at this point
19+
|
20+
note: required by a bound in `Mask`
21+
--> $SRC_DIR/core/src/../../portable-simd/crates/core_simd/src/masks.rs:LL:COL
22+
help: consider giving `y` an explicit type, where the value of const parameter `N` is specified
23+
|
24+
LL | let y: Mask<T, N> = Mask::<_, _>::splat(false);
25+
| ++++++++++++
26+
27+
error: aborting due to 2 previous errors
2228

23-
For more information about this error, try `rustc --explain E0283`.
29+
For more information about this error, try `rustc --explain E0284`.

tests/ui/const-generics/generic_const_exprs/issue-62504.full.stderr

+28-5
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,41 @@ help: try adding a `where` bound
1818
LL | pub const fn new() -> Self where [(); Self::SIZE]: {
1919
| +++++++++++++++++++++++
2020

21-
error[E0282]: type annotations needed for `ArrayHolder<_>`
21+
error[E0284]: type annotations needed for `ArrayHolder<_>`
2222
--> $DIR/issue-62504.rs:26:9
2323
|
2424
LL | let mut array = ArrayHolder::new();
25-
| ^^^^^^^^^
25+
| ^^^^^^^^^ ------------------ type must be known at this point
2626
|
27+
note: required by a bound in `ArrayHolder::<X>::new`
28+
--> $DIR/issue-62504.rs:16:6
29+
|
30+
LL | impl<const X: usize> ArrayHolder<X> {
31+
| ^^^^^^^^^^^^^^ required by this bound in `ArrayHolder::<X>::new`
32+
LL | pub const fn new() -> Self {
33+
| --- required by a bound in this associated function
34+
help: consider giving `array` an explicit type, where the value of const parameter `X` is specified
35+
|
36+
LL | let mut array: ArrayHolder<X> = ArrayHolder::new();
37+
| ++++++++++++++++
38+
39+
error[E0284]: type annotations needed for `ArrayHolder<_>`
40+
--> $DIR/issue-62504.rs:26:9
41+
|
42+
LL | let mut array = ArrayHolder::new();
43+
| ^^^^^^^^^ ----------- type must be known at this point
44+
|
45+
note: required by a bound in `ArrayHolder`
46+
--> $DIR/issue-62504.rs:14:20
47+
|
48+
LL | struct ArrayHolder<const X: usize>([u32; X]);
49+
| ^^^^^^^^^^^^^^ required by this bound in `ArrayHolder`
2750
help: consider giving `array` an explicit type, where the value of const parameter `X` is specified
2851
|
2952
LL | let mut array: ArrayHolder<X> = ArrayHolder::new();
3053
| ++++++++++++++++
3154

32-
error: aborting due to 3 previous errors
55+
error: aborting due to 4 previous errors
3356

34-
Some errors have detailed explanations: E0282, E0308.
35-
For more information about an error, try `rustc --explain E0282`.
57+
Some errors have detailed explanations: E0284, E0308.
58+
For more information about an error, try `rustc --explain E0284`.

tests/ui/const-generics/generic_const_exprs/issue-62504.min.stderr

+28-5
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,41 @@ note: tuple struct defined here
2222
LL | struct ArrayHolder<const X: usize>([u32; X]);
2323
| ^^^^^^^^^^^
2424

25-
error[E0282]: type annotations needed for `ArrayHolder<_>`
25+
error[E0284]: type annotations needed for `ArrayHolder<_>`
2626
--> $DIR/issue-62504.rs:26:9
2727
|
2828
LL | let mut array = ArrayHolder::new();
29-
| ^^^^^^^^^
29+
| ^^^^^^^^^ ------------------ type must be known at this point
3030
|
31+
note: required by a bound in `ArrayHolder::<X>::new`
32+
--> $DIR/issue-62504.rs:16:6
33+
|
34+
LL | impl<const X: usize> ArrayHolder<X> {
35+
| ^^^^^^^^^^^^^^ required by this bound in `ArrayHolder::<X>::new`
36+
LL | pub const fn new() -> Self {
37+
| --- required by a bound in this associated function
38+
help: consider giving `array` an explicit type, where the value of const parameter `X` is specified
39+
|
40+
LL | let mut array: ArrayHolder<X> = ArrayHolder::new();
41+
| ++++++++++++++++
42+
43+
error[E0284]: type annotations needed for `ArrayHolder<_>`
44+
--> $DIR/issue-62504.rs:26:9
45+
|
46+
LL | let mut array = ArrayHolder::new();
47+
| ^^^^^^^^^ ----------- type must be known at this point
48+
|
49+
note: required by a bound in `ArrayHolder`
50+
--> $DIR/issue-62504.rs:14:20
51+
|
52+
LL | struct ArrayHolder<const X: usize>([u32; X]);
53+
| ^^^^^^^^^^^^^^ required by this bound in `ArrayHolder`
3154
help: consider giving `array` an explicit type, where the value of const parameter `X` is specified
3255
|
3356
LL | let mut array: ArrayHolder<X> = ArrayHolder::new();
3457
| ++++++++++++++++
3558

36-
error: aborting due to 3 previous errors
59+
error: aborting due to 4 previous errors
3760

38-
Some errors have detailed explanations: E0282, E0308.
39-
For more information about an error, try `rustc --explain E0282`.
61+
Some errors have detailed explanations: E0284, E0308.
62+
For more information about an error, try `rustc --explain E0284`.

tests/ui/const-generics/generic_const_exprs/issue-62504.rs

+1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ impl<const X: usize> ArrayHolder<X> {
2525
fn main() {
2626
let mut array = ArrayHolder::new();
2727
//~^ ERROR: type annotations needed
28+
//~| ERROR type annotations needed
2829
}

tests/ui/const-generics/generic_const_exprs/object-safety-ok-infer-err.rs

+1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ fn use_dyn<const N: usize>(v: &dyn Foo<N>) where [u8; N + 1]: Sized {
1818
fn main() {
1919
use_dyn(&());
2020
//~^ ERROR type annotations needed
21+
//~| ERROR type annotations needed
2122
}

tests/ui/const-generics/generic_const_exprs/object-safety-ok-infer-err.stderr

+24-3
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,36 @@ LL | use_dyn(&());
55
| ^^^^^^^ cannot infer the value of the const parameter `N` declared on the function `use_dyn`
66
|
77
note: required by a bound in `use_dyn`
8-
--> $DIR/object-safety-ok-infer-err.rs:14:55
8+
--> $DIR/object-safety-ok-infer-err.rs:14:12
99
|
1010
LL | fn use_dyn<const N: usize>(v: &dyn Foo<N>) where [u8; N + 1]: Sized {
11-
| ^^^^^ required by this bound in `use_dyn`
11+
| ^^^^^^^^^^^^^^ required by this bound in `use_dyn`
1212
help: consider specifying the generic argument
1313
|
1414
LL | use_dyn::<N>(&());
1515
| +++++
1616

17-
error: aborting due to 1 previous error
17+
error[E0284]: type annotations needed
18+
--> $DIR/object-safety-ok-infer-err.rs:19:5
19+
|
20+
LL | use_dyn(&());
21+
| ^^^^^^^ --- type must be known at this point
22+
| |
23+
| cannot infer the value of the const parameter `N` declared on the function `use_dyn`
24+
|
25+
note: required for `()` to implement `Foo<_>`
26+
--> $DIR/object-safety-ok-infer-err.rs:8:22
27+
|
28+
LL | impl<const N: usize> Foo<N> for () {
29+
| -------------- ^^^^^^ ^^
30+
| |
31+
| unsatisfied trait bound introduced here
32+
= note: required for the cast from `&()` to `&dyn Foo<_>`
33+
help: consider specifying the generic argument
34+
|
35+
LL | use_dyn::<N>(&());
36+
| +++++
37+
38+
error: aborting due to 2 previous errors
1839

1940
For more information about this error, try `rustc --explain E0284`.
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
error[E0282]: type annotations needed
1+
error[E0284]: type annotations needed
22
--> $DIR/cannot-infer-const-args.rs:6:5
33
|
44
LL | foo();
55
| ^^^ cannot infer the value of the const parameter `X` declared on the function `foo`
66
|
7+
note: required by a bound in `foo`
8+
--> $DIR/cannot-infer-const-args.rs:1:8
9+
|
10+
LL | fn foo<const X: usize>() -> usize {
11+
| ^^^^^^^^^^^^^^ required by this bound in `foo`
712
help: consider specifying the generic argument
813
|
914
LL | foo::<X>();
1015
| +++++
1116

1217
error: aborting due to 1 previous error
1318

14-
For more information about this error, try `rustc --explain E0282`.
19+
For more information about this error, try `rustc --explain E0284`.
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
use std::convert::TryInto;
22

33
fn take_array_from_mut<T, const N: usize>(data: &mut [T], start: usize) -> &mut [T; N] {
4-
(&mut data[start .. start + N]).try_into().unwrap()
4+
(&mut data[start..start + N]).try_into().unwrap()
55
}
66

77
fn main() {
88
let mut arr = [0, 1, 2, 3, 4, 5, 6, 7, 8];
99

10-
for i in 1 .. 4 {
10+
for i in 1..4 {
1111
println!("{:?}", take_array_from_mut(&mut arr, i));
1212
//~^ ERROR type annotations needed
13+
//~| ERROR type annotations needed
1314
}
1415
}

0 commit comments

Comments
 (0)