Description
If I take this arbitrary example (that supports cross-crate spans, via tcx.def_span(...)
):
struct Foo;
impl Extend<()> for Foo {
fn extend(&mut self, _: impl IntoIterator<Item = ()>) {}
}
fn main() {}
and compiling it with a local rustc build, I get this error (note the libcore
snippet):
(NB: if that snippet disappears, find other tcx.def_span(...)
-using diagnostics and replace the test)
error[E0643]: method `extend` has incompatible signature for trait
--> xcrate-span.rs:3:29
|
3 | fn extend(&mut self, _: impl IntoIterator<Item = ()>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected generic parameter, found `impl Trait`
|
::: /home/eddy/Projects/rust-2/src/libcore/iter/traits.rs:355:15
|
355 | fn extend<T: IntoIterator<Item=A>>(&mut self, iter: T);
| - declaration in trait here
but if try with rustup
-provided rustc
, I only get this shorter error:
error[E0643]: method `extend` has incompatible signature for trait
--> xcrate-spans.rs:3:29
|
3 | fn extend(&mut self, _: impl IntoIterator<Item = ()>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected generic parameter, found `impl Trait`
But $(rustc --print=sysroot)/lib/rustlib/src/rust/src/libcore/iter/traits.rs
does exist, because I have the rust-src
component enabled (it's enabled by default, which makes it likely to exist for most users), so it should be possible in theory, to teach rustc to look up certain paths relative to lib/rustlib/src/rust
inside the sysroot, if it exists.
Running this:
strings $(rustc --print=sysroot)/lib/rustlib/*/lib/libcore-*.rlib | rg 'iter/traits\.rs'
shows that /checkout/src/libcore/iter/traits.rs
and libcore/iter/traits.rs
both exist in the rlib
, and I assume the former is the one that it tries to load - we can even test this:
# Let's live a little...
sudo ln -s $(rustc --print=sysroot)/lib/rustlib/src/rust /checkout
Trying the test again, we now get:
error[E0643]: method `extend` has incompatible signature for trait
--> xcrate-spans.rs:3:29
|
3 | fn extend(&mut self, _: impl IntoIterator<Item = ()>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected generic parameter, found `impl Trait`
|
::: /checkout/src/libcore/iter/traits.rs:355:15
|
355 | fn extend<T: IntoIterator<Item=A>>(&mut self, iter: T);
| - declaration in trait here
So it's definitely compatible, the hash check passes and whatnot, we just need to rename /checkout
to something artificial like $rust
, I'm guessing.
# ... but also clean up afterwards.
sudo rm /checkout
cc @alexcrichton @rust-lang/dev-tools @rust-lang/compiler