Skip to content

Try to only suggest traits that can be implemented for method calls. #21675

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
Feb 3, 2015

Conversation

huonw
Copy link
Member

@huonw huonw commented Jan 27, 2015

That is, when offering suggestions for unresolved method calls, avoid
suggesting traits for which implementing the trait for the receiver type
either makes little sense (e.g. type errors, or sugared unboxed
closures), or violates coherence.

The latter is approximated by ensuring that at least one of {receiver type, trait} is local. This isn't precisely correct due to
multidispatch, but the error messages one encounters in such situation
are useless more often than not; it is better to be conservative and
miss some cases, than have overly many false positives (e.g. writing
some_slice.map(|x| ...) uselessly suggested that one should implement
IteratorExt for &[T], while the correct fix is to call .iter()).

Closes #21420.

@rust-highfive
Copy link
Contributor

r? @nikomatsakis

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

@huonw huonw force-pushed the less-false-positives branch from 3a89b6e to 78119ae Compare January 30, 2015 01:56
@nikomatsakis
Copy link
Contributor

@bors r+ 78119ae

@bors
Copy link
Collaborator

bors commented Jan 30, 2015

⌛ Testing commit 78119ae with merge 8f50ce0...

@bors
Copy link
Collaborator

bors commented Jan 30, 2015

💔 Test failed - auto-mac-64-opt

@huonw huonw force-pushed the less-false-positives branch 2 times, most recently from efbac8a to 4ec027f Compare January 31, 2015 05:38
@huonw
Copy link
Member Author

huonw commented Jan 31, 2015

@bors r=nikomatsakis 4ec027f

@bors
Copy link
Collaborator

bors commented Jan 31, 2015

⌛ Testing commit 4ec027f with merge bbcb2b8...

@bors
Copy link
Collaborator

bors commented Jan 31, 2015

💔 Test failed - auto-mac-64-opt

That is, when offering suggestions for unresolved method calls, avoid
suggesting traits for which implementing the trait for the receiver type
either makes little sense (e.g. type errors, or sugared unboxed
closures), or violates coherence.

The latter is approximated by ensuring that at least one of `{receiver
type, trait}` is local. This isn't precisely correct due to
multidispatch, but the error messages one encounters in such situation
are useless more often than not; it is better to be conservative and
miss some cases, than have overly many false positives (e.g. writing
`some_slice.map(|x| ...)` uselessly suggested that one should implement
`IteratorExt` for `&[T]`, while the correct fix is to call `.iter()`).

Closes rust-lang#21420.
@huonw huonw force-pushed the less-false-positives branch from 4ec027f to e81ae40 Compare February 3, 2015 11:34
@huonw
Copy link
Member Author

huonw commented Feb 3, 2015

@bors r=nikomatsakis e81a

@bors
Copy link
Collaborator

bors commented Feb 3, 2015

⌛ Testing commit e81ae40 with merge 3d072a1...

bors added a commit that referenced this pull request Feb 3, 2015
That is, when offering suggestions for unresolved method calls, avoid
suggesting traits for which implementing the trait for the receiver type
either makes little sense (e.g. type errors, or sugared unboxed
closures), or violates coherence.

The latter is approximated by ensuring that at least one of `{receiver
type, trait}` is local. This isn't precisely correct due to
multidispatch, but the error messages one encounters in such situation
are useless more often than not; it is better to be conservative and
miss some cases, than have overly many false positives (e.g. writing
`some_slice.map(|x| ...)` uselessly suggested that one should implement
`IteratorExt` for `&[T]`, while the correct fix is to call `.iter()`).

Closes #21420.
@bors bors merged commit e81ae40 into rust-lang:master Feb 3, 2015
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.

"implement this trait" suggestions should only list traits for which that is actually legal
4 participants