Skip to content

Commit

Permalink
Rollup merge of #121480 - nnethercote:fix-more-121208-fallout, r=lcnr
Browse files Browse the repository at this point in the history
Fix more #121208 fallout

#121208 converted lots of delayed bugs to bugs. Unsurprisingly, there were a few invalid conversion found via fuzzing.

r? `@lcnr`
  • Loading branch information
matthiaskrgr committed Feb 23, 2024
2 parents 7ae95b2 + 938e594 commit 5de3a4c
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,17 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
trait_m_sig.inputs_and_output,
));
if !ocx.select_all_or_error().is_empty() {
// This code path is not reached in any tests, but may be reachable. If
// this is triggered, it should be converted to `delayed_bug` and the
// triggering case turned into a test.
tcx.dcx().bug("encountered errors when checking RPITIT refinement (selection)");
tcx.dcx().delayed_bug("encountered errors when checking RPITIT refinement (selection)");
return;
}
let outlives_env = OutlivesEnvironment::with_bounds(
param_env,
infcx.implied_bounds_tys(param_env, impl_m.def_id.expect_local(), &implied_wf_types),
);
let errors = infcx.resolve_regions(&outlives_env);
if !errors.is_empty() {
// This code path is not reached in any tests, but may be reachable. If
// this is triggered, it should be converted to `delayed_bug` and the
// triggering case turned into a test.
tcx.dcx().bug("encountered errors when checking RPITIT refinement (regions)");
tcx.dcx().delayed_bug("encountered errors when checking RPITIT refinement (regions)");
return;
}
// Resolve any lifetime variables that may have been introduced during normalization.
let Ok((trait_bounds, impl_bounds)) = infcx.fully_resolve((trait_bounds, impl_bounds)) else {
Expand Down
7 changes: 5 additions & 2 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// coercions from ! to `expected`.
if ty.is_never() {
if let Some(_) = self.typeck_results.borrow().adjustments().get(expr.hir_id) {
self.dcx()
.span_bug(expr.span, "expression with never type wound up being adjusted");
let reported = self.dcx().span_delayed_bug(
expr.span,
"expression with never type wound up being adjusted",
);
return Ty::new_error(self.tcx(), reported);
}

let adj_ty = self.next_ty_var(TypeVariableOrigin {
Expand Down
18 changes: 18 additions & 0 deletions tests/ui/impl-trait/in-trait/span-bug-issue-121457.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
pub trait Iterable {
type Item<'a>
where
Self: 'a;

fn iter(&self) -> impl Iterator;
}

impl<'a, I: 'a + Iterable> Iterable for &'a I {
type Item = u32;
//~^ ERROR lifetime parameters or bounds on type `Item` do not match the trait declaration

fn iter(&self) -> impl for<'missing> Iterator<Item = Self::Item<'missing>> {}
//~^ ERROR binding for associated type `Item` references lifetime `'missing`
//~| ERROR `()` is not an iterator
}

fn main() {}
30 changes: 30 additions & 0 deletions tests/ui/impl-trait/in-trait/span-bug-issue-121457.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
error[E0582]: binding for associated type `Item` references lifetime `'missing`, which does not appear in the trait input types
--> $DIR/span-bug-issue-121457.rs:13:51
|
LL | fn iter(&self) -> impl for<'missing> Iterator<Item = Self::Item<'missing>> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0195]: lifetime parameters or bounds on type `Item` do not match the trait declaration
--> $DIR/span-bug-issue-121457.rs:10:14
|
LL | type Item<'a>
| ---- lifetimes in impl do not match this type in trait
LL | where
LL | Self: 'a;
| -- this bound might be missing in the impl
...
LL | type Item = u32;
| ^ lifetimes do not match type in trait

error[E0277]: `()` is not an iterator
--> $DIR/span-bug-issue-121457.rs:13:23
|
LL | fn iter(&self) -> impl for<'missing> Iterator<Item = Self::Item<'missing>> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `()` is not an iterator
|
= help: the trait `Iterator` is not implemented for `()`

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0195, E0277, E0582.
For more information about an error, try `rustc --explain E0195`.
15 changes: 15 additions & 0 deletions tests/ui/never_type/span-bug-issue-121445.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#![feature(never_type)]

fn test2() {
let x: !;
let c2 = SingleVariant::Points(0)
| match x { //~ ERROR no implementation for `SingleVariant | ()`
_ => (),
};
}

enum SingleVariant {
Points(u32),
}

fn main() {}
22 changes: 22 additions & 0 deletions tests/ui/never_type/span-bug-issue-121445.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
error[E0369]: no implementation for `SingleVariant | ()`
--> $DIR/span-bug-issue-121445.rs:6:9
|
LL | let c2 = SingleVariant::Points(0)
| ------------------------ SingleVariant
LL | | match x {
| _________^_-
LL | | _ => (),
LL | | };
| |_________- ()
|
note: an implementation of `BitOr<()>` might be missing for `SingleVariant`
--> $DIR/span-bug-issue-121445.rs:11:1
|
LL | enum SingleVariant {
| ^^^^^^^^^^^^^^^^^^ must implement `BitOr<()>`
note: the trait `BitOr` must be implemented
--> $SRC_DIR/core/src/ops/bit.rs:LL:COL

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0369`.

0 comments on commit 5de3a4c

Please sign in to comment.