From a4b7ed7a42c716ab9f05e351f003d589124fd55d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:18:58 +0200 Subject: Adding upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- tests/ui/fmt/auxiliary/format-string-proc-macro.rs | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 tests/ui/fmt/auxiliary/format-string-proc-macro.rs (limited to 'tests/ui/fmt/auxiliary/format-string-proc-macro.rs') diff --git a/tests/ui/fmt/auxiliary/format-string-proc-macro.rs b/tests/ui/fmt/auxiliary/format-string-proc-macro.rs new file mode 100644 index 000000000..1b7ef93f4 --- /dev/null +++ b/tests/ui/fmt/auxiliary/format-string-proc-macro.rs @@ -0,0 +1,52 @@ +// force-host +// no-prefer-dynamic + +#![crate_type = "proc-macro"] + +extern crate proc_macro; + +use proc_macro::{Delimiter, Group, Ident, Literal, Punct, Spacing, Span, TokenStream, TokenTree}; +use std::iter::FromIterator; + +#[proc_macro] +pub fn foo_with_input_span(input: TokenStream) -> TokenStream { + let span = input.into_iter().next().unwrap().span(); + + let mut lit = Literal::string("{foo}"); + lit.set_span(span); + + TokenStream::from(TokenTree::Literal(lit)) +} + +#[proc_macro] +pub fn err_with_input_span(input: TokenStream) -> TokenStream { + let span = input.into_iter().next().unwrap().span(); + + let mut lit = Literal::string(" }"); + lit.set_span(span); + + TokenStream::from(TokenTree::Literal(lit)) +} + + +#[proc_macro] +pub fn respan_to_invalid_format_literal(input: TokenStream) -> TokenStream { + let mut s = Literal::string("{"); + s.set_span(input.into_iter().next().unwrap().span()); + TokenStream::from_iter([ + TokenTree::from(Ident::new("format", Span::call_site())), + TokenTree::from(Punct::new('!', Spacing::Alone)), + TokenTree::from(Group::new(Delimiter::Parenthesis, TokenTree::from(s).into())), + ]) +} + +#[proc_macro] +pub fn capture_a_with_prepended_space_preserve_span(input: TokenStream) -> TokenStream { + let mut s = Literal::string(" {a}"); + s.set_span(input.into_iter().next().unwrap().span()); + TokenStream::from_iter([ + TokenTree::from(Ident::new("format", Span::call_site())), + TokenTree::from(Punct::new('!', Spacing::Alone)), + TokenTree::from(Group::new(Delimiter::Parenthesis, TokenTree::from(s).into())), + ]) +} -- cgit v1.2.3