@@ -156,10 +156,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
156
156
match item_segment. parameters {
157
157
hir:: AngleBracketedParameters ( _) => { }
158
158
hir:: ParenthesizedParameters ( ..) => {
159
- struct_span_err ! ( tcx. sess, span, E0214 ,
160
- "parenthesized parameters may only be used with a trait" )
161
- . span_label ( span, "only traits may use parentheses" )
162
- . emit ( ) ;
159
+ self . prohibit_parenthesized_params ( item_segment) ;
163
160
164
161
return Substs :: for_item ( tcx, def_id, |_, _| {
165
162
tcx. types . re_static
@@ -370,6 +367,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
370
367
self_ty : Ty < ' tcx > )
371
368
-> ty:: TraitRef < ' tcx >
372
369
{
370
+ self . prohibit_type_params ( trait_ref. path . segments . split_last ( ) . unwrap ( ) . 1 ) ;
371
+
373
372
let trait_def_id = self . trait_def_id ( trait_ref) ;
374
373
self . ast_path_to_mono_trait_ref ( trait_ref. path . span ,
375
374
trait_def_id,
@@ -402,6 +401,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
402
401
403
402
debug ! ( "ast_path_to_poly_trait_ref({:?}, def_id={:?})" , trait_ref, trait_def_id) ;
404
403
404
+ self . prohibit_type_params ( trait_ref. path . segments . split_last ( ) . unwrap ( ) . 1 ) ;
405
+
405
406
let ( substs, assoc_bindings) =
406
407
self . create_substs_for_ast_trait_ref ( trait_ref. path . span ,
407
408
trait_def_id,
@@ -623,6 +624,13 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
623
624
dummy_self,
624
625
& mut projection_bounds) ;
625
626
627
+ for trait_bound in trait_bounds[ 1 ..] . iter ( ) {
628
+ // Sanity check for non-principal trait bounds
629
+ self . instantiate_poly_trait_ref ( trait_bound,
630
+ dummy_self,
631
+ & mut vec ! [ ] ) ;
632
+ }
633
+
626
634
let ( auto_traits, trait_bounds) = split_auto_traits ( tcx, & trait_bounds[ 1 ..] ) ;
627
635
628
636
if !trait_bounds. is_empty ( ) {
@@ -937,6 +945,10 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
937
945
938
946
pub fn prohibit_type_params ( & self , segments : & [ hir:: PathSegment ] ) {
939
947
for segment in segments {
948
+ if let hir:: ParenthesizedParameters ( _) = segment. parameters {
949
+ self . prohibit_parenthesized_params ( segment) ;
950
+ break ;
951
+ }
940
952
for typ in segment. parameters . types ( ) {
941
953
struct_span_err ! ( self . tcx( ) . sess, typ. span, E0109 ,
942
954
"type parameters are not allowed on this type" )
@@ -959,6 +971,15 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
959
971
}
960
972
}
961
973
974
+ pub fn prohibit_parenthesized_params ( & self , segment : & hir:: PathSegment ) {
975
+ if let hir:: ParenthesizedParameters ( ref data) = segment. parameters {
976
+ struct_span_err ! ( self . tcx( ) . sess, data. span, E0214 ,
977
+ "parenthesized parameters may only be used with a trait" )
978
+ . span_label ( data. span , "only traits may use parentheses" )
979
+ . emit ( ) ;
980
+ }
981
+ }
982
+
962
983
pub fn prohibit_projection ( & self , span : Span ) {
963
984
let mut err = struct_span_err ! ( self . tcx( ) . sess, span, E0229 ,
964
985
"associated type bindings are not allowed here" ) ;
0 commit comments