Check arguments length in trivial diagnostic lint

This commit is contained in:
clubby789 2023-05-06 14:42:35 +01:00
parent 151a070afe
commit 9027d208f2
3 changed files with 27 additions and 2 deletions

View file

@ -478,8 +478,10 @@ fn check_stmt(&mut self, cx: &EarlyContext<'_>, stmt: &ast::Stmt) {
}
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;
}

View file

@ -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() {}

View file

@ -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`.