Skip to content

Commit 7c3ff67

Browse files
committed
Add test for incorrect macro span replacement
1 parent 6e41e61 commit 7c3ff67

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
macro_rules! macro_with_format { () => {
2+
fn check_5(arg : usize) -> String {
3+
let s : &str;
4+
if arg < 5 {
5+
s = format!("{arg}");
6+
} else {
7+
s = String::new(); //~ ERROR mismatched types
8+
}
9+
String::from(s)
10+
}
11+
}}
12+
13+
fn main() {
14+
macro_with_format!(); //~ ERROR mismatched types
15+
println!( "{}", check_5(6) );
16+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/macro-span-caller-replacement.rs:5:17
3+
|
4+
LL | macro_with_format!();
5+
| ^^^^^^^^^^^^^^^^^^^^ expected `&str`, found `String`
6+
|
7+
= note: this error originates in the macro `format` which comes from the expansion of the macro `macro_with_format` (in Nightly builds, run with -Z macro-backtrace for more info)
8+
9+
error[E0308]: mismatched types
10+
--> $DIR/macro-span-caller-replacement.rs:7:17
11+
|
12+
LL | let s : &str;
13+
| ---- expected due to this type
14+
...
15+
LL | s = String::new();
16+
| ^^^^^^^^^^^^^ expected `&str`, found `String`
17+
...
18+
LL | macro_with_format!();
19+
| -------------------- in this macro invocation
20+
|
21+
= note: this error originates in the macro `macro_with_format` (in Nightly builds, run with -Z macro-backtrace for more info)
22+
help: consider borrowing here
23+
|
24+
LL | s = &String::new();
25+
| +
26+
27+
error: aborting due to 2 previous errors
28+
29+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)