Skip to content

Commit 5cffc1e

Browse files
committed
Taint obligations in confirmation
1 parent 074fff2 commit 5cffc1e

25 files changed

+97
-212
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 4 additions & 0 deletions
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"

compiler/rustc_middle/src/ty/generic_args.rs

Lines changed: 9 additions & 0 deletions
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> {

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

Lines changed: 12 additions & 0 deletions
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());

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/const-generics/generic_const_exprs/post-analysis-user-facing-param-env.rs

Lines changed: 0 additions & 1 deletion
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
}

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

Lines changed: 2 additions & 17 deletions
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`.

0 commit comments

Comments
 (0)