Rollup merge of #147320 - chenyukang:yukang-fix-147303-fn-arg, r=jieyouxu
Avoid to suggest pattern match on the similarly named in fn signature Fixes rust-lang/rust#147303
This commit is contained in:
commit
cae84c695a
4 changed files with 33 additions and 12 deletions
|
|
@ -1691,7 +1691,10 @@ impl<'tcx> Liveness<'_, 'tcx> {
|
|||
if ln == self.exit_ln { false } else { self.assigned_on_exit(ln, var) };
|
||||
|
||||
let mut typo = None;
|
||||
for (hir_id, _, span) in &hir_ids_and_spans {
|
||||
let filtered_hir_ids_and_spans = hir_ids_and_spans.iter().filter(|(hir_id, ..)| {
|
||||
!matches!(self.ir.tcx.parent_hir_node(*hir_id), hir::Node::Param(_))
|
||||
});
|
||||
for (hir_id, _, span) in filtered_hir_ids_and_spans.clone() {
|
||||
let ty = self.typeck_results.node_type(*hir_id);
|
||||
if let ty::Adt(adt, _) = ty.peel_refs().kind() {
|
||||
let name = Symbol::intern(&name);
|
||||
|
|
@ -1717,7 +1720,7 @@ impl<'tcx> Liveness<'_, 'tcx> {
|
|||
}
|
||||
}
|
||||
if typo.is_none() {
|
||||
for (hir_id, _, span) in &hir_ids_and_spans {
|
||||
for (hir_id, _, span) in filtered_hir_ids_and_spans {
|
||||
let ty = self.typeck_results.node_type(*hir_id);
|
||||
// Look for consts of the same type with similar names as well, not just unit
|
||||
// structs and variants.
|
||||
|
|
|
|||
13
tests/ui/fn/invalid-sugg-for-unused-fn-arg-147303.rs
Normal file
13
tests/ui/fn/invalid-sugg-for-unused-fn-arg-147303.rs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
// Regression test for <https://github.com/rust-lang/rust/issues/147303>.
|
||||
|
||||
#![deny(unused_assignments, unused_variables)]
|
||||
|
||||
mod m1 {
|
||||
const _MAX_FMTVER_X1X_EVENTNUM: i32 = 0;
|
||||
}
|
||||
|
||||
mod m2 {
|
||||
fn fun(rough: i32) {} //~ERROR unused variable
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
14
tests/ui/fn/invalid-sugg-for-unused-fn-arg-147303.stderr
Normal file
14
tests/ui/fn/invalid-sugg-for-unused-fn-arg-147303.stderr
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
error: unused variable: `rough`
|
||||
--> $DIR/invalid-sugg-for-unused-fn-arg-147303.rs:10:12
|
||||
|
|
||||
LL | fn fun(rough: i32) {}
|
||||
| ^^^^^ help: if this is intentional, prefix it with an underscore: `_rough`
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/invalid-sugg-for-unused-fn-arg-147303.rs:3:29
|
||||
|
|
||||
LL | #![deny(unused_assignments, unused_variables)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
|
@ -58,16 +58,7 @@ warning: unused variable: `Foo`
|
|||
--> $DIR/lint-uppercase-variables.rs:33:17
|
||||
|
|
||||
LL | fn in_param(Foo: foo::Foo) {}
|
||||
| ^^^
|
||||
|
|
||||
help: if this is intentional, prefix it with an underscore
|
||||
|
|
||||
LL | fn in_param(_Foo: foo::Foo) {}
|
||||
| +
|
||||
help: you might have meant to pattern match on the similarly named variant `Foo`
|
||||
|
|
||||
LL | fn in_param(foo::Foo::Foo: foo::Foo) {}
|
||||
| ++++++++++
|
||||
| ^^^ help: if this is intentional, prefix it with an underscore: `_Foo`
|
||||
|
||||
error: structure field `X` should have a snake case name
|
||||
--> $DIR/lint-uppercase-variables.rs:10:5
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue