Improve error message
This commit is contained in:
parent
e8445818d4
commit
32c8bfdb11
8 changed files with 66 additions and 11 deletions
|
@ -53,6 +53,9 @@ parse_bare_cr = {$double_quotes ->
|
|||
|
||||
parse_bare_cr_in_raw_string = bare CR not allowed in raw string
|
||||
|
||||
parse_binder_before_modifiers = `for<...>` binder should be placed before trait bound modifiers
|
||||
.label = place the `for<...>` binder before any modifiers
|
||||
|
||||
parse_bounds_not_allowed_on_trait_aliases = bounds are not allowed on trait aliases
|
||||
|
||||
parse_box_not_pat = expected pattern, found {$descr}
|
||||
|
|
|
@ -3041,3 +3041,12 @@ pub struct UnsafeAttrOutsideUnsafeSuggestion {
|
|||
#[suggestion_part(code = ")")]
|
||||
pub right: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(parse_binder_before_modifiers)]
|
||||
pub struct BinderBeforeModifiers {
|
||||
#[primary_span]
|
||||
pub binder_span: Span,
|
||||
#[label]
|
||||
pub modifiers_span: Span,
|
||||
}
|
||||
|
|
|
@ -989,7 +989,10 @@ impl<'a> Parser<'a> {
|
|||
leading_token: &Token,
|
||||
) -> PResult<'a, GenericBound> {
|
||||
let (mut lifetime_defs, binder_span) = self.parse_late_bound_lifetime_defs()?;
|
||||
|
||||
let modifiers_lo = self.token.span;
|
||||
let modifiers = self.parse_trait_bound_modifiers()?;
|
||||
let modifiers_span = modifiers_lo.to(self.prev_token.span);
|
||||
|
||||
// Recover erroneous lifetime bound with modifiers or binder.
|
||||
// e.g. `T: for<'a> 'a` or `T: ~const 'a`.
|
||||
|
@ -998,6 +1001,11 @@ impl<'a> Parser<'a> {
|
|||
return self.parse_generic_lt_bound(lo, has_parens);
|
||||
}
|
||||
|
||||
if let (more_lifetime_defs, Some(binder_span)) = self.parse_late_bound_lifetime_defs()? {
|
||||
lifetime_defs.extend(more_lifetime_defs);
|
||||
self.dcx().emit_err(errors::BinderBeforeModifiers { binder_span, modifiers_span });
|
||||
}
|
||||
|
||||
let mut path = if self.token.is_keyword(kw::Fn)
|
||||
&& self.look_ahead(1, |tok| tok.kind == TokenKind::OpenDelim(Delimiter::Parenthesis))
|
||||
&& let Some(path) = self.recover_path_from_fn()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue