@@ -26,10 +26,8 @@ use rustc_hir::def::{CtorOf, DefKind, Namespace, Res};
2626use rustc_hir:: def_id:: { DefId , LocalDefId } ;
2727use rustc_hir:: intravisit:: { walk_generics, Visitor as _} ;
2828use rustc_hir:: { GenericArg , GenericArgs , OpaqueTyOrigin } ;
29- use rustc_infer:: infer:: type_variable:: { TypeVariableOrigin , TypeVariableOriginKind } ;
3029use rustc_infer:: infer:: { InferCtxt , TyCtxtInferExt } ;
3130use rustc_infer:: traits:: ObligationCause ;
32- use rustc_middle:: infer:: unify_key:: { ConstVariableOrigin , ConstVariableOriginKind } ;
3331use rustc_middle:: middle:: stability:: AllowUnstable ;
3432use rustc_middle:: ty:: fold:: FnMutDelegate ;
3533use rustc_middle:: ty:: subst:: { self , GenericArgKind , InternalSubsts , SubstsRef } ;
@@ -1215,6 +1213,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
12151213 }
12161214
12171215 let projection_ty = if return_type_notation {
1216+ let mut emitted_bad_param_err = false ;
12181217 // If we have an method return type bound, then we need to substitute
12191218 // the method's early bound params with suitable late-bound params.
12201219 let mut num_bound_vars = candidate. bound_vars ( ) . len ( ) ;
@@ -1230,16 +1229,35 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
12301229 } ,
12311230 )
12321231 . into ( ) ,
1233- GenericParamDefKind :: Type { .. } => tcx
1234- . mk_bound (
1232+ GenericParamDefKind :: Type { .. } => {
1233+ if !emitted_bad_param_err {
1234+ tcx. sess . emit_err (
1235+ crate :: errors:: ReturnTypeNotationIllegalParam :: Type {
1236+ span : path_span,
1237+ param_span : tcx. def_span ( param. def_id ) ,
1238+ } ,
1239+ ) ;
1240+ emitted_bad_param_err = true ;
1241+ }
1242+ tcx. mk_bound (
12351243 ty:: INNERMOST ,
12361244 ty:: BoundTy {
12371245 var : ty:: BoundVar :: from_usize ( num_bound_vars) ,
12381246 kind : ty:: BoundTyKind :: Param ( param. def_id , param. name ) ,
12391247 } ,
12401248 )
1241- . into ( ) ,
1249+ . into ( )
1250+ }
12421251 GenericParamDefKind :: Const { .. } => {
1252+ if !emitted_bad_param_err {
1253+ tcx. sess . emit_err (
1254+ crate :: errors:: ReturnTypeNotationIllegalParam :: Const {
1255+ span : path_span,
1256+ param_span : tcx. def_span ( param. def_id ) ,
1257+ } ,
1258+ ) ;
1259+ emitted_bad_param_err = true ;
1260+ }
12431261 let ty = tcx
12441262 . type_of ( param. def_id )
12451263 . no_bound_vars ( )
@@ -2472,7 +2490,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
24722490 infcx. probe ( |_| {
24732491 let ocx = ObligationCtxt :: new_in_snapshot ( & infcx) ;
24742492
2475- let impl_substs = infcx. fresh_item_substs ( impl_) ;
2493+ let impl_substs = infcx. fresh_substs_for_item ( span , impl_) ;
24762494 let impl_ty = tcx. type_of ( impl_) . subst ( tcx, impl_substs) ;
24772495 let impl_ty = ocx. normalize ( & cause, param_env, impl_ty) ;
24782496
@@ -3759,36 +3777,3 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
37593777 }
37603778 }
37613779}
3762-
3763- pub trait InferCtxtExt < ' tcx > {
3764- fn fresh_item_substs ( & self , def_id : DefId ) -> SubstsRef < ' tcx > ;
3765- }
3766-
3767- impl < ' tcx > InferCtxtExt < ' tcx > for InferCtxt < ' tcx > {
3768- fn fresh_item_substs ( & self , def_id : DefId ) -> SubstsRef < ' tcx > {
3769- InternalSubsts :: for_item ( self . tcx , def_id, |param, _| match param. kind {
3770- GenericParamDefKind :: Lifetime => self . tcx . lifetimes . re_erased . into ( ) ,
3771- GenericParamDefKind :: Type { .. } => self
3772- . next_ty_var ( TypeVariableOrigin {
3773- kind : TypeVariableOriginKind :: SubstitutionPlaceholder ,
3774- span : self . tcx . def_span ( def_id) ,
3775- } )
3776- . into ( ) ,
3777- GenericParamDefKind :: Const { .. } => {
3778- let span = self . tcx . def_span ( def_id) ;
3779- let origin = ConstVariableOrigin {
3780- kind : ConstVariableOriginKind :: SubstitutionPlaceholder ,
3781- span,
3782- } ;
3783- self . next_const_var (
3784- self . tcx
3785- . type_of ( param. def_id )
3786- . no_bound_vars ( )
3787- . expect ( "const parameter types cannot be generic" ) ,
3788- origin,
3789- )
3790- . into ( )
3791- }
3792- } )
3793- }
3794- }
0 commit comments