Skip to content

Commit 907e2b8

Browse files
committed
Add test sugg-swap-equality-in-macro-issue-139050.rs
Signed-off-by: xizheyin <[email protected]>
1 parent 460259d commit 907e2b8

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// if we use lhs == rhs in a macro, we should not suggest to swap the equality
2+
// because the origin span of lhs and rhs can not be found. See issue #139050
3+
4+
use std::fmt::Debug;
5+
6+
pub fn foo<I: Iterator>(mut iter: I, value: &I::Item)
7+
where
8+
Item: Eq + Debug, //~ ERROR cannot find type `Item` in this scope [E0412]
9+
{
10+
debug_assert_eq!(iter.next(), Some(value)); //~ ERROR mismatched types [E0308]
11+
assert_eq!(iter.next(), Some(value)); //~ ERROR mismatched types [E0308]
12+
}
13+
fn main() {}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
error[E0412]: cannot find type `Item` in this scope
2+
--> $DIR/sugg-swap-equality-in-macro-issue-139050.rs:8:5
3+
|
4+
LL | Item: Eq + Debug,
5+
| ^^^^ not found in this scope
6+
7+
error[E0308]: mismatched types
8+
--> $DIR/sugg-swap-equality-in-macro-issue-139050.rs:10:35
9+
|
10+
LL | debug_assert_eq!(iter.next(), Some(value));
11+
| ^^^^^^^^^^^ expected `Option<<I as Iterator>::Item>`, found `Option<&<I as Iterator>::Item>`
12+
|
13+
= note: expected enum `Option<_>`
14+
found enum `Option<&_>`
15+
16+
error[E0308]: mismatched types
17+
--> $DIR/sugg-swap-equality-in-macro-issue-139050.rs:11:29
18+
|
19+
LL | assert_eq!(iter.next(), Some(value));
20+
| ^^^^^^^^^^^ expected `Option<<I as Iterator>::Item>`, found `Option<&<I as Iterator>::Item>`
21+
|
22+
= note: expected enum `Option<_>`
23+
found enum `Option<&_>`
24+
25+
error: aborting due to 3 previous errors
26+
27+
Some errors have detailed explanations: E0308, E0412.
28+
For more information about an error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)