From edda2a7d3e7e541097285c03c0a8f68ad9b2fbc4 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 26 Feb 2024 08:40:51 +1100 Subject: [PATCH] Revert some `span_bug`s to `span_delayed_bug`. Fixes #121503. Fixes #121597. --- .../src/collect/resolve_bound_vars.rs | 2 +- compiler/rustc_hir_typeck/src/method/probe.rs | 3 +- .../trait-bounds/span-bug-issue-121597.rs | 20 ++++++++ .../trait-bounds/span-bug-issue-121597.stderr | 49 +++++++++++++++++++ .../could-not-resolve-issue-121503.rs | 13 +++++ .../could-not-resolve-issue-121503.stderr | 28 +++++++++++ 6 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 tests/ui/higher-ranked/trait-bounds/span-bug-issue-121597.rs create mode 100644 tests/ui/higher-ranked/trait-bounds/span-bug-issue-121597.stderr create mode 100644 tests/ui/lifetimes/could-not-resolve-issue-121503.rs create mode 100644 tests/ui/lifetimes/could-not-resolve-issue-121503.stderr diff --git a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs index efde4e11c79dd..22beac14b24db 100644 --- a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs +++ b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs @@ -1331,7 +1331,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> { } } - self.tcx.dcx().span_bug( + self.tcx.dcx().span_delayed_bug( lifetime_ref.ident.span, format!("Could not resolve {:?} in scope {:#?}", lifetime_ref, self.scope,), ); diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index 7117a59c40987..bdc796aca3a46 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -804,10 +804,11 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { let trait_ref = principal.with_self_ty(self.tcx, self_ty); self.elaborate_bounds(iter::once(trait_ref), |this, new_trait_ref, item| { if new_trait_ref.has_non_region_bound_vars() { - this.dcx().span_bug( + this.dcx().span_delayed_bug( this.span, "tried to select method from HRTB with non-lifetime bound vars", ); + return; } let new_trait_ref = this.instantiate_bound_regions_with_erased(new_trait_ref); diff --git a/tests/ui/higher-ranked/trait-bounds/span-bug-issue-121597.rs b/tests/ui/higher-ranked/trait-bounds/span-bug-issue-121597.rs new file mode 100644 index 0000000000000..aeace9f2158ae --- /dev/null +++ b/tests/ui/higher-ranked/trait-bounds/span-bug-issue-121597.rs @@ -0,0 +1,20 @@ +#![allow(incomplete_features)] +#![feature(non_lifetime_binders)] + +trait Foo: for Bar {} + +trait Bar { + fn method(&self) {} +} + +struct Type2; +fn needs_bar(_: *mut Type2) {} + +fn main() { + let x: &dyn Foo = &(); + //~^ ERROR the trait `Foo` cannot be made into an object + //~| ERROR the trait `Foo` cannot be made into an object + + needs_bar(x); + //~^ ERROR mismatched types +} diff --git a/tests/ui/higher-ranked/trait-bounds/span-bug-issue-121597.stderr b/tests/ui/higher-ranked/trait-bounds/span-bug-issue-121597.stderr new file mode 100644 index 0000000000000..27f82563aae7d --- /dev/null +++ b/tests/ui/higher-ranked/trait-bounds/span-bug-issue-121597.stderr @@ -0,0 +1,49 @@ +error[E0038]: the trait `Foo` cannot be made into an object + --> $DIR/span-bug-issue-121597.rs:14:23 + | +LL | let x: &dyn Foo = &(); + | ^^^ `Foo` cannot be made into an object + | +note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit + --> $DIR/span-bug-issue-121597.rs:4:12 + | +LL | trait Foo: for Bar {} + | --- ^^^^^^^^^^^^^ ...because where clause cannot reference non-lifetime `for<...>` variables + | | + | this trait cannot be made into an object... + = note: required for the cast from `&()` to `&dyn Foo` + +error[E0038]: the trait `Foo` cannot be made into an object + --> $DIR/span-bug-issue-121597.rs:14:12 + | +LL | let x: &dyn Foo = &(); + | ^^^^^^^^ `Foo` cannot be made into an object + | +note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit + --> $DIR/span-bug-issue-121597.rs:4:12 + | +LL | trait Foo: for Bar {} + | --- ^^^^^^^^^^^^^ ...because where clause cannot reference non-lifetime `for<...>` variables + | | + | this trait cannot be made into an object... + +error[E0308]: mismatched types + --> $DIR/span-bug-issue-121597.rs:18:15 + | +LL | needs_bar(x); + | --------- ^ types differ in mutability + | | + | arguments to this function are incorrect + | + = note: expected raw pointer `*mut Type2` + found reference `&dyn Foo` +note: function defined here + --> $DIR/span-bug-issue-121597.rs:11:4 + | +LL | fn needs_bar(_: *mut Type2) {} + | ^^^^^^^^^ ------------- + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0038, E0308. +For more information about an error, try `rustc --explain E0038`. diff --git a/tests/ui/lifetimes/could-not-resolve-issue-121503.rs b/tests/ui/lifetimes/could-not-resolve-issue-121503.rs new file mode 100644 index 0000000000000..6bc70a907d9e9 --- /dev/null +++ b/tests/ui/lifetimes/could-not-resolve-issue-121503.rs @@ -0,0 +1,13 @@ +//@ edition:2018 + +#![feature(allocator_api)] +struct Struct; +impl Struct { + async fn box_ref_Struct(self: Box) -> &u32 { + //~^ ERROR the trait bound `impl FnMut(&mut Self): Allocator` is not satisfied + //~| ERROR Box` cannot be used as the type of `self` without + &1 + } +} + +fn main() {} diff --git a/tests/ui/lifetimes/could-not-resolve-issue-121503.stderr b/tests/ui/lifetimes/could-not-resolve-issue-121503.stderr new file mode 100644 index 0000000000000..a5d8239a2df05 --- /dev/null +++ b/tests/ui/lifetimes/could-not-resolve-issue-121503.stderr @@ -0,0 +1,28 @@ +error[E0277]: the trait bound `impl FnMut(&mut Self): Allocator` is not satisfied + --> $DIR/could-not-resolve-issue-121503.rs:6:5 + | +LL | async fn box_ref_Struct(self: Box) -> &u32 { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Allocator` is not implemented for `impl FnMut(&mut Self)` + | +note: required by a bound in `Box` + --> $SRC_DIR/alloc/src/boxed.rs:LL:COL +help: consider further restricting this bound + | +LL | async fn box_ref_Struct(self: Box) -> &u32 { + | +++++++++++++++++++++++ + +error[E0658]: `Box` cannot be used as the type of `self` without the `arbitrary_self_types` feature + --> $DIR/could-not-resolve-issue-121503.rs:6:35 + | +LL | async fn box_ref_Struct(self: Box) -> &u32 { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #44874 for more information + = help: add `#![feature(arbitrary_self_types)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + = help: consider changing to `self`, `&self`, `&mut self`, `self: Box`, `self: Rc`, `self: Arc`, or `self: Pin

` (where P is one of the previous types except `Self`) + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0277, E0658. +For more information about an error, try `rustc --explain E0277`.