@@ -22,6 +22,7 @@ use rustc::ty::subst::{Kind, Subst, Substs};
22
22
use rustc:: traits;
23
23
use rustc:: ty:: { self , Ty , TyCtxt , ToPredicate , TypeFoldable } ;
24
24
use rustc:: ty:: wf:: object_region_bounds;
25
+ use rustc:: lint:: builtin:: PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES ;
25
26
use rustc_back:: slice;
26
27
use require_c_abi_if_variadic;
27
28
use util:: common:: { ErrorReported , FN_OUTPUT_NAME } ;
@@ -156,10 +157,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
156
157
match item_segment. parameters {
157
158
hir:: AngleBracketedParameters ( _) => { }
158
159
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 ( ) ;
160
+ self . prohibit_parenthesized_params ( item_segment, true ) ;
163
161
164
162
return Substs :: for_item ( tcx, def_id, |_, _| {
165
163
tcx. types . re_static
@@ -370,6 +368,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
370
368
self_ty : Ty < ' tcx > )
371
369
-> ty:: TraitRef < ' tcx >
372
370
{
371
+ self . prohibit_type_params ( trait_ref. path . segments . split_last ( ) . unwrap ( ) . 1 ) ;
372
+
373
373
let trait_def_id = self . trait_def_id ( trait_ref) ;
374
374
self . ast_path_to_mono_trait_ref ( trait_ref. path . span ,
375
375
trait_def_id,
@@ -402,6 +402,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
402
402
403
403
debug ! ( "ast_path_to_poly_trait_ref({:?}, def_id={:?})" , trait_ref, trait_def_id) ;
404
404
405
+ self . prohibit_type_params ( trait_ref. path . segments . split_last ( ) . unwrap ( ) . 1 ) ;
406
+
405
407
let ( substs, assoc_bindings) =
406
408
self . create_substs_for_ast_trait_ref ( trait_ref. path . span ,
407
409
trait_def_id,
@@ -623,6 +625,13 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
623
625
dummy_self,
624
626
& mut projection_bounds) ;
625
627
628
+ for trait_bound in trait_bounds[ 1 ..] . iter ( ) {
629
+ // Sanity check for non-principal trait bounds
630
+ self . instantiate_poly_trait_ref ( trait_bound,
631
+ dummy_self,
632
+ & mut vec ! [ ] ) ;
633
+ }
634
+
626
635
let ( auto_traits, trait_bounds) = split_auto_traits ( tcx, & trait_bounds[ 1 ..] ) ;
627
636
628
637
if !trait_bounds. is_empty ( ) {
@@ -938,6 +947,10 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
938
947
939
948
pub fn prohibit_type_params ( & self , segments : & [ hir:: PathSegment ] ) {
940
949
for segment in segments {
950
+ if let hir:: ParenthesizedParameters ( _) = segment. parameters {
951
+ self . prohibit_parenthesized_params ( segment, false ) ;
952
+ break ;
953
+ }
941
954
for typ in segment. parameters . types ( ) {
942
955
struct_span_err ! ( self . tcx( ) . sess, typ. span, E0109 ,
943
956
"type parameters are not allowed on this type" )
@@ -960,6 +973,21 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
960
973
}
961
974
}
962
975
976
+ pub fn prohibit_parenthesized_params ( & self , segment : & hir:: PathSegment , emit_error : bool ) {
977
+ if let hir:: ParenthesizedParameters ( ref data) = segment. parameters {
978
+ if emit_error {
979
+ struct_span_err ! ( self . tcx( ) . sess, data. span, E0214 ,
980
+ "parenthesized parameters may only be used with a trait" )
981
+ . span_label ( data. span , "only traits may use parentheses" )
982
+ . emit ( ) ;
983
+ } else {
984
+ let msg = "parenthesized parameters may only be used with a trait" . to_string ( ) ;
985
+ self . tcx ( ) . sess . add_lint ( PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES ,
986
+ ast:: CRATE_NODE_ID , data. span , msg) ;
987
+ }
988
+ }
989
+ }
990
+
963
991
pub fn prohibit_projection ( & self , span : Span ) {
964
992
let mut err = struct_span_err ! ( self . tcx( ) . sess, span, E0229 ,
965
993
"associated type bindings are not allowed here" ) ;
0 commit comments