diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-01-03 09:58:32 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-01-03 09:58:32 +0000 |
commit | 354c1daedc91abd15ca0ce6ada417053ce45ecfa (patch) | |
tree | ce9f416dc64893872cba2d25b4012af0183021e1 /crates | |
parent | 1cc73d60bbd7149773f2eb57296d5611cbe941b1 (diff) | |
parent | 26b9c793f1008e1c5cb1ca61f3c5892f8025f387 (diff) |
Merge #7136
7136: Fixed nested eager macro bug r=edwin0cheng a=edwin0cheng
fixes #7126
bors r+
Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r-- | crates/hir_expand/src/eager.rs | 6 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/macros.rs | 46 |
2 files changed, 52 insertions, 0 deletions
diff --git a/crates/hir_expand/src/eager.rs b/crates/hir_expand/src/eager.rs index 6354b090d..ae7b51a08 100644 --- a/crates/hir_expand/src/eager.rs +++ b/crates/hir_expand/src/eager.rs | |||
@@ -218,6 +218,12 @@ fn eager_macro_recur( | |||
218 | } | 218 | } |
219 | }; | 219 | }; |
220 | 220 | ||
221 | // check if the whole original sytnax is replaced | ||
222 | // Note that SyntaxRewriter cannot replace the root node itself | ||
223 | if child.syntax() == &original { | ||
224 | return Ok(insert); | ||
225 | } | ||
226 | |||
221 | rewriter.replace(child.syntax(), &insert); | 227 | rewriter.replace(child.syntax(), &insert); |
222 | } | 228 | } |
223 | 229 | ||
diff --git a/crates/hir_ty/src/tests/macros.rs b/crates/hir_ty/src/tests/macros.rs index 23b79abc4..c64f0b5b5 100644 --- a/crates/hir_ty/src/tests/macros.rs +++ b/crates/hir_ty/src/tests/macros.rs | |||
@@ -571,6 +571,52 @@ fn bar() -> u32 {0} | |||
571 | } | 571 | } |
572 | 572 | ||
573 | #[test] | 573 | #[test] |
574 | fn infer_builtin_macros_include_str() { | ||
575 | check_types( | ||
576 | r#" | ||
577 | //- /main.rs | ||
578 | #[rustc_builtin_macro] | ||
579 | macro_rules! include_str {() => {}} | ||
580 | |||
581 | fn main() { | ||
582 | let a = include_str!("foo.rs"); | ||
583 | a; | ||
584 | } //^ &str | ||
585 | |||
586 | //- /foo.rs | ||
587 | hello | ||
588 | "#, | ||
589 | ); | ||
590 | } | ||
591 | |||
592 | #[test] | ||
593 | fn infer_builtin_macros_include_str_with_lazy_nested() { | ||
594 | check_types( | ||
595 | r#" | ||
596 | //- /main.rs | ||
597 | #[rustc_builtin_macro] | ||
598 | macro_rules! concat {() => {}} | ||
599 | #[rustc_builtin_macro] | ||
600 | macro_rules! include_str {() => {}} | ||
601 | |||
602 | macro_rules! m { | ||
603 | ($x:expr) => { | ||
604 | concat!("foo", $x) | ||
605 | }; | ||
606 | } | ||
607 | |||
608 | fn main() { | ||
609 | let a = include_str!(m!(".rs")); | ||
610 | a; | ||
611 | } //^ &str | ||
612 | |||
613 | //- /foo.rs | ||
614 | hello | ||
615 | "#, | ||
616 | ); | ||
617 | } | ||
618 | |||
619 | #[test] | ||
574 | #[ignore] | 620 | #[ignore] |
575 | fn include_accidentally_quadratic() { | 621 | fn include_accidentally_quadratic() { |
576 | let file = project_dir().join("crates/syntax/test_data/accidentally_quadratic"); | 622 | let file = project_dir().join("crates/syntax/test_data/accidentally_quadratic"); |