Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Classify closure arguments in refutable pattern in argument error #120382

Merged
merged 1 commit into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion compiler/rustc_mir_build/src/thir/pattern/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,18 @@ pub(crate) fn check_match(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), Err
};
visitor.visit_expr(&thir[expr]);

let origin = match tcx.def_kind(def_id) {
DefKind::AssocFn | DefKind::Fn => "function argument",
DefKind::Closure => "closure argument",
// other types of MIR don't have function parameters, and we don't need to
// categorize those for the irrefutable check.
_ if thir.params.is_empty() => "",
kind => bug!("unexpected function parameters in THIR: {kind:?} {def_id:?}"),
};

for param in thir.params.iter() {
if let Some(box ref pattern) = param.pat {
visitor.check_binding_is_irrefutable(pattern, "function argument", None, None);
visitor.check_binding_is_irrefutable(pattern, origin, None, None);
}
}
visitor.error
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/pattern/usefulness/refutable-pattern-in-fn-arg.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fn main() {
let f = |3: isize| println!("hello");
//~^ ERROR refutable pattern in function argument
//~^ ERROR refutable pattern in closure argument
//~| `..=2_isize` and `4_isize..` not covered
f(4);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0005]: refutable pattern in function argument
error[E0005]: refutable pattern in closure argument
--> $DIR/refutable-pattern-in-fn-arg.rs:2:14
|
LL | let f = |3: isize| println!("hello");
Expand Down
Loading