diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-06-02 15:23:50 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-06-02 15:23:50 +0200 |
| commit | 247e0a688ddd4c7d8d45f1be5d159d5e0d9dde2c (patch) | |
| tree | 710789c3c2203e9b3b0e41ff200e948969ef4a9a | |
| parent | 83b74f2aad1191ca93265aece416f8641e49524a (diff) | |
| parent | 3d0eae18c6aca881a3daf72110386b805d1e1dc4 (diff) | |
| download | rust-247e0a688ddd4c7d8d45f1be5d159d5e0d9dde2c.tar.gz rust-247e0a688ddd4c7d8d45f1be5d159d5e0d9dde2c.zip | |
Rollup merge of #61441 - estebank:fn-call-in-match, r=varkor
Tweak wording when encountering `fn` call in pattern Fix #60642
| -rw-r--r-- | src/librustc_typeck/check/_match.rs | 14 | ||||
| -rw-r--r-- | src/test/ui/fn-in-pat.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-55587.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/match/match-fn-call.stderr | 8 |
4 files changed, 24 insertions, 6 deletions
diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index 64e2eedd721..9607427baa9 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -1089,8 +1089,18 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); let msg = format!("expected tuple struct/variant, found {} `{}`", res.descr(), hir::print::to_string(tcx.hir(), |s| s.print_qpath(qpath, false))); - struct_span_err!(tcx.sess, pat.span, E0164, "{}", msg) - .span_label(pat.span, "not a tuple variant or struct").emit(); + let mut err = struct_span_err!(tcx.sess, pat.span, E0164, "{}", msg); + match (res, &pat.node) { + (Res::Def(DefKind::Fn, _), _) | (Res::Def(DefKind::Method, _), _) => { + err.span_label(pat.span, "`fn` calls are not allowed in patterns"); + err.help("for more information, visit \ + https://doc.rust-lang.org/book/ch18-00-patterns.html"); + } + _ => { + err.span_label(pat.span, "not a tuple variant or struct"); + } + } + err.emit(); on_error(); }; diff --git a/src/test/ui/fn-in-pat.stderr b/src/test/ui/fn-in-pat.stderr index eee97fe9587..0bb24365ef4 100644 --- a/src/test/ui/fn-in-pat.stderr +++ b/src/test/ui/fn-in-pat.stderr @@ -2,7 +2,9 @@ error[E0164]: expected tuple struct/variant, found method `<A>::new` --> $DIR/fn-in-pat.rs:11:9 | LL | A::new() => (), - | ^^^^^^^^ not a tuple variant or struct + | ^^^^^^^^ `fn` calls are not allowed in patterns + | + = help: for more information, visit https://doc.rust-lang.org/book/ch18-00-patterns.html error: aborting due to previous error diff --git a/src/test/ui/issues/issue-55587.stderr b/src/test/ui/issues/issue-55587.stderr index 1334f249256..3928a3cd532 100644 --- a/src/test/ui/issues/issue-55587.stderr +++ b/src/test/ui/issues/issue-55587.stderr @@ -2,7 +2,9 @@ error[E0164]: expected tuple struct/variant, found method `<Path>::new` --> $DIR/issue-55587.rs:4:9 | LL | let Path::new(); - | ^^^^^^^^^^^ not a tuple variant or struct + | ^^^^^^^^^^^ `fn` calls are not allowed in patterns + | + = help: for more information, visit https://doc.rust-lang.org/book/ch18-00-patterns.html error: aborting due to previous error diff --git a/src/test/ui/match/match-fn-call.stderr b/src/test/ui/match/match-fn-call.stderr index 4e24621706b..bd918428351 100644 --- a/src/test/ui/match/match-fn-call.stderr +++ b/src/test/ui/match/match-fn-call.stderr @@ -2,13 +2,17 @@ error[E0164]: expected tuple struct/variant, found method `<Path>::new` --> $DIR/match-fn-call.rs:6:9 | LL | Path::new("foo") => println!("foo"), - | ^^^^^^^^^^^^^^^^ not a tuple variant or struct + | ^^^^^^^^^^^^^^^^ `fn` calls are not allowed in patterns + | + = help: for more information, visit https://doc.rust-lang.org/book/ch18-00-patterns.html error[E0164]: expected tuple struct/variant, found method `<Path>::new` --> $DIR/match-fn-call.rs:8:9 | LL | Path::new("bar") => println!("bar"), - | ^^^^^^^^^^^^^^^^ not a tuple variant or struct + | ^^^^^^^^^^^^^^^^ `fn` calls are not allowed in patterns + | + = help: for more information, visit https://doc.rust-lang.org/book/ch18-00-patterns.html error: aborting due to 2 previous errors |
