Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect invalid exprs in parser used by pretty-printer tests #134599

Merged
merged 4 commits into from
Dec 22, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Check that pretty-printer parenthesis test operates on the whole test…
… case
  • Loading branch information
dtolnay committed Dec 21, 2024
commit 3f98f76d70f229025594e7b23fe7c4d9563766d7
8 changes: 7 additions & 1 deletion tests/ui-fulldeps/pprust-parenthesis-insertion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use rustc_ast::ast::{DUMMY_NODE_ID, Expr, ExprKind};
use rustc_ast::mut_visit::{self, DummyAstNode as _, MutVisitor};
use rustc_ast::node_id::NodeId;
use rustc_ast::ptr::P;
use rustc_ast::token;
use rustc_ast_pretty::pprust;
use rustc_errors::Diag;
use rustc_parse::parser::Recovery;
Expand Down Expand Up @@ -177,7 +178,12 @@ fn parse_expr(psess: &ParseSess, source_code: &str) -> Option<P<Expr>> {
source_code.to_owned(),
));

let mut expr = parser.recovery(Recovery::Forbidden).parse_expr().map_err(Diag::cancel).ok()?;
let mut parser = parser.recovery(Recovery::Forbidden);
let mut expr = parser.parse_expr().map_err(Diag::cancel).ok()?;
if parser.token != token::Eof {
return None;
}

Normalize.visit_expr(&mut expr);
Some(expr)
}
Expand Down