Skip to content

Commit 267cd1d

Browse files
committed
Auto merge of rust-lang#107721 - megakorre:issue_105700, r=petrochenkov
create dummy placeholder crate to prevent compiler from panicing This PR is to address the panic found in rust-lang#105700. There are 2 separate things going on with this panic. First the code could not generate a dummy response for crate fragment types when it hits the recursion limit. This PR adds the method to the trait implementation for `DymmyResult` to be able to create a dummy crate node. This stops the panic from happening. The second thing that is not addressed (and maybe does not need addressing? 🤷🏻) is that when you have multiple attributes it ends up treating attributes that follow another as being the result of expanding the former (maybe there is a better way to say that). So you end up hitting the recursion limit. Even though you would think there is no expansion happening here. If you did not hit the recursion limit the compiler would output that `invalid_attribute` does not exists. But it currently exits before the resolution step when the recursion limit is reached here.
2 parents e7eaed2 + 0fd2a70 commit 267cd1d

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

compiler/rustc_expand/src/base.rs

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::expand::{self, AstFragment, Invocation};
55
use crate::module::DirOwnership;
66

77
use rustc_ast::attr::MarkedAttrs;
8+
use rustc_ast::mut_visit::DummyAstNode;
89
use rustc_ast::ptr::P;
910
use rustc_ast::token::{self, Nonterminal};
1011
use rustc_ast::tokenstream::TokenStream;
@@ -640,6 +641,10 @@ impl MacResult for DummyResult {
640641
fn make_variants(self: Box<DummyResult>) -> Option<SmallVec<[ast::Variant; 1]>> {
641642
Some(SmallVec::new())
642643
}
644+
645+
fn make_crate(self: Box<DummyResult>) -> Option<ast::Crate> {
646+
Some(DummyAstNode::dummy())
647+
}
643648
}
644649

645650
/// A syntax extension kind.
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![recursion_limit="4"]
2+
#![invalid_attribute]
3+
#![invalid_attribute]
4+
#![invalid_attribute]
5+
#![invalid_attribute]
6+
#![invalid_attribute]
7+
//~^ERROR recursion limit reached while expanding
8+
9+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: recursion limit reached while expanding `#[invalid_attribute]`
2+
--> $DIR/issue_21102.rs:6:1
3+
|
4+
LL | #![invalid_attribute]
5+
| ^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "8"]` attribute to your crate (`issue_21102`)
8+
9+
error: aborting due to previous error
10+

0 commit comments

Comments
 (0)