Skip to content

Commit fe0663c

Browse files
committed
Add test sugg-field-in-format-string-issue-141136
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
1 parent a69bc17 commit fe0663c

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
struct Foo {
2+
x: i32
3+
}
4+
5+
impl Foo {
6+
fn foo(&self) {
7+
let _ = format!("{x}"); //~ ERROR cannot find value `x` in this scope [E0425]
8+
let _ = format!("{x }"); //~ ERROR cannot find value `x` in this scope [E0425]
9+
let _ = format!("{ x}"); //~ ERROR invalid format string: expected `}`, found `x`
10+
let _ = format!("{}", x); //~ ERROR cannot find value `x` in this scope [E0425]
11+
}
12+
}
13+
14+
fn main(){}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
error: invalid format string: expected `}`, found `x`
2+
--> $DIR/sugg-field-in-format-string-issue-141136.rs:9:28
3+
|
4+
LL | let _ = format!("{ x}");
5+
| - ^ expected `}` in format string
6+
| |
7+
| because of this opening brace
8+
|
9+
= note: if you intended to print `{`, you can escape it using `{{`
10+
11+
error[E0425]: cannot find value `x` in this scope
12+
--> $DIR/sugg-field-in-format-string-issue-141136.rs:7:27
13+
|
14+
LL | let _ = format!("{x}");
15+
| ^
16+
|
17+
help: you might have meant to use the available field
18+
|
19+
LL | let _ = format!("{self.x}");
20+
| +++++
21+
22+
error[E0425]: cannot find value `x` in this scope
23+
--> $DIR/sugg-field-in-format-string-issue-141136.rs:8:27
24+
|
25+
LL | let _ = format!("{x }");
26+
| ^^
27+
|
28+
help: you might have meant to use the available field
29+
|
30+
LL | let _ = format!("{self.x }");
31+
| +++++
32+
33+
error[E0425]: cannot find value `x` in this scope
34+
--> $DIR/sugg-field-in-format-string-issue-141136.rs:10:31
35+
|
36+
LL | let _ = format!("{}", x);
37+
| ^
38+
|
39+
help: you might have meant to use the available field
40+
|
41+
LL | let _ = format!("{}", self.x);
42+
| +++++
43+
44+
error: aborting due to 4 previous errors
45+
46+
For more information about this error, try `rustc --explain E0425`.

0 commit comments

Comments
 (0)