Skip to content

Commit

Permalink
Fix unused_variables in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HKalbasi committed Sep 24, 2023
1 parent 7834b8f commit ab52ba2
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 104 deletions.
5 changes: 3 additions & 2 deletions crates/hir-ty/src/mir/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1774,13 +1774,14 @@ impl<'ctx> MirLowerCtx<'ctx> {
}
}
}
hir_def::hir::Statement::Expr { expr, has_semi: _ } => {
&hir_def::hir::Statement::Expr { expr, has_semi: _ } => {
let scope2 = self.push_drop_scope();
let Some((_, c)) = self.lower_expr_as_place(current, *expr, true)? else {
let Some((p, c)) = self.lower_expr_as_place(current, expr, true)? else {
scope2.pop_assume_dropped(self);
scope.pop_assume_dropped(self);
return Ok(None);
};
self.push_fake_read(c, p, expr.into());
current = scope2.pop_and_drop(self, c);
}
}
Expand Down
6 changes: 5 additions & 1 deletion crates/ide-diagnostics/src/handlers/field_shorthand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ fn main() {
check_diagnostics(
r#"
struct A { a: &'static str }
fn f(a: A) { let A { a: hello } = a; }
fn f(a: A) { let A { a: _hello } = a; }
"#,
);
check_diagnostics(
Expand All @@ -181,12 +181,14 @@ fn f(a: A) { let A { 0: 0 } = a; }
struct A { a: &'static str }
fn f(a: A) {
let A { a$0: a } = a;
_ = a;
}
"#,
r#"
struct A { a: &'static str }
fn f(a: A) {
let A { a } = a;
_ = a;
}
"#,
);
Expand All @@ -196,12 +198,14 @@ fn f(a: A) {
struct A { a: &'static str, b: &'static str }
fn f(a: A) {
let A { a$0: a, b } = a;
_ = (a, b);
}
"#,
r#"
struct A { a: &'static str, b: &'static str }
fn f(a: A) {
let A { a, b } = a;
_ = (a, b);
}
"#,
);
Expand Down
18 changes: 13 additions & 5 deletions crates/ide-diagnostics/src/handlers/incorrect_case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,10 @@ fn NonSnakeCaseName() {}
fn incorrect_function_params() {
check_diagnostics(
r#"
fn foo(SomeParam: u8) {}
fn foo(SomeParam: u8) { _ = SomeParam; }
// ^^^^^^^^^ 💡 warn: Parameter `SomeParam` should have snake_case name, e.g. `some_param`
fn foo2(ok_param: &str, CAPS_PARAM: u8) {}
fn foo2(ok_param: &str, CAPS_PARAM: u8) { _ = (ok_param, CAPS_PARAM); }
// ^^^^^^^^^^ 💡 warn: Parameter `CAPS_PARAM` should have snake_case name, e.g. `caps_param`
"#,
);
Expand All @@ -188,6 +188,7 @@ fn foo2(ok_param: &str, CAPS_PARAM: u8) {}
fn incorrect_variable_names() {
check_diagnostics(
r#"
#[allow(unused)]
fn foo() {
let SOME_VALUE = 10;
// ^^^^^^^^^^ 💡 warn: Variable `SOME_VALUE` should have snake_case name, e.g. `some_value`
Expand Down Expand Up @@ -294,6 +295,7 @@ impl someStruct {
// ^^^^^^^^ 💡 warn: Function `SomeFunc` should have snake_case name, e.g. `some_func`
let WHY_VAR_IS_CAPS = 10;
// ^^^^^^^^^^^^^^^ 💡 warn: Variable `WHY_VAR_IS_CAPS` should have snake_case name, e.g. `why_var_is_caps`
_ = WHY_VAR_IS_CAPS;
}
}
"#,
Expand All @@ -306,6 +308,7 @@ impl someStruct {
r#"
enum Option { Some, None }
#[allow(unused)]
fn main() {
match Option::None {
None => (),
Expand All @@ -322,6 +325,7 @@ fn main() {
r#"
enum Option { Some, None }
#[allow(unused)]
fn main() {
match Option::None {
SOME_VAR @ None => (),
Expand Down Expand Up @@ -349,7 +353,9 @@ enum E {
}
mod F {
fn CheckItWorksWithCrateAttr(BAD_NAME_HI: u8) {}
fn CheckItWorksWithCrateAttr(BAD_NAME_HI: u8) {
_ = BAD_NAME_HI;
}
}
"#,
);
Expand Down Expand Up @@ -395,7 +401,7 @@ fn qualify() {

#[test] // Issue #8809.
fn parenthesized_parameter() {
check_diagnostics(r#"fn f((O): _) {}"#)
check_diagnostics(r#"fn f((O): _) { _ = O; }"#)
}

#[test]
Expand Down Expand Up @@ -472,7 +478,9 @@ mod CheckBadStyle {
mod F {
#![allow(non_snake_case)]
fn CheckItWorksWithModAttr(BAD_NAME_HI: u8) {}
fn CheckItWorksWithModAttr(BAD_NAME_HI: u8) {
_ = BAD_NAME_HI;
}
}
#[allow(non_snake_case, non_camel_case_types)]
Expand Down
22 changes: 11 additions & 11 deletions crates/ide-diagnostics/src/handlers/mismatched_arg_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ fn f() { zero(); }
fn simple_free_fn_one() {
check_diagnostics(
r#"
fn one(arg: u8) {}
fn one(_arg: u8) {}
fn f() { one(); }
//^^ error: expected 1 argument, found 0
"#,
);

check_diagnostics(
r#"
fn one(arg: u8) {}
fn one(_arg: u8) {}
fn f() { one(1); }
"#,
);
Expand Down Expand Up @@ -176,7 +176,7 @@ fn f() {
check_diagnostics(
r#"
struct S;
impl S { fn method(&self, arg: u8) {} }
impl S { fn method(&self, _arg: u8) {} }
fn f() {
S.method();
Expand All @@ -187,7 +187,7 @@ impl S { fn method(&self, arg: u8) {} }
check_diagnostics(
r#"
struct S;
impl S { fn method(&self, arg: u8) {} }
impl S { fn method(&self, _arg: u8) {} }
fn f() {
S::method(&S, 0);
Expand Down Expand Up @@ -335,8 +335,8 @@ struct S;
impl S {
fn method(#[cfg(NEVER)] self) {}
fn method2(#[cfg(NEVER)] self, arg: u8) {}
fn method3(self, #[cfg(NEVER)] arg: u8) {}
fn method2(#[cfg(NEVER)] self, _arg: u8) {}
fn method3(self, #[cfg(NEVER)] _arg: u8) {}
}
extern "C" {
Expand Down Expand Up @@ -365,8 +365,8 @@ fn main() {
r#"
#[rustc_legacy_const_generics(1, 3)]
fn mixed<const N1: &'static str, const N2: bool>(
a: u8,
b: i8,
_a: u8,
_b: i8,
) {}
fn f() {
Expand All @@ -376,8 +376,8 @@ fn f() {
#[rustc_legacy_const_generics(1, 3)]
fn b<const N1: u8, const N2: u8>(
a: u8,
b: u8,
_a: u8,
_b: u8,
) {}
fn g() {
Expand All @@ -403,7 +403,7 @@ fn f(
// ^^ error: this pattern has 0 fields, but the corresponding tuple struct has 2 fields
S(e, f, .., g, d): S
// ^^^^^^^^^ error: this pattern has 4 fields, but the corresponding tuple struct has 2 fields
) {}
) { _ = (a, b, c, d, e, f, g); }
"#,
)
}
Expand Down
3 changes: 2 additions & 1 deletion crates/ide-diagnostics/src/handlers/missing_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ fn x(a: S) {
struct S { s: u32 }
fn x(a: S) {
let S { ref s } = a;
_ = s;
}
",
)
Expand Down Expand Up @@ -626,7 +627,7 @@ struct TestStruct { one: i32, two: i64 }
fn test_fn() {
let one = 1;
let s = TestStruct{ one, two: 2 };
let _s = TestStruct{ one, two: 2 };
}
"#,
);
Expand Down
6 changes: 4 additions & 2 deletions crates/ide-diagnostics/src/handlers/missing_match_arms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub(crate) fn missing_match_arms(
mod tests {
use crate::tests::check_diagnostics;

#[track_caller]
fn check_diagnostics_no_bails(ra_fixture: &str) {
cov_mark::check_count!(validate_match_bailed_out, 0);
crate::tests::check_diagnostics(ra_fixture)
Expand Down Expand Up @@ -564,6 +565,7 @@ fn bang(never: !) {
r#"
enum Option<T> { Some(T), None }
#[allow(unused)]
fn main() {
// `Never` is deliberately not defined so that it's an uninferred type.
match Option::<Never>::None {
Expand Down Expand Up @@ -719,7 +721,7 @@ fn main() {
r#"
struct S { a: char}
fn main(v: S) {
match v { S{ a } => {} }
match v { S{ a } => { _ = a; } }
match v { S{ a: _x } => {} }
match v { S{ a: 'a' } => {} }
match v { S{..} => {} }
Expand Down Expand Up @@ -901,7 +903,7 @@ enum E{ A, B }
fn foo() {
match &E::A {
E::A => {}
x => {}
_x => {}
}
}",
);
Expand Down

0 comments on commit ab52ba2

Please sign in to comment.