File tree 5 files changed +37
-6
lines changed
compiler/rustc_ast_passes
tests/ui/traits/negative-bounds
5 files changed +37
-6
lines changed Original file line number Diff line number Diff line change @@ -188,6 +188,9 @@ ast_passes_module_nonascii = trying to load file for module `{$name}` with non-a
188
188
ast_passes_negative_bound_not_supported =
189
189
negative bounds are not supported
190
190
191
+ ast_passes_negative_bound_with_parenthetical_notation =
192
+ parenthetical notation may not be used for negative bounds
193
+
191
194
ast_passes_nested_impl_trait = nested `impl Trait` is not allowed
192
195
.outer = outer `impl Trait`
193
196
.inner = nested `impl Trait` here
Original file line number Diff line number Diff line change @@ -1257,13 +1257,24 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
1257
1257
if let GenericBound :: Trait ( trait_ref, modifiers) = bound
1258
1258
&& let BoundPolarity :: Negative ( _) = modifiers. polarity
1259
1259
&& let Some ( segment) = trait_ref. trait_ref . path . segments . last ( )
1260
- && let Some ( ast:: GenericArgs :: AngleBracketed ( args) ) = segment. args . as_deref ( )
1261
1260
{
1262
- for arg in & args. args {
1263
- if let ast:: AngleBracketedArg :: Constraint ( constraint) = arg {
1264
- self . dcx ( )
1265
- . emit_err ( errors:: ConstraintOnNegativeBound { span : constraint. span } ) ;
1261
+ match segment. args . as_deref ( ) {
1262
+ Some ( ast:: GenericArgs :: AngleBracketed ( args) ) => {
1263
+ for arg in & args. args {
1264
+ if let ast:: AngleBracketedArg :: Constraint ( constraint) = arg {
1265
+ self . dcx ( ) . emit_err ( errors:: ConstraintOnNegativeBound {
1266
+ span : constraint. span ,
1267
+ } ) ;
1268
+ }
1269
+ }
1270
+ }
1271
+ // The lowered form of parenthesized generic args contains a type binding.
1272
+ Some ( ast:: GenericArgs :: Parenthesized ( args) ) => {
1273
+ self . dcx ( ) . emit_err ( errors:: NegativeBoundWithParentheticalNotation {
1274
+ span : args. span ,
1275
+ } ) ;
1266
1276
}
1277
+ None => { }
1267
1278
}
1268
1279
}
1269
1280
Original file line number Diff line number Diff line change @@ -745,6 +745,13 @@ pub struct ConstraintOnNegativeBound {
745
745
pub span : Span ,
746
746
}
747
747
748
+ #[ derive( Diagnostic ) ]
749
+ #[ diag( ast_passes_negative_bound_with_parenthetical_notation) ]
750
+ pub struct NegativeBoundWithParentheticalNotation {
751
+ #[ primary_span]
752
+ pub span : Span ,
753
+ }
754
+
748
755
#[ derive( Diagnostic ) ]
749
756
#[ diag( ast_passes_invalid_unnamed_field_ty) ]
750
757
pub struct InvalidUnnamedFieldTy {
Original file line number Diff line number Diff line change @@ -16,4 +16,7 @@ fn test3<T: !Trait<Assoc: Send>>() {}
16
16
fn test4 < T > ( ) where T : !Trait < Assoc : Send > { }
17
17
//~^ ERROR associated type constraints not allowed on negative bounds
18
18
19
+ fn test5 < T > ( ) where T : !Fn ( ) -> i32 { }
20
+ //~^ ERROR parenthetical notation may not be used for negative bounds
21
+
19
22
fn main ( ) { }
Original file line number Diff line number Diff line change @@ -22,4 +22,11 @@ error: associated type constraints not allowed on negative bounds
22
22
LL | fn test4<T>() where T: !Trait<Assoc: Send> {}
23
23
| ^^^^^^^^^^^
24
24
25
- error: aborting due to 4 previous errors
25
+ error: parenthetical notation may not be used for negative bounds
26
+ --> $DIR/associated-constraints.rs:19:25
27
+ |
28
+ LL | fn test5<T>() where T: !Fn() -> i32 {}
29
+ | ^^^^^^^^^^^
30
+
31
+ error: aborting due to 5 previous errors
32
+
You can’t perform that action at this time.
0 commit comments