Skip to content

Commit

Permalink
Rollup merge of #111289 - clubby789:fix-111280, r=jyn514
Browse files Browse the repository at this point in the history
Check arguments length in trivial diagnostic lint

Fixes #111280
  • Loading branch information
matthiaskrgr authored May 6, 2023
2 parents eb53ccf + 9027d20 commit c56f165
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
6 changes: 4 additions & 2 deletions compiler/rustc_lint/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/lint/internal/trivial-diagnostics.rs
Original file line number Diff line number Diff line change
@@ -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() {}
15 changes: 15 additions & 0 deletions tests/ui/lint/internal/trivial-diagnostics.stderr
Original file line number Diff line number Diff line change
@@ -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`.

0 comments on commit c56f165

Please sign in to comment.