@@ -37,19 +37,19 @@ extern crate rustc_parse;
3737extern crate rustc_session;
3838extern crate rustc_span;
3939
40+ #[ path = "auxiliary/parser.rs" ]
41+ mod parser;
42+
4043use std:: mem;
4144use std:: process:: ExitCode ;
4245
43- use rustc_ast:: ast:: { DUMMY_NODE_ID , Expr , ExprKind } ;
46+ use rustc_ast:: ast:: { Expr , ExprKind } ;
4447use rustc_ast:: mut_visit:: { self , DummyAstNode as _, MutVisitor } ;
45- use rustc_ast:: node_id:: NodeId ;
4648use rustc_ast:: ptr:: P ;
47- use rustc_ast:: token;
4849use rustc_ast_pretty:: pprust;
49- use rustc_errors:: Diag ;
50- use rustc_parse:: parser:: Recovery ;
5150use rustc_session:: parse:: ParseSess ;
52- use rustc_span:: { DUMMY_SP , FileName , Span } ;
51+
52+ use crate :: parser:: parse_expr;
5353
5454// Every parenthesis in the following expressions is re-inserted by the
5555// pretty-printer.
@@ -155,39 +155,6 @@ impl MutVisitor for Unparenthesize {
155155 }
156156}
157157
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-
191158fn main ( ) -> ExitCode {
192159 let mut status = ExitCode :: SUCCESS ;
193160 let mut fail = |description : & str , before : & str , after : & str | {
0 commit comments