Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3a6a29b
Use associated_type_bounds where applicable - closes #61738
iluuu1994 Jul 31, 2019
322a7d6
Add test for issue 36804
jackh726 Aug 8, 2019
3d231ac
Add missing #![feature(associated_type_bounds)]
iluuu1994 Aug 8, 2019
77bfd7f
Don't use associated type bounds in docs until it is stable
iluuu1994 Aug 9, 2019
c076392
Tweak mismatched types error on break expressions
estebank Aug 6, 2019
799b13a
Do not suggest using ! with break
estebank Aug 7, 2019
4fbbf99
Be more accurate when mentioning type of found match arms
estebank Aug 7, 2019
01a6139
Change wording for function without return value
estebank Aug 7, 2019
94fe8a3
Suggest calling function on type error when finding bare fn
estebank Aug 7, 2019
195d837
When suggesting fn call use an appropriate number of placeholder argu…
estebank Aug 8, 2019
b7f7756
Recover parser from `foo(_, _)`
estebank Aug 8, 2019
0d53f69
review comments
estebank Aug 8, 2019
efa62d6
Tweak wording of fn without explicit return
estebank Aug 8, 2019
52da091
Differentiate between tuple structs and tuple variants
estebank Aug 8, 2019
5a54945
Extend suggestion support for traits and foreign items
estebank Aug 8, 2019
33d1082
review comment: review wording or missing return error
estebank Aug 8, 2019
bc1a4f5
review comments: typo and rewording
estebank Aug 8, 2019
45a5bc7
fix tests
estebank Aug 9, 2019
7c96d90
More explicit diagnostic when using a `vec![]` in a pattern
estebank Aug 9, 2019
75c5ad2
review comments: use structured suggestion
estebank Aug 9, 2019
4dd96d2
check against more collisions for TypeId of fn pointer
RalfJung Aug 9, 2019
b9865d9
Mention that tuple structs are private if their fields are
estebank Aug 9, 2019
cbcc7dd
Give built-in macros stable addresses in the standard library
petrochenkov Jul 27, 2019
0ef7c28
resolve: Populate external modules in more automatic and lazy way
petrochenkov Jul 29, 2019
3ee614b
resolve: Populate external traits lazily as well
petrochenkov Jul 30, 2019
2cb9207
resolve: Move some code around
petrochenkov Jul 30, 2019
a38cbcf
Rollup merge of #63056 - petrochenkov:macstd2, r=alexcrichton
Centril Aug 10, 2019
a14318d
Rollup merge of #63149 - petrochenkov:lazypop2, r=eddyb
Centril Aug 10, 2019
5379a7d
Rollup merge of #63337 - estebank:break-ee0308, r=Centril
Centril Aug 10, 2019
a29196d
Rollup merge of #63350 - iluuu1994:use-associated-type-bounds, r=Centril
Centril Aug 10, 2019
45d089a
Rollup merge of #63394 - jackh726:issue-36804, r=jonas-schievink
Centril Aug 10, 2019
9ece794
Rollup merge of #63399 - estebank:vec-in-pat, r=Centril
Centril Aug 10, 2019
664b34d
Rollup merge of #63419 - RalfJung:typeid, r=alexcrichton
Centril Aug 10, 2019
2dfa3a9
Rollup merge of #63423 - estebank:priv-tuple, r=zackmdavis
Centril Aug 10, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
review comments: use structured suggestion
  • Loading branch information
estebank committed Aug 9, 2019
commit 75c5ad2e827a077c3738dee11d9e0dc99962f384
17 changes: 2 additions & 15 deletions src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::config::StripUnconfigured;
use crate::ext::base::*;
use crate::ext::proc_macro::collect_derives;
use crate::ext::hygiene::{ExpnId, SyntaxContext, ExpnInfo, ExpnKind};
use crate::ext::tt::macro_rules::annotate_err_with_kind;
use crate::ext::placeholders::{placeholder, PlaceholderExpander};
use crate::feature_gate::{self, Features, GateIssue, is_builtin_attr, emit_feature_err};
use crate::mut_visit::*;
Expand Down Expand Up @@ -701,21 +702,7 @@ 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",
);
}
_ => {}
};
annotate_err_with_kind(&mut err, kind, span);
err.emit();
self.cx.trace_macros_diag();
kind.dummy(span)
Expand Down
53 changes: 34 additions & 19 deletions src/libsyntax/ext/tt/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::symbol::{kw, sym, Symbol};
use crate::tokenstream::{DelimSpan, TokenStream, TokenTree};
use crate::{ast, attr, attr::TransparencyError};

use errors::FatalError;
use errors::{DiagnosticBuilder, FatalError};
use log::debug;
use syntax_pos::Span;

Expand All @@ -43,6 +43,18 @@ pub struct ParserAnyMacro<'a> {
arm_span: Span,
}

pub fn annotate_err_with_kind(err: &mut DiagnosticBuilder<'_>, kind: AstFragmentKind, 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");
}
_ => {}
};
}

impl<'a> ParserAnyMacro<'a> {
pub fn make(mut self: Box<ParserAnyMacro<'a>>, kind: AstFragmentKind) -> AstFragment {
let ParserAnyMacro { site_span, macro_ident, ref mut parser, arm_span } = *self;
Expand Down Expand Up @@ -71,27 +83,30 @@ impl<'a> ParserAnyMacro<'a> {
e.span_label(site_span, "in this macro invocation");
}
match kind {
AstFragmentKind::Ty => {
e.span_label(
site_span,
"this macro call doesn't expand to a type",
);
}
AstFragmentKind::Pat if macro_ident.name == sym::vec => {
e.span_label(
site_span,
"use a slice pattern here instead",
);
let mut suggestion = None;
if let Ok(code) = parser.sess.source_map().span_to_snippet(site_span) {
if let Some(bang) = code.find('!') {
suggestion = Some(code[bang + 1..].to_string());
}
}
if let Some(suggestion) = suggestion {
e.span_suggestion(
site_span,
"use a slice pattern here instead",
suggestion,
Applicability::MachineApplicable,
);
} else {
e.span_label(
site_span,
"use a slice pattern here instead",
);
}
e.help("for more information, see https://doc.rust-lang.org/edition-guide/\
rust-2018/slice-patterns.html");
}
AstFragmentKind::Pat => {
e.span_label(
site_span,
"this macro call doesn't expand to a pattern",
);
rust-2018/slice-patterns.html");
}
_ => {}
_ => annotate_err_with_kind(&mut e, kind, site_span),
};
e
}));
Expand Down
8 changes: 8 additions & 0 deletions src/test/ui/suggestions/vec-macro-in-pattern.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// run-rustfix
fn main() {
// everything after `.as_ref` should be suggested
match Some(vec![3]).as_ref().map(|v| v.as_slice()) {
Some([_x]) => (), //~ ERROR unexpected `(` after qualified path
_ => (),
}
}
6 changes: 4 additions & 2 deletions src/test/ui/suggestions/vec-macro-in-pattern.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// run-rustfix
fn main() {
match Some(vec![3]) {
Some(vec![x]) => (), //~ ERROR unexpected `(` after qualified path
// everything after `.as_ref` should be suggested
match Some(vec![3]).as_ref().map(|v| v.as_slice()) {
Some(vec![_x]) => (), //~ ERROR unexpected `(` after qualified path
_ => (),
}
}
8 changes: 4 additions & 4 deletions src/test/ui/suggestions/vec-macro-in-pattern.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
error: unexpected `(` after qualified path
--> $DIR/vec-macro-in-pattern.rs:3:14
--> $DIR/vec-macro-in-pattern.rs:5:14
|
LL | Some(vec![x]) => (),
| ^^^^^^^
LL | Some(vec![_x]) => (),
| ^^^^^^^^
| |
| unexpected `(` after qualified path
| in this macro invocation
| use a slice pattern here instead
| help: use a slice pattern here instead: `[_x]`
|
= 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)
Expand Down