Skip to content

Commit 247e0a6

Browse files
authored
Rollup merge of #61441 - estebank:fn-call-in-match, r=varkor
Tweak wording when encountering `fn` call in pattern Fix #60642
2 parents 83b74f2 + 3d0eae1 commit 247e0a6

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

src/librustc_typeck/check/_match.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -1089,8 +1089,18 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
10891089
let msg = format!("expected tuple struct/variant, found {} `{}`",
10901090
res.descr(),
10911091
hir::print::to_string(tcx.hir(), |s| s.print_qpath(qpath, false)));
1092-
struct_span_err!(tcx.sess, pat.span, E0164, "{}", msg)
1093-
.span_label(pat.span, "not a tuple variant or struct").emit();
1092+
let mut err = struct_span_err!(tcx.sess, pat.span, E0164, "{}", msg);
1093+
match (res, &pat.node) {
1094+
(Res::Def(DefKind::Fn, _), _) | (Res::Def(DefKind::Method, _), _) => {
1095+
err.span_label(pat.span, "`fn` calls are not allowed in patterns");
1096+
err.help("for more information, visit \
1097+
https://doc.rust-lang.org/book/ch18-00-patterns.html");
1098+
}
1099+
_ => {
1100+
err.span_label(pat.span, "not a tuple variant or struct");
1101+
}
1102+
}
1103+
err.emit();
10941104
on_error();
10951105
};
10961106

src/test/ui/fn-in-pat.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0164]: expected tuple struct/variant, found method `<A>::new`
22
--> $DIR/fn-in-pat.rs:11:9
33
|
44
LL | A::new() => (),
5-
| ^^^^^^^^ not a tuple variant or struct
5+
| ^^^^^^^^ `fn` calls are not allowed in patterns
6+
|
7+
= help: for more information, visit https://doc.rust-lang.org/book/ch18-00-patterns.html
68

79
error: aborting due to previous error
810

src/test/ui/issues/issue-55587.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0164]: expected tuple struct/variant, found method `<Path>::new`
22
--> $DIR/issue-55587.rs:4:9
33
|
44
LL | let Path::new();
5-
| ^^^^^^^^^^^ not a tuple variant or struct
5+
| ^^^^^^^^^^^ `fn` calls are not allowed in patterns
6+
|
7+
= help: for more information, visit https://doc.rust-lang.org/book/ch18-00-patterns.html
68

79
error: aborting due to previous error
810

src/test/ui/match/match-fn-call.stderr

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ error[E0164]: expected tuple struct/variant, found method `<Path>::new`
22
--> $DIR/match-fn-call.rs:6:9
33
|
44
LL | Path::new("foo") => println!("foo"),
5-
| ^^^^^^^^^^^^^^^^ not a tuple variant or struct
5+
| ^^^^^^^^^^^^^^^^ `fn` calls are not allowed in patterns
6+
|
7+
= help: for more information, visit https://doc.rust-lang.org/book/ch18-00-patterns.html
68

79
error[E0164]: expected tuple struct/variant, found method `<Path>::new`
810
--> $DIR/match-fn-call.rs:8:9
911
|
1012
LL | Path::new("bar") => println!("bar"),
11-
| ^^^^^^^^^^^^^^^^ not a tuple variant or struct
13+
| ^^^^^^^^^^^^^^^^ `fn` calls are not allowed in patterns
14+
|
15+
= help: for more information, visit https://doc.rust-lang.org/book/ch18-00-patterns.html
1216

1317
error: aborting due to 2 previous errors
1418

0 commit comments

Comments
 (0)