Remove references to libsyntax

This commit is contained in:
David Tolnay
2020-05-25 01:49:27 -07:00
parent d2d24be5d3
commit 1a93ef8280
6 changed files with 28 additions and 28 deletions
+2 -2
View File
@@ -35,7 +35,7 @@ mod syn_parse {
}
#[cfg(not(syn_only))]
mod libsyntax_parse {
mod librustc_parse {
extern crate rustc_ast;
extern crate rustc_data_structures;
extern crate rustc_errors;
@@ -145,7 +145,7 @@ fn main() {
tokenstream_parse,
syn_parse,
#[cfg(not(syn_only))]
libsyntax_parse,
librustc_parse,
) {
eprint!("{:20}", format!("{}:", name));
let elapsed = exec(f);
+1 -1
View File
@@ -1191,7 +1191,7 @@ ast_enum! {
#[cfg(any(feature = "parsing", feature = "printing"))]
#[cfg(feature = "full")]
pub(crate) fn requires_terminator(expr: &Expr) -> bool {
// see https://github.com/rust-lang/rust/blob/eb8f2586e/src/libsyntax/parse/classify.rs#L17-L37
// see https://github.com/rust-lang/rust/blob/2679c38fc/src/librustc_ast/util/classify.rs#L7-L25
match *expr {
Expr::Unsafe(..)
| Expr::Block(..)
+2 -2
View File
@@ -12,7 +12,7 @@ use rustc_span::FileName;
use std::panic;
pub fn libsyntax_expr(input: &str) -> Option<P<ast::Expr>> {
pub fn librustc_expr(input: &str) -> Option<P<ast::Expr>> {
match panic::catch_unwind(|| {
let sess = ParseSess::new(FilePathMapping::empty());
let e = parse::new_parser_from_source_str(
@@ -32,7 +32,7 @@ pub fn libsyntax_expr(input: &str) -> Option<P<ast::Expr>> {
Ok(Some(e)) => Some(e),
Ok(None) => None,
Err(_) => {
errorf!("libsyntax panicked\n");
errorf!("librustc panicked\n");
None
}
}
+16 -16
View File
@@ -4,12 +4,12 @@
//! The tests in this module do the following:
//!
//! 1. Parse a given expression in both `syn` and `libsyntax`.
//! 1. Parse a given expression in both `syn` and `librustc`.
//! 2. Fold over the expression adding brackets around each subexpression (with
//! some complications - see the `syn_brackets` and `libsyntax_brackets`
//! some complications - see the `syn_brackets` and `librustc_brackets`
//! methods).
//! 3. Serialize the `syn` expression back into a string, and re-parse it with
//! `libsyntax`.
//! `librustc`.
//! 4. Respan all of the expressions, replacing the spans with the default
//! spans.
//! 5. Compare the expressions with one another, if they are not equal fail.
@@ -160,28 +160,28 @@ fn test_expressions(edition: Edition, exprs: Vec<syn::Expr>) -> (usize, usize) {
for expr in exprs {
let raw = quote!(#expr).to_string();
let libsyntax_ast = if let Some(e) = libsyntax_parse_and_rewrite(&raw) {
let librustc_ast = if let Some(e) = librustc_parse_and_rewrite(&raw) {
e
} else {
failed += 1;
errorf!("\nFAIL - libsyntax failed to parse raw\n");
errorf!("\nFAIL - librustc failed to parse raw\n");
continue;
};
let syn_expr = syn_brackets(expr);
let syn_ast = if let Some(e) = parse::libsyntax_expr(&quote!(#syn_expr).to_string()) {
let syn_ast = if let Some(e) = parse::librustc_expr(&quote!(#syn_expr).to_string()) {
e
} else {
failed += 1;
errorf!("\nFAIL - libsyntax failed to parse bracketed\n");
errorf!("\nFAIL - librustc failed to parse bracketed\n");
continue;
};
if SpanlessEq::eq(&syn_ast, &libsyntax_ast) {
if SpanlessEq::eq(&syn_ast, &librustc_ast) {
passed += 1;
} else {
failed += 1;
errorf!("\nFAIL\n{:?}\n!=\n{:?}\n", syn_ast, libsyntax_ast);
errorf!("\nFAIL\n{:?}\n!=\n{:?}\n", syn_ast, librustc_ast);
}
}
});
@@ -189,16 +189,16 @@ fn test_expressions(edition: Edition, exprs: Vec<syn::Expr>) -> (usize, usize) {
(passed, failed)
}
fn libsyntax_parse_and_rewrite(input: &str) -> Option<P<ast::Expr>> {
parse::libsyntax_expr(input).and_then(libsyntax_brackets)
fn librustc_parse_and_rewrite(input: &str) -> Option<P<ast::Expr>> {
parse::librustc_expr(input).and_then(librustc_brackets)
}
/// Wrap every expression which is not already wrapped in parens with parens, to
/// reveal the precidence of the parsed expressions, and produce a stringified
/// form of the resulting expression.
///
/// This method operates on libsyntax objects.
fn libsyntax_brackets(mut libsyntax_expr: P<ast::Expr>) -> 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, ExprKind, Field, GenericArg, MacCall, Pat, Stmt, StmtKind, Ty,
};
@@ -302,7 +302,7 @@ fn libsyntax_brackets(mut libsyntax_expr: P<ast::Expr>) -> Option<P<ast::Expr>>
}
fn visit_mac(&mut self, mac: &mut MacCall) {
// By default when folding over macros, libsyntax panics. This is
// By default when folding over macros, librustc panics. This is
// because it's usually not what you want, you want to run after
// macro expansion. We do want to do that (syn doesn't do macro
// expansion), so we implement visit_mac to just return the macro
@@ -312,11 +312,11 @@ fn libsyntax_brackets(mut libsyntax_expr: P<ast::Expr>) -> Option<P<ast::Expr>>
}
let mut folder = BracketsVisitor { failed: false };
folder.visit_expr(&mut libsyntax_expr);
folder.visit_expr(&mut librustc_expr);
if folder.failed {
None
} else {
Some(libsyntax_expr)
Some(librustc_expr)
}
}
+6 -6
View File
@@ -81,7 +81,7 @@ fn test_round_trip() {
let equal = panic::catch_unwind(|| {
rustc_ast::with_globals(edition, || {
let sess = ParseSess::new(FilePathMapping::empty());
let before = match libsyntax_parse(content, &sess) {
let before = match librustc_parse(content, &sess) {
Ok(before) => before,
Err(mut diagnostic) => {
diagnostic.cancel();
@@ -92,7 +92,7 @@ fn test_round_trip() {
errorf!("=== {}: ignore\n", path.display());
} else {
errorf!(
"=== {}: ignore - libsyntax failed to parse original content: {}\n",
"=== {}: ignore - librustc failed to parse original content: {}\n",
path.display(),
diagnostic.message()
);
@@ -100,10 +100,10 @@ fn test_round_trip() {
return true;
}
};
let after = match libsyntax_parse(back, &sess) {
let after = match librustc_parse(back, &sess) {
Ok(after) => after,
Err(mut diagnostic) => {
errorf!("=== {}: libsyntax failed to parse", path.display());
errorf!("=== {}: librustc failed to parse", path.display());
diagnostic.emit();
return false;
}
@@ -129,7 +129,7 @@ fn test_round_trip() {
})
});
match equal {
Err(_) => errorf!("=== {}: ignoring libsyntax panic\n", path.display()),
Err(_) => errorf!("=== {}: ignoring librustc panic\n", path.display()),
Ok(true) => {}
Ok(false) => {
let prev_failed = failed.fetch_add(1, Ordering::SeqCst);
@@ -146,7 +146,7 @@ fn test_round_trip() {
}
}
fn libsyntax_parse(content: String, sess: &ParseSess) -> PResult<ast::Crate> {
fn librustc_parse(content: String, sess: &ParseSess) -> PResult<ast::Crate> {
let name = FileName::Custom("test_round_trip".to_string());
parse::parse_crate_from_source_str(name, content, sess)
}
+1 -1
View File
@@ -8,7 +8,7 @@ const MSG: &str = "\
‖ WARNING:
‖ This is not a nightly compiler so not all tests were able to
‖ run. Syn includes tests that compare Syn's parser against the
‖ compiler's parser, which requires access to unstable libsyntax
‖ compiler's parser, which requires access to unstable librustc
‖ data structures and a nightly compiler.
";