File tree Expand file tree Collapse file tree 5 files changed +37
-6
lines changed
compiler/rustc_ast_passes
tests/ui/traits/negative-bounds Expand file tree Collapse file tree 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
188188ast_passes_negative_bound_not_supported =
189189 negative bounds are not supported
190190
191+ ast_passes_negative_bound_with_parenthetical_notation =
192+ parenthetical notation may not be used for negative bounds
193+
191194ast_passes_nested_impl_trait = nested `impl Trait` is not allowed
192195 .outer = outer `impl Trait`
193196 .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> {
12571257 if let GenericBound :: Trait ( trait_ref, modifiers) = bound
12581258 && let BoundPolarity :: Negative ( _) = modifiers. polarity
12591259 && let Some ( segment) = trait_ref. trait_ref . path . segments . last ( )
1260- && let Some ( ast:: GenericArgs :: AngleBracketed ( args) ) = segment. args . as_deref ( )
12611260 {
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+ } ) ;
12661276 }
1277+ None => { }
12671278 }
12681279 }
12691280
Original file line number Diff line number Diff line change @@ -745,6 +745,13 @@ pub struct ConstraintOnNegativeBound {
745745 pub span : Span ,
746746}
747747
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+
748755#[ derive( Diagnostic ) ]
749756#[ diag( ast_passes_invalid_unnamed_field_ty) ]
750757pub struct InvalidUnnamedFieldTy {
Original file line number Diff line number Diff line change @@ -16,4 +16,7 @@ fn test3<T: !Trait<Assoc: Send>>() {}
1616fn test4 < T > ( ) where T : !Trait < Assoc : Send > { }
1717//~^ ERROR associated type constraints not allowed on negative bounds
1818
19+ fn test5 < T > ( ) where T : !Fn ( ) -> i32 { }
20+ //~^ ERROR parenthetical notation may not be used for negative bounds
21+
1922fn main ( ) { }
Original file line number Diff line number Diff line change @@ -22,4 +22,11 @@ error: associated type constraints not allowed on negative bounds
2222LL | fn test4<T>() where T: !Trait<Assoc: Send> {}
2323 | ^^^^^^^^^^^
2424
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