File tree Expand file tree Collapse file tree 5 files changed +32
-7
lines changed
compiler/rustc_metadata/src/rmeta
tests/ui/impl-trait/in-trait Expand file tree Collapse file tree 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 {
837837 | DefKind :: AnonConst
838838 | DefKind :: InlineConst
839839 | DefKind :: OpaqueTy
840+ | DefKind :: ImplTraitPlaceholder
840841 | DefKind :: Field
841842 | DefKind :: Impl { .. }
842843 | DefKind :: Closure
843844 | DefKind :: Generator => true ,
844- DefKind :: ForeignMod | DefKind :: ImplTraitPlaceholder | DefKind :: GlobalAsm => false ,
845+ DefKind :: ForeignMod | DefKind :: GlobalAsm => false ,
845846 }
846847}
847848
Original file line number Diff line number Diff line change 55use std:: ops:: Deref ;
66
77pub trait Foo {
8- fn bar ( ) -> impl Deref < Target = impl Sized > ;
8+ fn bar ( self ) -> impl Deref < Target = impl Sized > ;
99}
1010
1111pub struct Foreign ;
1212impl Foo for Foreign {
13- fn bar ( ) -> & ' static ( ) { & ( ) }
13+ fn bar ( self ) -> & ' static ( ) { & ( ) }
1414}
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 55
66extern crate rpitit;
77
8+ use rpitit:: { Foo , Foreign } ;
89use std:: sync:: Arc ;
910
1011// Implement an RPITIT from another crate.
1112struct 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 ( ) ) }
1415}
1516
1617fn main ( ) {
1718 // Witness an RPITIT from another crate.
18- let & ( ) = <rpitit :: Foreign as rpitit :: Foo > :: bar ( ) ;
19+ let & ( ) = Foreign . bar ( ) ;
1920
20- let x: Arc < String > = < Local as rpitit :: Foo > :: bar ( ) ;
21+ let x: Arc < String > = Local . bar ( ) ;
2122}
You can’t perform that action at this time.
0 commit comments