Skip to content

Commit ecab78c

Browse files
committed
Taint obligations in confirmation
1 parent 3dcdbcd commit ecab78c

21 files changed

+115
-211
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
634634
};
635635
let is_method = mode == Mode::MethodCall;
636636
let unsatisfied_predicates = &no_match_data.unsatisfied_predicates;
637+
if let Err(guar) = unsatisfied_predicates.error_reported() {
638+
return guar;
639+
}
640+
637641
let similar_candidate = no_match_data.similar_candidate;
638642
let item_kind = if is_method {
639643
"method"

compiler/rustc_middle/src/ty/generic_args.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc_hir::def_id::DefId;
1515
use rustc_macros::extension;
1616
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
1717
use rustc_serialize::{Decodable, Encodable};
18+
use rustc_span::ErrorGuaranteed;
1819
use rustc_type_ir::WithCachedTypeInfo;
1920
use smallvec::SmallVec;
2021

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

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

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2755,6 +2755,18 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
27552755
// `$1: Copy`, so we must ensure the obligations are emitted in
27562756
// that order.
27572757
let predicates = tcx.predicates_of(def_id);
2758+
if let Err(guar) = predicates.errored_due_to_unconstrained_params {
2759+
self.infcx.set_tainted_by_errors(guar);
2760+
// Constrain any inference variables to their error variant to ensure unconstrained
2761+
// generic parameters don't leak as they'll never get constrained.
2762+
for arg in args {
2763+
let _ = self.infcx.at(cause, param_env).eq(
2764+
DefineOpaqueTypes::Yes,
2765+
arg,
2766+
arg.to_error(tcx, guar),
2767+
);
2768+
}
2769+
}
27582770
assert_eq!(predicates.parent, None);
27592771
let predicates = predicates.instantiate_own(tcx, args);
27602772
let mut obligations = Vec::with_capacity(predicates.len());

tests/crashes/123141.rs

Lines changed: 0 additions & 23 deletions
This file was deleted.

tests/crashes/125874.rs

Lines changed: 0 additions & 22 deletions
This file was deleted.

tests/crashes/126942.rs

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
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() {}
Lines changed: 9 additions & 0 deletions
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`.

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

Lines changed: 1 addition & 67 deletions
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

Lines changed: 1 addition & 1 deletion
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() {}

0 commit comments

Comments
 (0)