More explicit diagnostic when using a vec![] in a pattern
``` error: unexpected `(` after qualified path --> $DIR/vec-macro-in-pattern.rs:3:14 | LL | Some(vec![x]) => (), | ^^^^^^^ | | | unexpected `(` after qualified path | in this macro invocation | use a slice pattern here instead | = help: for more information, see https://doc.rust-lang.org/edition-guide/rust-2018/slice-patterns.html = note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) ```
This commit is contained in:
@@ -686,12 +686,13 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
||||
);
|
||||
}
|
||||
|
||||
fn parse_ast_fragment(&mut self,
|
||||
toks: TokenStream,
|
||||
kind: AstFragmentKind,
|
||||
path: &Path,
|
||||
span: Span)
|
||||
-> AstFragment {
|
||||
fn parse_ast_fragment(
|
||||
&mut self,
|
||||
toks: TokenStream,
|
||||
kind: AstFragmentKind,
|
||||
path: &Path,
|
||||
span: Span,
|
||||
) -> AstFragment {
|
||||
let mut parser = self.cx.new_parser_from_tts(&toks.into_trees().collect::<Vec<_>>());
|
||||
match parser.parse_ast_fragment(kind, false) {
|
||||
Ok(fragment) => {
|
||||
@@ -700,6 +701,21 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
||||
}
|
||||
Err(mut err) => {
|
||||
err.set_span(span);
|
||||
match kind {
|
||||
AstFragmentKind::Ty => {
|
||||
err.span_label(
|
||||
span,
|
||||
"this macro call doesn't expand to a type",
|
||||
);
|
||||
}
|
||||
AstFragmentKind::Pat => {
|
||||
err.span_label(
|
||||
span,
|
||||
"this macro call doesn't expand to a pattern",
|
||||
);
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
err.emit();
|
||||
self.cx.trace_macros_diag();
|
||||
kind.dummy(span)
|
||||
|
||||
Reference in New Issue
Block a user