Rollup merge of #91519 - petrochenkov:cratexp2, r=Aaron1011
ast: Avoid aborts on fatal errors thrown from mutable AST visitor Set the node to some dummy value and rethrow the error instead. When using the old aborting `visit_clobber` in `InvocationCollector::visit_crate` the next tests abort due to fatal errors: ``` ui\modules\path-invalid-form.rs ui\modules\path-macro.rs ui\modules\path-no-file-name.rs ui\parser\issues\issue-5806.rs ui\parser\mod_file_with_path_attr.rs ``` Follow up to https://github.com/rust-lang/rust/pull/91313.
This commit is contained in:
commit
b9f7197ab3
2 changed files with 127 additions and 21 deletions
|
@ -1160,13 +1160,18 @@ macro_rules! assign_id {
|
|||
|
||||
impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
|
||||
fn visit_crate(&mut self, krate: &mut ast::Crate) {
|
||||
let span = krate.span;
|
||||
let empty_crate =
|
||||
|| ast::Crate { attrs: Vec::new(), items: Vec::new(), span, is_placeholder: None };
|
||||
let mut fold_crate = |krate: ast::Crate| {
|
||||
visit_clobber(krate, |krate| {
|
||||
let span = krate.span;
|
||||
let mut krate = match self.configure(krate) {
|
||||
Some(krate) => krate,
|
||||
None => return empty_crate(),
|
||||
None => {
|
||||
return ast::Crate {
|
||||
attrs: Vec::new(),
|
||||
items: Vec::new(),
|
||||
span,
|
||||
is_placeholder: None,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(attr) = self.take_first_attr(&mut krate) {
|
||||
|
@ -1177,10 +1182,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
|
|||
|
||||
noop_visit_crate(&mut krate, self);
|
||||
krate
|
||||
};
|
||||
|
||||
// Cannot use `visit_clobber` here, see the FIXME on it.
|
||||
*krate = fold_crate(mem::replace(krate, empty_crate()));
|
||||
})
|
||||
}
|
||||
|
||||
fn visit_expr(&mut self, expr: &mut P<ast::Expr>) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue