diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs index 7bdbab4325cbf..b5e69b8e3766e 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs @@ -154,10 +154,8 @@ 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, @@ -165,10 +163,8 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>( ); 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 { diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 89cc46dc5ab80..81440b0562e24 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -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 { diff --git a/tests/ui/impl-trait/in-trait/span-bug-issue-121457.rs b/tests/ui/impl-trait/in-trait/span-bug-issue-121457.rs new file mode 100644 index 0000000000000..10167ee935262 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/span-bug-issue-121457.rs @@ -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> {} + //~^ ERROR binding for associated type `Item` references lifetime `'missing` + //~| ERROR `()` is not an iterator +} + +fn main() {} diff --git a/tests/ui/impl-trait/in-trait/span-bug-issue-121457.stderr b/tests/ui/impl-trait/in-trait/span-bug-issue-121457.stderr new file mode 100644 index 0000000000000..96c3644f89348 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/span-bug-issue-121457.stderr @@ -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> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +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> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `()` 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`. diff --git a/tests/ui/never_type/span-bug-issue-121445.rs b/tests/ui/never_type/span-bug-issue-121445.rs new file mode 100644 index 0000000000000..2fe22529c4e9d --- /dev/null +++ b/tests/ui/never_type/span-bug-issue-121445.rs @@ -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() {} diff --git a/tests/ui/never_type/span-bug-issue-121445.stderr b/tests/ui/never_type/span-bug-issue-121445.stderr new file mode 100644 index 0000000000000..b211afa236fef --- /dev/null +++ b/tests/ui/never_type/span-bug-issue-121445.stderr @@ -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`.