Skip to content

Commit 988c41f

Browse files
authored
Rollup merge of rust-lang#111039 - compiler-errors:foreign-span-rpitit, r=tmiasko
Encode def span for foreign return-position `impl Trait` in trait Fixes rust-lang#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` rust-lang#2 [check_is_object_safe] checking if trait `rpitit::Foo` is object safe rust-lang#3 [typeck] type-checking `main` rust-lang#4 [used_trait_imports] finding used_trait_imports `main` rust-lang#5 [analysis] running analysis passes on this crate ``` Luckily since this only affects nightly, this desn't need to be backported.
2 parents 0b1d571 + ed468ee commit 988c41f

File tree

5 files changed

+32
-7
lines changed

5 files changed

+32
-7
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

+2-1
Original file line numberDiff line numberDiff 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

tests/ui/impl-trait/in-trait/auxiliary/rpitit.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
use std::ops::Deref;
66

77
pub trait Foo {
8-
fn bar() -> impl Deref<Target = impl Sized>;
8+
fn bar(self) -> impl Deref<Target = impl Sized>;
99
}
1010

1111
pub struct Foreign;
1212
impl Foo for Foreign {
13-
fn bar() -> &'static () { &() }
13+
fn bar(self) -> &'static () { &() }
1414
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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`.

tests/ui/impl-trait/in-trait/foreign.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@
55

66
extern crate rpitit;
77

8+
use rpitit::{Foo, Foreign};
89
use std::sync::Arc;
910

1011
// Implement an RPITIT from another crate.
1112
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()) }
1415
}
1516

1617
fn 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
}

0 commit comments

Comments
 (0)