Skip to content

Commit 02dac5c

Browse files
committed
add test suggest-clone-in-macro-issue-139253.rs
Signed-off-by: xizheyin <[email protected]>
1 parent 55d4364 commit 02dac5c

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#[derive(Debug, Clone)]
2+
struct Struct { field: S }
3+
4+
#[derive(Debug, Clone)]
5+
struct S;
6+
7+
macro_rules! expand {
8+
($ident:ident) => { Struct { $ident } }
9+
}
10+
11+
fn test1() {
12+
let field = &S;
13+
let a: Struct = dbg!(expand!(field)); //~ ERROR mismatched types [E0308]
14+
let b: Struct = dbg!(Struct { field }); //~ ERROR mismatched types [E0308]
15+
let c: S = dbg!(field); //~ ERROR mismatched types [E0308]
16+
let c: S = dbg!(dbg!(field)); //~ ERROR mismatched types [E0308]
17+
}
18+
19+
fn main() {}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/suggest-clone-in-macro-issue-139253.rs:13:34
3+
|
4+
LL | let a: Struct = dbg!(expand!(field));
5+
| ^^^^^ expected `S`, found `&S`
6+
|
7+
help: consider using clone here
8+
|
9+
LL | let a: Struct = dbg!(expand!(field: field.clone()));
10+
| +++++++++++++++
11+
12+
error[E0308]: mismatched types
13+
--> $DIR/suggest-clone-in-macro-issue-139253.rs:14:35
14+
|
15+
LL | let b: Struct = dbg!(Struct { field });
16+
| ^^^^^ expected `S`, found `&S`
17+
|
18+
help: consider using clone here
19+
|
20+
LL | let b: Struct = dbg!(Struct { field: field.clone() });
21+
| +++++++++++++++
22+
23+
error[E0308]: mismatched types
24+
--> $DIR/suggest-clone-in-macro-issue-139253.rs:15:16
25+
|
26+
LL | let c: S = dbg!(field);
27+
| ^^^^^^^^^^^ expected `S`, found `&S`
28+
|
29+
= note: this error originates in the macro `dbg` (in Nightly builds, run with -Z macro-backtrace for more info)
30+
31+
error[E0308]: mismatched types
32+
--> $DIR/suggest-clone-in-macro-issue-139253.rs:16:16
33+
|
34+
LL | let c: S = dbg!(dbg!(field));
35+
| ^^^^^^^^^^^^^^^^^ expected `S`, found `&S`
36+
|
37+
= note: this error originates in the macro `dbg` (in Nightly builds, run with -Z macro-backtrace for more info)
38+
39+
error: aborting due to 4 previous errors
40+
41+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)