diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-07 05:48:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-07 05:48:48 +0000 |
commit | ef24de24a82fe681581cc130f342363c47c0969a (patch) | |
tree | 0d494f7e1a38b95c92426f58fe6eaa877303a86c /vendor/syn/tests | |
parent | Releasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip |
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/syn/tests')
-rw-r--r-- | vendor/syn/tests/common/eq.rs | 9 | ||||
-rw-r--r-- | vendor/syn/tests/debug/gen.rs | 1 | ||||
-rw-r--r-- | vendor/syn/tests/repo/mod.rs | 29 | ||||
-rw-r--r-- | vendor/syn/tests/test_lit.rs | 16 | ||||
-rw-r--r-- | vendor/syn/tests/test_precedence.rs | 98 |
5 files changed, 114 insertions, 39 deletions
diff --git a/vendor/syn/tests/common/eq.rs b/vendor/syn/tests/common/eq.rs index 68fd1949e..3c2b1c124 100644 --- a/vendor/syn/tests/common/eq.rs +++ b/vendor/syn/tests/common/eq.rs @@ -156,7 +156,7 @@ use rustc_ast::tokenstream::{ use rustc_data_structures::sync::Lrc; use rustc_span::source_map::Spanned; use rustc_span::symbol::{sym, Ident}; -use rustc_span::{Span, Symbol, SyntaxContext, DUMMY_SP}; +use rustc_span::{ErrorGuaranteed, Span, Symbol, SyntaxContext, DUMMY_SP}; use std::collections::HashMap; use std::hash::{BuildHasher, Hash}; use thin_vec::ThinVec; @@ -296,6 +296,7 @@ spanless_eq_partial_eq!(CommentKind); spanless_eq_partial_eq!(Delimiter); spanless_eq_partial_eq!(InlineAsmOptions); spanless_eq_partial_eq!(token::LitKind); +spanless_eq_partial_eq!(ErrorGuaranteed); macro_rules! spanless_eq_struct { { @@ -579,7 +580,7 @@ spanless_eq_enum!(VariantData; Struct(0 1) Tuple(0 1) Unit(0)); spanless_eq_enum!(VisibilityKind; Public Restricted(path id shorthand) Inherited); spanless_eq_enum!(WherePredicate; BoundPredicate(0) RegionPredicate(0) EqPredicate(0)); spanless_eq_enum!(ExprKind; Array(0) ConstBlock(0) Call(0 1) MethodCall(0) - Tup(0) Binary(0 1 2) Unary(0 1) Lit(0) Cast(0 1) Type(0 1) Let(0 1 2) + Tup(0) Binary(0 1 2) Unary(0 1) Lit(0) Cast(0 1) Type(0 1) Let(0 1 2 3) If(0 1 2) While(0 1 2) ForLoop(0 1 2 3) Loop(0 1 2) Match(0 1) Closure(0) Block(0 1) Async(0 1) Await(0 1) TryBlock(0) Assign(0 1 2) AssignOp(0 1 2) Field(0 1) Index(0 1 2) Underscore Range(0 1 2) Path(0 1) AddrOf(0 1 2) @@ -598,8 +599,8 @@ spanless_eq_enum!(PatKind; Wild Ident(0 1 2) Struct(0 1 2 3) TupleStruct(0 1 2) Or(0) Path(0 1) Tuple(0) Box(0) Ref(0 1) Lit(0) Range(0 1 2) Slice(0) Rest Paren(0) MacCall(0)); spanless_eq_enum!(TyKind; Slice(0) Array(0 1) Ptr(0) Ref(0 1) BareFn(0) Never - Tup(0) Path(0 1) TraitObject(0 1) ImplTrait(0 1) Paren(0) Typeof(0) Infer - ImplicitSelf MacCall(0) Err CVarArgs); + Tup(0) AnonStruct(0) AnonUnion(0) Path(0 1) TraitObject(0 1) ImplTrait(0 1) + Paren(0) Typeof(0) Infer ImplicitSelf MacCall(0) Err CVarArgs); impl SpanlessEq for Ident { fn eq(&self, other: &Self) -> bool { diff --git a/vendor/syn/tests/debug/gen.rs b/vendor/syn/tests/debug/gen.rs index b64cc3e7e..3f92598d7 100644 --- a/vendor/syn/tests/debug/gen.rs +++ b/vendor/syn/tests/debug/gen.rs @@ -1,6 +1,7 @@ // This file is @generated by syn-internal-codegen. // It is not intended for manual editing. +#![allow(repr_transparent_external_private_fields)] #![allow(clippy::match_wildcard_for_single_variants)] use super::{Lite, Present}; use ref_cast::RefCast; diff --git a/vendor/syn/tests/repo/mod.rs b/vendor/syn/tests/repo/mod.rs index 780ad823b..61d5ff35f 100644 --- a/vendor/syn/tests/repo/mod.rs +++ b/vendor/syn/tests/repo/mod.rs @@ -13,15 +13,16 @@ use std::path::{Path, PathBuf}; use tar::Archive; use walkdir::{DirEntry, WalkDir}; -const REVISION: &str = "85bf07972a1041b9e25393b803d0e006bec3eaaf"; +const REVISION: &str = "9f5fc1bd443f59583e7af0d94d289f95fe1e20c4"; #[rustfmt::skip] static EXCLUDE_FILES: &[&str] = &[ - // CStr literals (c"…") are not yet supported by rustc's lexer - // https://github.com/rust-lang/rust/issues/113333 - "src/tools/clippy/tests/ui/needless_raw_string_hashes.rs", - "src/tools/rust-analyzer/crates/parser/test_data/parser/inline/ok/0085_expr_literals.rs", + // TODO: CStr literals: c"…", cr"…" + // https://github.com/dtolnay/syn/issues/1502 "src/tools/rust-analyzer/crates/parser/test_data/parser/inline/ok/0085_expr_literals.rs", + + // TODO: explicit tail calls: `become _g()` + // https://github.com/dtolnay/syn/issues/1501 "tests/ui/explicit-tail-calls/return-lifetime-sub.rs", // TODO: non-lifetime binders: `where for<'a, T> &'a Struct<T>: Trait` @@ -115,7 +116,6 @@ static EXCLUDE_FILES: &[&str] = &[ // Various extensions to Rust syntax made up by rust-analyzer "src/tools/rust-analyzer/crates/parser/test_data/parser/inline/ok/0012_type_item_where_clause.rs", - "src/tools/rust-analyzer/crates/parser/test_data/parser/inline/ok/0040_crate_keyword_vis.rs", "src/tools/rust-analyzer/crates/parser/test_data/parser/inline/ok/0058_range_pat.rs", "src/tools/rust-analyzer/crates/parser/test_data/parser/inline/ok/0123_param_list_vararg.rs", "src/tools/rust-analyzer/crates/parser/test_data/parser/inline/ok/0131_existential_type.rs", @@ -288,21 +288,38 @@ pub fn clone_rust() { if needs_clone { download_and_unpack().unwrap(); } + let mut missing = String::new(); let test_src = Path::new("tests/rust"); + + let mut exclude_files_set = BTreeSet::new(); for exclude in EXCLUDE_FILES { + if !exclude_files_set.insert(exclude) { + panic!("duplicate path in EXCLUDE_FILES: {}", exclude); + } + for dir in EXCLUDE_DIRS { + if Path::new(exclude).starts_with(dir) { + panic!("excluded file {} is inside an excluded dir", exclude); + } + } if !test_src.join(exclude).is_file() { missing += "\ntests/rust/"; missing += exclude; } } + + let mut exclude_dirs_set = BTreeSet::new(); for exclude in EXCLUDE_DIRS { + if !exclude_dirs_set.insert(exclude) { + panic!("duplicate path in EXCLUDE_DIRS: {}", exclude); + } if !test_src.join(exclude).is_dir() { missing += "\ntests/rust/"; missing += exclude; missing += "/"; } } + if !missing.is_empty() { panic!("excluded test file does not exist:{}\n", missing); } diff --git a/vendor/syn/tests/test_lit.rs b/vendor/syn/tests/test_lit.rs index 82d229001..bc50136f6 100644 --- a/vendor/syn/tests/test_lit.rs +++ b/vendor/syn/tests/test_lit.rs @@ -1,6 +1,7 @@ #![allow( clippy::float_cmp, clippy::non_ascii_literal, + clippy::single_match_else, clippy::uninlined_format_args )] @@ -13,14 +14,13 @@ use std::str::FromStr; use syn::{Lit, LitFloat, LitInt, LitStr}; fn lit(s: &str) -> Lit { - match TokenStream::from_str(s) - .unwrap() - .into_iter() - .next() - .unwrap() - { - TokenTree::Literal(lit) => Lit::new(lit), - _ => panic!(), + let mut tokens = TokenStream::from_str(s).unwrap().into_iter(); + match tokens.next().unwrap() { + TokenTree::Literal(lit) => { + assert!(tokens.next().is_none()); + Lit::new(lit) + } + wrong => panic!("{:?}", wrong), } } diff --git a/vendor/syn/tests/test_precedence.rs b/vendor/syn/tests/test_precedence.rs index b49577f0f..bf0510bb3 100644 --- a/vendor/syn/tests/test_precedence.rs +++ b/vendor/syn/tests/test_precedence.rs @@ -30,6 +30,7 @@ extern crate rustc_ast_pretty; extern crate rustc_data_structures; extern crate rustc_driver; extern crate rustc_span; +extern crate smallvec; extern crate thin_vec; use crate::common::eq::SpanlessEq; @@ -168,15 +169,17 @@ 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::{ - Attribute, BinOpKind, Block, BorrowKind, Expr, ExprField, ExprKind, GenericArg, - GenericBound, Local, LocalKind, Pat, Stmt, StmtKind, StructExpr, StructRest, - TraitBoundModifier, Ty, + AssocItem, AssocItemKind, Attribute, BinOpKind, Block, BorrowKind, Expr, ExprField, + ExprKind, GenericArg, GenericBound, ItemKind, Local, LocalKind, Pat, Stmt, StmtKind, + StructExpr, StructRest, TraitBoundModifier, Ty, }; use rustc_ast::mut_visit::{ - noop_visit_generic_arg, noop_visit_local, noop_visit_param_bound, MutVisitor, + noop_flat_map_assoc_item, noop_visit_generic_arg, noop_visit_item_kind, noop_visit_local, + noop_visit_param_bound, MutVisitor, }; use rustc_data_structures::flat_map_in_place::FlatMapInPlace; use rustc_span::DUMMY_SP; + use smallvec::SmallVec; use std::mem; use std::ops::DerefMut; use thin_vec::ThinVec; @@ -185,6 +188,17 @@ fn librustc_brackets(mut librustc_expr: P<ast::Expr>) -> Option<P<ast::Expr>> { failed: bool, } + fn contains_let_chain(expr: &Expr) -> bool { + match &expr.kind { + ExprKind::Let(..) => true, + ExprKind::Binary(binop, left, right) => { + binop.node == BinOpKind::And + && (contains_let_chain(left) || contains_let_chain(right)) + } + _ => false, + } + } + fn flat_map_field<T: MutVisitor>(mut f: ExprField, vis: &mut T) -> Vec<ExprField> { if f.is_shorthand { noop_visit_expr(&mut f.expr, vis); @@ -241,12 +255,7 @@ fn librustc_brackets(mut librustc_expr: P<ast::Expr>) -> Option<P<ast::Expr>> { noop_visit_expr(e, self); match e.kind { ExprKind::Block(..) | ExprKind::If(..) | ExprKind::Let(..) => {} - ExprKind::Binary(binop, ref left, ref right) - if match (&left.kind, binop.node, &right.kind) { - (ExprKind::Let(..), BinOpKind::And, _) - | (_, BinOpKind::And, ExprKind::Let(..)) => true, - _ => false, - } => {} + ExprKind::Binary(..) if contains_let_chain(e) => {} _ => { let inner = mem::replace( e, @@ -300,6 +309,39 @@ fn librustc_brackets(mut librustc_expr: P<ast::Expr>) -> Option<P<ast::Expr>> { } } + fn visit_item_kind(&mut self, item: &mut ItemKind) { + match item { + ItemKind::Const(const_item) + if !const_item.generics.params.is_empty() + || !const_item.generics.where_clause.predicates.is_empty() => {} + _ => noop_visit_item_kind(item, self), + } + } + + fn flat_map_trait_item(&mut self, item: P<AssocItem>) -> SmallVec<[P<AssocItem>; 1]> { + match &item.kind { + AssocItemKind::Const(const_item) + if !const_item.generics.params.is_empty() + || !const_item.generics.where_clause.predicates.is_empty() => + { + SmallVec::from([item]) + } + _ => noop_flat_map_assoc_item(item, self), + } + } + + fn flat_map_impl_item(&mut self, item: P<AssocItem>) -> SmallVec<[P<AssocItem>; 1]> { + match &item.kind { + AssocItemKind::Const(const_item) + if !const_item.generics.params.is_empty() + || !const_item.generics.where_clause.predicates.is_empty() => + { + SmallVec::from([item]) + } + _ => noop_flat_map_assoc_item(item, 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. @@ -334,28 +376,42 @@ fn syn_brackets(syn_expr: syn::Expr) -> syn::Expr { struct ParenthesizeEveryExpr; + fn parenthesize(expr: Expr) -> Expr { + Expr::Paren(ExprParen { + attrs: Vec::new(), + expr: Box::new(expr), + paren_token: token::Paren::default(), + }) + } + fn needs_paren(expr: &Expr) -> bool { match expr { Expr::Group(_) => unreachable!(), Expr::If(_) | Expr::Unsafe(_) | Expr::Block(_) | Expr::Let(_) => false, - Expr::Binary(bin) => match (&*bin.left, bin.op, &*bin.right) { - (Expr::Let(_), BinOp::And(_), _) | (_, BinOp::And(_), Expr::Let(_)) => false, - _ => true, - }, + Expr::Binary(_) => !contains_let_chain(expr), _ => true, } } + fn contains_let_chain(expr: &Expr) -> bool { + match expr { + Expr::Let(_) => true, + Expr::Binary(expr) => { + matches!(expr.op, BinOp::And(_)) + && (contains_let_chain(&expr.left) || contains_let_chain(&expr.right)) + } + _ => false, + } + } + impl Fold for ParenthesizeEveryExpr { fn fold_expr(&mut self, expr: Expr) -> Expr { - if needs_paren(&expr) { - Expr::Paren(ExprParen { - attrs: Vec::new(), - expr: Box::new(fold_expr(self, expr)), - paren_token: token::Paren::default(), - }) + let needs_paren = needs_paren(&expr); + let folded = fold_expr(self, expr); + if needs_paren { + parenthesize(folded) } else { - fold_expr(self, expr) + folded } } |