mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 07:44:10 +00:00
Fix ICE #75307 in format
Remove usages of `unwrap` (even when some are safe today).
This commit is contained in:
parent
db870ea71b
commit
0a4f4e87e0
@ -149,7 +149,7 @@ fn parse_args<'a>(
|
||||
return Err(err);
|
||||
} else {
|
||||
// ...after that delegate to `expect` to also include the other expected tokens.
|
||||
return Err(p.expect(&token::Comma).err().unwrap());
|
||||
let _ = p.expect(&token::Comma)?;
|
||||
}
|
||||
}
|
||||
first = false;
|
||||
@ -359,24 +359,18 @@ impl<'a, 'b> Context<'a, 'b> {
|
||||
// for `println!("{7:7$}", 1);`
|
||||
refs.sort();
|
||||
refs.dedup();
|
||||
let (arg_list, mut sp) = if refs.len() == 1 {
|
||||
let spans: Vec<_> = spans.into_iter().filter_map(|sp| sp.copied()).collect();
|
||||
(
|
||||
format!("argument {}", refs[0]),
|
||||
if spans.is_empty() {
|
||||
let sp = if self.arg_spans.is_empty() || spans.is_empty() {
|
||||
MultiSpan::from_span(self.fmtsp)
|
||||
} else {
|
||||
MultiSpan::from_spans(spans)
|
||||
},
|
||||
)
|
||||
} else {
|
||||
let pos = MultiSpan::from_spans(spans.into_iter().map(|s| *s.unwrap()).collect());
|
||||
let reg = refs.pop().unwrap();
|
||||
(format!("arguments {head} and {tail}", head = refs.join(", "), tail = reg,), pos)
|
||||
};
|
||||
if self.arg_spans.is_empty() {
|
||||
sp = MultiSpan::from_span(self.fmtsp);
|
||||
}
|
||||
let arg_list = if refs.len() == 1 {
|
||||
format!("argument {}", refs[0])
|
||||
} else {
|
||||
let reg = refs.pop().unwrap();
|
||||
format!("arguments {head} and {tail}", head = refs.join(", "), tail = reg)
|
||||
};
|
||||
|
||||
e = self.ecx.struct_span_err(
|
||||
sp,
|
||||
@ -1067,10 +1061,9 @@ pub fn expand_preparsed_format_args(
|
||||
let args_unused = errs_len;
|
||||
|
||||
let mut diag = {
|
||||
if errs_len == 1 {
|
||||
let (sp, msg) = errs.into_iter().next().unwrap();
|
||||
let mut diag = cx.ecx.struct_span_err(sp, msg);
|
||||
diag.span_label(sp, msg);
|
||||
if let [(sp, msg)] = &errs[..] {
|
||||
let mut diag = cx.ecx.struct_span_err(*sp, *msg);
|
||||
diag.span_label(*sp, *msg);
|
||||
diag
|
||||
} else {
|
||||
let mut diag = cx.ecx.struct_span_err(
|
||||
|
3
src/test/ui/issues/issue-75307.rs
Normal file
3
src/test/ui/issues/issue-75307.rs
Normal file
@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
format!(r"{}{}{}", named_arg=1); //~ ERROR invalid reference to positional arguments 1 and 2
|
||||
}
|
10
src/test/ui/issues/issue-75307.stderr
Normal file
10
src/test/ui/issues/issue-75307.stderr
Normal file
@ -0,0 +1,10 @@
|
||||
error: invalid reference to positional arguments 1 and 2 (there is 1 argument)
|
||||
--> $DIR/issue-75307.rs:2:13
|
||||
|
|
||||
LL | format!(r"{}{}{}", named_arg=1);
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= note: positional arguments are zero-based
|
||||
|
||||
error: aborting due to previous error
|
||||
|
Loading…
Reference in New Issue
Block a user