Skip to content

Commit a1ad9fd

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

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
@@ -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/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)