@@ -22,6 +22,7 @@ use rustc::ty::subst::{Kind, Subst, Substs};
2222use rustc:: traits;
2323use rustc:: ty:: { self , Ty , TyCtxt , ToPredicate , TypeFoldable } ;
2424use rustc:: ty:: wf:: object_region_bounds;
25+ use rustc:: lint:: builtin:: PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES ;
2526use rustc_back:: slice;
2627use require_c_abi_if_variadic;
2728use util:: common:: { ErrorReported , FN_OUTPUT_NAME } ;
@@ -156,10 +157,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
156157 match item_segment. parameters {
157158 hir:: AngleBracketedParameters ( _) => { }
158159 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 ) ;
163161
164162 return Substs :: for_item ( tcx, def_id, |_, _| {
165163 tcx. types . re_static
@@ -370,6 +368,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
370368 self_ty : Ty < ' tcx > )
371369 -> ty:: TraitRef < ' tcx >
372370 {
371+ self . prohibit_type_params ( trait_ref. path . segments . split_last ( ) . unwrap ( ) . 1 ) ;
372+
373373 let trait_def_id = self . trait_def_id ( trait_ref) ;
374374 self . ast_path_to_mono_trait_ref ( trait_ref. path . span ,
375375 trait_def_id,
@@ -402,6 +402,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
402402
403403 debug ! ( "ast_path_to_poly_trait_ref({:?}, def_id={:?})" , trait_ref, trait_def_id) ;
404404
405+ self . prohibit_type_params ( trait_ref. path . segments . split_last ( ) . unwrap ( ) . 1 ) ;
406+
405407 let ( substs, assoc_bindings) =
406408 self . create_substs_for_ast_trait_ref ( trait_ref. path . span ,
407409 trait_def_id,
@@ -623,6 +625,13 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
623625 dummy_self,
624626 & mut projection_bounds) ;
625627
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+
626635 let ( auto_traits, trait_bounds) = split_auto_traits ( tcx, & trait_bounds[ 1 ..] ) ;
627636
628637 if !trait_bounds. is_empty ( ) {
@@ -938,6 +947,10 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
938947
939948 pub fn prohibit_type_params ( & self , segments : & [ hir:: PathSegment ] ) {
940949 for segment in segments {
950+ if let hir:: ParenthesizedParameters ( _) = segment. parameters {
951+ self . prohibit_parenthesized_params ( segment, false ) ;
952+ break ;
953+ }
941954 for typ in segment. parameters . types ( ) {
942955 struct_span_err ! ( self . tcx( ) . sess, typ. span, E0109 ,
943956 "type parameters are not allowed on this type" )
@@ -960,6 +973,21 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
960973 }
961974 }
962975
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+
963991 pub fn prohibit_projection ( & self , span : Span ) {
964992 let mut err = struct_span_err ! ( self . tcx( ) . sess, span, E0229 ,
965993 "associated type bindings are not allowed here" ) ;
0 commit comments