aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Galenson <jgalenson@google.com>2021-09-23 15:02:47 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-09-23 15:02:47 +0000
commit9a0bbb5cfe75e9fe9b391d4d21e8246e4eece0ae (patch)
treeceeca6d5f10ba0e5f4268445479c91ad3855c4d6
parentc4c013bf3542faed7124d79f70cd2bbd4ed8e378 (diff)
parent76261debf521a8b327fc5625b77712b4fb806645 (diff)
downloadsyn-9a0bbb5cfe75e9fe9b391d4d21e8246e4eece0ae.tar.gz
Upgrade rust/crates/syn to 1.0.76 am: 0773d8db28 am: 5339c37666 am: 76261debf5
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/syn/+/1832704 Change-Id: I9568d519b9dd35a21fb23482b7c5f9801b88b005
-rw-r--r--.cargo_vcs_info.json2
-rw-r--r--Android.bp9
-rw-r--r--Cargo.toml4
-rw-r--r--Cargo.toml.orig4
-rw-r--r--METADATA8
-rw-r--r--src/data.rs6
-rw-r--r--src/expr.rs13
-rw-r--r--src/generics.rs6
-rw-r--r--src/item.rs2
-rw-r--r--src/lib.rs6
-rw-r--r--src/pat.rs28
-rw-r--r--src/stmt.rs83
-rw-r--r--tests/common/eq.rs31
-rw-r--r--tests/repo/mod.rs37
-rw-r--r--tests/test_precedence.rs49
-rw-r--r--tests/test_round_trip.rs7
16 files changed, 195 insertions, 100 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index 86f59567..225992b2 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,5 +1,5 @@
{
"git": {
- "sha1": "9e206dad2346e2f4542abb2200c397ceefddfc06"
+ "sha1": "8820d7320f98befc3715d651edc33463393967d3"
}
}
diff --git a/Android.bp b/Android.bp
index 5f12c463..f2a44691 100644
--- a/Android.bp
+++ b/Android.bp
@@ -1,4 +1,4 @@
-// This file is generated by cargo2android.py --run --dependencies --features=full,visit,visit-mut,extra-traits --features=default,full,visit,visit-mut,extra-traits --host-first-multilib.
+// This file is generated by cargo2android.py --run --features=full,visit,visit-mut,extra-traits --features=default,full,visit,visit-mut,extra-traits --host-first-multilib.
// Do not modify this file as changes will be overridden on upgrade.
package {
@@ -40,6 +40,8 @@ license {
rust_library_host {
name: "libsyn",
crate_name: "syn",
+ cargo_env_compat: true,
+ cargo_pkg_version: "1.0.76",
srcs: ["src/lib.rs"],
edition: "2018",
features: [
@@ -63,8 +65,3 @@ rust_library_host {
],
compile_multilib: "first",
}
-
-// dependent_library ["feature_list"]
-// proc-macro2-1.0.28 "default,proc-macro"
-// quote-1.0.9 "default,proc-macro"
-// unicode-xid-0.2.2 "default"
diff --git a/Cargo.toml b/Cargo.toml
index 34b0f818..a3b50895 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,7 +12,7 @@
[package]
edition = "2018"
name = "syn"
-version = "1.0.74"
+version = "1.0.76"
authors = ["David Tolnay <dtolnay@gmail.com>"]
include = ["/benches/**", "/build.rs", "/Cargo.toml", "/LICENSE-APACHE", "/LICENSE-MIT", "/README.md", "/src/**", "/tests/**"]
description = "Parser for Rust source code"
@@ -67,7 +67,7 @@ version = "1.0"
version = "1.0"
[dev-dependencies.reqwest]
-version = "0.10"
+version = "0.11"
features = ["blocking"]
[dev-dependencies.syn-test-suite]
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index efcfcb90..ed6e1821 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,6 +1,6 @@
[package]
name = "syn"
-version = "1.0.74" # don't forget to update html_root_url and syn.json
+version = "1.0.76" # don't forget to update html_root_url and syn.json
authors = ["David Tolnay <dtolnay@gmail.com>"]
license = "MIT OR Apache-2.0"
description = "Parser for Rust source code"
@@ -46,7 +46,7 @@ insta = "1.0"
rayon = "1.0"
ref-cast = "1.0"
regex = "1.0"
-reqwest = { version = "0.10", features = ["blocking"] }
+reqwest = { version = "0.11", features = ["blocking"] }
syn-test-suite = { version = "0", path = "tests/features" }
tar = "0.4.16"
termcolor = "1.0"
diff --git a/METADATA b/METADATA
index 666d8a47..856e272b 100644
--- a/METADATA
+++ b/METADATA
@@ -7,13 +7,13 @@ third_party {
}
url {
type: ARCHIVE
- value: "https://static.crates.io/crates/syn/syn-1.0.74.crate"
+ value: "https://static.crates.io/crates/syn/syn-1.0.76.crate"
}
- version: "1.0.74"
+ version: "1.0.76"
license_type: NOTICE
last_upgrade_date {
year: 2021
- month: 8
- day: 9
+ month: 9
+ day: 22
}
}
diff --git a/src/data.rs b/src/data.rs
index 837224e1..dc2138c1 100644
--- a/src/data.rs
+++ b/src/data.rs
@@ -313,7 +313,11 @@ pub mod parsing {
Ok(Field {
attrs: input.call(Attribute::parse_outer)?,
vis: input.parse()?,
- ident: Some(input.parse()?),
+ ident: Some(if input.peek(Token![_]) {
+ input.call(Ident::parse_any)
+ } else {
+ input.parse()
+ }?),
colon_token: Some(input.parse()?),
ty: input.parse()?,
})
diff --git a/src/expr.rs b/src/expr.rs
index 24f79117..d9319ddd 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -1824,12 +1824,10 @@ pub(crate) mod parsing {
#[cfg(feature = "full")]
fn path_or_macro_or_struct(input: ParseStream, allow_struct: AllowStruct) -> Result<Expr> {
+ let begin = input.fork();
let expr: ExprPath = input.parse()?;
- if expr.qself.is_some() {
- return Ok(Expr::Path(expr));
- }
- if input.peek(Token![!]) && !input.peek(Token![!=]) {
+ if expr.qself.is_none() && input.peek(Token![!]) && !input.peek(Token![!=]) {
let mut contains_arguments = false;
for segment in &expr.path.segments {
match segment.arguments {
@@ -1857,7 +1855,12 @@ pub(crate) mod parsing {
if allow_struct.0 && input.peek(token::Brace) {
let outer_attrs = Vec::new();
- expr_struct_helper(input, outer_attrs, expr.path).map(Expr::Struct)
+ let expr_struct = expr_struct_helper(input, outer_attrs, expr.path)?;
+ if expr.qself.is_some() {
+ Ok(Expr::Verbatim(verbatim::between(begin, input)))
+ } else {
+ Ok(Expr::Struct(expr_struct))
+ }
} else {
Ok(Expr::Path(expr))
}
diff --git a/src/generics.rs b/src/generics.rs
index 0950c1cb..9df6b405 100644
--- a/src/generics.rs
+++ b/src/generics.rs
@@ -770,8 +770,8 @@ pub mod parsing {
if input.peek(Token![,]) || input.peek(Token![>]) || input.peek(Token![=]) {
break;
}
- if input.peek(Token![?]) && input.peek2(Token![const]) {
- input.parse::<Token![?]>()?;
+ if input.peek(Token![~]) && input.peek2(Token![const]) {
+ input.parse::<Token![~]>()?;
input.parse::<Token![const]>()?;
is_maybe_const = true;
}
@@ -1188,7 +1188,7 @@ mod printing {
let mut iter = default.clone().into_iter().peekable();
while let Some(token) = iter.next() {
if let TokenTree::Punct(q) = token {
- if q.as_char() == '?' {
+ if q.as_char() == '~' {
if let Some(TokenTree::Ident(c)) = iter.peek() {
if c == "const" {
if self.bounds.is_empty() {
diff --git a/src/item.rs b/src/item.rs
index 40d94e05..0fd1226a 100644
--- a/src/item.rs
+++ b/src/item.rs
@@ -2687,7 +2687,7 @@ pub mod parsing {
punct.set_span(semi.span);
let tokens = TokenStream::from_iter(vec![TokenTree::Punct(punct)]);
Block {
- brace_token: Brace::default(),
+ brace_token: Brace { span: semi.span },
stmts: vec![Stmt::Item(Item::Verbatim(tokens))],
}
} else {
diff --git a/src/lib.rs b/src/lib.rs
index b8390953..077dd200 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -250,11 +250,12 @@
//! dynamic library libproc_macro from rustc toolchain.
// Syn types in rustdoc of other crates get linked to here.
-#![doc(html_root_url = "https://docs.rs/syn/1.0.74")]
+#![doc(html_root_url = "https://docs.rs/syn/1.0.76")]
#![cfg_attr(doc_cfg, feature(doc_cfg))]
#![allow(non_camel_case_types)]
// Ignored clippy lints.
#![allow(
+ clippy::collapsible_match, // https://github.com/rust-lang/rust-clippy/issues/7575
clippy::doc_markdown,
clippy::eval_order_dependence,
clippy::inherent_to_string,
@@ -890,6 +891,9 @@ pub fn parse<T: parse::Parse>(tokens: proc_macro::TokenStream) -> Result<T> {
/// Parse a proc-macro2 token stream into the chosen syntax tree node.
///
+/// This function will check that the input is fully parsed. If there are
+/// any unparsed tokens at the end of the stream, an error is returned.
+///
/// This function parses a `proc_macro2::TokenStream` which is commonly useful
/// when the input comes from a node of the Syn syntax tree, for example the
/// body tokens of a [`Macro`] node. When in a procedural macro parsing the
diff --git a/src/pat.rs b/src/pat.rs
index d25843fc..bfabfe66 100644
--- a/src/pat.rs
+++ b/src/pat.rs
@@ -376,19 +376,7 @@ pub mod parsing {
let begin = input.fork();
let (qself, path) = path::parsing::qpath(input, true)?;
- if input.peek(Token![..]) {
- return pat_range(input, begin, qself, path);
- }
-
- if qself.is_some() {
- return Ok(Pat::Path(PatPath {
- attrs: Vec::new(),
- qself,
- path,
- }));
- }
-
- if input.peek(Token![!]) && !input.peek(Token![!=]) {
+ if qself.is_none() && input.peek(Token![!]) && !input.peek(Token![!=]) {
let mut contains_arguments = false;
for segment in &path.segments {
match segment.arguments {
@@ -415,9 +403,19 @@ pub mod parsing {
}
if input.peek(token::Brace) {
- pat_struct(input, path).map(Pat::Struct)
+ let pat = pat_struct(input, path)?;
+ if qself.is_some() {
+ Ok(Pat::Verbatim(verbatim::between(begin, input)))
+ } else {
+ Ok(Pat::Struct(pat))
+ }
} else if input.peek(token::Paren) {
- pat_tuple_struct(input, path).map(Pat::TupleStruct)
+ let pat = pat_tuple_struct(input, path)?;
+ if qself.is_some() {
+ Ok(Pat::Verbatim(verbatim::between(begin, input)))
+ } else {
+ Ok(Pat::TupleStruct(pat))
+ }
} else if input.peek(Token![..]) {
pat_range(input, begin, qself, path)
} else {
diff --git a/src/stmt.rs b/src/stmt.rs
index ba2b22e5..abdefaae 100644
--- a/src/stmt.rs
+++ b/src/stmt.rs
@@ -165,7 +165,7 @@ pub mod parsing {
}
if input.peek(Token![let]) {
- stmt_local(input, attrs).map(Stmt::Local)
+ stmt_local(input, attrs)
} else if input.peek(Token![pub])
|| input.peek(Token![crate]) && !input.peek2(Token![::])
|| input.peek(Token![extern])
@@ -219,35 +219,51 @@ pub mod parsing {
})))
}
- fn stmt_local(input: ParseStream, attrs: Vec<Attribute>) -> Result<Local> {
- Ok(Local {
+ fn stmt_local(input: ParseStream, attrs: Vec<Attribute>) -> Result<Stmt> {
+ let begin = input.fork();
+
+ let let_token: Token![let] = input.parse()?;
+
+ let mut pat: Pat = pat::parsing::multi_pat_with_leading_vert(input)?;
+ if input.peek(Token![:]) {
+ let colon_token: Token![:] = input.parse()?;
+ let ty: Type = input.parse()?;
+ pat = Pat::Type(PatType {
+ attrs: Vec::new(),
+ pat: Box::new(pat),
+ colon_token,
+ ty: Box::new(ty),
+ });
+ }
+
+ let init = if input.peek(Token![=]) {
+ let eq_token: Token![=] = input.parse()?;
+ let init: Expr = input.parse()?;
+
+ if input.peek(Token![else]) {
+ input.parse::<Token![else]>()?;
+ let content;
+ braced!(content in input);
+ content.call(Block::parse_within)?;
+ let verbatim = Expr::Verbatim(verbatim::between(begin, input));
+ let semi_token: Token![;] = input.parse()?;
+ return Ok(Stmt::Semi(verbatim, semi_token));
+ }
+
+ Some((eq_token, Box::new(init)))
+ } else {
+ None
+ };
+
+ let semi_token: Token![;] = input.parse()?;
+
+ Ok(Stmt::Local(Local {
attrs,
- let_token: input.parse()?,
- pat: {
- let mut pat: Pat = pat::parsing::multi_pat_with_leading_vert(input)?;
- if input.peek(Token![:]) {
- let colon_token: Token![:] = input.parse()?;
- let ty: Type = input.parse()?;
- pat = Pat::Type(PatType {
- attrs: Vec::new(),
- pat: Box::new(pat),
- colon_token,
- ty: Box::new(ty),
- });
- }
- pat
- },
- init: {
- if input.peek(Token![=]) {
- let eq_token: Token![=] = input.parse()?;
- let init: Expr = input.parse()?;
- Some((eq_token, Box::new(init)))
- } else {
- None
- }
- },
- semi_token: input.parse()?,
- })
+ let_token,
+ pat,
+ init,
+ semi_token,
+ }))
}
fn stmt_expr(
@@ -258,8 +274,13 @@ pub mod parsing {
let mut e = expr::parsing::expr_early(input)?;
let mut attr_target = &mut e;
- while let Expr::Binary(e) = attr_target {
- attr_target = &mut e.left;
+ loop {
+ attr_target = match attr_target {
+ Expr::Assign(e) => &mut e.left,
+ Expr::AssignOp(e) => &mut e.left,
+ Expr::Binary(e) => &mut e.left,
+ _ => break,
+ };
}
attrs.extend(attr_target.replace_attrs(Vec::new()));
attr_target.replace_attrs(attrs);
diff --git a/tests/common/eq.rs b/tests/common/eq.rs
index 4f195502..3ece45b3 100644
--- a/tests/common/eq.rs
+++ b/tests/common/eq.rs
@@ -11,13 +11,13 @@ use rustc_ast::ast::{
GenericParam, GenericParamKind, Generics, ImplKind, ImplPolarity, Inline, InlineAsm,
InlineAsmOperand, InlineAsmOptions, InlineAsmRegOrRegClass, InlineAsmTemplatePiece, IntTy,
IsAuto, Item, ItemKind, Label, Lifetime, Lit, LitFloatType, LitIntType, LitKind,
- LlvmAsmDialect, LlvmInlineAsm, LlvmInlineAsmOutput, Local, MacArgs, MacCall, MacCallStmt,
- MacDelimiter, MacStmtStyle, MacroDef, ModKind, Movability, MutTy, Mutability, NodeId, Param,
- ParenthesizedArgs, Pat, PatField, PatKind, Path, PathSegment, PolyTraitRef, QSelf, RangeEnd,
- RangeLimits, RangeSyntax, Stmt, StmtKind, StrLit, StrStyle, StructExpr, StructRest,
- TraitBoundModifier, TraitKind, TraitObjectSyntax, TraitRef, Ty, TyAliasKind, TyKind, UintTy,
- UnOp, Unsafe, UnsafeSource, UseTree, UseTreeKind, Variant, VariantData, Visibility,
- VisibilityKind, WhereBoundPredicate, WhereClause, WhereEqPredicate, WherePredicate,
+ LlvmAsmDialect, LlvmInlineAsm, LlvmInlineAsmOutput, Local, LocalKind, MacArgs, MacCall,
+ MacCallStmt, MacDelimiter, MacStmtStyle, MacroDef, ModKind, Movability, MutTy, Mutability,
+ NodeId, Param, ParenthesizedArgs, Pat, PatField, PatKind, Path, PathSegment, PolyTraitRef,
+ QSelf, RangeEnd, RangeLimits, RangeSyntax, Stmt, StmtKind, StrLit, StrStyle, StructExpr,
+ StructRest, TraitBoundModifier, TraitKind, TraitObjectSyntax, TraitRef, Ty, TyAliasKind,
+ TyKind, UintTy, UnOp, Unsafe, UnsafeSource, UseTree, UseTreeKind, Variant, VariantData,
+ Visibility, VisibilityKind, WhereBoundPredicate, WhereClause, WhereEqPredicate, WherePredicate,
WhereRegionPredicate,
};
use rustc_ast::ptr::P;
@@ -36,7 +36,7 @@ pub trait SpanlessEq {
fn eq(&self, other: &Self) -> bool;
}
-impl<T: SpanlessEq> SpanlessEq for Box<T> {
+impl<T: ?Sized + SpanlessEq> SpanlessEq for Box<T> {
fn eq(&self, other: &Self) -> bool {
SpanlessEq::eq(&**self, &**other)
}
@@ -98,6 +98,14 @@ impl<A: SpanlessEq, B: SpanlessEq> SpanlessEq for (A, B) {
}
}
+impl<A: SpanlessEq, B: SpanlessEq, C: SpanlessEq> SpanlessEq for (A, B, C) {
+ fn eq(&self, other: &Self) -> bool {
+ SpanlessEq::eq(&self.0, &other.0)
+ && SpanlessEq::eq(&self.1, &other.1)
+ && SpanlessEq::eq(&self.2, &other.2)
+ }
+}
+
macro_rules! spanless_eq_true {
($name:ty) => {
impl SpanlessEq for $name {
@@ -308,14 +316,14 @@ spanless_eq_struct!(ForeignMod; unsafety abi items);
spanless_eq_struct!(GenericParam; id ident attrs bounds is_placeholder kind);
spanless_eq_struct!(Generics; params where_clause span);
spanless_eq_struct!(ImplKind; unsafety polarity defaultness constness generics of_trait self_ty items);
-spanless_eq_struct!(InlineAsm; template operands options line_spans);
+spanless_eq_struct!(InlineAsm; template template_strs operands clobber_abi options line_spans);
spanless_eq_struct!(Item<K>; attrs id span vis ident kind !tokens);
spanless_eq_struct!(Label; ident);
spanless_eq_struct!(Lifetime; id ident);
spanless_eq_struct!(Lit; token kind span);
spanless_eq_struct!(LlvmInlineAsm; asm asm_str_style outputs inputs clobbers volatile alignstack dialect);
spanless_eq_struct!(LlvmInlineAsmOutput; constraint expr is_rw is_indirect);
-spanless_eq_struct!(Local; pat ty init id span attrs !tokens);
+spanless_eq_struct!(Local; pat ty kind id span attrs !tokens);
spanless_eq_struct!(MacCall; path args prior_type_ascription);
spanless_eq_struct!(MacCallStmt; mac style attrs tokens);
spanless_eq_struct!(MacroDef; body macro_rules);
@@ -374,6 +382,7 @@ spanless_eq_enum!(IsAuto; Yes No);
spanless_eq_enum!(LitFloatType; Suffixed(0) Unsuffixed);
spanless_eq_enum!(LitIntType; Signed(0) Unsigned(0) Unsuffixed);
spanless_eq_enum!(LlvmAsmDialect; Att Intel);
+spanless_eq_enum!(LocalKind; Decl Init(0) InitElse(0 1));
spanless_eq_enum!(MacArgs; Empty Delimited(0 1 2) Eq(0 1));
spanless_eq_enum!(MacDelimiter; Parenthesis Bracket Brace);
spanless_eq_enum!(MacStmtStyle; Semicolon Braces NoBraces);
@@ -398,7 +407,7 @@ spanless_eq_enum!(VisibilityKind; Public Crate(0) Restricted(path id) Inherited)
spanless_eq_enum!(WherePredicate; BoundPredicate(0) RegionPredicate(0) EqPredicate(0));
spanless_eq_enum!(ExprKind; Box(0) Array(0) ConstBlock(0) Call(0 1)
MethodCall(0 1 2) Tup(0) Binary(0 1 2) Unary(0 1) Lit(0) Cast(0 1) Type(0 1)
- Let(0 1) If(0 1 2) While(0 1 2) ForLoop(0 1 2 3) Loop(0 1) Match(0 1)
+ Let(0 1 2) If(0 1 2) While(0 1 2) ForLoop(0 1 2 3) Loop(0 1) Match(0 1)
Closure(0 1 2 3 4 5) Block(0 1) Async(0 1 2) Await(0) TryBlock(0)
Assign(0 1 2) AssignOp(0 1 2) Field(0 1) Index(0 1) Underscore Range(0 1 2)
Path(0 1) AddrOf(0 1 2) Break(0 1) Continue(0) Ret(0) InlineAsm(0)
diff --git a/tests/repo/mod.rs b/tests/repo/mod.rs
index 58c239ac..b819a3aa 100644
--- a/tests/repo/mod.rs
+++ b/tests/repo/mod.rs
@@ -8,27 +8,52 @@ use std::path::Path;
use tar::Archive;
use walkdir::DirEntry;
-const REVISION: &str = "716394d6581b60c75cfdd88b8e5b876f2db88b62";
+const REVISION: &str = "50171c310cd15e1b2d3723766ce64e2e4d6696fc";
#[rustfmt::skip]
static EXCLUDE: &[&str] = &[
- // Rustc loses some attributes
- // https://github.com/rust-lang/rust/issues/84879
- "src/test/ui/proc-macro/issue-81555.rs",
+ // TODO: anonymous structs/unions
+ // type A = struct { field: u8 };
+ // https://github.com/dtolnay/syn/issues/1049
+ "src/test/pretty/anonymous-types.rs",
+
+ // TODO: impl ~const T {}
+ // https://github.com/dtolnay/syn/issues/1051
+ "src/test/ui/rfc-2632-const-trait-impl/syntax.rs",
+
+ // TODO: ~const in where-clause
+ // https://github.com/dtolnay/syn/issues/1051
+ "src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-run.rs",
+ "src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-self-referential.rs",
// Compile-fail expr parameter in const generic position: f::<1 + 2>()
- "src/test/ui/const-generics/closing-args-token.rs",
- "src/test/ui/const-generics/const-expression-parameter.rs",
+ "src/test/ui/const-generics/early/closing-args-token.rs",
+ "src/test/ui/const-generics/early/const-expression-parameter.rs",
// Deprecated anonymous parameter syntax in traits
"src/test/ui/issues/issue-13105.rs",
"src/test/ui/issues/issue-13775.rs",
"src/test/ui/issues/issue-34074.rs",
"src/test/ui/proc-macro/trait-fn-args-2015.rs",
+ "src/tools/rustfmt/tests/source/trait.rs",
+ "src/tools/rustfmt/tests/target/trait.rs",
// Excessive nesting
"src/test/ui/issues/issue-74564-if-expr-stack-overflow.rs",
+ // Testing rustfmt on invalid syntax
+ "src/tools/rustfmt/tests/coverage/target/comments.rs",
+ "src/tools/rustfmt/tests/parser/issue-4126/invalid.rs",
+ "src/tools/rustfmt/tests/parser/issue_4418.rs",
+ "src/tools/rustfmt/tests/parser/unclosed-delims/issue_4466.rs",
+ "src/tools/rustfmt/tests/source/configs/disable_all_formatting/true.rs",
+ "src/tools/rustfmt/tests/source/configs/spaces_around_ranges/false.rs",
+ "src/tools/rustfmt/tests/source/configs/spaces_around_ranges/true.rs",
+ "src/tools/rustfmt/tests/source/type.rs",
+ "src/tools/rustfmt/tests/target/configs/spaces_around_ranges/false.rs",
+ "src/tools/rustfmt/tests/target/configs/spaces_around_ranges/true.rs",
+ "src/tools/rustfmt/tests/target/type.rs",
+
// Not actually test cases
"src/test/rustdoc-ui/test-compile-fail2.rs",
"src/test/rustdoc-ui/test-compile-fail3.rs",
diff --git a/tests/test_precedence.rs b/tests/test_precedence.rs
index b4526308..8d212b03 100644
--- a/tests/test_precedence.rs
+++ b/tests/test_precedence.rs
@@ -195,10 +195,10 @@ fn librustc_parse_and_rewrite(input: &str) -> Option<P<ast::Expr>> {
/// This method operates on librustc objects.
fn librustc_brackets(mut librustc_expr: P<ast::Expr>) -> Option<P<ast::Expr>> {
use rustc_ast::ast::{
- Block, BorrowKind, Expr, ExprField, ExprKind, GenericArg, Pat, Stmt, StmtKind, StructExpr,
- StructRest, Ty,
+ Attribute, Block, BorrowKind, Expr, ExprField, ExprKind, GenericArg, Local, LocalKind, Pat,
+ Stmt, StmtKind, StructExpr, StructRest, Ty,
};
- use rustc_ast::mut_visit::{noop_visit_generic_arg, MutVisitor};
+ use rustc_ast::mut_visit::{noop_visit_generic_arg, noop_visit_local, MutVisitor};
use rustc_data_structures::map_in_place::MapInPlace;
use rustc_data_structures::thin_vec::ThinVec;
use rustc_span::DUMMY_SP;
@@ -286,8 +286,12 @@ fn librustc_brackets(mut librustc_expr: P<ast::Expr>) -> Option<P<ast::Expr>> {
fn visit_generic_arg(&mut self, arg: &mut GenericArg) {
match arg {
- // Don't wrap const generic arg as that's invalid syntax.
- GenericArg::Const(arg) => noop_visit_expr(&mut arg.value, self),
+ // Don't wrap unbraced const generic arg as that's invalid syntax.
+ GenericArg::Const(anon_const) => {
+ if let ExprKind::Block(..) = &mut anon_const.value.kind {
+ noop_visit_expr(&mut anon_const.value, self);
+ }
+ }
_ => noop_visit_generic_arg(arg, self),
}
}
@@ -300,6 +304,13 @@ fn librustc_brackets(mut librustc_expr: P<ast::Expr>) -> Option<P<ast::Expr>> {
self.visit_span(&mut block.span);
}
+ fn visit_local(&mut self, local: &mut P<Local>) {
+ match local.kind {
+ LocalKind::InitElse(..) => {}
+ _ => noop_visit_local(local, self),
+ }
+ }
+
// We don't want to look at expressions that might appear in patterns or
// types yet. We'll look into comparing those in the future. For now
// focus on expressions appearing in other places.
@@ -310,6 +321,10 @@ fn librustc_brackets(mut librustc_expr: P<ast::Expr>) -> Option<P<ast::Expr>> {
fn visit_ty(&mut self, ty: &mut P<Ty>) {
let _ = ty;
}
+
+ fn visit_attribute(&mut self, attr: &mut Attribute) {
+ let _ = attr;
+ }
}
let mut folder = BracketsVisitor { failed: false };
@@ -346,8 +361,11 @@ fn syn_brackets(syn_expr: syn::Expr) -> syn::Expr {
fn fold_generic_argument(&mut self, arg: GenericArgument) -> GenericArgument {
match arg {
- // Don't wrap const generic arg as that's invalid syntax.
- GenericArgument::Const(a) => GenericArgument::Const(fold_expr(self, a)),
+ GenericArgument::Const(arg) => GenericArgument::Const(match arg {
+ Expr::Block(_) => fold_expr(self, arg),
+ // Don't wrap unbraced const generic arg as that's invalid syntax.
+ _ => arg,
+ }),
_ => fold_generic_argument(self, arg),
}
}
@@ -357,8 +375,11 @@ fn syn_brackets(syn_expr: syn::Expr) -> syn::Expr {
arg: GenericMethodArgument,
) -> GenericMethodArgument {
match arg {
- // Don't wrap const generic arg as that's invalid syntax.
- GenericMethodArgument::Const(a) => GenericMethodArgument::Const(fold_expr(self, a)),
+ GenericMethodArgument::Const(arg) => GenericMethodArgument::Const(match arg {
+ Expr::Block(_) => fold_expr(self, arg),
+ // Don't wrap unbraced const generic arg as that's invalid syntax.
+ _ => arg,
+ }),
_ => fold_generic_method_argument(self, arg),
}
}
@@ -367,7 +388,13 @@ fn syn_brackets(syn_expr: syn::Expr) -> syn::Expr {
match stmt {
// Don't wrap toplevel expressions in statements.
Stmt::Expr(e) => Stmt::Expr(fold_expr(self, e)),
- Stmt::Semi(e, semi) => Stmt::Semi(fold_expr(self, e), semi),
+ Stmt::Semi(e, semi) => {
+ if let Expr::Verbatim(_) = e {
+ Stmt::Semi(e, semi)
+ } else {
+ Stmt::Semi(fold_expr(self, e), semi)
+ }
+ }
s => s,
}
}
@@ -398,7 +425,7 @@ fn collect_exprs(file: syn::File) -> Vec<syn::Expr> {
impl Fold for CollectExprs {
fn fold_expr(&mut self, expr: Expr) -> Expr {
match expr {
- Expr::Verbatim(tokens) if tokens.is_empty() => {}
+ Expr::Verbatim(_) => {}
_ => self.0.push(expr),
}
diff --git a/tests/test_round_trip.rs b/tests/test_round_trip.rs
index 0be16eb4..f350c3fa 100644
--- a/tests/test_round_trip.rs
+++ b/tests/test_round_trip.rs
@@ -14,6 +14,7 @@ use quote::quote;
use rayon::iter::{IntoParallelIterator, ParallelIterator};
use rustc_ast::ast::{
AngleBracketedArg, AngleBracketedArgs, Crate, GenericArg, GenericParamKind, Generics,
+ WhereClause,
};
use rustc_ast::mut_visit::{self, MutVisitor};
use rustc_errors::PResult;
@@ -194,6 +195,12 @@ fn normalize(krate: &mut Crate) {
});
mut_visit::noop_visit_generics(e, self);
}
+
+ fn visit_where_clause(&mut self, e: &mut WhereClause) {
+ if e.predicates.is_empty() {
+ e.has_where_token = false;
+ }
+ }
}
NormalizeVisitor.visit_crate(krate);