Skip to content

Commit 6b46613

Browse files
Stop being so bail-y in candidate assembly
1 parent f61306d commit 6b46613

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+381
-252
lines changed

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

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
9191
} else if tcx.is_lang_item(def_id, LangItem::Sized) {
9292
// Sized is never implementable by end-users, it is
9393
// always automatically computed.
94-
95-
// FIXME: Consider moving this check to the top level as it
96-
// may also be useful for predicates other than `Sized`
97-
// Error type cannot possibly implement `Sized` (fixes #123154)
98-
if let Err(e) = obligation.predicate.skip_binder().self_ty().error_reported() {
99-
return Err(SelectionError::Overflow(e.into()));
100-
}
101-
10294
let sized_conditions = self.sized_conditions(obligation);
10395
self.assemble_builtin_bound_candidates(sized_conditions, &mut candidates);
10496
} else if tcx.is_lang_item(def_id, LangItem::Unsize) {
@@ -232,13 +224,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
232224
) -> Result<(), SelectionError<'tcx>> {
233225
debug!(?stack.obligation);
234226

235-
// An error type will unify with anything. So, avoid
236-
// matching an error type with `ParamCandidate`.
237-
// This helps us avoid spurious errors like issue #121941.
238-
if stack.obligation.predicate.references_error() {
239-
return Ok(());
240-
}
241-
242227
let bounds = stack
243228
.obligation
244229
.param_env
@@ -565,19 +550,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
565550
obligation: &PolyTraitObligation<'tcx>,
566551
candidates: &mut SelectionCandidateSet<'tcx>,
567552
) {
568-
// Essentially any user-written impl will match with an error type,
569-
// so creating `ImplCandidates` isn't useful. However, we might
570-
// end up finding a candidate elsewhere (e.g. a `BuiltinCandidate` for `Sized`)
571-
// This helps us avoid overflow: see issue #72839
572-
// Since compilation is already guaranteed to fail, this is just
573-
// to try to show the 'nicest' possible errors to the user.
574-
// We don't check for errors in the `ParamEnv` - in practice,
575-
// it seems to cause us to be overly aggressive in deciding
576-
// to give up searching for candidates, leading to spurious errors.
577-
if obligation.predicate.references_error() {
578-
return;
579-
}
580-
581553
let drcx = DeepRejectCtxt::relate_rigid_infer(self.tcx());
582554
let obligation_args = obligation.predicate.skip_binder().trait_ref.args;
583555
self.tcx().for_each_relevant_impl(

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2493,10 +2493,6 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
24932493
let impl_args = self.infcx.fresh_args_for_item(obligation.cause.span, impl_def_id);
24942494

24952495
let trait_ref = impl_trait_header.trait_ref.instantiate(self.tcx(), impl_args);
2496-
if trait_ref.references_error() {
2497-
return Err(());
2498-
}
2499-
25002496
debug!(?impl_trait_header);
25012497

25022498
let Normalized { value: impl_trait_ref, obligations: mut nested_obligations } =

compiler/rustc_ty_utils/src/ty.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ use rustc_index::bit_set::BitSet;
66
use rustc_middle::bug;
77
use rustc_middle::query::Providers;
88
use rustc_middle::ty::{
9-
self, EarlyBinder, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt,
10-
TypeVisitor, Upcast,
9+
self, EarlyBinder, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor, Upcast,
1110
};
1211
use rustc_span::DUMMY_SP;
1312
use rustc_span::def_id::{CRATE_DEF_ID, DefId, LocalDefId};
@@ -95,9 +94,6 @@ fn adt_sized_constraint<'tcx>(
9594
let tail_ty = tcx.type_of(tail_def.did).instantiate_identity();
9695

9796
let constraint_ty = sized_constraint_for_ty(tcx, tail_ty)?;
98-
if let Err(guar) = constraint_ty.error_reported() {
99-
return Some(ty::EarlyBinder::bind(Ty::new_error(tcx, guar)));
100-
}
10197

10298
// perf hack: if there is a `constraint_ty: Sized` bound, then we know
10399
// that the type is sized and do not need to check it on the impl.

tests/crashes/124350.rs

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

tests/crashes/125758.rs

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

tests/crashes/127351.rs

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

tests/crashes/127353.rs

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

tests/crashes/127742.rs

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

tests/crashes/130521.rs

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// regression test for #124350
2+
3+
struct Node<const D: usize> {}
4+
5+
impl<const D: usize> Node<D>
6+
where
7+
SmallVec<{ D * 2 }>:,
8+
//~^ ERROR generic parameters may not be used in const operations
9+
//~| ERROR constant provided when a type was expected
10+
{
11+
fn new() -> Self {
12+
Node::new()
13+
}
14+
}
15+
16+
struct SmallVec<T1>(T1);
17+
18+
fn main() {}

0 commit comments

Comments
 (0)