return when captured argument is not a struct field
This commit is contained in:
parent
a0a2ec3326
commit
dcd70c0995
@ -1279,20 +1279,21 @@ pub fn expand_preparsed_format_args(
|
||||
let captured_arg_span =
|
||||
fmt_span.from_inner(InnerSpan::new(err.span.start, err.span.end));
|
||||
let positional_args = args.iter().filter(|arg| !arg.named).collect::<Vec<_>>();
|
||||
let mut suggestions = vec![(captured_arg_span, positional_args.len().to_string())];
|
||||
if let Ok(arg) = ecx.source_map().span_to_snippet(captured_arg_span) {
|
||||
let span = match positional_args.last() {
|
||||
Some(arg) => arg.expr.span,
|
||||
None => fmt_sp,
|
||||
};
|
||||
suggestions.push((span.shrink_to_hi(), format!(", {}", arg)))
|
||||
}
|
||||
e.multipart_suggestion_verbose(
|
||||
"consider using a positional formatting argument instead",
|
||||
suggestions,
|
||||
vec![
|
||||
(captured_arg_span, positional_args.len().to_string()),
|
||||
(span.shrink_to_hi(), format!(", {}", arg)),
|
||||
],
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
}
|
||||
}
|
||||
e.emit();
|
||||
return DummyResult::raw_expr(sp, true);
|
||||
}
|
||||
|
@ -229,21 +229,17 @@ impl<'a> Iterator for Parser<'a> {
|
||||
Some(String(self.string(pos + 1)))
|
||||
} else {
|
||||
let arg = self.argument(lbrace_end);
|
||||
match self.must_consume('}') {
|
||||
Some(rbrace_byte_idx) => {
|
||||
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(
|
||||
lbrace_inner_offset
|
||||
.to(InnerOffset(rbrace_inner_offset.0 + 1)),
|
||||
lbrace_inner_offset.to(InnerOffset(rbrace_inner_offset.0 + 1)),
|
||||
);
|
||||
}
|
||||
}
|
||||
None => {
|
||||
} else {
|
||||
self.suggest_positional_arg_instead_of_captured_arg(arg);
|
||||
}
|
||||
}
|
||||
Some(NextArgument(arg))
|
||||
}
|
||||
}
|
||||
@ -767,6 +763,9 @@ impl<'a> Parser<'a> {
|
||||
let byte_pos = self.to_span_index(end);
|
||||
let start = InnerOffset(byte_pos.0 + 1);
|
||||
let field = self.argument(start);
|
||||
if !self.consume('}') {
|
||||
return;
|
||||
}
|
||||
if let ArgumentNamed(_) = arg.position {
|
||||
if let ArgumentNamed(_) = field.position {
|
||||
self.errors.insert(
|
||||
|
Loading…
x
Reference in New Issue
Block a user