Skip to content

Commit 12a5681

Browse files
committed
Taint obligations in confirmation
1 parent cd9e1e3 commit 12a5681

24 files changed

+138
-228
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

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

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::{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

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

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

tests/crashes/124350.rs

Lines changed: 0 additions & 17 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`.
Lines changed: 14 additions & 0 deletions
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+
}

0 commit comments

Comments
 (0)