-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Point out the type of associated types in every method call of iterator chains #105332
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
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
bc60d50
Provide associated type information in method chains
compiler-errors 49d5bef
Expand iterator chain test
estebank 64bc975
Mention only assoc types changes
estebank 71db025
Account for method call chains split across multiple bindings
estebank c77ad2d
Remove mention of "assoc type" in label as it is already in the `note…
estebank aff0ab4
Add label to method chains where assoc type remains the same
estebank 78f9759
Only point at methods that might be relevant
estebank 8d9ffa3
fix rebase
estebank ce486d5
Use `with_forced_trimmed_paths`
estebank 2838b8e
Point at method call when it is the source of the bound error
estebank 3483869
Move logic to their own methods
estebank f4ed2d1
Do not `skip_binder`s
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
388 changes: 352 additions & 36 deletions
388
compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
fn main() { | ||
let scores = vec![(0, 0)] | ||
.iter() | ||
.map(|(a, b)| { | ||
a + b; | ||
}); | ||
println!("{}", scores.sum::<i32>()); //~ ERROR E0277 | ||
println!( | ||
"{}", | ||
vec![0, 1] //~ ERROR E0277 | ||
.iter() | ||
.map(|x| x * 2) | ||
.map(|x| x as f64) | ||
.map(|x| x as i64) | ||
.filter(|x| *x > 0) | ||
.map(|x| { x + 1 }) | ||
.map(|x| { x; }) | ||
.sum::<i32>(), | ||
); | ||
println!( | ||
"{}", | ||
vec![0, 1] //~ ERROR E0277 | ||
.iter() | ||
.map(|x| x * 2) | ||
.map(|x| x as f64) | ||
.filter(|x| *x > 0.0) | ||
.map(|x| { x + 1.0 }) | ||
.sum::<i32>(), | ||
); | ||
println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::<i32>()); //~ ERROR E0277 | ||
println!("{}", vec![(), ()].iter().sum::<i32>()); //~ ERROR E0277 | ||
let a = vec![0]; | ||
let b = a.into_iter(); | ||
let c = b.map(|x| x + 1); | ||
let d = c.filter(|x| *x > 10 ); | ||
let e = d.map(|x| { | ||
x + 1; | ||
}); | ||
let f = e.filter(|_| false); | ||
let g: Vec<i32> = f.collect(); //~ ERROR E0277 | ||
} |
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,199 @@ | ||
error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `()` | ||
--> $DIR/invalid-iterator-chain.rs:7:20 | ||
| | ||
LL | println!("{}", scores.sum::<i32>()); | ||
| ^^^^^^ --- required by a bound introduced by this call | ||
| | | ||
| value of type `i32` cannot be made by summing a `std::iter::Iterator<Item=()>` | ||
| | ||
= help: the trait `Sum<()>` is not implemented for `i32` | ||
= help: the following other types implement trait `Sum<A>`: | ||
<i32 as Sum<&'a i32>> | ||
<i32 as Sum> | ||
note: the method call chain might not have had the expected associated types | ||
--> $DIR/invalid-iterator-chain.rs:4:10 | ||
| | ||
LL | let scores = vec![(0, 0)] | ||
| ------------ this expression has type `Vec<({integer}, {integer})>` | ||
LL | .iter() | ||
| ------ `Iterator::Item` is `&({integer}, {integer})` here | ||
LL | .map(|(a, b)| { | ||
| __________^ | ||
LL | | a + b; | ||
LL | | }); | ||
| |__________^ `Iterator::Item` changed to `()` here | ||
note: required by a bound in `std::iter::Iterator::sum` | ||
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | ||
| | ||
LL | S: Sum<Self::Item>, | ||
| ^^^^^^^^^^^^^^^ required by this bound in `Iterator::sum` | ||
|
||
error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `()` | ||
--> $DIR/invalid-iterator-chain.rs:10:9 | ||
| | ||
LL | / vec![0, 1] | ||
LL | | .iter() | ||
LL | | .map(|x| x * 2) | ||
LL | | .map(|x| x as f64) | ||
... | | ||
LL | | .map(|x| { x + 1 }) | ||
LL | | .map(|x| { x; }) | ||
| |____________________________^ value of type `i32` cannot be made by summing a `std::iter::Iterator<Item=()>` | ||
LL | .sum::<i32>(), | ||
| --- required by a bound introduced by this call | ||
| | ||
= help: the trait `Sum<()>` is not implemented for `i32` | ||
= help: the following other types implement trait `Sum<A>`: | ||
<i32 as Sum<&'a i32>> | ||
<i32 as Sum> | ||
note: the method call chain might not have had the expected associated types | ||
--> $DIR/invalid-iterator-chain.rs:12:14 | ||
| | ||
LL | vec![0, 1] | ||
| ---------- this expression has type `Vec<{integer}>` | ||
LL | .iter() | ||
| ------ `Iterator::Item` is `&{integer}` here | ||
LL | .map(|x| x * 2) | ||
| ^^^^^^^^^^^^^^ `Iterator::Item` changed to `{integer}` here | ||
LL | .map(|x| x as f64) | ||
| ----------------- `Iterator::Item` changed to `f64` here | ||
LL | .map(|x| x as i64) | ||
| ----------------- `Iterator::Item` changed to `i64` here | ||
LL | .filter(|x| *x > 0) | ||
| ------------------ `Iterator::Item` remains `i64` here | ||
LL | .map(|x| { x + 1 }) | ||
| ------------------ `Iterator::Item` remains `i64` here | ||
LL | .map(|x| { x; }) | ||
| ^^^^^^^^^^^^^^^ `Iterator::Item` changed to `()` here | ||
note: required by a bound in `std::iter::Iterator::sum` | ||
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | ||
| | ||
LL | S: Sum<Self::Item>, | ||
| ^^^^^^^^^^^^^^^ required by this bound in `Iterator::sum` | ||
|
||
error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `f64` | ||
--> $DIR/invalid-iterator-chain.rs:22:9 | ||
| | ||
LL | / vec![0, 1] | ||
LL | | .iter() | ||
LL | | .map(|x| x * 2) | ||
LL | | .map(|x| x as f64) | ||
LL | | .filter(|x| *x > 0.0) | ||
LL | | .map(|x| { x + 1.0 }) | ||
| |_________________________________^ value of type `i32` cannot be made by summing a `std::iter::Iterator<Item=f64>` | ||
LL | .sum::<i32>(), | ||
| --- required by a bound introduced by this call | ||
| | ||
= help: the trait `Sum<f64>` is not implemented for `i32` | ||
= help: the following other types implement trait `Sum<A>`: | ||
<i32 as Sum<&'a i32>> | ||
<i32 as Sum> | ||
note: the method call chain might not have had the expected associated types | ||
--> $DIR/invalid-iterator-chain.rs:24:14 | ||
| | ||
LL | vec![0, 1] | ||
| ---------- this expression has type `Vec<{integer}>` | ||
LL | .iter() | ||
| ------ `Iterator::Item` is `&{integer}` here | ||
LL | .map(|x| x * 2) | ||
| ^^^^^^^^^^^^^^ `Iterator::Item` changed to `{integer}` here | ||
LL | .map(|x| x as f64) | ||
| ^^^^^^^^^^^^^^^^^ `Iterator::Item` changed to `f64` here | ||
LL | .filter(|x| *x > 0.0) | ||
| -------------------- `Iterator::Item` remains `f64` here | ||
LL | .map(|x| { x + 1.0 }) | ||
| -------------------- `Iterator::Item` remains `f64` here | ||
note: required by a bound in `std::iter::Iterator::sum` | ||
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | ||
| | ||
LL | S: Sum<Self::Item>, | ||
| ^^^^^^^^^^^^^^^ required by this bound in `Iterator::sum` | ||
|
||
error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `()` | ||
--> $DIR/invalid-iterator-chain.rs:30:20 | ||
| | ||
LL | println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::<i32>()); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ --- required by a bound introduced by this call | ||
| | | ||
| value of type `i32` cannot be made by summing a `std::iter::Iterator<Item=()>` | ||
| | ||
= help: the trait `Sum<()>` is not implemented for `i32` | ||
= help: the following other types implement trait `Sum<A>`: | ||
<i32 as Sum<&'a i32>> | ||
<i32 as Sum> | ||
note: the method call chain might not have had the expected associated types | ||
--> $DIR/invalid-iterator-chain.rs:30:38 | ||
| | ||
LL | println!("{}", vec![0, 1].iter().map(|x| { x; }).sum::<i32>()); | ||
| ---------- ------ ^^^^^^^^^^^^^^^ `Iterator::Item` changed to `()` here | ||
| | | | ||
| | `Iterator::Item` is `&{integer}` here | ||
| this expression has type `Vec<{integer}>` | ||
note: required by a bound in `std::iter::Iterator::sum` | ||
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | ||
| | ||
LL | S: Sum<Self::Item>, | ||
| ^^^^^^^^^^^^^^^ required by this bound in `Iterator::sum` | ||
|
||
error[E0277]: a value of type `i32` cannot be made by summing an iterator over elements of type `&()` | ||
--> $DIR/invalid-iterator-chain.rs:31:20 | ||
| | ||
LL | println!("{}", vec![(), ()].iter().sum::<i32>()); | ||
| ^^^^^^^^^^^^^^^^^^^ --- required by a bound introduced by this call | ||
| | | ||
| value of type `i32` cannot be made by summing a `std::iter::Iterator<Item=&()>` | ||
| | ||
= help: the trait `Sum<&()>` is not implemented for `i32` | ||
= help: the following other types implement trait `Sum<A>`: | ||
<i32 as Sum<&'a i32>> | ||
<i32 as Sum> | ||
note: the method call chain might not have had the expected associated types | ||
--> $DIR/invalid-iterator-chain.rs:31:33 | ||
| | ||
LL | println!("{}", vec![(), ()].iter().sum::<i32>()); | ||
| ------------ ^^^^^^ `Iterator::Item` is `&()` here | ||
| | | ||
| this expression has type `Vec<()>` | ||
note: required by a bound in `std::iter::Iterator::sum` | ||
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | ||
| | ||
LL | S: Sum<Self::Item>, | ||
| ^^^^^^^^^^^^^^^ required by this bound in `Iterator::sum` | ||
|
||
error[E0277]: a value of type `Vec<i32>` cannot be built from an iterator over elements of type `()` | ||
--> $DIR/invalid-iterator-chain.rs:40:23 | ||
| | ||
LL | let g: Vec<i32> = f.collect(); | ||
| ^ ------- required by a bound introduced by this call | ||
| | | ||
| value of type `Vec<i32>` cannot be built from `std::iter::Iterator<Item=()>` | ||
| | ||
= help: the trait `FromIterator<()>` is not implemented for `Vec<i32>` | ||
= help: the trait `FromIterator<T>` is implemented for `Vec<T>` | ||
note: the method call chain might not have had the expected associated types | ||
--> $DIR/invalid-iterator-chain.rs:36:15 | ||
| | ||
LL | let a = vec![0]; | ||
| ------- this expression has type `Vec<{integer}>` | ||
LL | let b = a.into_iter(); | ||
| ----------- `Iterator::Item` is `{integer}` here | ||
LL | let c = b.map(|x| x + 1); | ||
| -------------- `Iterator::Item` remains `{integer}` here | ||
LL | let d = c.filter(|x| *x > 10 ); | ||
| -------------------- `Iterator::Item` remains `{integer}` here | ||
LL | let e = d.map(|x| { | ||
| _______________^ | ||
LL | | x + 1; | ||
LL | | }); | ||
| |______^ `Iterator::Item` changed to `()` here | ||
LL | let f = e.filter(|_| false); | ||
| ----------------- `Iterator::Item` remains `()` here | ||
note: required by a bound in `collect` | ||
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | ||
| | ||
LL | fn collect<B: FromIterator<Self::Item>>(self) -> B | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Iterator::collect` | ||
|
||
error: aborting due to 6 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
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
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.