Skip to content

Commit

Permalink
Rollup merge of rust-lang#132090 - compiler-errors:baily, r=lcnr
Browse files Browse the repository at this point in the history
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
  • Loading branch information
compiler-errors authored Nov 22, 2024
2 parents 8f3ee9f + 0465f71 commit b397caf
Show file tree
Hide file tree
Showing 39 changed files with 328 additions and 240 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
} else if tcx.is_lang_item(def_id, LangItem::Sized) {
// Sized is never implementable by end-users, it is
// always automatically computed.

// FIXME: Consider moving this check to the top level as it
// may also be useful for predicates other than `Sized`
// Error type cannot possibly implement `Sized` (fixes #123154)
if let Err(e) = obligation.predicate.skip_binder().self_ty().error_reported() {
return Err(SelectionError::Overflow(e.into()));
}

let sized_conditions = self.sized_conditions(obligation);
self.assemble_builtin_bound_candidates(sized_conditions, &mut candidates);
} else if tcx.is_lang_item(def_id, LangItem::Unsize) {
Expand Down Expand Up @@ -230,13 +222,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
) -> Result<(), SelectionError<'tcx>> {
debug!(?stack.obligation);

// An error type will unify with anything. So, avoid
// matching an error type with `ParamCandidate`.
// This helps us avoid spurious errors like issue #121941.
if stack.obligation.predicate.references_error() {
return Ok(());
}

let bounds = stack
.obligation
.param_env
Expand Down Expand Up @@ -563,19 +548,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
obligation: &PolyTraitObligation<'tcx>,
candidates: &mut SelectionCandidateSet<'tcx>,
) {
// Essentially any user-written impl will match with an error type,
// so creating `ImplCandidates` isn't useful. However, we might
// end up finding a candidate elsewhere (e.g. a `BuiltinCandidate` for `Sized`)
// This helps us avoid overflow: see issue #72839
// Since compilation is already guaranteed to fail, this is just
// to try to show the 'nicest' possible errors to the user.
// We don't check for errors in the `ParamEnv` - in practice,
// it seems to cause us to be overly aggressive in deciding
// to give up searching for candidates, leading to spurious errors.
if obligation.predicate.references_error() {
return;
}

let drcx = DeepRejectCtxt::relate_rigid_infer(self.tcx());
let obligation_args = obligation.predicate.skip_binder().trait_ref.args;
self.tcx().for_each_relevant_impl(
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2487,10 +2487,6 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
let impl_args = self.infcx.fresh_args_for_item(obligation.cause.span, impl_def_id);

let trait_ref = impl_trait_header.trait_ref.instantiate(self.tcx(), impl_args);
if trait_ref.references_error() {
return Err(());
}

debug!(?impl_trait_header);

let Normalized { value: impl_trait_ref, obligations: mut nested_obligations } =
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_ty_utils/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use rustc_index::bit_set::BitSet;
use rustc_middle::bug;
use rustc_middle::query::Providers;
use rustc_middle::ty::{
self, EarlyBinder, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt,
TypeVisitor, Upcast,
self, EarlyBinder, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor, Upcast,
};
use rustc_span::DUMMY_SP;
use rustc_span::def_id::{CRATE_DEF_ID, DefId, LocalDefId};
Expand Down Expand Up @@ -95,9 +94,6 @@ fn adt_sized_constraint<'tcx>(
let tail_ty = tcx.type_of(tail_def.did).instantiate_identity();

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

// perf hack: if there is a `constraint_ty: Sized` bound, then we know
// that the type is sized and do not need to check it on the impl.
Expand Down
17 changes: 0 additions & 17 deletions tests/crashes/124350.rs

This file was deleted.

26 changes: 0 additions & 26 deletions tests/crashes/125758.rs

This file was deleted.

17 changes: 0 additions & 17 deletions tests/crashes/127351.rs

This file was deleted.

18 changes: 0 additions & 18 deletions tests/crashes/127353.rs

This file was deleted.

11 changes: 0 additions & 11 deletions tests/crashes/127742.rs

This file was deleted.

2 changes: 1 addition & 1 deletion tests/crashes/130521.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ struct Vtable(dyn Cap);
trait Cap<'a> {}

union Transmute {
t: u64,
t: u128,
u: &'static Vtable,
}

Expand Down
18 changes: 18 additions & 0 deletions tests/ui/const-generics/generic_const_exprs/bad-multiply.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// regression test for #124350

struct Node<const D: usize> {}

impl<const D: usize> Node<D>
where
SmallVec<{ D * 2 }>:,
//~^ ERROR generic parameters may not be used in const operations
//~| ERROR constant provided when a type was expected
{
fn new() -> Self {
Node::new()
}
}

struct SmallVec<T1>(T1);

fn main() {}
18 changes: 18 additions & 0 deletions tests/ui/const-generics/generic_const_exprs/bad-multiply.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error: generic parameters may not be used in const operations
--> $DIR/bad-multiply.rs:7:16
|
LL | SmallVec<{ D * 2 }>:,
| ^ cannot perform const operation using `D`
|
= help: const parameters may only be used as standalone arguments, i.e. `D`
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions

error[E0747]: constant provided when a type was expected
--> $DIR/bad-multiply.rs:7:14
|
LL | SmallVec<{ D * 2 }>:,
| ^^^^^^^^^

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0747`.
1 change: 0 additions & 1 deletion tests/ui/const-generics/kind_mismatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ pub fn remove_key<K, S: SubsetExcept<K>>() -> S {

fn main() {
let map: KeyHolder<0> = remove_key::<_, _>();
//~^ ERROR: the trait bound `KeyHolder<0>: SubsetExcept<_>` is not satisfied
}
24 changes: 2 additions & 22 deletions tests/ui/const-generics/kind_mismatch.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,6 @@ LL | impl<K> ContainsKey<K> for KeyHolder<K> {}
| |
| help: consider changing this type parameter to a const parameter: `const K: u8`

error[E0277]: the trait bound `KeyHolder<0>: SubsetExcept<_>` is not satisfied
--> $DIR/kind_mismatch.rs:22:45
|
LL | let map: KeyHolder<0> = remove_key::<_, _>();
| ^ the trait `ContainsKey<0>` is not implemented for `KeyHolder<0>`
|
note: required for `KeyHolder<0>` to implement `SubsetExcept<_>`
--> $DIR/kind_mismatch.rs:15:28
|
LL | impl<P, T: ContainsKey<0>> SubsetExcept<P> for T {}
| -------------- ^^^^^^^^^^^^^^^ ^
| |
| unsatisfied trait bound introduced here
note: required by a bound in `remove_key`
--> $DIR/kind_mismatch.rs:17:25
|
LL | pub fn remove_key<K, S: SubsetExcept<K>>() -> S {
| ^^^^^^^^^^^^^^^ required by this bound in `remove_key`

error: aborting due to 3 previous errors
error: aborting due to 2 previous errors

Some errors have detailed explanations: E0277, E0747.
For more information about an error, try `rustc --explain E0277`.
For more information about this error, try `rustc --explain E0747`.
4 changes: 3 additions & 1 deletion tests/ui/generic-associated-types/issue-71176.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ struct Holder<B> {

fn main() {
Holder {
inner: Box::new(()), //~ ERROR: the trait `Provider` cannot be made into an object
inner: Box::new(()),
//~^ ERROR: the trait `Provider` cannot be made into an object
//~| ERROR: the trait `Provider` cannot be made into an object
};
}
19 changes: 18 additions & 1 deletion tests/ui/generic-associated-types/issue-71176.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,24 @@ LL | type A<'a>;
= help: consider moving `A` to another trait
= help: only type `()` implements the trait, consider using it directly instead

error: aborting due to 5 previous errors
error[E0038]: the trait `Provider` cannot be made into an object
--> $DIR/issue-71176.rs:19:16
|
LL | inner: Box::new(()),
| ^^^^^^^^^^^^ `Provider` cannot be made into an object
|
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/issue-71176.rs:2:10
|
LL | trait Provider {
| -------- this trait cannot be made into an object...
LL | type A<'a>;
| ^ ...because it contains the generic associated type `A`
= help: consider moving `A` to another trait
= help: only type `()` implements the trait, consider using it directly instead
= note: required for the cast from `Box<()>` to `Box<(dyn Provider<A<'_> = _> + 'static), {type error}>`

error: aborting due to 6 previous errors

Some errors have detailed explanations: E0038, E0107.
For more information about an error, try `rustc --explain E0038`.
3 changes: 3 additions & 0 deletions tests/ui/layout/ice-type-error-in-tail-124031.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//@ normalize-stderr-test: "\d+ bits" -> "$$BITS bits"

// Regression test for issue #124031
// Checks that we don't ICE when the tail
// of an ADT has a type error
Expand All @@ -16,5 +18,6 @@ struct Other {
fn main() {
unsafe {
std::mem::transmute::<Option<()>, Option<&Other>>(None);
//~^ ERROR cannot transmute between types of different sizes
}
}
16 changes: 13 additions & 3 deletions tests/ui/layout/ice-type-error-in-tail-124031.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
error[E0046]: not all trait items implemented, missing: `RefTarget`
--> $DIR/ice-type-error-in-tail-124031.rs:9:1
--> $DIR/ice-type-error-in-tail-124031.rs:11:1
|
LL | type RefTarget;
| -------------- `RefTarget` from trait
...
LL | impl Trait for () {}
| ^^^^^^^^^^^^^^^^^ missing `RefTarget` in implementation

error: aborting due to 1 previous error
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> $DIR/ice-type-error-in-tail-124031.rs:20:9
|
LL | std::mem::transmute::<Option<()>, Option<&Other>>(None);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: source type: `Option<()>` ($BITS bits)
= note: target type: `Option<&Other>` ($BITS bits)

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0046`.
Some errors have detailed explanations: E0046, E0512.
For more information about an error, try `rustc --explain E0046`.
18 changes: 18 additions & 0 deletions tests/ui/lazy-type-alias/bad-lazy-type-alias.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// regression test for #127351

#![feature(lazy_type_alias)]
//~^ WARN the feature `lazy_type_alias` is incomplete

type ExplicitTypeOutlives<T> = T;

pub struct Warns {
_significant_drop: ExplicitTypeOutlives,
//~^ ERROR missing generics for type alias `ExplicitTypeOutlives`
field: String,
}

pub fn test(w: Warns) {
let _ = || drop(w.field);
}

fn main() {}
28 changes: 28 additions & 0 deletions tests/ui/lazy-type-alias/bad-lazy-type-alias.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
warning: the feature `lazy_type_alias` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/bad-lazy-type-alias.rs:3:12
|
LL | #![feature(lazy_type_alias)]
| ^^^^^^^^^^^^^^^
|
= note: see issue #112792 <https://github.com/rust-lang/rust/issues/112792> for more information
= note: `#[warn(incomplete_features)]` on by default

error[E0107]: missing generics for type alias `ExplicitTypeOutlives`
--> $DIR/bad-lazy-type-alias.rs:9:24
|
LL | _significant_drop: ExplicitTypeOutlives,
| ^^^^^^^^^^^^^^^^^^^^ expected 1 generic argument
|
note: type alias defined here, with 1 generic parameter: `T`
--> $DIR/bad-lazy-type-alias.rs:6:6
|
LL | type ExplicitTypeOutlives<T> = T;
| ^^^^^^^^^^^^^^^^^^^^ -
help: add missing generic argument
|
LL | _significant_drop: ExplicitTypeOutlives<T>,
| +++

error: aborting due to 1 previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0107`.
1 change: 0 additions & 1 deletion tests/ui/nll/user-annotations/region-error-ice-109072.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ impl Lt<'missing> for () { //~ ERROR undeclared lifetime

fn main() {
let _: <() as Lt<'_>>::T = &();
//~^ ERROR the trait bound `(): Lt<'_>` is not satisfied
}
Loading

0 comments on commit b397caf

Please sign in to comment.