Skip to content
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

Fix ICE when arg types can't be found in impl/trait methods while comparing #35877

Merged
merged 2 commits into from
Aug 27, 2016

Conversation

KiChjang
Copy link
Member

Fixes #35869.

@rust-highfive
Copy link
Collaborator

r? @pnkfelix

(rust_highfive has picked a reviewer for you, use r? to override)

@KiChjang
Copy link
Member Author

r? @jonathandturner

@KiChjang
Copy link
Member Author

Gah, this isn't as easy as I thought, we'd have to go through all wrapper types in the argument...

expected: ty::Ty<'tcx>,
found: ty::Ty<'tcx>) -> bool {
(impl_arg_ty == found && trait_arg_ty == expected) ||
match (&impl_arg_ty.sty, &trait_arg_ty.sty) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Hopefully I caught all the necessary types in this match...

@nikomatsakis
Copy link
Contributor

r? @nikomatsakis

@KiChjang
Copy link
Member Author

KiChjang commented Aug 23, 2016

Okay, discussions with @eddyb on IRC indicated that this enormous match against types is pretty hacky and inaccurate. Instead, we should either:

  1. Copy the FnSig Relate impl and recording where the mismatch happened; or
  2. Have a second pass at sub_types for each argument in case of an error (the calling syntax would be infcx.sub_types(true, origin, trait_arg_ty, impl_arg_ty))

Both of which are much better than traversing through the type variants that I currently have in my implementation.

@KiChjang
Copy link
Member Author

KiChjang commented Aug 24, 2016

The giant match is gone, and is now replaced with several passes to infcx.sub_types for each argument. r? @nikomatsakis


if infcx.sub_types(false, origin, impl_sig.output, trait_sig.output).is_err() {
return (impl_m_output.span(), Some(trait_m_output.span()));
}
Copy link
Member

Choose a reason for hiding this comment

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

This should be last, because it's checked last in the whole function check.

@KiChjang
Copy link
Member Author

Comments addressed.

@arielb1
Copy link
Contributor

arielb1 commented Aug 25, 2016

@bors r+

@bors
Copy link
Contributor

bors commented Aug 25, 2016

📌 Commit 3d9cf30 has been approved by arielb1

@arielb1
Copy link
Contributor

arielb1 commented Aug 25, 2016

I think this would have an ugly span when the mismatch is on the return type. e.g. when the trait fn is fn foo(&self) -> i32 and the impl fn is fn foo(&self) -> i64.

@bors r-

.unwrap_or_else(|| {
if infcx.sub_types(false, origin, impl_sig.output,
trait_sig.output).is_err() {
(impl_m_output.span(), Some(trait_m_output.span()))
Copy link
Member Author

@KiChjang KiChjang Aug 26, 2016

Choose a reason for hiding this comment

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

@arielb1 I don't see a way to improve this? If we're not grabbing the span of the type, are we supposed to grab the span of the entire function declaration?

@arielb1
Copy link
Contributor

arielb1 commented Aug 26, 2016

@bors r+

@bors
Copy link
Contributor

bors commented Aug 26, 2016

📌 Commit 3d9cf30 has been approved by arielb1


impl Foo for Bar {
fn foo(_: fn(u16) -> ()) {}
//~^ ERROR method `foo` has an incompatible type for trait
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: maybe this should be a ui test? It's hard to tell just what is being highlighted here. :)

@nikomatsakis
Copy link
Contributor

I've not had a chance to read this patch carefully, but if @arielb1 is satisfied, I guess I am. ;) Still, I think a ui test would be better.

Manishearth added a commit to Manishearth/rust that referenced this pull request Aug 27, 2016
Fix ICE when arg types can't be found in impl/trait methods while comparing

Fixes rust-lang#35869.
@bors
Copy link
Contributor

bors commented Aug 27, 2016

⌛ Testing commit 3d9cf30 with merge 698d4c9...

@bors
Copy link
Contributor

bors commented Aug 27, 2016

⛄ The build was interrupted to prioritize another pull request.

@bors
Copy link
Contributor

bors commented Aug 27, 2016

⌛ Testing commit 3d9cf30 with merge 6b74503...

bors added a commit that referenced this pull request Aug 27, 2016
Fix ICE when arg types can't be found in impl/trait methods while comparing

Fixes #35869.
@bors bors merged commit 3d9cf30 into rust-lang:master Aug 27, 2016
bors added a commit that referenced this pull request Aug 27, 2016
Rollup of 7 pull requests

- Successful merges: #35124, #35877, #35953, #36002, #36004, #36005, #36014
- Failed merges:
@KiChjang KiChjang deleted the issue-35869 branch August 27, 2016 10:21
@durka
Copy link
Contributor

durka commented Aug 30, 2016

Did this not fix the bug or is the playpen not updating anymore?

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.

9 participants