diff options
| author | bors <bors@rust-lang.org> | 2023-01-18 22:58:30 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-01-18 22:58:30 +0000 |
| commit | 8b11574ca07f95dd33861d145a43708c20cb4eb5 (patch) | |
| tree | e01a6e2adbef96b60c5d06afcb9992c5e93a72cb /tests | |
| parent | 333ee6c466972185973d5097f8b5fb0f9fb13fa5 (diff) | |
| parent | a8086cf9dfbe733f1172dfba816c8e65d3f35e76 (diff) | |
| download | rust-8b11574ca07f95dd33861d145a43708c20cb4eb5.tar.gz rust-8b11574ca07f95dd33861d145a43708c20cb4eb5.zip | |
Auto merge of #107041 - Nilstrieb:back-to-being-clueless-whether-it-really-is-a-literal, r=compiler-errors
Revert "Improve heuristics whether `format_args` string is a source literal" This reverts commit e6c02aad9345925cfed74f86b414c4d0715d381b (from #106195). Keeps the code improvements from the PR and the test (as a known-bug). Works around #106408 while a proper fix is discussed more thoroughly in #106505, as proposed by `@tmandry.` Reopens #106191 r? compiler-errors
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/fmt/auxiliary/format-string-proc-macro.rs | 12 | ||||
| -rw-r--r-- | tests/ui/fmt/indoc-issue-106408.rs | 9 | ||||
| -rw-r--r-- | tests/ui/fmt/respanned-literal-issue-106191.rs | 9 | ||||
| -rw-r--r-- | tests/ui/fmt/respanned-literal-issue-106191.stderr | 21 |
4 files changed, 30 insertions, 21 deletions
diff --git a/tests/ui/fmt/auxiliary/format-string-proc-macro.rs b/tests/ui/fmt/auxiliary/format-string-proc-macro.rs index 539c8fb27b3..1b7ef93f41d 100644 --- a/tests/ui/fmt/auxiliary/format-string-proc-macro.rs +++ b/tests/ui/fmt/auxiliary/format-string-proc-macro.rs @@ -28,6 +28,7 @@ pub fn err_with_input_span(input: TokenStream) -> TokenStream { TokenStream::from(TokenTree::Literal(lit)) } + #[proc_macro] pub fn respan_to_invalid_format_literal(input: TokenStream) -> TokenStream { let mut s = Literal::string("{"); @@ -38,3 +39,14 @@ pub fn respan_to_invalid_format_literal(input: TokenStream) -> TokenStream { 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())), + ]) +} diff --git a/tests/ui/fmt/indoc-issue-106408.rs b/tests/ui/fmt/indoc-issue-106408.rs new file mode 100644 index 00000000000..e4e3093b590 --- /dev/null +++ b/tests/ui/fmt/indoc-issue-106408.rs @@ -0,0 +1,9 @@ +// aux-build:format-string-proc-macro.rs +// check-pass + +extern crate format_string_proc_macro; + +fn main() { + let a = 0; + format_string_proc_macro::capture_a_with_prepended_space_preserve_span!("{a}"); +} diff --git a/tests/ui/fmt/respanned-literal-issue-106191.rs b/tests/ui/fmt/respanned-literal-issue-106191.rs index 44642a10fc0..bb741c0ef93 100644 --- a/tests/ui/fmt/respanned-literal-issue-106191.rs +++ b/tests/ui/fmt/respanned-literal-issue-106191.rs @@ -1,10 +1,15 @@ // aux-build:format-string-proc-macro.rs +// check-fail +// known-bug: #106191 +// unset-rustc-env:RUST_BACKTRACE +// had to be reverted +// error-pattern:internal compiler error +// failure-status:101 +// dont-check-compiler-stderr extern crate format_string_proc_macro; fn main() { format_string_proc_macro::respan_to_invalid_format_literal!("¡"); - //~^ ERROR invalid format string: expected `'}'` but string was terminated format_args!(r#concat!("¡ {")); - //~^ ERROR invalid format string: expected `'}'` but string was terminated } diff --git a/tests/ui/fmt/respanned-literal-issue-106191.stderr b/tests/ui/fmt/respanned-literal-issue-106191.stderr index 73a3af65a38..16717f42253 100644 --- a/tests/ui/fmt/respanned-literal-issue-106191.stderr +++ b/tests/ui/fmt/respanned-literal-issue-106191.stderr @@ -1,19 +1,2 @@ -error: invalid format string: expected `'}'` but string was terminated - --> $DIR/respanned-literal-issue-106191.rs:6:65 - | -LL | format_string_proc_macro::respan_to_invalid_format_literal!("¡"); - | ^^^ expected `'}'` in format string - | - = note: if you intended to print `{`, you can escape it using `{{` - -error: invalid format string: expected `'}'` but string was terminated - --> $DIR/respanned-literal-issue-106191.rs:8:18 - | -LL | format_args!(r#concat!("¡ {")); - | ^^^^^^^^^^^^^^^^^^^^^^^ expected `'}'` in format string - | - = note: if you intended to print `{`, you can escape it using `{{` - = note: this error originates in the macro `concat` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 2 previous errors - + query stack during panic: +end of query stack |
