Skip to content

Commit

Permalink
add some tests for tuples with type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
y21 committed Jun 14, 2023
1 parent e00976f commit a78c53a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions tests/ui/map_identity.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@ fn issue7189() {

let y = [(1, 2, (3, (4,))), (5, 6, (7, (8,)))];
let _ = y.iter();
let _ = y
.iter();

// should not lint
let _ = x.iter().map(|(x, y)| (x, y, y));
let _ = x.iter().map(|(x, _y)| (x,));
let _ = x.iter().map(|(x, _)| (x,));
let _ = x.iter().map(|(x, ..)| (x,));
let _ = y.iter().map(|(x, y, (z, _))| (x, y, (z, z)));
let _ = y
.iter()
.map(|(x, y, (z, _)): &(i32, i32, (i32, (i32,)))| (x, y, (z, z)));
}

fn not_identity(x: &u16) -> u16 {
Expand Down
6 changes: 6 additions & 0 deletions tests/ui/map_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,19 @@ fn issue7189() {

let y = [(1, 2, (3, (4,))), (5, 6, (7, (8,)))];
let _ = y.iter().map(|(x, y, (z, (w,)))| (x, y, (z, (w,))));
let _ = y
.iter()
.map(|(x, y, (z, (w,))): &(i32, i32, (i32, (i32,)))| (x, y, (z, (w,))));

// should not lint
let _ = x.iter().map(|(x, y)| (x, y, y));
let _ = x.iter().map(|(x, _y)| (x,));
let _ = x.iter().map(|(x, _)| (x,));
let _ = x.iter().map(|(x, ..)| (x,));
let _ = y.iter().map(|(x, y, (z, _))| (x, y, (z, z)));
let _ = y
.iter()
.map(|(x, y, (z, _)): &(i32, i32, (i32, (i32,)))| (x, y, (z, z)));
}

fn not_identity(x: &u16) -> u16 {
Expand Down
10 changes: 9 additions & 1 deletion tests/ui/map_identity.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,13 @@ error: unnecessary map of the identity function
LL | let _ = y.iter().map(|(x, y, (z, (w,)))| (x, y, (z, (w,))));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the call to `map`

error: aborting due to 10 previous errors
error: unnecessary map of the identity function
--> $DIR/map_identity.rs:38:16
|
LL | .iter()
| ________________^
LL | | .map(|(x, y, (z, (w,))): &(i32, i32, (i32, (i32,)))| (x, y, (z, (w,))));
| |_______________________________________________________________________________^ help: remove the call to `map`

error: aborting due to 11 previous errors

0 comments on commit a78c53a

Please sign in to comment.