diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-03-21 16:02:07 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-03-21 16:02:07 +0000 |
commit | 50c6a315ab2bef493b618742989744fb370a32ca (patch) | |
tree | fc4ee3a02310c55167d62d4bd95931d161178155 /crates/ra_hir_ty/src | |
parent | 5e827bd948ea206328b126345ab8e909978b3b9b (diff) | |
parent | 9ff50d7e839c635632021d47e2dd3982916e4738 (diff) |
Merge #3671
3671: Add identity expansion checking in ill-form expansion r=flodiebold a=edwin0cheng
This PR try to add more checking code in error case in macro expansion. The bug in #3642 is introduced by #3580 , which allow ill-form macro expansion in *all* kind of macro expansions.
In general we should separate hypothetical macro expansion and the actual macro expansion call. However, currently the `Semantic` workflow we are using only support single macro expansion type, we might want to review it and make it works in both ways. (Maybe add a field in `MacroCallLoc` for differentiation)
Fix #3642
Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/ra_hir_ty/src')
-rw-r--r-- | crates/ra_hir_ty/src/tests/regression.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/tests/regression.rs b/crates/ra_hir_ty/src/tests/regression.rs index 14c8ed3a9..a02e3ee05 100644 --- a/crates/ra_hir_ty/src/tests/regression.rs +++ b/crates/ra_hir_ty/src/tests/regression.rs | |||
@@ -453,3 +453,34 @@ pub mod str { | |||
453 | // should be Option<char>, but currently not because of Chalk ambiguity problem | 453 | // should be Option<char>, but currently not because of Chalk ambiguity problem |
454 | assert_eq!("(Option<{unknown}>, Option<{unknown}>)", super::type_at_pos(&db, pos)); | 454 | assert_eq!("(Option<{unknown}>, Option<{unknown}>)", super::type_at_pos(&db, pos)); |
455 | } | 455 | } |
456 | |||
457 | #[test] | ||
458 | fn issue_3642_bad_macro_stackover() { | ||
459 | let (db, pos) = TestDB::with_position( | ||
460 | r#" | ||
461 | //- /main.rs | ||
462 | #[macro_export] | ||
463 | macro_rules! match_ast { | ||
464 | (match $node:ident { $($tt:tt)* }) => { match_ast!(match ($node) { $($tt)* }) }; | ||
465 | |||
466 | (match ($node:expr) { | ||
467 | $( ast::$ast:ident($it:ident) => $res:expr, )* | ||
468 | _ => $catch_all:expr $(,)? | ||
469 | }) => {{ | ||
470 | $( if let Some($it) = ast::$ast::cast($node.clone()) { $res } else )* | ||
471 | { $catch_all } | ||
472 | }}; | ||
473 | } | ||
474 | |||
475 | fn main() { | ||
476 | let anchor<|> = match_ast! { | ||
477 | match parent { | ||
478 | as => {}, | ||
479 | _ => return None | ||
480 | } | ||
481 | }; | ||
482 | }"#, | ||
483 | ); | ||
484 | |||
485 | assert_eq!("()", super::type_at_pos(&db, pos)); | ||
486 | } | ||