Skip to content

Commit 80930c3

Browse files
authored
Unrolled build for #120382
Rollup merge of #120382 - fee1-dead-contrib:classify-closure-argument, r=Nadrieril Classify closure arguments in refutable pattern in argument error You can call it a function (and people may or may not agree with that), but it's better to just say those are closure arguments instead.
2 parents c073f56 + e17f91d commit 80930c3

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,18 @@ pub(crate) fn check_match(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), Err
4747
};
4848
visitor.visit_expr(&thir[expr]);
4949

50+
let origin = match tcx.def_kind(def_id) {
51+
DefKind::AssocFn | DefKind::Fn => "function argument",
52+
DefKind::Closure => "closure argument",
53+
// other types of MIR don't have function parameters, and we don't need to
54+
// categorize those for the irrefutable check.
55+
_ if thir.params.is_empty() => "",
56+
kind => bug!("unexpected function parameters in THIR: {kind:?} {def_id:?}"),
57+
};
58+
5059
for param in thir.params.iter() {
5160
if let Some(box ref pattern) = param.pat {
52-
visitor.check_binding_is_irrefutable(pattern, "function argument", None, None);
61+
visitor.check_binding_is_irrefutable(pattern, origin, None, None);
5362
}
5463
}
5564
visitor.error
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
fn main() {
22
let f = |3: isize| println!("hello");
3-
//~^ ERROR refutable pattern in function argument
3+
//~^ ERROR refutable pattern in closure argument
44
//~| `..=2_isize` and `4_isize..` not covered
55
f(4);
66
}

tests/ui/pattern/usefulness/refutable-pattern-in-fn-arg.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0005]: refutable pattern in function argument
1+
error[E0005]: refutable pattern in closure argument
22
--> $DIR/refutable-pattern-in-fn-arg.rs:2:14
33
|
44
LL | let f = |3: isize| println!("hello");

0 commit comments

Comments
 (0)