Encode def span for foreign RPITITs
This commit is contained in:
parent
831c9298c8
commit
ed468eebf6
@ -837,11 +837,12 @@ fn should_encode_span(def_kind: DefKind) -> bool {
|
|||||||
| DefKind::AnonConst
|
| DefKind::AnonConst
|
||||||
| DefKind::InlineConst
|
| DefKind::InlineConst
|
||||||
| DefKind::OpaqueTy
|
| DefKind::OpaqueTy
|
||||||
|
| DefKind::ImplTraitPlaceholder
|
||||||
| DefKind::Field
|
| DefKind::Field
|
||||||
| DefKind::Impl { .. }
|
| DefKind::Impl { .. }
|
||||||
| DefKind::Closure
|
| DefKind::Closure
|
||||||
| DefKind::Generator => true,
|
| DefKind::Generator => true,
|
||||||
DefKind::ForeignMod | DefKind::ImplTraitPlaceholder | DefKind::GlobalAsm => false,
|
DefKind::ForeignMod | DefKind::GlobalAsm => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,10 +5,10 @@
|
|||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
pub trait Foo {
|
pub trait Foo {
|
||||||
fn bar() -> impl Deref<Target = impl Sized>;
|
fn bar(self) -> impl Deref<Target = impl Sized>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Foreign;
|
pub struct Foreign;
|
||||||
impl Foo for Foreign {
|
impl Foo for Foreign {
|
||||||
fn bar() -> &'static () { &() }
|
fn bar(self) -> &'static () { &() }
|
||||||
}
|
}
|
||||||
|
8
tests/ui/impl-trait/in-trait/foreign-dyn-error.rs
Normal file
8
tests/ui/impl-trait/in-trait/foreign-dyn-error.rs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
// aux-build: rpitit.rs
|
||||||
|
|
||||||
|
extern crate rpitit;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let _: &dyn rpitit::Foo = todo!();
|
||||||
|
//~^ ERROR the trait `Foo` cannot be made into an object
|
||||||
|
}
|
15
tests/ui/impl-trait/in-trait/foreign-dyn-error.stderr
Normal file
15
tests/ui/impl-trait/in-trait/foreign-dyn-error.stderr
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
error[E0038]: the trait `Foo` cannot be made into an object
|
||||||
|
--> $DIR/foreign-dyn-error.rs:6:12
|
||||||
|
|
|
||||||
|
LL | let _: &dyn rpitit::Foo = todo!();
|
||||||
|
| ^^^^^^^^^^^^^^^^ `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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
|
||||||
|
--> $DIR/auxiliary/rpitit.rs:8:21
|
||||||
|
|
|
||||||
|
LL | fn bar(self) -> impl Deref<Target = impl Sized>;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait cannot be made into an object because method `bar` references an `impl Trait` type in its return type
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0038`.
|
@ -5,17 +5,18 @@
|
|||||||
|
|
||||||
extern crate rpitit;
|
extern crate rpitit;
|
||||||
|
|
||||||
|
use rpitit::{Foo, Foreign};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
// Implement an RPITIT from another crate.
|
// Implement an RPITIT from another crate.
|
||||||
struct Local;
|
struct Local;
|
||||||
impl rpitit::Foo for Local {
|
impl Foo for Local {
|
||||||
fn bar() -> Arc<String> { Arc::new(String::new()) }
|
fn bar(self) -> Arc<String> { Arc::new(String::new()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Witness an RPITIT from another crate.
|
// Witness an RPITIT from another crate.
|
||||||
let &() = <rpitit::Foreign as rpitit::Foo>::bar();
|
let &() = Foreign.bar();
|
||||||
|
|
||||||
let x: Arc<String> = <Local as rpitit::Foo>::bar();
|
let x: Arc<String> = Local.bar();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user