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 =
|
ast_passes_negative_bound_not_supported =
|
||||||
negative bounds are 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
|
ast_passes_nested_impl_trait = nested `impl Trait` is not allowed
|
||||||
.outer = outer `impl Trait`
|
.outer = outer `impl Trait`
|
||||||
.inner = nested `impl Trait` here
|
.inner = nested `impl Trait` here
|
||||||
|
@ -1257,13 +1257,24 @@ fn visit_param_bound(&mut self, bound: &'a GenericBound, ctxt: BoundKind) {
|
|||||||
if let GenericBound::Trait(trait_ref, modifiers) = bound
|
if let GenericBound::Trait(trait_ref, modifiers) = bound
|
||||||
&& let BoundPolarity::Negative(_) = modifiers.polarity
|
&& let BoundPolarity::Negative(_) = modifiers.polarity
|
||||||
&& let Some(segment) = trait_ref.trait_ref.path.segments.last()
|
&& 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 {
|
match segment.args.as_deref() {
|
||||||
if let ast::AngleBracketedArg::Constraint(constraint) = arg {
|
Some(ast::GenericArgs::AngleBracketed(args)) => {
|
||||||
self.dcx()
|
for arg in &args.args {
|
||||||
.emit_err(errors::ConstraintOnNegativeBound { span: constraint.span });
|
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,
|
pub span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(ast_passes_negative_bound_with_parenthetical_notation)]
|
||||||
|
pub struct NegativeBoundWithParentheticalNotation {
|
||||||
|
#[primary_span]
|
||||||
|
pub span: Span,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(ast_passes_invalid_unnamed_field_ty)]
|
#[diag(ast_passes_invalid_unnamed_field_ty)]
|
||||||
pub struct InvalidUnnamedFieldTy {
|
pub struct InvalidUnnamedFieldTy {
|
||||||
|
@ -16,4 +16,7 @@ fn test3<T: !Trait<Assoc: Send>>() {}
|
|||||||
fn test4<T>() where T: !Trait<Assoc: Send> {}
|
fn test4<T>() where T: !Trait<Assoc: Send> {}
|
||||||
//~^ ERROR associated type constraints not allowed on negative bounds
|
//~^ 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() {}
|
fn main() {}
|
||||||
|
@ -22,4 +22,11 @@ error: associated type constraints not allowed on negative bounds
|
|||||||
LL | fn test4<T>() where T: !Trait<Assoc: Send> {}
|
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