mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Deny parenthetical notation for negative bounds
This commit is contained in:
parent
5f56465621
commit
a251974015
@ -188,6 +188,9 @@ ast_passes_module_nonascii = trying to load file for module `{$name}` with non-a
|
||||
ast_passes_negative_bound_not_supported =
|
||||
negative bounds are not supported
|
||||
|
||||
ast_passes_negative_bound_with_parenthetical_notation =
|
||||
parenthetical notation may not be used for negative bounds
|
||||
|
||||
ast_passes_nested_impl_trait = nested `impl Trait` is not allowed
|
||||
.outer = outer `impl Trait`
|
||||
.inner = nested `impl Trait` here
|
||||
|
@ -1257,13 +1257,24 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
||||
if let GenericBound::Trait(trait_ref, modifiers) = bound
|
||||
&& let BoundPolarity::Negative(_) = modifiers.polarity
|
||||
&& let Some(segment) = trait_ref.trait_ref.path.segments.last()
|
||||
&& let Some(ast::GenericArgs::AngleBracketed(args)) = segment.args.as_deref()
|
||||
{
|
||||
for arg in &args.args {
|
||||
if let ast::AngleBracketedArg::Constraint(constraint) = arg {
|
||||
self.dcx()
|
||||
.emit_err(errors::ConstraintOnNegativeBound { span: constraint.span });
|
||||
match segment.args.as_deref() {
|
||||
Some(ast::GenericArgs::AngleBracketed(args)) => {
|
||||
for arg in &args.args {
|
||||
if let ast::AngleBracketedArg::Constraint(constraint) = arg {
|
||||
self.dcx().emit_err(errors::ConstraintOnNegativeBound {
|
||||
span: constraint.span,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
// The lowered form of parenthesized generic args contains a type binding.
|
||||
Some(ast::GenericArgs::Parenthesized(args)) => {
|
||||
self.dcx().emit_err(errors::NegativeBoundWithParentheticalNotation {
|
||||
span: args.span,
|
||||
});
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -745,6 +745,13 @@ pub struct ConstraintOnNegativeBound {
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(ast_passes_negative_bound_with_parenthetical_notation)]
|
||||
pub struct NegativeBoundWithParentheticalNotation {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(ast_passes_invalid_unnamed_field_ty)]
|
||||
pub struct InvalidUnnamedFieldTy {
|
||||
|
@ -16,4 +16,7 @@ fn test3<T: !Trait<Assoc: Send>>() {}
|
||||
fn test4<T>() where T: !Trait<Assoc: Send> {}
|
||||
//~^ ERROR associated type constraints not allowed on negative bounds
|
||||
|
||||
fn test5<T>() where T: !Fn() -> i32 {}
|
||||
//~^ ERROR parenthetical notation may not be used for negative bounds
|
||||
|
||||
fn main() {}
|
||||
|
@ -22,4 +22,11 @@ error: associated type constraints not allowed on negative bounds
|
||||
LL | fn test4<T>() where T: !Trait<Assoc: Send> {}
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
error: parenthetical notation may not be used for negative bounds
|
||||
--> $DIR/associated-constraints.rs:19:25
|
||||
|
|
||||
LL | fn test5<T>() where T: !Fn() -> i32 {}
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user