Skip to content

Commit 3d0eae1

Browse files
committed
Tweak wording when encountering fn call in pattern
1 parent 7840a0b commit 3d0eae1

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
@@ -1080,8 +1080,18 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
10801080
let msg = format!("expected tuple struct/variant, found {} `{}`",
10811081
res.descr(),
10821082
hir::print::to_string(tcx.hir(), |s| s.print_qpath(qpath, false)));
1083-
struct_span_err!(tcx.sess, pat.span, E0164, "{}", msg)
1084-
.span_label(pat.span, "not a tuple variant or struct").emit();
1083+
let mut err = struct_span_err!(tcx.sess, pat.span, E0164, "{}", msg);
1084+
match (res, &pat.node) {
1085+
(Res::Def(DefKind::Fn, _), _) | (Res::Def(DefKind::Method, _), _) => {
1086+
err.span_label(pat.span, "`fn` calls are not allowed in patterns");
1087+
err.help("for more information, visit \
1088+
https://doc.rust-lang.org/book/ch18-00-patterns.html");
1089+
}
1090+
_ => {
1091+
err.span_label(pat.span, "not a tuple variant or struct");
1092+
}
1093+
}
1094+
err.emit();
10851095
on_error();
10861096
};
10871097

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)