Skip to content

Commit 76f303d

Browse files
Rollup merge of #121620 - nnethercote:fix-even-more-121208-fallout, r=lcnr
Fix more #121208 fallout (round 3) #121208 converted lots of delayed bugs to bugs. Unsurprisingly, there were a few invalid conversion found via fuzzing. r? `@lcnr`
2 parents a1593a6 + edda2a7 commit 76f303d

File tree

6 files changed

+113
-2
lines changed

6 files changed

+113
-2
lines changed

Diff for: compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
13311331
}
13321332
}
13331333

1334-
self.tcx.dcx().span_bug(
1334+
self.tcx.dcx().span_delayed_bug(
13351335
lifetime_ref.ident.span,
13361336
format!("Could not resolve {:?} in scope {:#?}", lifetime_ref, self.scope,),
13371337
);

Diff for: compiler/rustc_hir_typeck/src/method/probe.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -804,10 +804,11 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
804804
let trait_ref = principal.with_self_ty(self.tcx, self_ty);
805805
self.elaborate_bounds(iter::once(trait_ref), |this, new_trait_ref, item| {
806806
if new_trait_ref.has_non_region_bound_vars() {
807-
this.dcx().span_bug(
807+
this.dcx().span_delayed_bug(
808808
this.span,
809809
"tried to select method from HRTB with non-lifetime bound vars",
810810
);
811+
return;
811812
}
812813

813814
let new_trait_ref = this.instantiate_bound_regions_with_erased(new_trait_ref);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![allow(incomplete_features)]
2+
#![feature(non_lifetime_binders)]
3+
4+
trait Foo: for<T> Bar<T> {}
5+
6+
trait Bar<T: ?Sized> {
7+
fn method(&self) {}
8+
}
9+
10+
struct Type2;
11+
fn needs_bar(_: *mut Type2) {}
12+
13+
fn main() {
14+
let x: &dyn Foo = &();
15+
//~^ ERROR the trait `Foo` cannot be made into an object
16+
//~| ERROR the trait `Foo` cannot be made into an object
17+
18+
needs_bar(x);
19+
//~^ ERROR mismatched types
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
error[E0038]: the trait `Foo` cannot be made into an object
2+
--> $DIR/span-bug-issue-121597.rs:14:23
3+
|
4+
LL | let x: &dyn Foo = &();
5+
| ^^^ `Foo` cannot be made into an object
6+
|
7+
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
8+
--> $DIR/span-bug-issue-121597.rs:4:12
9+
|
10+
LL | trait Foo: for<T> Bar<T> {}
11+
| --- ^^^^^^^^^^^^^ ...because where clause cannot reference non-lifetime `for<...>` variables
12+
| |
13+
| this trait cannot be made into an object...
14+
= note: required for the cast from `&()` to `&dyn Foo`
15+
16+
error[E0038]: the trait `Foo` cannot be made into an object
17+
--> $DIR/span-bug-issue-121597.rs:14:12
18+
|
19+
LL | let x: &dyn Foo = &();
20+
| ^^^^^^^^ `Foo` cannot be made into an object
21+
|
22+
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
23+
--> $DIR/span-bug-issue-121597.rs:4:12
24+
|
25+
LL | trait Foo: for<T> Bar<T> {}
26+
| --- ^^^^^^^^^^^^^ ...because where clause cannot reference non-lifetime `for<...>` variables
27+
| |
28+
| this trait cannot be made into an object...
29+
30+
error[E0308]: mismatched types
31+
--> $DIR/span-bug-issue-121597.rs:18:15
32+
|
33+
LL | needs_bar(x);
34+
| --------- ^ types differ in mutability
35+
| |
36+
| arguments to this function are incorrect
37+
|
38+
= note: expected raw pointer `*mut Type2`
39+
found reference `&dyn Foo`
40+
note: function defined here
41+
--> $DIR/span-bug-issue-121597.rs:11:4
42+
|
43+
LL | fn needs_bar(_: *mut Type2) {}
44+
| ^^^^^^^^^ -------------
45+
46+
error: aborting due to 3 previous errors
47+
48+
Some errors have detailed explanations: E0038, E0308.
49+
For more information about an error, try `rustc --explain E0038`.

Diff for: tests/ui/lifetimes/could-not-resolve-issue-121503.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@ edition:2018
2+
3+
#![feature(allocator_api)]
4+
struct Struct;
5+
impl Struct {
6+
async fn box_ref_Struct(self: Box<Self, impl FnMut(&mut Self)>) -> &u32 {
7+
//~^ ERROR the trait bound `impl FnMut(&mut Self): Allocator` is not satisfied
8+
//~| ERROR Box<Struct, impl FnMut(&mut Self)>` cannot be used as the type of `self` without
9+
&1
10+
}
11+
}
12+
13+
fn main() {}
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
error[E0277]: the trait bound `impl FnMut(&mut Self): Allocator` is not satisfied
2+
--> $DIR/could-not-resolve-issue-121503.rs:6:5
3+
|
4+
LL | async fn box_ref_Struct(self: Box<Self, impl FnMut(&mut Self)>) -> &u32 {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Allocator` is not implemented for `impl FnMut(&mut Self)`
6+
|
7+
note: required by a bound in `Box`
8+
--> $SRC_DIR/alloc/src/boxed.rs:LL:COL
9+
help: consider further restricting this bound
10+
|
11+
LL | async fn box_ref_Struct(self: Box<Self, impl FnMut(&mut Self) + std::alloc::Allocator>) -> &u32 {
12+
| +++++++++++++++++++++++
13+
14+
error[E0658]: `Box<Struct, impl FnMut(&mut Self)>` cannot be used as the type of `self` without the `arbitrary_self_types` feature
15+
--> $DIR/could-not-resolve-issue-121503.rs:6:35
16+
|
17+
LL | async fn box_ref_Struct(self: Box<Self, impl FnMut(&mut Self)>) -> &u32 {
18+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19+
|
20+
= note: see issue #44874 <https://github.com/rust-lang/rust/issues/44874> for more information
21+
= help: add `#![feature(arbitrary_self_types)]` to the crate attributes to enable
22+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
23+
= help: consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`)
24+
25+
error: aborting due to 2 previous errors
26+
27+
Some errors have detailed explanations: E0277, E0658.
28+
For more information about an error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)