diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index ef843da7307d3..a5be91bb87209 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -1636,7 +1636,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { if let Some(old_def_id) = self.orig_opt_local_def_id(param) { old_def_id } else { - self.dcx().span_bug(lifetime.ident.span, "no def-id for fresh lifetime"); + self.dcx() + .span_delayed_bug(lifetime.ident.span, "no def-id for fresh lifetime"); + continue; } } diff --git a/compiler/rustc_hir_analysis/src/collect/generics_of.rs b/compiler/rustc_hir_analysis/src/collect/generics_of.rs index 410a069f9568f..9cc6c16c12639 100644 --- a/compiler/rustc_hir_analysis/src/collect/generics_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/generics_of.rs @@ -315,7 +315,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics { if is_host_effect { if let Some(idx) = host_effect_index { - tcx.dcx().span_bug( + tcx.dcx().span_delayed_bug( param.span, format!("parent also has host effect param? index: {idx}, def: {def_id:?}"), ); diff --git a/compiler/rustc_hir_typeck/src/mem_categorization.rs b/compiler/rustc_hir_typeck/src/mem_categorization.rs index c300ec7444b2e..1a860aa406791 100644 --- a/compiler/rustc_hir_typeck/src/mem_categorization.rs +++ b/compiler/rustc_hir_typeck/src/mem_categorization.rs @@ -582,7 +582,8 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { match ty.kind() { ty::Tuple(args) => Ok(args.len()), _ => { - self.tcx().dcx().span_bug(span, "tuple pattern not applied to a tuple"); + self.tcx().dcx().span_delayed_bug(span, "tuple pattern not applied to a tuple"); + Err(()) } } } diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index cac5379674790..9eec60ea06c21 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -172,9 +172,7 @@ fn do_normalize_predicates<'tcx>( // the normalized predicates. let errors = infcx.resolve_regions(&outlives_env); if !errors.is_empty() { - // @lcnr: Let's still ICE here for now. I want a test case - // for that. - tcx.dcx().span_bug( + tcx.dcx().span_delayed_bug( span, format!("failed region resolution while normalizing {elaborated_env:?}: {errors:?}"), ); diff --git a/tests/ui/lowering/span-bug-issue-121431.rs b/tests/ui/lowering/span-bug-issue-121431.rs new file mode 100644 index 0000000000000..b855577bcfbff --- /dev/null +++ b/tests/ui/lowering/span-bug-issue-121431.rs @@ -0,0 +1,4 @@ +fn bug() -> impl CallbackMarker< Item = [(); { |_: &mut ()| 3; 4 }] > {} +//~^ ERROR cannot find trait `CallbackMarker` in this scope + +fn main() {} diff --git a/tests/ui/lowering/span-bug-issue-121431.stderr b/tests/ui/lowering/span-bug-issue-121431.stderr new file mode 100644 index 0000000000000..595500b580640 --- /dev/null +++ b/tests/ui/lowering/span-bug-issue-121431.stderr @@ -0,0 +1,9 @@ +error[E0405]: cannot find trait `CallbackMarker` in this scope + --> $DIR/span-bug-issue-121431.rs:1:21 + | +LL | fn bug() -> impl CallbackMarker< Item = [(); { |_: &mut ()| 3; 4 }] > {} + | ^^^^^^^^^^^^^^ not found in this scope + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0405`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/span-bug-issue-121418.rs b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/span-bug-issue-121418.rs new file mode 100644 index 0000000000000..97e89f96fe1b0 --- /dev/null +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/span-bug-issue-121418.rs @@ -0,0 +1,13 @@ +#![feature(const_trait_impl)] +#![feature(effects)] + +struct S; +trait T {} + +impl const dyn T { + //~^ ERROR inherent impls cannot be `const` + //~| ERROR the const parameter `host` is not constrained by the impl trait, self type, or + pub const fn new() -> std::sync::Mutex {} +} + +fn main() {} diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/span-bug-issue-121418.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/span-bug-issue-121418.stderr new file mode 100644 index 0000000000000..11577d9ec1d0f --- /dev/null +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/span-bug-issue-121418.stderr @@ -0,0 +1,22 @@ +error: inherent impls cannot be `const` + --> $DIR/span-bug-issue-121418.rs:7:12 + | +LL | impl const dyn T { + | ----- ^^^^^ inherent impl for this type + | | + | `const` because of this + | + = note: only trait implementations may be annotated with `const` + +error[E0207]: the const parameter `host` is not constrained by the impl trait, self type, or predicates + --> $DIR/span-bug-issue-121418.rs:7:6 + | +LL | impl const dyn T { + | ^^^^^ unconstrained const parameter + | + = note: expressions using a const parameter must map each value to a distinct output value + = note: proving the result of expressions other than the parameter are unique is not supported + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0207`. diff --git a/tests/ui/traits/span-bug-issue-121414.rs b/tests/ui/traits/span-bug-issue-121414.rs new file mode 100644 index 0000000000000..6fbe2c179c652 --- /dev/null +++ b/tests/ui/traits/span-bug-issue-121414.rs @@ -0,0 +1,15 @@ +trait Bar { + type Type; +} +struct Foo<'a>(&'a ()); +impl<'a> Bar for Foo<'f> { //~ ERROR undeclared lifetime + type Type = u32; +} + +fn test() //~ ERROR implementation of `Bar` is not general enough +where + for<'a> as Bar>::Type: Sized, +{ +} + +fn main() {} diff --git a/tests/ui/traits/span-bug-issue-121414.stderr b/tests/ui/traits/span-bug-issue-121414.stderr new file mode 100644 index 0000000000000..3c97f64e781e3 --- /dev/null +++ b/tests/ui/traits/span-bug-issue-121414.stderr @@ -0,0 +1,20 @@ +error[E0261]: use of undeclared lifetime name `'f` + --> $DIR/span-bug-issue-121414.rs:5:22 + | +LL | impl<'a> Bar for Foo<'f> { + | - ^^ undeclared lifetime + | | + | help: consider introducing lifetime `'f` here: `'f,` + +error: implementation of `Bar` is not general enough + --> $DIR/span-bug-issue-121414.rs:9:4 + | +LL | fn test() + | ^^^^ implementation of `Bar` is not general enough + | + = note: `Bar` would have to be implemented for the type `Foo<'0>`, for any lifetime `'0`... + = note: ...but `Bar` is actually implemented for the type `Foo<'1>`, for some specific lifetime `'1` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0261`. diff --git a/tests/ui/typeck/span-bug-issue-121410.rs b/tests/ui/typeck/span-bug-issue-121410.rs new file mode 100644 index 0000000000000..324b398d74f77 --- /dev/null +++ b/tests/ui/typeck/span-bug-issue-121410.rs @@ -0,0 +1,15 @@ +fn test_missing_unsafe_warning_on_repr_packed() { + struct Foo { + x: String, + } + + let foo = Foo { x: String::new() }; + + let c = || { + let (_, t2) = foo.x; //~ ERROR mismatched types + }; + + c(); +} + +fn main() {} diff --git a/tests/ui/typeck/span-bug-issue-121410.stderr b/tests/ui/typeck/span-bug-issue-121410.stderr new file mode 100644 index 0000000000000..f745ac51a5e3e --- /dev/null +++ b/tests/ui/typeck/span-bug-issue-121410.stderr @@ -0,0 +1,14 @@ +error[E0308]: mismatched types + --> $DIR/span-bug-issue-121410.rs:9:13 + | +LL | let (_, t2) = foo.x; + | ^^^^^^^ ----- this expression has type `String` + | | + | expected `String`, found `(_, _)` + | + = note: expected struct `String` + found tuple `(_, _)` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0308`.