Skip to content

Provide a note if method lookup fails and there are static definitions with the same name. #13685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2014

Conversation

Ryman
Copy link
Contributor

@Ryman Ryman commented Apr 22, 2014

Closes #7575.

I don't think the change from a contains lookup to an iteration of the HashSet in the resolver should be much of a burden as the set of methods with the same name should be relatively small.

t.is_str()
//~^ ERROR type `T` does not implement any method in scope named `is_str`
//~^^ NOTE found defined static methods, did you forget a self parameter?
//~^^^ NOTE candidate #1 is `std::path::BytesContainer::is_str`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move the dependence from libstd into this test? The standard library often changes over time and may cause this to be accidentally deleted at some point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I can replicate a similar test in the file. But, do you have a good reference for a test using an external crates definitions? I'd like to ensure that methods from other crates are listed.

@eddyb
Copy link
Member

eddyb commented Apr 23, 2014

cc @nikomatsakis I can't tell how badly this impacts method lookup.
@Ryman you'd be surprised to see hundreds of methods per name, don't take performance issues lightly ;).

@Ryman
Copy link
Contributor Author

Ryman commented Apr 23, 2014

@eddyb Actually, scratch that, there was a reason why I couldn't use a Hashmap at one point, but looking back on this freshly I don't see whatever reason I had. So, I'll update to a Hashmap<DefId, ExplicitSelf_> and it should be back to as before.

@Ryman
Copy link
Contributor Author

Ryman commented Apr 24, 2014

Updated commit includes above feedback and is rebased on master (fixed conflicts with @ removal)

@huonw
Copy link
Member

huonw commented May 2, 2014

This looks very helpful, thanks.

There's some docs here for cross-crate tests.

@@ -5152,7 +5154,7 @@ impl<'a> Resolver<'a> {
Some(DefTrait(trait_def_id)) => trait_def_id,
Some(..) | None => continue,
};
if self.method_set.borrow().contains(&(name, did)) {
if self.method_map.borrow().contains_key(&(name, did)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes to resolve look like they'll start resolving static functions as candidates for methods (possibly). Can you make sure that code like this still compiles?

trait Foo {
    fn new() {}
}

trait Bar {
    fn new(&self) {}
}

impl Bar for int {}
impl Foo for int {}

fn main() {
    1i.new();
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only checks for static methods on failed method lookup (and it's going to report an error regardless of finding a static, it just sugars the error), so this code will compile fine as the method lookup won't fail.

I couldn't find a runpass test for this name overlap, so I just added one for posterity. (In latest commit)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh excellent, thank you!

@alexcrichton
Copy link
Member

This looks great, thanks @Ryman!

bors added a commit that referenced this pull request May 3, 2014
Closes #7575.

I don't think the change from a contains lookup to an iteration of the HashSet in the resolver should be much of a burden as the set of methods with the same name should be relatively small.
@bors bors closed this May 3, 2014
@bors bors merged commit cb08cb8 into rust-lang:master May 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

unhelpful error message for missing (first) self param on traiit method
5 participants