Skip to content

Regression: "no method found" error when calling same method twice, with HRTB impl #37154

Closed
@mbrubeck

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

Assignees

Labels

P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions