File tree 5 files changed +32
-7
lines changed
compiler/rustc_metadata/src/rmeta
tests/ui/impl-trait/in-trait
5 files changed +32
-7
lines changed Original file line number Diff line number Diff line change @@ -837,11 +837,12 @@ fn should_encode_span(def_kind: DefKind) -> bool {
837
837
| DefKind :: AnonConst
838
838
| DefKind :: InlineConst
839
839
| DefKind :: OpaqueTy
840
+ | DefKind :: ImplTraitPlaceholder
840
841
| DefKind :: Field
841
842
| DefKind :: Impl { .. }
842
843
| DefKind :: Closure
843
844
| DefKind :: Generator => true ,
844
- DefKind :: ForeignMod | DefKind :: ImplTraitPlaceholder | DefKind :: GlobalAsm => false ,
845
+ DefKind :: ForeignMod | DefKind :: GlobalAsm => false ,
845
846
}
846
847
}
847
848
Original file line number Diff line number Diff line change 5
5
use std:: ops:: Deref ;
6
6
7
7
pub trait Foo {
8
- fn bar ( ) -> impl Deref < Target = impl Sized > ;
8
+ fn bar ( self ) -> impl Deref < Target = impl Sized > ;
9
9
}
10
10
11
11
pub struct Foreign ;
12
12
impl Foo for Foreign {
13
- fn bar ( ) -> & ' static ( ) { & ( ) }
13
+ fn bar ( self ) -> & ' static ( ) { & ( ) }
14
14
}
Original file line number Diff line number Diff line change
1
+ // aux-build: rpitit.rs
2
+
3
+ extern crate rpitit;
4
+
5
+ fn main ( ) {
6
+ let _: & dyn rpitit:: Foo = todo ! ( ) ;
7
+ //~^ ERROR the trait `Foo` cannot be made into an object
8
+ }
Original file line number Diff line number Diff line change
1
+ error[E0038]: the trait `Foo` cannot be made into an object
2
+ --> $DIR/foreign-dyn-error.rs:6:12
3
+ |
4
+ LL | let _: &dyn rpitit::Foo = todo!();
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/auxiliary/rpitit.rs:8:21
9
+ |
10
+ LL | fn bar(self) -> impl Deref<Target = impl Sized>;
11
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait cannot be made into an object because method `bar` references an `impl Trait` type in its return type
12
+
13
+ error: aborting due to previous error
14
+
15
+ For more information about this error, try `rustc --explain E0038`.
Original file line number Diff line number Diff line change 5
5
6
6
extern crate rpitit;
7
7
8
+ use rpitit:: { Foo , Foreign } ;
8
9
use std:: sync:: Arc ;
9
10
10
11
// Implement an RPITIT from another crate.
11
12
struct Local ;
12
- impl rpitit :: Foo for Local {
13
- fn bar ( ) -> Arc < String > { Arc :: new ( String :: new ( ) ) }
13
+ impl Foo for Local {
14
+ fn bar ( self ) -> Arc < String > { Arc :: new ( String :: new ( ) ) }
14
15
}
15
16
16
17
fn main ( ) {
17
18
// Witness an RPITIT from another crate.
18
- let & ( ) = <rpitit :: Foreign as rpitit :: Foo > :: bar ( ) ;
19
+ let & ( ) = Foreign . bar ( ) ;
19
20
20
- let x: Arc < String > = < Local as rpitit :: Foo > :: bar ( ) ;
21
+ let x: Arc < String > = Local . bar ( ) ;
21
22
}
You can’t perform that action at this time.
0 commit comments