Correctly mark the span of captured arguments in format_args!()

It should only include the identifier, or misspelling suggestions will be wrong.
This commit is contained in:
Chayim Refael Friedman 2022-02-16 00:38:04 +00:00 committed by GitHub
parent 1e12aef3fa
commit 91adb6ccd6
15 changed files with 105 additions and 74 deletions

View file

@ -23,10 +23,10 @@ LL | asm!("{1}", in(reg) foo);
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {0} */"`
error: there is no argument named `a`
--> $DIR/bad-template.rs:36:15
--> $DIR/bad-template.rs:36:16
|
LL | asm!("{a}");
| ^^^
| ^
error: invalid reference to argument at index 0
--> $DIR/bad-template.rs:38:15
@ -123,10 +123,10 @@ LL | global_asm!("{1}", const FOO);
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {0} */"`
error: there is no argument named `a`
--> $DIR/bad-template.rs:63:14
--> $DIR/bad-template.rs:63:15
|
LL | global_asm!("{a}");
| ^^^
| ^
error: invalid reference to argument at index 0
--> $DIR/bad-template.rs:65:14

View file

@ -23,10 +23,10 @@ LL | asm!("{1}", in(reg) foo);
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {0} */"`
error: there is no argument named `a`
--> $DIR/bad-template.rs:36:15
--> $DIR/bad-template.rs:36:16
|
LL | asm!("{a}");
| ^^^
| ^
error: invalid reference to argument at index 0
--> $DIR/bad-template.rs:38:15
@ -123,10 +123,10 @@ LL | global_asm!("{1}", const FOO);
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {0} */"`
error: there is no argument named `a`
--> $DIR/bad-template.rs:63:14
--> $DIR/bad-template.rs:63:15
|
LL | global_asm!("{a}");
| ^^^
| ^
error: invalid reference to argument at index 0
--> $DIR/bad-template.rs:65:14

View file

@ -23,10 +23,10 @@ LL | asm!("{1}", in(reg) foo);
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {0} */"`
error: there is no argument named `a`
--> $DIR/bad-template.rs:36:15
--> $DIR/bad-template.rs:36:16
|
LL | asm!("{a}");
| ^^^
| ^
error: invalid reference to argument at index 0
--> $DIR/bad-template.rs:38:15
@ -123,10 +123,10 @@ LL | global_asm!("{1}", const FOO);
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {0} */"`
error: there is no argument named `a`
--> $DIR/bad-template.rs:63:14
--> $DIR/bad-template.rs:63:15
|
LL | global_asm!("{a}");
| ^^^
| ^
error: invalid reference to argument at index 0
--> $DIR/bad-template.rs:65:14

View file

@ -23,10 +23,10 @@ LL | asm!("{1}", in(reg) foo);
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {0} */"`
error: there is no argument named `a`
--> $DIR/bad-template.rs:36:15
--> $DIR/bad-template.rs:36:16
|
LL | asm!("{a}");
| ^^^
| ^
error: invalid reference to argument at index 0
--> $DIR/bad-template.rs:38:15
@ -123,10 +123,10 @@ LL | global_asm!("{1}", const FOO);
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {0} */"`
error: there is no argument named `a`
--> $DIR/bad-template.rs:63:14
--> $DIR/bad-template.rs:63:15
|
LL | global_asm!("{a}");
| ^^^
| ^
error: invalid reference to argument at index 0
--> $DIR/bad-template.rs:65:14

View file

@ -10,10 +10,10 @@ error: invalid reference to positional argument 0 (no arguments were given)
--> $DIR/format-args-capture-issue-93378.rs:9:23
|
LL | println!("{a:.n$} {b:.*}");
| ------- ^^^--^
| | |
| | this precision flag adds an extra required argument at position 0, which is why there are 3 arguments expected
| this parameter corresponds to the precision flag
| - ^^^--^
| | |
| | this precision flag adds an extra required argument at position 0, which is why there are 3 arguments expected
| this parameter corresponds to the precision flag
|
= note: positional arguments are zero-based
= note: for information about formatting flags, visit https://doc.rust-lang.org/std/fmt/index.html

View file

@ -0,0 +1,7 @@
fn main() {
const FOO: i32 = 123;
println!("{foo:X}");
//~^ ERROR: cannot find value `foo` in this scope
println!("{:.foo$}", 0);
//~^ ERROR: cannot find value `foo` in this scope
}

View file

@ -0,0 +1,20 @@
error[E0425]: cannot find value `foo` in this scope
--> $DIR/format-args-capture-issue-94010.rs:3:16
|
LL | const FOO: i32 = 123;
| --------------------- similarly named constant `FOO` defined here
LL | println!("{foo:X}");
| ^^^ help: a constant with a similar name exists (notice the capitalization): `FOO`
error[E0425]: cannot find value `foo` in this scope
--> $DIR/format-args-capture-issue-94010.rs:5:18
|
LL | const FOO: i32 = 123;
| --------------------- similarly named constant `FOO` defined here
...
LL | println!("{:.foo$}", 0);
| ^^^ help: a constant with a similar name exists (notice the capitalization): `FOO`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0425`.

View file

@ -7,40 +7,40 @@ LL | format!("{valuea} {valueb}", valuea=5, valuec=7);
| formatting specifier missing
error[E0425]: cannot find value `foo` in this scope
--> $DIR/format-args-capture-missing-variables.rs:2:17
--> $DIR/format-args-capture-missing-variables.rs:2:18
|
LL | format!("{} {foo} {} {bar} {}", 1, 2, 3);
| ^^^^^ not found in this scope
| ^^^ not found in this scope
error[E0425]: cannot find value `bar` in this scope
--> $DIR/format-args-capture-missing-variables.rs:2:26
--> $DIR/format-args-capture-missing-variables.rs:2:27
|
LL | format!("{} {foo} {} {bar} {}", 1, 2, 3);
| ^^^^^ not found in this scope
| ^^^ not found in this scope
error[E0425]: cannot find value `foo` in this scope
--> $DIR/format-args-capture-missing-variables.rs:6:14
--> $DIR/format-args-capture-missing-variables.rs:6:15
|
LL | format!("{foo}");
| ^^^^^ not found in this scope
| ^^^ not found in this scope
error[E0425]: cannot find value `valueb` in this scope
--> $DIR/format-args-capture-missing-variables.rs:8:23
--> $DIR/format-args-capture-missing-variables.rs:8:24
|
LL | format!("{valuea} {valueb}", valuea=5, valuec=7);
| ^^^^^^^^ not found in this scope
| ^^^^^^ not found in this scope
error[E0425]: cannot find value `foo` in this scope
--> $DIR/format-args-capture-missing-variables.rs:14:9
--> $DIR/format-args-capture-missing-variables.rs:14:10
|
LL | {foo}
| ^^^^^ not found in this scope
| ^^^ not found in this scope
error[E0425]: cannot find value `foo` in this scope
--> $DIR/format-args-capture-missing-variables.rs:19:13
--> $DIR/format-args-capture-missing-variables.rs:19:14
|
LL | panic!("{foo} {bar}", bar=1);
| ^^^^^ not found in this scope
| ^^^ not found in this scope
error: aborting due to 7 previous errors

View file

@ -263,34 +263,34 @@ LL | println!("{:.*}");
= note: for information about formatting flags, visit https://doc.rust-lang.org/std/fmt/index.html
error[E0425]: cannot find value `foo` in this scope
--> $DIR/ifmt-bad-arg.rs:27:17
--> $DIR/ifmt-bad-arg.rs:27:18
|
LL | format!("{} {foo} {} {bar} {}", 1, 2, 3);
| ^^^^^ not found in this scope
| ^^^ not found in this scope
error[E0425]: cannot find value `bar` in this scope
--> $DIR/ifmt-bad-arg.rs:27:26
--> $DIR/ifmt-bad-arg.rs:27:27
|
LL | format!("{} {foo} {} {bar} {}", 1, 2, 3);
| ^^^^^ not found in this scope
| ^^^ not found in this scope
error[E0425]: cannot find value `foo` in this scope
--> $DIR/ifmt-bad-arg.rs:31:14
--> $DIR/ifmt-bad-arg.rs:31:15
|
LL | format!("{foo}");
| ^^^^^ not found in this scope
| ^^^ not found in this scope
error[E0425]: cannot find value `valueb` in this scope
--> $DIR/ifmt-bad-arg.rs:45:23
--> $DIR/ifmt-bad-arg.rs:45:24
|
LL | format!("{valuea} {valueb}", valuea=5, valuec=7);
| ^^^^^^^^ not found in this scope
| ^^^^^^ not found in this scope
error[E0425]: cannot find value `foo` in this scope
--> $DIR/ifmt-bad-arg.rs:60:9
--> $DIR/ifmt-bad-arg.rs:60:10
|
LL | {foo}
| ^^^^^ not found in this scope
| ^^^ not found in this scope
error[E0308]: mismatched types
--> $DIR/ifmt-bad-arg.rs:78:32

View file

@ -453,7 +453,7 @@ impl SimpleFormatArgs {
}
}
},
ArgumentNamed(n) => {
ArgumentNamed(n, _) => {
if let Some(x) = self.named.iter_mut().find(|x| x.0 == n) {
match x.1.as_slice() {
// A non-empty format string has been seen already.