Skip to content

Conversation

rozbb
Copy link

@rozbb rozbb commented Jul 13, 2016

The code below triggers the panic, and is included in a new regression test.

trait Foo {
    fn foo();
}

use Foo::foo;

fn main() {
    foo();
}

The bug is caused by librustc_resolve allowing the illegal binding to be imported even after displaying the error message above.

The fix amounts to importing a dummy binding (rustc::hir::def::Def::Err) instead of the actual trait method.

@jseyfried
Copy link
Contributor

@doomrobo
The run-pass test won't pass since importing the method is an error.
The test should be in compile-fail -- there, use Foo::foo; //~ ERROR not directly importable will allow (and require) the error on that line.

Also, two nits:

  • the impl items are irrelevant to this issue and can be removed from the test and the initial comment, and
  • I don't think the old rustc output isn't needed in the initial comment (which ends up being the merge commit message for the PR).

@rozbb rozbb force-pushed the fix-import-trait-method branch from dcddb16 to dfad625 Compare July 13, 2016 06:25
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs a comment //~ ERROR not directly importable for the test to pass

Copy link
Contributor

Choose a reason for hiding this comment

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

i.e. use Foo::foo; //~ ERROR not directly importable

@rozbb rozbb force-pushed the fix-import-trait-method branch from dfad625 to 5a99d79 Compare July 13, 2016 06:34
@jseyfried
Copy link
Contributor

Thanks! @bors r+

@bors
Copy link
Collaborator

bors commented Jul 13, 2016

📌 Commit 5a99d79 has been approved by jseyfried

@bors
Copy link
Collaborator

bors commented Jul 14, 2016

⌛ Testing commit 5a99d79 with merge e08a6c2...

bors added a commit that referenced this pull request Jul 14, 2016
Fixed issue where importing a trait method directly and then calling the method causes a compiler panic

The code below triggers the panic, and is included in a new regression test.

```rust
trait Foo {
    fn foo();
}

use Foo::foo;

fn main() {
    foo();
}
```
The bug is caused by `librustc_resolve` allowing the illegal binding to be imported even after displaying the error message above.

The fix amounts to importing a dummy binding (`rustc::hir::def::Def::Err`) instead of the actual trait method.
@bors bors merged commit 5a99d79 into rust-lang:master Jul 15, 2016
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.

4 participants