diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:06:37 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:06:37 +0000 |
commit | 246f239d9f40f633160f0c18f87a20922d4e77bb (patch) | |
tree | 5a88572663584b3d4d28e5a20e10abab1be40884 /src/test/ui/proc-macro/auxiliary/expand-expr.rs | |
parent | Releasing progress-linux version 1.64.0+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-246f239d9f40f633160f0c18f87a20922d4e77bb.tar.xz rustc-246f239d9f40f633160f0c18f87a20922d4e77bb.zip |
Merging debian version 1.65.0+dfsg1-2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/proc-macro/auxiliary/expand-expr.rs')
-rw-r--r-- | src/test/ui/proc-macro/auxiliary/expand-expr.rs | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/test/ui/proc-macro/auxiliary/expand-expr.rs b/src/test/ui/proc-macro/auxiliary/expand-expr.rs index 5463e79d7..1d6ef8a13 100644 --- a/src/test/ui/proc-macro/auxiliary/expand-expr.rs +++ b/src/test/ui/proc-macro/auxiliary/expand-expr.rs @@ -80,13 +80,21 @@ fn assert_ts_eq(lhs: &TokenStream, rhs: &TokenStream) { pub fn expand_expr_is(input: TokenStream) -> TokenStream { let mut iter = input.into_iter(); let mut expected_tts = Vec::new(); - loop { + let comma = loop { match iter.next() { - Some(TokenTree::Punct(ref p)) if p.as_char() == ',' => break, + Some(TokenTree::Punct(p)) if p.as_char() == ',' => break p, Some(tt) => expected_tts.push(tt), None => panic!("expected comma"), } - } + }; + + // Make sure that `Ident` and `Literal` objects from this proc-macro's + // environment are not invalidated when `expand_expr` recursively invokes + // another macro by taking a local copy, and checking it after the fact. + let pre_expand_span = comma.span(); + let pre_expand_ident = Ident::new("ident", comma.span()); + let pre_expand_literal = Literal::string("literal"); + let pre_expand_call_site = Span::call_site(); let expected = expected_tts.into_iter().collect::<TokenStream>(); let expanded = iter.collect::<TokenStream>().expand_expr().expect("expand_expr failed"); @@ -100,6 +108,15 @@ pub fn expand_expr_is(input: TokenStream) -> TokenStream { // Also compare the raw tts to make sure they line up. assert_ts_eq(&expected, &expanded); + assert!(comma.span().eq(&pre_expand_span), "pre-expansion span is still equal"); + assert_eq!(pre_expand_ident.to_string(), "ident", "pre-expansion identifier is still valid"); + assert_eq!( + pre_expand_literal.to_string(), + "\"literal\"", + "pre-expansion literal is still valid" + ); + assert!(Span::call_site().eq(&pre_expand_call_site), "pre-expansion call-site is still equal"); + TokenStream::new() } |