From 8039cb37a02cbf080f48416651141d4c77c05075 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 1 Nov 2024 14:47:22 -0700 Subject: [PATCH] Test that every expr can be scanned --- tests/test_precedence.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/test_precedence.rs b/tests/test_precedence.rs index 077e8d486..1fa64b320 100644 --- a/tests/test_precedence.rs +++ b/tests/test_precedence.rs @@ -49,6 +49,7 @@ use std::fs; use std::path::Path; use std::process; use std::sync::atomic::{AtomicUsize, Ordering}; +use syn::parse::Parser as _; #[macro_use] mod macros; @@ -57,7 +58,6 @@ mod common; mod repo; #[path = "../src/scan_expr.rs"] -#[allow(dead_code)] mod scan_expr; #[test] @@ -119,7 +119,8 @@ fn test_expressions(path: &Path, edition: Edition, exprs: Vec) -> (us rustc_span::create_session_if_not_set_then(edition, |_| { for expr in exprs { - let source_code = expr.to_token_stream().to_string(); + let expr_tokens = expr.to_token_stream(); + let source_code = expr_tokens.to_string(); let librustc_ast = if let Some(e) = librustc_parse_and_rewrite(&source_code) { e } else { @@ -177,6 +178,16 @@ fn test_expressions(path: &Path, edition: Edition, exprs: Vec) -> (us continue; } + if scan_expr::scan_expr.parse2(expr_tokens).is_err() { + failed += 1; + errorf!( + "\nFAIL {} - failed to scan expr\n{}\n", + path.display(), + source_code, + ); + continue; + } + passed += 1; } });