Closed
Description
The following code (playground link) results in a method resolution error on the second call to x.method()
. It compiles successfully if x.method()
is called only once:
trait Foo {
fn method(&self) {}
}
struct Wrapper<T>(T);
impl<T> Foo for Wrapper<T> where for<'a> &'a T: IntoIterator<Item=&'a ()> {}
fn f(x: Wrapper<Vec<()>>) {
x.method(); // This works.
x.method(); // error: no method named `method`
}
The error is:
error: no method named `method` found for type `Wrapper<std::vec::Vec<()>>` in the current scope
--> <anon>:11:7
|
11 | x.method(); // error: no method named `method`
| ^^^^^^
|
= help: items from traits can only be used if the trait is implemented and in scope; the following trait defines an item `method`, perhaps you need to implement it:
= help: candidate #1: `Foo`
@jonas-schievink suggested this might be a bug in the projection cache or some other cache.
This is a regression from Rust 1.10.0-stable to 1.11.0-stable.
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
jonas-schievink commentedon Oct 13, 2016
In case it's useful to anyone, here's a
rustc::traits=DEBUG
log at the current master (commit d34318d)EDIT:
Here is the log with
rustc_typeck::check::method=DEBUG,rustc::traits=DEBUG,rustc::middle=DEBUG
and a smalldebug!
in method probing added by me: https://gist.github.com/jonas-schievink/9551715c4f2bc05a8359e1dafddf7f8eIn particular, the first call causes this:
While the log contains 2 (not sure why not just one) occurrences of this (this logging statement was added by me, so don't go searching the logs from master), after the first call has been resolved:
Which then causes
method::probe
to drop the candidate on the ground.jonas-schievink commentedon Oct 14, 2016
This, like #36325, was introduced between these two nightlies:
Works on
nightly-2016-06-04
Broken on
nightly-2016-06-05
These regressions likely have the same cause. I suspect the projection cache, introduced in #33816.
cc @nikomatsakis
arielb1 commentedon Oct 14, 2016
The projection cache indeed looks like it.
nikomatsakis commentedon Oct 18, 2016
So yes did a bit of digging and the projection cache is indeed doing some inappropriate caching here. I have a hacky fix; currently debating about a mildly less hacky one. Still not overly happy with how we handle skolemization today but that's another story. =)
nikomatsakis commentedon Oct 19, 2016
Pending PR: #37294
brson commentedon Oct 20, 2016
Thanks @nikomatsakis !
add regression test for rust-lang#37154
Auto merge of #37294 - nikomatsakis:issue-37154, r=nikomatsakis