1
Fork 0

Enforce that ? and for<...> are not combined

This commit is contained in:
Michael Goulet 2024-07-10 17:49:50 -04:00
parent 32c8bfdb11
commit 898ed2ffa6
6 changed files with 38 additions and 4 deletions

View file

@ -3050,3 +3050,13 @@ pub struct BinderBeforeModifiers {
#[label]
pub modifiers_span: Span,
}
#[derive(Diagnostic)]
#[diag(parse_binder_and_polarity)]
pub struct BinderAndPolarity {
#[primary_span]
pub polarity_span: Span,
#[label]
pub binder_span: Span,
pub polarity: &'static str,
}

View file

@ -994,6 +994,19 @@ impl<'a> Parser<'a> {
let modifiers = self.parse_trait_bound_modifiers()?;
let modifiers_span = modifiers_lo.to(self.prev_token.span);
if let Some(binder_span) = binder_span {
match modifiers.polarity {
BoundPolarity::Negative(polarity_span) | BoundPolarity::Maybe(polarity_span) => {
self.dcx().emit_err(errors::BinderAndPolarity {
binder_span,
polarity_span,
polarity: modifiers.polarity.as_str(),
});
}
BoundPolarity::Positive => {}
}
}
// Recover erroneous lifetime bound with modifiers or binder.
// e.g. `T: for<'a> 'a` or `T: ~const 'a`.
if self.token.is_lifetime() {