-
Notifications
You must be signed in to change notification settings - Fork 13.4k
On type mismatch involving associated type, suggest constraint #71108
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
bors
merged 11 commits into
rust-lang:master
from
estebank:suggest-proj-type-mismatch-constraint
May 4, 2020
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3a795fb
On type mismatch involving associated type, suggest constraint
estebank 31b3566
When a projection is expected, suggest constraining or calling method
estebank ee96b8b
review comment: use or patterns
estebank 299bd12
Point at associated types when they have a default type
estebank 6648a08
fix rebase
estebank b0085c8
Suggest constraint on `impl Trait` in return type
estebank 9bb5b54
Add docs
estebank 74b7ed7
trailing newlines
estebank de3b4d4
fix rebase
estebank 3c872e2
review comments: move logic to their own methods
estebank b368229
review comment: use early return
estebank File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 7 additions & 5 deletions
12
src/test/ui/associated-types/defaults-in-other-trait-items.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/test/ui/associated-types/impl-trait-return-missing-constraint.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
trait Foo { | ||
type Item; | ||
} | ||
|
||
trait Bar: Foo {} | ||
|
||
struct S; | ||
|
||
impl Foo for S { | ||
type Item = i32; | ||
} | ||
impl Bar for S {} | ||
|
||
struct T; | ||
|
||
impl Foo for T { | ||
type Item = u32; | ||
} | ||
impl Bar for T {} | ||
|
||
fn bar() -> impl Bar { | ||
T | ||
} | ||
|
||
fn baz() -> impl Bar<Item = i32> { | ||
//~^ ERROR type mismatch resolving `<impl Bar as Foo>::Item == i32` | ||
bar() | ||
} | ||
|
||
fn main() { | ||
let _ = baz(); | ||
} |
20 changes: 20 additions & 0 deletions
20
src/test/ui/associated-types/impl-trait-return-missing-constraint.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
error[E0271]: type mismatch resolving `<impl Bar as Foo>::Item == i32` | ||
--> $DIR/impl-trait-return-missing-constraint.rs:25:13 | ||
| | ||
LL | fn bar() -> impl Bar { | ||
| -------- the expected opaque type | ||
... | ||
LL | fn baz() -> impl Bar<Item = i32> { | ||
| ^^^^^^^^^^^^^^^^^^^^ expected associated type, found `i32` | ||
| | ||
= note: expected associated type `<impl Bar as Foo>::Item` | ||
found type `i32` | ||
= note: the return type of a function must have a statically known size | ||
help: consider constraining the associated type `<impl Bar as Foo>::Item` to `i32` | ||
| | ||
LL | fn bar() -> impl Bar<Item = i32> { | ||
| ^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0271`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.