Skip to content

Commit e07a5aa

Browse files
authored
Rollup merge of rust-lang#121281 - kadiwa4:test_103626, r=estebank,lcnr
regression test for rust-lang#103626 I don't know what a descriptive filename for this would be. Fixes rust-lang#103626
2 parents d959730 + 188c46a commit e07a5aa

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
trait FromResidual<R = <Self as Try>::Residual> {
2+
fn from_residual(residual: R) -> Self;
3+
}
4+
5+
trait Try {
6+
type Residual;
7+
}
8+
9+
fn w<'a, T: 'a, F: Fn(&'a T)>() {
10+
let b: &dyn FromResidual = &();
11+
//~^ ERROR: the trait `FromResidual` cannot be made into an object
12+
//~| ERROR: the trait `FromResidual` cannot be made into an object
13+
}
14+
15+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
error[E0038]: the trait `FromResidual` cannot be made into an object
2+
--> $DIR/canonicalize-fresh-infer-vars-issue-103626.rs:10:17
3+
|
4+
LL | let b: &dyn FromResidual = &();
5+
| ^^^^^^^^^^^^
6+
|
7+
= note: it cannot use `Self` as a type parameter in a supertrait or `where`-clause
8+
9+
error[E0038]: the trait `FromResidual` cannot be made into an object
10+
--> $DIR/canonicalize-fresh-infer-vars-issue-103626.rs:10:12
11+
|
12+
LL | let b: &dyn FromResidual = &();
13+
| ^^^^^^^^^^^^^^^^^ `FromResidual` cannot be made into an object
14+
|
15+
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>
16+
--> $DIR/canonicalize-fresh-infer-vars-issue-103626.rs:2:8
17+
|
18+
LL | trait FromResidual<R = <Self as Try>::Residual> {
19+
| ------------ this trait cannot be made into an object...
20+
LL | fn from_residual(residual: R) -> Self;
21+
| ^^^^^^^^^^^^^ ...because associated function `from_residual` has no `self` parameter
22+
help: consider turning `from_residual` into a method by giving it a `&self` argument
23+
|
24+
LL | fn from_residual(&self, residual: R) -> Self;
25+
| ++++++
26+
help: alternatively, consider constraining `from_residual` so it does not apply to trait objects
27+
|
28+
LL | fn from_residual(residual: R) -> Self where Self: Sized;
29+
| +++++++++++++++++
30+
31+
error: aborting due to 2 previous errors
32+
33+
For more information about this error, try `rustc --explain E0038`.

0 commit comments

Comments
 (0)