Skip to content

Commit 3377c2f

Browse files
committed
Taint obligations in confirmation
1 parent 1dd3d2a commit 3377c2f

25 files changed

+97
-212
lines changed

Diff for: compiler/rustc_hir_typeck/src/method/suggest.rs

+4
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
598598
};
599599
let is_method = mode == Mode::MethodCall;
600600
let unsatisfied_predicates = &no_match_data.unsatisfied_predicates;
601+
if let Err(guar) = unsatisfied_predicates.error_reported() {
602+
return guar;
603+
}
604+
601605
let similar_candidate = no_match_data.similar_candidate;
602606
let item_kind = if is_method {
603607
"method"

Diff for: compiler/rustc_middle/src/ty/generic_args.rs

+9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use rustc_errors::{DiagArgValue, IntoDiagArg};
1313
use rustc_hir::def_id::DefId;
1414
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable, extension};
1515
use rustc_serialize::{Decodable, Encodable};
16+
use rustc_span::ErrorGuaranteed;
1617
use rustc_type_ir::WithCachedTypeInfo;
1718
use smallvec::SmallVec;
1819

@@ -300,6 +301,14 @@ impl<'tcx> GenericArg<'tcx> {
300301
GenericArgKind::Const(ct) => ct.is_ct_infer(),
301302
}
302303
}
304+
305+
pub fn to_error(self, tcx: TyCtxt<'tcx>, guar: ErrorGuaranteed) -> Self {
306+
match self.unpack() {
307+
ty::GenericArgKind::Lifetime(_) => ty::Region::new_error(tcx, guar).into(),
308+
ty::GenericArgKind::Type(_) => Ty::new_error(tcx, guar).into(),
309+
ty::GenericArgKind::Const(_) => ty::Const::new_error(tcx, guar).into(),
310+
}
311+
}
303312
}
304313

305314
impl<'a, 'tcx> Lift<TyCtxt<'tcx>> for GenericArg<'a> {

Diff for: compiler/rustc_trait_selection/src/traits/select/mod.rs

+12
Original file line numberDiff line numberDiff line change
@@ -2828,6 +2828,18 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
28282828
// `$1: Copy`, so we must ensure the obligations are emitted in
28292829
// that order.
28302830
let predicates = tcx.predicates_of(def_id);
2831+
if let Err(guar) = predicates.errored_due_to_unconstrained_params {
2832+
self.infcx.set_tainted_by_errors(guar);
2833+
// Constrain any inference variables to their error variant to ensure unconstrained
2834+
// generic parameters don't leak as they'll never get constrained.
2835+
for arg in args {
2836+
let _ = self.infcx.at(cause, param_env).eq(
2837+
DefineOpaqueTypes::Yes,
2838+
arg,
2839+
arg.to_error(tcx, guar),
2840+
);
2841+
}
2842+
}
28312843
assert_eq!(predicates.parent, None);
28322844
let predicates = predicates.instantiate_own(tcx, args);
28332845
let mut obligations = PredicateObligations::with_capacity(predicates.len());

Diff for: tests/crashes/123141.rs

-23
This file was deleted.

Diff for: tests/crashes/125874.rs

-22
This file was deleted.

Diff for: tests/crashes/126942.rs

-11
This file was deleted.

Diff for: tests/ui/associated-item/unconstrained_impl_param.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//! This test used to ICE during the normalization of
2+
//! `I`'s type, because of the mismatch of generic parameters
3+
//! on the impl with the generic parameters the projection can
4+
//! fulfill.
5+
6+
struct Thing;
7+
8+
pub trait Every {
9+
type Assoc;
10+
}
11+
impl<T: ?Sized> Every for Thing {
12+
//~^ ERROR: `T` is not constrained
13+
type Assoc = T;
14+
}
15+
16+
static I: <Thing as Every>::Assoc = 3;
17+
18+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
2+
--> $DIR/unconstrained_impl_param.rs:11:6
3+
|
4+
LL | impl<T: ?Sized> Every for Thing {
5+
| ^ unconstrained type parameter
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0207`.

Diff for: tests/ui/const-generics/generic_const_exprs/post-analysis-user-facing-param-env.rs

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ where
1010
{
1111
fn unimplemented(self, _: &Foo) -> Self::Output {
1212
//~^ ERROR method `unimplemented` is not a member of trait `std::ops::Add`
13-
//~| ERROR type annotations needed
1413
loop {}
1514
}
1615
}

Diff for: tests/ui/const-generics/generic_const_exprs/post-analysis-user-facing-param-env.stderr

+2-17
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ error[E0407]: method `unimplemented` is not a member of trait `std::ops::Add`
33
|
44
LL | / fn unimplemented(self, _: &Foo) -> Self::Output {
55
LL | |
6-
LL | |
76
LL | | loop {}
87
LL | | }
98
| |_____^ not a member of trait `std::ops::Add`
@@ -26,21 +25,7 @@ LL | impl<'a, const NUM: usize> std::ops::Add<&'a Foo> for Foo
2625
= note: expressions using a const parameter must map each value to a distinct output value
2726
= note: proving the result of expressions other than the parameter are unique is not supported
2827

29-
error[E0284]: type annotations needed
30-
--> $DIR/post-analysis-user-facing-param-env.rs:11:40
31-
|
32-
LL | fn unimplemented(self, _: &Foo) -> Self::Output {
33-
| ^^^^^^^^^^^^ cannot infer the value of const parameter `NUM`
34-
|
35-
note: required for `Foo` to implement `Add<&'a Foo>`
36-
--> $DIR/post-analysis-user-facing-param-env.rs:6:28
37-
|
38-
LL | impl<'a, const NUM: usize> std::ops::Add<&'a Foo> for Foo
39-
| ---------------- ^^^^^^^^^^^^^^^^^^^^^^ ^^^
40-
| |
41-
| unsatisfied trait bound introduced here
42-
43-
error: aborting due to 3 previous errors; 1 warning emitted
28+
error: aborting due to 2 previous errors; 1 warning emitted
4429

45-
Some errors have detailed explanations: E0207, E0284, E0407.
30+
Some errors have detailed explanations: E0207, E0407.
4631
For more information about an error, try `rustc --explain E0207`.

Diff for: tests/ui/const-generics/kind_mismatch.rs

+1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ pub fn remove_key<K, S: SubsetExcept<K>>() -> S {
2020

2121
fn main() {
2222
let map: KeyHolder<0> = remove_key::<_, _>();
23+
//~^ ERROR: type annotations needed
2324
}

Diff for: tests/ui/const-generics/kind_mismatch.stderr

+9-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ LL | impl<K> ContainsKey<K> for KeyHolder<K> {}
1414
| |
1515
| help: consider changing this type parameter to a const parameter: `const K: u8`
1616

17-
error: aborting due to 2 previous errors
17+
error[E0282]: type annotations needed
18+
--> $DIR/kind_mismatch.rs:22:29
19+
|
20+
LL | let map: KeyHolder<0> = remove_key::<_, _>();
21+
| ^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `K` declared on the function `remove_key`
22+
23+
error: aborting due to 3 previous errors
1824

19-
For more information about this error, try `rustc --explain E0747`.
25+
Some errors have detailed explanations: E0282, E0747.
26+
For more information about an error, try `rustc --explain E0282`.

Diff for: tests/ui/const-generics/kind_mismatch2.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
struct Node<const D: usize> {}
2+
3+
impl<const D: usize> Node<{ D }>
4+
where
5+
SmallVec<D>:, //~ ERROR: constant provided when a type was expected
6+
{
7+
fn new() {}
8+
}
9+
10+
struct SmallVec<T>(T);
11+
12+
fn main() {
13+
Node::new();
14+
}

Diff for: tests/ui/const-generics/kind_mismatch2.stderr

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0747]: constant provided when a type was expected
2+
--> $DIR/kind_mismatch2.rs:5:14
3+
|
4+
LL | SmallVec<D>:,
5+
| ^
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0747`.

Diff for: tests/ui/generic-associated-types/bugs/issue-87735.stderr

+1-67
Original file line numberDiff line numberDiff line change
@@ -22,73 +22,7 @@ help: consider adding an explicit lifetime bound
2222
LL | type Output<'a> = FooRef<'a, U> where Self: 'a, U: 'a;
2323
| +++++++
2424

25-
error[E0309]: the parameter type `T` may not live long enough
26-
--> $DIR/issue-87735.rs:31:15
27-
|
28-
LL | impl<'b, T, U> AsRef2 for Foo<T>
29-
| -- the parameter type `T` must be valid for the lifetime `'b` as defined here...
30-
...
31-
LL | T: AsRef2<Output<'b> = &'b [U]>,
32-
| ^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds...
33-
|
34-
note: ...that is required by this bound
35-
--> $DIR/issue-87735.rs:7:31
36-
|
37-
LL | type Output<'a> where Self: 'a;
38-
| ^^
39-
help: consider adding an explicit lifetime bound
40-
|
41-
LL | T: AsRef2<Output<'b> = &'b [U]> + 'b,
42-
| ++++
43-
44-
error[E0309]: the parameter type `T` may not live long enough
45-
--> $DIR/issue-87735.rs:36:31
46-
|
47-
LL | impl<'b, T, U> AsRef2 for Foo<T>
48-
| -- the parameter type `T` must be valid for the lifetime `'b` as defined here...
49-
...
50-
LL | fn as_ref2<'a>(&'a self) -> Self::Output<'a> {
51-
| ^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds...
52-
|
53-
note: ...that is required by this bound
54-
--> $DIR/issue-87735.rs:7:31
55-
|
56-
LL | type Output<'a> where Self: 'a;
57-
| ^^
58-
help: consider adding an explicit lifetime bound
59-
|
60-
LL | T: AsRef2<Output<'b> = &'b [U]> + 'b,
61-
| ++++
62-
63-
error: lifetime may not live long enough
64-
--> $DIR/issue-87735.rs:37:5
65-
|
66-
LL | impl<'b, T, U> AsRef2 for Foo<T>
67-
| -- lifetime `'b` defined here
68-
...
69-
LL | fn as_ref2<'a>(&'a self) -> Self::Output<'a> {
70-
| -- lifetime `'a` defined here
71-
LL | FooRef(self.0.as_ref2())
72-
| ^^^^^^^^^^^^^^^^^^^^^^^^ method was supposed to return data with lifetime `'a` but it is returning data with lifetime `'b`
73-
|
74-
= help: consider adding the following bound: `'b: 'a`
75-
76-
error: lifetime may not live long enough
77-
--> $DIR/issue-87735.rs:37:12
78-
|
79-
LL | impl<'b, T, U> AsRef2 for Foo<T>
80-
| -- lifetime `'b` defined here
81-
...
82-
LL | fn as_ref2<'a>(&'a self) -> Self::Output<'a> {
83-
| -- lifetime `'a` defined here
84-
LL | FooRef(self.0.as_ref2())
85-
| ^^^^^^^^^^^^^^^^ argument requires that `'a` must outlive `'b`
86-
|
87-
= help: consider adding the following bound: `'a: 'b`
88-
89-
help: `'b` and `'a` must be the same: replace one with the other
90-
91-
error: aborting due to 6 previous errors
25+
error: aborting due to 2 previous errors
9226

9327
Some errors have detailed explanations: E0207, E0309.
9428
For more information about an error, try `rustc --explain E0207`.

Diff for: tests/ui/impl-trait/in-trait/refine-resolution-errors.rs

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ impl<T: ?Sized> Mirror for () {
1313

1414
pub trait First {
1515
async fn first() -> <() as Mirror>::Assoc;
16-
//~^ ERROR type annotations needed
1716
}
1817

1918
impl First for () {

Diff for: tests/ui/impl-trait/in-trait/refine-resolution-errors.stderr

+2-9
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@ error[E0207]: the type parameter `T` is not constrained by the impl trait, self
44
LL | impl<T: ?Sized> Mirror for () {
55
| ^ unconstrained type parameter
66

7-
error[E0282]: type annotations needed
8-
--> $DIR/refine-resolution-errors.rs:15:5
9-
|
10-
LL | async fn first() -> <() as Mirror>::Assoc;
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
12-
13-
error: aborting due to 2 previous errors
7+
error: aborting due to 1 previous error
148

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

Diff for: tests/ui/impl-trait/issues/issue-87340.rs

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ impl<T> X for () {
99
//~^ ERROR `T` is not constrained by the impl trait, self type, or predicates
1010
type I = impl Sized;
1111
fn f() -> Self::I {}
12-
//~^ ERROR type annotations needed
13-
//~| ERROR type annotations needed
1412
}
1513

1614
fn main() {}

Diff for: tests/ui/impl-trait/issues/issue-87340.stderr

+2-15
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,6 @@ error[E0207]: the type parameter `T` is not constrained by the impl trait, self
44
LL | impl<T> X for () {
55
| ^ unconstrained type parameter
66

7-
error[E0282]: type annotations needed
8-
--> $DIR/issue-87340.rs:11:23
9-
|
10-
LL | fn f() -> Self::I {}
11-
| ^^ cannot infer type for type parameter `T`
12-
13-
error[E0282]: type annotations needed
14-
--> $DIR/issue-87340.rs:11:15
15-
|
16-
LL | fn f() -> Self::I {}
17-
| ^^^^^^^ cannot infer type for type parameter `T`
18-
19-
error: aborting due to 3 previous errors
7+
error: aborting due to 1 previous error
208

21-
Some errors have detailed explanations: E0207, E0282.
22-
For more information about an error, try `rustc --explain E0207`.
9+
For more information about this error, try `rustc --explain E0207`.

Diff for: tests/ui/type-alias-impl-trait/ice-failed-to-resolve-instance-for-110696.rs

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ impl<T: MyFrom<Phantom2<DummyT<U>>>, U> MyIndex<DummyT<T>> for Scope<U> {
4242
//~^ ERROR the type parameter `T` is not constrained by the impl
4343
type O = T;
4444
fn my_index(self) -> Self::O {
45-
//~^ ERROR item does not constrain
4645
MyFrom::my_from(self.0).ok().unwrap()
4746
}
4847
}

Diff for: tests/ui/type-alias-impl-trait/ice-failed-to-resolve-instance-for-110696.stderr

+1-14
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,6 @@ note: this opaque type is in the signature
1717
LL | type DummyT<T> = impl F;
1818
| ^^^^^^
1919

20-
error: item does not constrain `DummyT::{opaque#0}`, but has it in its signature
21-
--> $DIR/ice-failed-to-resolve-instance-for-110696.rs:44:8
22-
|
23-
LL | fn my_index(self) -> Self::O {
24-
| ^^^^^^^^
25-
|
26-
= note: consider moving the opaque type's declaration and defining uses into a separate module
27-
note: this opaque type is in the signature
28-
--> $DIR/ice-failed-to-resolve-instance-for-110696.rs:20:18
29-
|
30-
LL | type DummyT<T> = impl F;
31-
| ^^^^^^
32-
33-
error: aborting due to 3 previous errors
20+
error: aborting due to 2 previous errors
3421

3522
For more information about this error, try `rustc --explain E0207`.

Diff for: tests/ui/type-alias-impl-trait/impl-with-unconstrained-param.rs

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ impl<T> X for () {
1212
//~^ ERROR the type parameter `T` is not constrained
1313
type I = impl Sized;
1414
fn f() -> Self::I {}
15-
//~^ ERROR type annotations needed
16-
//~| ERROR type annotations needed
1715
}
1816

1917
fn main() {}

0 commit comments

Comments
 (0)