Rollup merge of #118409 - klensy:position-opt, r=compiler-errors
format_foreign.rs: unwrap return Option value for `fn position`, as it always returns Some Trivial cleanup. It will be nice to have way to run exhaustiveness analysis on similar cases to see dead code.
This commit is contained in:
commit
69e48d0f6e
@ -672,15 +672,14 @@ fn report_missing_placeholders(
|
|||||||
if explained.contains(&sub) {
|
if explained.contains(&sub) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
explained.insert(sub.clone());
|
explained.insert(sub);
|
||||||
|
|
||||||
if !found_foreign {
|
if !found_foreign {
|
||||||
found_foreign = true;
|
found_foreign = true;
|
||||||
show_doc_note = true;
|
show_doc_note = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(inner_sp) = pos {
|
let sp = fmt_span.from_inner(pos);
|
||||||
let sp = fmt_span.from_inner(inner_sp);
|
|
||||||
|
|
||||||
if success {
|
if success {
|
||||||
suggestions.push((sp, trn));
|
suggestions.push((sp, trn));
|
||||||
@ -690,13 +689,6 @@ fn report_missing_placeholders(
|
|||||||
format!("format specifiers use curly braces, and {}", trn),
|
format!("format specifiers use curly braces, and {}", trn),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if success {
|
|
||||||
diag.help(format!("`{}` should be written as `{}`", sub, trn));
|
|
||||||
} else {
|
|
||||||
diag.note(format!("`{}` should use curly braces, and {}", sub, trn));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if show_doc_note {
|
if show_doc_note {
|
||||||
|
@ -19,10 +19,10 @@ pub(crate) mod printf {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn position(&self) -> Option<InnerSpan> {
|
pub fn position(&self) -> InnerSpan {
|
||||||
match self {
|
match self {
|
||||||
Substitution::Format(fmt) => Some(fmt.position),
|
Substitution::Format(fmt) => fmt.position,
|
||||||
&Substitution::Escape((start, end)) => Some(InnerSpan::new(start, end)),
|
&Substitution::Escape((start, end)) => InnerSpan::new(start, end),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,10 +302,9 @@ pub(crate) mod printf {
|
|||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
let (mut sub, tail) = parse_next_substitution(self.s)?;
|
let (mut sub, tail) = parse_next_substitution(self.s)?;
|
||||||
self.s = tail;
|
self.s = tail;
|
||||||
if let Some(InnerSpan { start, end }) = sub.position() {
|
let InnerSpan { start, end } = sub.position();
|
||||||
sub.set_position(start + self.pos, end + self.pos);
|
sub.set_position(start + self.pos, end + self.pos);
|
||||||
self.pos += end;
|
self.pos += end;
|
||||||
}
|
|
||||||
Some(sub)
|
Some(sub)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -629,9 +628,9 @@ pub mod shell {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn position(&self) -> Option<InnerSpan> {
|
pub fn position(&self) -> InnerSpan {
|
||||||
let (Self::Ordinal(_, pos) | Self::Name(_, pos) | Self::Escape(pos)) = self;
|
let (Self::Ordinal(_, pos) | Self::Name(_, pos) | Self::Escape(pos)) = self;
|
||||||
Some(InnerSpan::new(pos.0, pos.1))
|
InnerSpan::new(pos.0, pos.1)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_position(&mut self, start: usize, end: usize) {
|
pub fn set_position(&mut self, start: usize, end: usize) {
|
||||||
@ -664,10 +663,9 @@ pub mod shell {
|
|||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
let (mut sub, tail) = parse_next_substitution(self.s)?;
|
let (mut sub, tail) = parse_next_substitution(self.s)?;
|
||||||
self.s = tail;
|
self.s = tail;
|
||||||
if let Some(InnerSpan { start, end }) = sub.position() {
|
let InnerSpan { start, end } = sub.position();
|
||||||
sub.set_position(start + self.pos, end + self.pos);
|
sub.set_position(start + self.pos, end + self.pos);
|
||||||
self.pos += end;
|
self.pos += end;
|
||||||
}
|
|
||||||
Some(sub)
|
Some(sub)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user