extract error_negative_bounds
This commit is contained in:
parent
b5f00beaa5
commit
f221b394de
@ -371,33 +371,7 @@ fn parse_generic_bounds_common(
|
||||
}
|
||||
|
||||
if !negative_bounds.is_empty() {
|
||||
let negative_bounds_len = negative_bounds.len();
|
||||
let last_span = *negative_bounds.last().unwrap();
|
||||
let mut err = self.struct_span_err(
|
||||
negative_bounds,
|
||||
"negative bounds are not supported",
|
||||
);
|
||||
err.span_label(last_span, "negative bounds are not supported");
|
||||
if let Some(bound_list) = colon_span {
|
||||
let bound_list = bound_list.to(self.prev_span);
|
||||
let mut new_bound_list = String::new();
|
||||
if !bounds.is_empty() {
|
||||
let mut snippets = bounds.iter().map(|bound| bound.span())
|
||||
.map(|span| self.span_to_snippet(span));
|
||||
while let Some(Ok(snippet)) = snippets.next() {
|
||||
new_bound_list.push_str(" + ");
|
||||
new_bound_list.push_str(&snippet);
|
||||
}
|
||||
new_bound_list = new_bound_list.replacen(" +", ":", 1);
|
||||
}
|
||||
err.span_suggestion_hidden(
|
||||
bound_list,
|
||||
&format!("remove the bound{}", pluralize!(negative_bounds_len)),
|
||||
new_bound_list,
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
}
|
||||
err.emit();
|
||||
self.error_negative_bounds(colon_span, &bounds, negative_bounds);
|
||||
}
|
||||
|
||||
Ok(bounds)
|
||||
@ -414,6 +388,40 @@ fn can_begin_bound(&mut self) -> bool {
|
||||
|| self.check(&token::OpenDelim(token::Paren))
|
||||
}
|
||||
|
||||
fn error_negative_bounds(
|
||||
&self,
|
||||
colon_span: Option<Span>,
|
||||
bounds: &[GenericBound],
|
||||
negative_bounds: Vec<Span>,
|
||||
) {
|
||||
let negative_bounds_len = negative_bounds.len();
|
||||
let last_span = *negative_bounds.last().unwrap();
|
||||
let mut err = self.struct_span_err(
|
||||
negative_bounds,
|
||||
"negative bounds are not supported",
|
||||
);
|
||||
err.span_label(last_span, "negative bounds are not supported");
|
||||
if let Some(bound_list) = colon_span {
|
||||
let bound_list = bound_list.to(self.prev_span);
|
||||
let mut new_bound_list = String::new();
|
||||
if !bounds.is_empty() {
|
||||
let mut snippets = bounds.iter().map(|bound| self.span_to_snippet(bound.span()));
|
||||
while let Some(Ok(snippet)) = snippets.next() {
|
||||
new_bound_list.push_str(" + ");
|
||||
new_bound_list.push_str(&snippet);
|
||||
}
|
||||
new_bound_list = new_bound_list.replacen(" +", ":", 1);
|
||||
}
|
||||
err.span_suggestion_hidden(
|
||||
bound_list,
|
||||
&format!("remove the bound{}", pluralize!(negative_bounds_len)),
|
||||
new_bound_list,
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
}
|
||||
err.emit();
|
||||
}
|
||||
|
||||
/// Parses a bound according to the grammar:
|
||||
/// ```
|
||||
/// BOUND = TY_BOUND | LT_BOUND
|
||||
|
Loading…
Reference in New Issue
Block a user