Skip to content

Commit

Permalink
Reorganize main.rs files
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Feb 7, 2025
1 parent 7dde2aa commit 2665856
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 33 deletions.
7 changes: 5 additions & 2 deletions examples/restriction/suboptimal_pattern/ui/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ fn main() {
let _ = xys.iter().map(|xy| *xy.0 == xy.1 .0).collect::<Vec<_>>();
let _ = yzs.iter().map(|yz| yz.0 .0 == yz.1).collect::<Vec<_>>();

let _ = wxs.iter().map(|(w, x)| w == *x).collect::<Vec<_>>();
let _ = xys.iter().map(|(x, y)| **x == y.0).collect::<Vec<_>>();
let _ = yzs.iter().map(|(y, z)| y.0 == z).collect::<Vec<_>>();

let _ = ws.clone().into_iter().map(|w| w == "").collect::<Vec<_>>();
let _ = xs.clone().into_iter().map(|x| *x == "").collect::<Vec<_>>();
Expand Down Expand Up @@ -80,6 +78,11 @@ fn main() {

// smoelius: Additional reference possible.
let _ = xs.iter().map(|&x| *x == "").collect::<Vec<_>>();

// smoelius: Negative tests. Do not warn in the following cases. The tuples have implicit outer
// references and the suggestions the lint would produce would be incorrect.
let _ = wxs.iter().map(|(w, x)| w == *x).collect::<Vec<_>>();
let _ = yzs.iter().map(|(y, z)| y.0 == z).collect::<Vec<_>>();
}

mod ref_necessity {
Expand Down
28 changes: 14 additions & 14 deletions examples/restriction/suboptimal_pattern/ui/main.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -37,85 +37,85 @@ LL | let _ = yzs.iter().map(|yz| yz.0 .0 == yz.1).collect::<Vec<_>>();
| ^^ help: use something like: `(yz_0, yz_1)`

warning: could destructure reference
--> $DIR/main.rs:37:29
--> $DIR/main.rs:36:29
|
LL | let _ = xys.iter().map(|(x, y)| **x == y.0).collect::<Vec<_>>();
| ^^^^^^ help: use: `&(x, y)`

warning: could destructure reference
--> $DIR/main.rs:41:41
--> $DIR/main.rs:39:41
|
LL | let _ = xs.clone().into_iter().map(|x| *x == "").collect::<Vec<_>>();
| ^ help: use: `&x`

warning: could destructure tuple
--> $DIR/main.rs:45:15
--> $DIR/main.rs:43:15
|
LL | .map(|y| y.0 == "")
| ^ help: use something like: `(y_0,)`

warning: could destructure tuple
--> $DIR/main.rs:52:15
--> $DIR/main.rs:50:15
|
LL | .map(|wx| wx.0 == *wx.1)
| ^^ help: use something like: `(wx_0, wx_1)`

warning: could destructure tuple
--> $DIR/main.rs:57:15
--> $DIR/main.rs:55:15
|
LL | .map(|xy| *xy.0 == xy.1 .0)
| ^^ help: use something like: `(xy_0, xy_1)`

warning: could destructure tuple
--> $DIR/main.rs:62:15
--> $DIR/main.rs:60:15
|
LL | .map(|yz| yz.0 .0 == yz.1)
| ^^ help: use something like: `(yz_0, yz_1)`

warning: could destructure reference
--> $DIR/main.rs:68:19
--> $DIR/main.rs:66:19
|
LL | .map(|(w, x)| w == *x)
| ^ help: use: `&x`

warning: could destructure reference
--> $DIR/main.rs:73:16
--> $DIR/main.rs:71:16
|
LL | .map(|(x, y)| *x == y.0)
| ^ help: use: `&x`

warning: could destructure tuple
--> $DIR/main.rs:73:19
--> $DIR/main.rs:71:19
|
LL | .map(|(x, y)| *x == y.0)
| ^ help: use something like: `(y_0,)`

warning: could destructure tuple
--> $DIR/main.rs:78:16
--> $DIR/main.rs:76:16
|
LL | .map(|(y, z)| y.0 == z)
| ^ help: use something like: `(y_0,)`

warning: could destructure reference
--> $DIR/main.rs:82:28
--> $DIR/main.rs:80:28
|
LL | let _ = xs.iter().map(|&x| *x == "").collect::<Vec<_>>();
| ^^ help: use: `&&x`

warning: could destructure reference
--> $DIR/main.rs:115:36
--> $DIR/main.rs:118:36
|
LL | let _ = [X(Y)].iter().map(|x| *x).collect::<Vec<_>>();
| ^ help: use: `&x`

warning: could destructure reference
--> $DIR/main.rs:116:36
--> $DIR/main.rs:119:36
|
LL | let _ = [X(Y)].iter().map(|x| **x).collect::<Vec<_>>();
| ^ help: use: `&x`

warning: could destructure reference
--> $DIR/main.rs:124:35
--> $DIR/main.rs:127:35
|
LL | let _ = ws.split_last().map(|(w, _)| *w);
| ^ help: use: `&w`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ fn main() {
let _ = xys.iter().map(|xy| *xy.0 == xy.1 .0).collect::<Vec<_>>();
let _ = yzs.iter().map(|yz| yz.0 .0 == yz.1).collect::<Vec<_>>();

let _ = wxs.iter().map(|(w, x)| w == *x).collect::<Vec<_>>();
let _ = xys.iter().map(|(x, y)| **x == y.0).collect::<Vec<_>>();
let _ = yzs.iter().map(|(y, z)| y.0 == z).collect::<Vec<_>>();

let _ = ws.clone().into_iter().map(|w| w == "").collect::<Vec<_>>();
let _ = xs.clone().into_iter().map(|x| *x == "").collect::<Vec<_>>();
Expand Down Expand Up @@ -80,6 +78,11 @@ fn main() {

// smoelius: Additional reference possible.
let _ = xs.iter().map(|&x| *x == "").collect::<Vec<_>>();

// smoelius: Negative tests. Do not warn in the following cases. The tuples have implicit outer
// references and the suggestions the lint would produce would be incorrect.
let _ = wxs.iter().map(|(w, x)| w == *x).collect::<Vec<_>>();
let _ = yzs.iter().map(|(y, z)| y.0 == z).collect::<Vec<_>>();
}

mod ref_necessity {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,91 +37,91 @@ LL | let _ = yzs.iter().map(|yz| yz.0 .0 == yz.1).collect::<Vec<_>>();
| ^^ help: use something like: `(yz_0, yz_1)`

warning: could destructure reference
--> $DIR/main.rs:37:29
--> $DIR/main.rs:36:29
|
LL | let _ = xys.iter().map(|(x, y)| **x == y.0).collect::<Vec<_>>();
| ^^^^^^ help: use: `&(x, y)`

warning: could destructure reference
--> $DIR/main.rs:41:41
--> $DIR/main.rs:39:41
|
LL | let _ = xs.clone().into_iter().map(|x| *x == "").collect::<Vec<_>>();
| ^ help: use: `&x`

warning: could destructure tuple
--> $DIR/main.rs:45:15
--> $DIR/main.rs:43:15
|
LL | .map(|y| y.0 == "")
| ^ help: use something like: `(y_0,)`

warning: could destructure tuple
--> $DIR/main.rs:52:15
--> $DIR/main.rs:50:15
|
LL | .map(|wx| wx.0 == *wx.1)
| ^^ help: use something like: `(wx_0, wx_1)`

warning: could destructure tuple
--> $DIR/main.rs:57:15
--> $DIR/main.rs:55:15
|
LL | .map(|xy| *xy.0 == xy.1 .0)
| ^^ help: use something like: `(xy_0, xy_1)`

warning: could destructure tuple
--> $DIR/main.rs:62:15
--> $DIR/main.rs:60:15
|
LL | .map(|yz| yz.0 .0 == yz.1)
| ^^ help: use something like: `(yz_0, yz_1)`

warning: could destructure reference
--> $DIR/main.rs:68:19
--> $DIR/main.rs:66:19
|
LL | .map(|(w, x)| w == *x)
| ^ help: use: `&x`

warning: could destructure reference
--> $DIR/main.rs:73:16
--> $DIR/main.rs:71:16
|
LL | .map(|(x, y)| *x == y.0)
| ^ help: use: `&x`

warning: could destructure tuple
--> $DIR/main.rs:73:19
--> $DIR/main.rs:71:19
|
LL | .map(|(x, y)| *x == y.0)
| ^ help: use something like: `(y_0,)`

warning: could destructure tuple
--> $DIR/main.rs:78:16
--> $DIR/main.rs:76:16
|
LL | .map(|(y, z)| y.0 == z)
| ^ help: use something like: `(y_0,)`

warning: could destructure reference
--> $DIR/main.rs:82:28
--> $DIR/main.rs:80:28
|
LL | let _ = xs.iter().map(|&x| *x == "").collect::<Vec<_>>();
| ^^ help: use: `&&x`

warning: could destructure reference
--> $DIR/main.rs:93:34
--> $DIR/main.rs:96:34
|
LL | let _ = [&X].iter().map(|x| foo(x)).collect::<Vec<_>>();
| ^ help: use: `&x`

warning: could destructure reference
--> $DIR/main.rs:115:36
--> $DIR/main.rs:118:36
|
LL | let _ = [X(Y)].iter().map(|x| *x).collect::<Vec<_>>();
| ^ help: use: `&x`

warning: could destructure reference
--> $DIR/main.rs:116:36
--> $DIR/main.rs:119:36
|
LL | let _ = [X(Y)].iter().map(|x| **x).collect::<Vec<_>>();
| ^ help: use: `&x`

warning: could destructure reference
--> $DIR/main.rs:124:35
--> $DIR/main.rs:127:35
|
LL | let _ = ws.split_last().map(|(w, _)| *w);
| ^ help: use: `&w`
Expand Down

0 comments on commit 2665856

Please sign in to comment.