Skip to content

Commit b397caf

Browse files
Rollup merge of rust-lang#132090 - compiler-errors:baily, r=lcnr
Stop being so bail-y in candidate assembly A conceptual follow-up to rust-lang#132084. We gotta stop bailing so much when there are errors; it's both unnecessary, leads to weird knock-on errors, and it's messing up the vibes lol
2 parents 8f3ee9f + 0465f71 commit b397caf

39 files changed

+328
-240
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) {
@@ -230,13 +222,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
230222
) -> Result<(), SelectionError<'tcx>> {
231223
debug!(?stack.obligation);
232224

233-
// An error type will unify with anything. So, avoid
234-
// matching an error type with `ParamCandidate`.
235-
// This helps us avoid spurious errors like issue #121941.
236-
if stack.obligation.predicate.references_error() {
237-
return Ok(());
238-
}
239-
240225
let bounds = stack
241226
.obligation
242227
.param_env
@@ -563,19 +548,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
563548
obligation: &PolyTraitObligation<'tcx>,
564549
candidates: &mut SelectionCandidateSet<'tcx>,
565550
) {
566-
// Essentially any user-written impl will match with an error type,
567-
// so creating `ImplCandidates` isn't useful. However, we might
568-
// end up finding a candidate elsewhere (e.g. a `BuiltinCandidate` for `Sized`)
569-
// This helps us avoid overflow: see issue #72839
570-
// Since compilation is already guaranteed to fail, this is just
571-
// to try to show the 'nicest' possible errors to the user.
572-
// We don't check for errors in the `ParamEnv` - in practice,
573-
// it seems to cause us to be overly aggressive in deciding
574-
// to give up searching for candidates, leading to spurious errors.
575-
if obligation.predicate.references_error() {
576-
return;
577-
}
578-
579551
let drcx = DeepRejectCtxt::relate_rigid_infer(self.tcx());
580552
let obligation_args = obligation.predicate.skip_binder().trait_ref.args;
581553
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
@@ -2487,10 +2487,6 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
24872487
let impl_args = self.infcx.fresh_args_for_item(obligation.cause.span, impl_def_id);
24882488

24892489
let trait_ref = impl_trait_header.trait_ref.instantiate(self.tcx(), impl_args);
2490-
if trait_ref.references_error() {
2491-
return Err(());
2492-
}
2493-
24942490
debug!(?impl_trait_header);
24952491

24962492
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ struct Vtable(dyn Cap);
66
trait Cap<'a> {}
77

88
union Transmute {
9-
t: u64,
9+
t: u128,
1010
u: &'static Vtable,
1111
}
1212

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)