Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

format macro argument parsing fix #83348

Merged
merged 1 commit into from
Mar 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions compiler/rustc_parse_format/src/lib.rs
Original file line number Diff line number Diff line change
@@ -213,11 +213,13 @@ impl<'a> Iterator for Parser<'a> {
Some(String(self.string(pos + 1)))
} else {
let arg = self.argument();
if let Some(end) = self.must_consume('}') {
let start = self.to_span_index(pos);
let end = self.to_span_index(end + 1);
if let Some(rbrace_byte_idx) = self.must_consume('}') {
let lbrace_inner_offset = self.to_span_index(pos);
let rbrace_inner_offset = self.to_span_index(rbrace_byte_idx);
if self.is_literal {
self.arg_places.push(start.to(end));
self.arg_places.push(
lbrace_inner_offset.to(InnerOffset(rbrace_inner_offset.0 + 1)),
);
}
}
Some(NextArgument(arg))
6 changes: 6 additions & 0 deletions src/test/ui/macros/issue-83344.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// check-fail

fn main() {
println!("{}\
"); //~^ ERROR: 1 positional argument in format string, but no arguments were given
}
8 changes: 8 additions & 0 deletions src/test/ui/macros/issue-83344.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: 1 positional argument in format string, but no arguments were given
--> $DIR/issue-83344.rs:4:15
|
LL | println!("{}\
| ^^

error: aborting due to previous error

5 changes: 3 additions & 2 deletions src/tools/clippy/tests/ui/write_literal_2.stderr
Original file line number Diff line number Diff line change
@@ -75,8 +75,9 @@ LL | "1", "2", "3",
|
help: try this
|
LL | "some 1{} / {}", "2", "3",
| ^ --
LL | "some 1/
LL | {} / {}", "2", "3",
|

error: literal with an empty format string
--> $DIR/write_literal_2.rs:25:14