diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-05-04 08:09:05 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-04 08:09:05 +0200 |
| commit | b194b43bd1ffdb6708b3eaa50c52d0a8c2199500 (patch) | |
| tree | 914809202b81b6b57dd30e2200637ec7de3161c1 | |
| parent | 6387eda3ba51acfcd27aa46429dc94cb66ae73a3 (diff) | |
| parent | ed468eebf6e852b80eeed6997c67444268795faa (diff) | |
| download | rust-b194b43bd1ffdb6708b3eaa50c52d0a8c2199500.tar.gz rust-b194b43bd1ffdb6708b3eaa50c52d0a8c2199500.zip | |
Rollup merge of #111039 - compiler-errors:foreign-span-rpitit, r=tmiasko
Encode def span for foreign return-position `impl Trait` in trait
Fixes #111031, yet another def-span encoding issue :/
Includes a smaller repro than the issue, but I can confirm it ICEs:
```
query stack during panic:
#0 [def_span] looking up span for `rpitit::Foo::bar::{opaque#0}`
#1 [object_safety_violations] determining object safety of trait `rpitit::Foo`
#2 [check_is_object_safe] checking if trait `rpitit::Foo` is object safe
#3 [typeck] type-checking `main`
#4 [used_trait_imports] finding used_trait_imports `main`
#5 [analysis] running analysis passes on this crate
```
Luckily since this only affects nightly, this desn't need to be backported.
| -rw-r--r-- | compiler/rustc_metadata/src/rmeta/encoder.rs | 3 | ||||
| -rw-r--r-- | tests/ui/impl-trait/in-trait/auxiliary/rpitit.rs | 4 | ||||
| -rw-r--r-- | tests/ui/impl-trait/in-trait/foreign-dyn-error.rs | 8 | ||||
| -rw-r--r-- | tests/ui/impl-trait/in-trait/foreign-dyn-error.stderr | 15 | ||||
| -rw-r--r-- | tests/ui/impl-trait/in-trait/foreign.rs | 9 |
5 files changed, 32 insertions, 7 deletions
diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 3253d0a9057..32f9e883fd6 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -837,11 +837,12 @@ fn should_encode_span(def_kind: DefKind) -> bool { | DefKind::AnonConst | DefKind::InlineConst | DefKind::OpaqueTy + | DefKind::ImplTraitPlaceholder | DefKind::Field | DefKind::Impl { .. } | DefKind::Closure | DefKind::Generator => true, - DefKind::ForeignMod | DefKind::ImplTraitPlaceholder | DefKind::GlobalAsm => false, + DefKind::ForeignMod | DefKind::GlobalAsm => false, } } diff --git a/tests/ui/impl-trait/in-trait/auxiliary/rpitit.rs b/tests/ui/impl-trait/in-trait/auxiliary/rpitit.rs index ffeabe5c2ed..776006124dc 100644 --- a/tests/ui/impl-trait/in-trait/auxiliary/rpitit.rs +++ b/tests/ui/impl-trait/in-trait/auxiliary/rpitit.rs @@ -5,10 +5,10 @@ use std::ops::Deref; pub trait Foo { - fn bar() -> impl Deref<Target = impl Sized>; + fn bar(self) -> impl Deref<Target = impl Sized>; } pub struct Foreign; impl Foo for Foreign { - fn bar() -> &'static () { &() } + fn bar(self) -> &'static () { &() } } diff --git a/tests/ui/impl-trait/in-trait/foreign-dyn-error.rs b/tests/ui/impl-trait/in-trait/foreign-dyn-error.rs new file mode 100644 index 00000000000..ecb5e62c433 --- /dev/null +++ b/tests/ui/impl-trait/in-trait/foreign-dyn-error.rs @@ -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 +} diff --git a/tests/ui/impl-trait/in-trait/foreign-dyn-error.stderr b/tests/ui/impl-trait/in-trait/foreign-dyn-error.stderr new file mode 100644 index 00000000000..6eef392c05f --- /dev/null +++ b/tests/ui/impl-trait/in-trait/foreign-dyn-error.stderr @@ -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`. diff --git a/tests/ui/impl-trait/in-trait/foreign.rs b/tests/ui/impl-trait/in-trait/foreign.rs index f4972d948b2..98417b343a1 100644 --- a/tests/ui/impl-trait/in-trait/foreign.rs +++ b/tests/ui/impl-trait/in-trait/foreign.rs @@ -5,17 +5,18 @@ extern crate rpitit; +use rpitit::{Foo, Foreign}; use std::sync::Arc; // Implement an RPITIT from another crate. struct Local; -impl rpitit::Foo for Local { - fn bar() -> Arc<String> { Arc::new(String::new()) } +impl Foo for Local { + fn bar(self) -> Arc<String> { Arc::new(String::new()) } } fn main() { // 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(); } |
