Rollup merge of #61441 - estebank:fn-call-in-match, r=varkor

Tweak wording when encountering `fn` call in pattern

Fix #60642
This commit is contained in:
Mazdak Farrokhzad 2019-06-02 15:23:50 +02:00 committed by GitHub
commit 247e0a688d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 6 deletions

View File

@ -1089,8 +1089,18 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
let msg = format!("expected tuple struct/variant, found {} `{}`", let msg = format!("expected tuple struct/variant, found {} `{}`",
res.descr(), res.descr(),
hir::print::to_string(tcx.hir(), |s| s.print_qpath(qpath, false))); hir::print::to_string(tcx.hir(), |s| s.print_qpath(qpath, false)));
struct_span_err!(tcx.sess, pat.span, E0164, "{}", msg) let mut err = struct_span_err!(tcx.sess, pat.span, E0164, "{}", msg);
.span_label(pat.span, "not a tuple variant or struct").emit(); 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(); on_error();
}; };

View File

@ -2,7 +2,9 @@ error[E0164]: expected tuple struct/variant, found method `<A>::new`
--> $DIR/fn-in-pat.rs:11:9 --> $DIR/fn-in-pat.rs:11:9
| |
LL | A::new() => (), 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 error: aborting due to previous error

View File

@ -2,7 +2,9 @@ error[E0164]: expected tuple struct/variant, found method `<Path>::new`
--> $DIR/issue-55587.rs:4:9 --> $DIR/issue-55587.rs:4:9
| |
LL | let Path::new(); 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 error: aborting due to previous error

View File

@ -2,13 +2,17 @@ error[E0164]: expected tuple struct/variant, found method `<Path>::new`
--> $DIR/match-fn-call.rs:6:9 --> $DIR/match-fn-call.rs:6:9
| |
LL | Path::new("foo") => println!("foo"), 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` error[E0164]: expected tuple struct/variant, found method `<Path>::new`
--> $DIR/match-fn-call.rs:8:9 --> $DIR/match-fn-call.rs:8:9
| |
LL | Path::new("bar") => println!("bar"), 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 error: aborting due to 2 previous errors