|
1 | 1 | //@ run-pass |
2 | 2 | //@ ignore-cross-compile |
| 3 | +//@ aux-crate: parser=parser.rs |
| 4 | +//@ edition: 2021 |
3 | 5 |
|
4 | 6 | // This test covers the AST pretty-printer's automatic insertion of parentheses |
5 | 7 | // into unparenthesized syntax trees according to precedence and various grammar |
|
31 | 33 |
|
32 | 34 | extern crate rustc_ast; |
33 | 35 | extern crate rustc_ast_pretty; |
34 | | -extern crate rustc_driver; |
35 | | -extern crate rustc_errors; |
36 | 36 | extern crate rustc_parse; |
37 | 37 | extern crate rustc_session; |
38 | 38 | extern crate rustc_span; |
39 | 39 |
|
40 | 40 | use std::mem; |
41 | 41 | use std::process::ExitCode; |
42 | 42 |
|
43 | | -use rustc_ast::ast::{DUMMY_NODE_ID, Expr, ExprKind}; |
| 43 | +use parser::parse_expr; |
| 44 | +use rustc_ast::ast::{Expr, ExprKind}; |
44 | 45 | use rustc_ast::mut_visit::{self, DummyAstNode as _, MutVisitor}; |
45 | | -use rustc_ast::node_id::NodeId; |
46 | 46 | use rustc_ast::ptr::P; |
47 | | -use rustc_ast::token; |
48 | 47 | use rustc_ast_pretty::pprust; |
49 | | -use rustc_errors::Diag; |
50 | | -use rustc_parse::parser::Recovery; |
51 | 48 | use rustc_session::parse::ParseSess; |
52 | | -use rustc_span::{DUMMY_SP, FileName, Span}; |
53 | 49 |
|
54 | 50 | // Every parenthesis in the following expressions is re-inserted by the |
55 | 51 | // pretty-printer. |
@@ -155,39 +151,6 @@ impl MutVisitor for Unparenthesize { |
155 | 151 | } |
156 | 152 | } |
157 | 153 |
|
158 | | -// Erase Span information that could distinguish between identical expressions |
159 | | -// parsed from different source strings. |
160 | | -struct Normalize; |
161 | | - |
162 | | -impl MutVisitor for Normalize { |
163 | | - const VISIT_TOKENS: bool = true; |
164 | | - |
165 | | - fn visit_id(&mut self, id: &mut NodeId) { |
166 | | - *id = DUMMY_NODE_ID; |
167 | | - } |
168 | | - |
169 | | - fn visit_span(&mut self, span: &mut Span) { |
170 | | - *span = DUMMY_SP; |
171 | | - } |
172 | | -} |
173 | | - |
174 | | -fn parse_expr(psess: &ParseSess, source_code: &str) -> Option<P<Expr>> { |
175 | | - let parser = rustc_parse::unwrap_or_emit_fatal(rustc_parse::new_parser_from_source_str( |
176 | | - psess, |
177 | | - FileName::anon_source_code(source_code), |
178 | | - source_code.to_owned(), |
179 | | - )); |
180 | | - |
181 | | - let mut parser = parser.recovery(Recovery::Forbidden); |
182 | | - let mut expr = parser.parse_expr().map_err(Diag::cancel).ok()?; |
183 | | - if parser.token != token::Eof { |
184 | | - return None; |
185 | | - } |
186 | | - |
187 | | - Normalize.visit_expr(&mut expr); |
188 | | - Some(expr) |
189 | | -} |
190 | | - |
191 | 154 | fn main() -> ExitCode { |
192 | 155 | let mut status = ExitCode::SUCCESS; |
193 | 156 | let mut fail = |description: &str, before: &str, after: &str| { |
|
0 commit comments