diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-05-06 23:32:03 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-06 23:32:03 +0200 |
| commit | 1de257bd33eecdcc1386beccd8ad3ed90012f358 (patch) | |
| tree | b3694730afdeb13a0052615a89268a44a86ebd8d | |
| parent | ecc061596746dd5902cd29f64b61003b35cf8904 (diff) | |
| parent | 9027d208f2b516a843aa6dcfd0ed30c882a04a28 (diff) | |
| download | rust-1de257bd33eecdcc1386beccd8ad3ed90012f358.tar.gz rust-1de257bd33eecdcc1386beccd8ad3ed90012f358.zip | |
Rollup merge of #111289 - clubby789:fix-111280, r=jyn514
Check arguments length in trivial diagnostic lint Fixes #111280
| -rw-r--r-- | compiler/rustc_lint/src/internal.rs | 6 | ||||
| -rw-r--r-- | tests/ui/lint/internal/trivial-diagnostics.rs | 8 | ||||
| -rw-r--r-- | tests/ui/lint/internal/trivial-diagnostics.stderr | 15 |
3 files changed, 27 insertions, 2 deletions
diff --git a/compiler/rustc_lint/src/internal.rs b/compiler/rustc_lint/src/internal.rs index 595b50c4063..0082aaa4a38 100644 --- a/compiler/rustc_lint/src/internal.rs +++ b/compiler/rustc_lint/src/internal.rs @@ -478,8 +478,10 @@ impl EarlyLintPass for Diagnostics { } if !segments.iter().all(|(name, args)| { let arg = match name.as_str() { - "struct_span_err" | "span_note" | "span_label" | "span_help" => &args[1], - "note" | "help" => &args[0], + "struct_span_err" | "span_note" | "span_label" | "span_help" if args.len() == 2 => { + &args[1] + } + "note" | "help" if args.len() == 1 => &args[0], _ => { return false; } diff --git a/tests/ui/lint/internal/trivial-diagnostics.rs b/tests/ui/lint/internal/trivial-diagnostics.rs new file mode 100644 index 00000000000..e536e1164fc --- /dev/null +++ b/tests/ui/lint/internal/trivial-diagnostics.rs @@ -0,0 +1,8 @@ +// compile-flags: -Zunstable-options + +pub fn issue_111280() { + struct_span_err(msg).emit(); //~ ERROR cannot find value `msg` + //~^ ERROR cannot find function `struct_span_err` +} + +fn main() {} diff --git a/tests/ui/lint/internal/trivial-diagnostics.stderr b/tests/ui/lint/internal/trivial-diagnostics.stderr new file mode 100644 index 00000000000..d47a7dae023 --- /dev/null +++ b/tests/ui/lint/internal/trivial-diagnostics.stderr @@ -0,0 +1,15 @@ +error[E0425]: cannot find value `msg` in this scope + --> $DIR/trivial-diagnostics.rs:4:21 + | +LL | struct_span_err(msg).emit(); + | ^^^ not found in this scope + +error[E0425]: cannot find function `struct_span_err` in this scope + --> $DIR/trivial-diagnostics.rs:4:5 + | +LL | struct_span_err(msg).emit(); + | ^^^^^^^^^^^^^^^ not found in this scope + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0425`. |
