summaryrefslogtreecommitdiffstats
path: root/vendor/syn/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/syn/tests
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+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.rs14
-rw-r--r--vendor/syn/tests/repo/mod.rs65
-rw-r--r--vendor/syn/tests/test_precedence.rs68
-rw-r--r--vendor/syn/tests/test_round_trip.rs16
4 files changed, 90 insertions, 73 deletions
diff --git a/vendor/syn/tests/common/eq.rs b/vendor/syn/tests/common/eq.rs
index 70a533768..5d1c775d8 100644
--- a/vendor/syn/tests/common/eq.rs
+++ b/vendor/syn/tests/common/eq.rs
@@ -32,6 +32,7 @@ use rustc_ast::ast::CaptureBy;
use rustc_ast::ast::Closure;
use rustc_ast::ast::ClosureBinder;
use rustc_ast::ast::Const;
+use rustc_ast::ast::ConstItem;
use rustc_ast::ast::Crate;
use rustc_ast::ast::Defaultness;
use rustc_ast::ast::DelimArgs;
@@ -115,6 +116,7 @@ use rustc_ast::ast::QSelf;
use rustc_ast::ast::RangeEnd;
use rustc_ast::ast::RangeLimits;
use rustc_ast::ast::RangeSyntax;
+use rustc_ast::ast::StaticItem;
use rustc_ast::ast::Stmt;
use rustc_ast::ast::StmtKind;
use rustc_ast::ast::StrLit;
@@ -454,6 +456,7 @@ spanless_eq_struct!(BareFnTy; unsafety ext generic_params decl decl_span);
spanless_eq_struct!(BindingAnnotation; 0 1);
spanless_eq_struct!(Block; stmts id rules span tokens could_be_bare_literal);
spanless_eq_struct!(Closure; binder capture_clause constness asyncness movability fn_decl body !fn_decl_span !fn_arg_span);
+spanless_eq_struct!(ConstItem; defaultness ty expr);
spanless_eq_struct!(Crate; attrs items spans id is_placeholder);
spanless_eq_struct!(DelimArgs; dspan delim tokens);
spanless_eq_struct!(EnumDef; variants);
@@ -495,6 +498,7 @@ spanless_eq_struct!(Path; span segments tokens);
spanless_eq_struct!(PathSegment; ident id args);
spanless_eq_struct!(PolyTraitRef; bound_generic_params trait_ref span);
spanless_eq_struct!(QSelf; ty path_span position);
+spanless_eq_struct!(StaticItem; ty mutability expr);
spanless_eq_struct!(Stmt; id kind span);
spanless_eq_struct!(StrLit; symbol suffix symbol_unescaped style span);
spanless_eq_struct!(StructExpr; qself path fields rest);
@@ -513,7 +517,7 @@ spanless_eq_struct!(WhereEqPredicate; span lhs_ty rhs_ty);
spanless_eq_struct!(WhereRegionPredicate; span lifetime bounds);
spanless_eq_enum!(AngleBracketedArg; Arg(0) Constraint(0));
spanless_eq_enum!(AssocConstraintKind; Equality(term) Bound(bounds));
-spanless_eq_enum!(AssocItemKind; Const(0 1 2) Fn(0) Type(0) MacCall(0));
+spanless_eq_enum!(AssocItemKind; Const(0) Fn(0) Type(0) MacCall(0));
spanless_eq_enum!(Async; Yes(span closure_id return_impl_trait_id) No);
spanless_eq_enum!(AttrArgs; Empty Delimited(0) Eq(0 1));
spanless_eq_enum!(AttrArgsEq; Ast(0) Hir(0));
@@ -540,7 +544,7 @@ spanless_eq_enum!(FormatDebugHex; Lower Upper);
spanless_eq_enum!(FormatSign; Plus Minus);
spanless_eq_enum!(FormatTrait; Display Debug LowerExp UpperExp Octal Pointer Binary LowerHex UpperHex);
spanless_eq_enum!(GenericArg; Lifetime(0) Type(0) Const(0));
-spanless_eq_enum!(GenericArgs; AngleBracketed(0) Parenthesized(0));
+spanless_eq_enum!(GenericArgs; AngleBracketed(0) Parenthesized(0) ReturnTypeNotation(0));
spanless_eq_enum!(GenericBound; Trait(0 1) Outlives(0));
spanless_eq_enum!(GenericParamKind; Lifetime Type(default) Const(ty kw_span default));
spanless_eq_enum!(ImplPolarity; Positive Negative(0));
@@ -577,15 +581,15 @@ spanless_eq_enum!(WherePredicate; BoundPredicate(0) RegionPredicate(0) EqPredica
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)
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 2) Await(0) TryBlock(0) Assign(0 1 2) AssignOp(0 1 2)
+ Block(0 1) Async(0 1) 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) MacCall(0) Struct(0) Repeat(0 1)
Paren(0) Try(0) Yield(0) Yeet(0) IncludedBytes(0) FormatArgs(0) Err);
spanless_eq_enum!(InlineAsmOperand; In(reg expr) Out(reg late expr)
InOut(reg late expr) SplitInOut(reg late in_expr out_expr) Const(anon_const)
Sym(sym));
-spanless_eq_enum!(ItemKind; ExternCrate(0) Use(0) Static(0 1 2) Const(0 1 2)
- Fn(0) Mod(0 1) ForeignMod(0) GlobalAsm(0) TyAlias(0) Enum(0 1) Struct(0 1)
+spanless_eq_enum!(ItemKind; ExternCrate(0) Use(0) Static(0) Const(0) Fn(0)
+ Mod(0 1) ForeignMod(0) GlobalAsm(0) TyAlias(0) Enum(0 1) Struct(0 1)
Union(0 1) Trait(0) TraitAlias(0 1) Impl(0) MacCall(0) MacroDef(0));
spanless_eq_enum!(LitKind; Str(0 1) ByteStr(0 1) Byte(0) Char(0) Int(0 1)
Float(0 1) Bool(0) Err);
diff --git a/vendor/syn/tests/repo/mod.rs b/vendor/syn/tests/repo/mod.rs
index 7be1cc323..cec42a6c6 100644
--- a/vendor/syn/tests/repo/mod.rs
+++ b/vendor/syn/tests/repo/mod.rs
@@ -5,15 +5,28 @@ mod progress;
use self::progress::Progress;
use anyhow::Result;
use flate2::read::GzDecoder;
+use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
+use std::collections::BTreeSet;
+use std::ffi::OsStr;
use std::fs;
-use std::path::Path;
+use std::path::{Path, PathBuf};
use tar::Archive;
-use walkdir::DirEntry;
+use walkdir::{DirEntry, WalkDir};
-const REVISION: &str = "22f247c6f3ed388cb702d01c2ff27da658a8b353";
+const REVISION: &str = "5e1d3299a290026b85787bc9c7e72bcc53ac283f";
#[rustfmt::skip]
static EXCLUDE_FILES: &[&str] = &[
+ // TODO: non-lifetime binders: `where for<'a, T> &'a Struct<T>: Trait`
+ // https://github.com/dtolnay/syn/issues/1435
+ "tests/rustdoc-json/non_lifetime_binders.rs",
+ "tests/rustdoc/non_lifetime_binders.rs",
+
+ // TODO: return type notation: `where T: Trait<method(): Send>`
+ // https://github.com/dtolnay/syn/issues/1434
+ "tests/ui/associated-type-bounds/return-type-notation/basic.rs",
+ "tests/ui/feature-gates/feature-gate-return_type_notation.rs",
+
// Compile-fail expr parameter in const generic position: f::<1 + 2>()
"tests/ui/const-generics/early/closing-args-token.rs",
"tests/ui/const-generics/early/const-expression-parameter.rs",
@@ -188,6 +201,42 @@ static EXCLUDE_DIRS: &[&str] = &[
"src/tools/rust-analyzer/crates/syntax/test_data/reparse/fuzz-failures",
];
+// Directories in which a .stderr implies the corresponding .rs is not expected
+// to work.
+static UI_TEST_DIRS: &[&str] = &["tests/ui", "tests/rustdoc-ui"];
+
+pub fn for_each_rust_file(for_each: impl Fn(&Path) + Sync + Send) {
+ let mut rs_files = BTreeSet::new();
+
+ let repo_dir = Path::new("tests/rust");
+ for entry in WalkDir::new(repo_dir)
+ .into_iter()
+ .filter_entry(base_dir_filter)
+ {
+ let entry = entry.unwrap();
+ if !entry.file_type().is_dir() {
+ rs_files.insert(entry.into_path());
+ }
+ }
+
+ for ui_test_dir in UI_TEST_DIRS {
+ for entry in WalkDir::new(repo_dir.join(ui_test_dir)) {
+ let mut path = entry.unwrap().into_path();
+ if path.extension() == Some(OsStr::new("stderr")) {
+ loop {
+ rs_files.remove(&path.with_extension("rs"));
+ path = path.with_extension("");
+ if path.extension().is_none() {
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ rs_files.par_iter().map(PathBuf::as_path).for_each(for_each);
+}
+
pub fn base_dir_filter(entry: &DirEntry) -> bool {
let path = entry.path();
@@ -207,18 +256,10 @@ pub fn base_dir_filter(entry: &DirEntry) -> bool {
return !EXCLUDE_DIRS.contains(&path_string);
}
- if path.extension().map_or(true, |e| e != "rs") {
+ if path.extension() != Some(OsStr::new("rs")) {
return false;
}
- if path_string.starts_with("tests/ui") || path_string.starts_with("tests/rustdoc-ui") {
- let stderr_path = path.with_extension("stderr");
- if stderr_path.exists() {
- // Expected to fail in some way
- return false;
- }
- }
-
!EXCLUDE_FILES.contains(&path_string)
}
diff --git a/vendor/syn/tests/test_precedence.rs b/vendor/syn/tests/test_precedence.rs
index e2931ff5a..b49577f0f 100644
--- a/vendor/syn/tests/test_precedence.rs
+++ b/vendor/syn/tests/test_precedence.rs
@@ -35,7 +35,6 @@ extern crate thin_vec;
use crate::common::eq::SpanlessEq;
use crate::common::parse;
use quote::quote;
-use rayon::iter::{IntoParallelIterator, ParallelIterator};
use regex::Regex;
use rustc_ast::ast;
use rustc_ast::ptr::P;
@@ -45,7 +44,6 @@ use std::fs;
use std::path::Path;
use std::process;
use std::sync::atomic::{AtomicUsize, Ordering};
-use walkdir::{DirEntry, WalkDir};
#[macro_use]
mod macros;
@@ -70,48 +68,36 @@ fn test_rustc_precedence() {
// 2018 edition is hard
let edition_regex = Regex::new(r"\b(async|try)[!(]").unwrap();
- WalkDir::new("tests/rust")
- .sort_by(|a, b| a.file_name().cmp(b.file_name()))
- .into_iter()
- .filter_entry(repo::base_dir_filter)
- .collect::<Result<Vec<DirEntry>, walkdir::Error>>()
- .unwrap()
- .into_par_iter()
- .for_each(|entry| {
- let path = entry.path();
- if path.is_dir() {
- return;
- }
+ repo::for_each_rust_file(|path| {
+ let content = fs::read_to_string(path).unwrap();
+ let content = edition_regex.replace_all(&content, "_$0");
- let content = fs::read_to_string(path).unwrap();
- let content = edition_regex.replace_all(&content, "_$0");
-
- let (l_passed, l_failed) = match syn::parse_file(&content) {
- Ok(file) => {
- let edition = repo::edition(path).parse().unwrap();
- let exprs = collect_exprs(file);
- let (l_passed, l_failed) = test_expressions(path, edition, exprs);
- errorf!(
- "=== {}: {} passed | {} failed\n",
- path.display(),
- l_passed,
- l_failed,
- );
- (l_passed, l_failed)
- }
- Err(msg) => {
- errorf!("\nFAIL {} - syn failed to parse: {}\n", path.display(), msg);
- (0, 1)
- }
- };
+ let (l_passed, l_failed) = match syn::parse_file(&content) {
+ Ok(file) => {
+ let edition = repo::edition(path).parse().unwrap();
+ let exprs = collect_exprs(file);
+ let (l_passed, l_failed) = test_expressions(path, edition, exprs);
+ errorf!(
+ "=== {}: {} passed | {} failed\n",
+ path.display(),
+ l_passed,
+ l_failed,
+ );
+ (l_passed, l_failed)
+ }
+ Err(msg) => {
+ errorf!("\nFAIL {} - syn failed to parse: {}\n", path.display(), msg);
+ (0, 1)
+ }
+ };
- passed.fetch_add(l_passed, Ordering::Relaxed);
- let prev_failed = failed.fetch_add(l_failed, Ordering::Relaxed);
+ passed.fetch_add(l_passed, Ordering::Relaxed);
+ let prev_failed = failed.fetch_add(l_failed, Ordering::Relaxed);
- if prev_failed + l_failed >= abort_after {
- process::exit(1);
- }
- });
+ if prev_failed + l_failed >= abort_after {
+ process::exit(1);
+ }
+ });
let passed = passed.load(Ordering::Relaxed);
let failed = failed.load(Ordering::Relaxed);
diff --git a/vendor/syn/tests/test_round_trip.rs b/vendor/syn/tests/test_round_trip.rs
index 853f45eae..0ef47b20f 100644
--- a/vendor/syn/tests/test_round_trip.rs
+++ b/vendor/syn/tests/test_round_trip.rs
@@ -22,7 +22,6 @@ extern crate rustc_span;
use crate::common::eq::SpanlessEq;
use quote::quote;
-use rayon::iter::{IntoParallelIterator, ParallelIterator};
use rustc_ast::ast::{
AngleBracketedArg, AngleBracketedArgs, Crate, GenericArg, GenericParamKind, Generics,
WhereClause,
@@ -40,7 +39,6 @@ use std::path::Path;
use std::process;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::time::Instant;
-use walkdir::{DirEntry, WalkDir};
#[macro_use]
mod macros;
@@ -61,19 +59,7 @@ fn test_round_trip() {
let failed = AtomicUsize::new(0);
- WalkDir::new("tests/rust")
- .sort_by(|a, b| a.file_name().cmp(b.file_name()))
- .into_iter()
- .filter_entry(repo::base_dir_filter)
- .collect::<Result<Vec<DirEntry>, walkdir::Error>>()
- .unwrap()
- .into_par_iter()
- .for_each(|entry| {
- let path = entry.path();
- if !path.is_dir() {
- test(path, &failed, abort_after);
- }
- });
+ repo::for_each_rust_file(|path| test(path, &failed, abort_after));
let failed = failed.load(Ordering::Relaxed);
if failed > 0 {