Skip to content

Commit 4938b6f

Browse files
committed
Taint obligations in confirmation
1 parent 973ce01 commit 4938b6f

24 files changed

+138
-228
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

+4
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
629629
};
630630
let is_method = mode == Mode::MethodCall;
631631
let unsatisfied_predicates = &no_match_data.unsatisfied_predicates;
632+
if let Err(guar) = unsatisfied_predicates.error_reported() {
633+
return guar;
634+
}
635+
632636
let similar_candidate = no_match_data.similar_candidate;
633637
let item_kind = if is_method {
634638
"method"

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::{extension, HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
1515
use rustc_serialize::{Decodable, Encodable};
16+
use rustc_span::ErrorGuaranteed;
1617
use rustc_type_ir::WithCachedTypeInfo;
1718
use smallvec::SmallVec;
1819

@@ -302,6 +303,14 @@ impl<'tcx> GenericArg<'tcx> {
302303
GenericArgKind::Const(ct) => ct.is_ct_infer(),
303304
}
304305
}
306+
307+
pub fn to_error(self, tcx: TyCtxt<'tcx>, guar: ErrorGuaranteed) -> Self {
308+
match self.unpack() {
309+
ty::GenericArgKind::Lifetime(_) => ty::Region::new_error(tcx, guar).into(),
310+
ty::GenericArgKind::Type(_) => Ty::new_error(tcx, guar).into(),
311+
ty::GenericArgKind::Const(_) => ty::Const::new_error(tcx, guar).into(),
312+
}
313+
}
305314
}
306315

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

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

+12
Original file line numberDiff line numberDiff line change
@@ -2766,6 +2766,18 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
27662766
// `$1: Copy`, so we must ensure the obligations are emitted in
27672767
// that order.
27682768
let predicates = tcx.predicates_of(def_id);
2769+
if let Err(guar) = predicates.errored_due_to_unconstrained_params {
2770+
self.infcx.set_tainted_by_errors(guar);
2771+
// Constrain any inference variables to their error variant to ensure unconstrained
2772+
// generic parameters don't leak as they'll never get constrained.
2773+
for arg in args {
2774+
let _ = self.infcx.at(cause, param_env).eq(
2775+
DefineOpaqueTypes::Yes,
2776+
arg,
2777+
arg.to_error(tcx, guar),
2778+
);
2779+
}
2780+
}
27692781
assert_eq!(predicates.parent, None);
27702782
let predicates = predicates.instantiate_own(tcx, args);
27712783
let mut obligations = Vec::with_capacity(predicates.len());

tests/crashes/123141.rs

-23
This file was deleted.

tests/crashes/124350.rs

-17
This file was deleted.

tests/crashes/125874.rs

-22
This file was deleted.

tests/crashes/126942.rs

-11
This file was deleted.
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`.
+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+
}
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`.

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

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ 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 () {
2019
async fn first() {}
20+
//~^ WARN does not match trait method signature
2121
}
2222

2323
fn main() {}

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

+16-6
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,23 @@ 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
7+
warning: impl trait in impl method signature does not match trait method signature
8+
--> $DIR/refine-resolution-errors.rs:19:5
99
|
1010
LL | async fn first() -> <() as Mirror>::Assoc;
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
11+
| ------------------------------------------ return type from trait method defined here
12+
...
13+
LL | async fn first() {}
14+
| ^^^^^^^^^^^^^^^^ this bound is stronger than that defined on the trait
15+
|
16+
= note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate
17+
= note: we are soliciting feedback, see issue #121718 <https://github.com/rust-lang/rust/issues/121718> for more information
18+
= note: `#[warn(refining_impl_trait_reachable)]` on by default
19+
help: replace the return type so that it matches the trait
20+
|
21+
LL | <() as Mirror>::Assoc {}
22+
| ~~~~~~~~~~~~~~~~~~~~~
1223

13-
error: aborting due to 2 previous errors
24+
error: aborting due to 1 previous error; 1 warning emitted
1425

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

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() {}

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

tests/ui/impl-unused-tps.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//~ ERROR overflow evaluating the requirement `([isize; 0], _): Sized
2-
31
trait Foo<A> {
42
fn get(&self, A: &A) { }
53
}
@@ -36,7 +34,7 @@ impl<T,U> Bar for T {
3634
// Using `U` in an associated type within the impl is not good enough!
3735
}
3836

39-
impl<T,U> Bar for T
37+
impl<T,U> Bar for T //~ ERROR conflicting implementations
4038
where T : Bar<Out=U>
4139
{
4240
//~^^^ ERROR the type parameter `U` is not constrained
@@ -49,12 +47,13 @@ impl<T,U,V> Foo<T> for T
4947
{
5048
//~^^^ ERROR the type parameter `U` is not constrained
5149
//~| ERROR the type parameter `V` is not constrained
50+
//~| ERROR conflicting implementations
5251

5352
// Here, `V` is bound by an output type parameter, but the inputs
5453
// are not themselves constrained.
5554
}
5655

57-
impl<T,U,V> Foo<(T,U)> for T
56+
impl<T,U,V> Foo<(T,U)> for T //~ ERROR conflicting implementations
5857
where (T,U): Bar<Out=V>
5958
{
6059
// As above, but both T and U ARE constrained.

0 commit comments

Comments
 (0)