@@ -26,10 +26,8 @@ use rustc_hir::def::{CtorOf, DefKind, Namespace, Res};
26
26
use rustc_hir:: def_id:: { DefId , LocalDefId } ;
27
27
use rustc_hir:: intravisit:: { walk_generics, Visitor as _} ;
28
28
use rustc_hir:: { GenericArg , GenericArgs , OpaqueTyOrigin } ;
29
- use rustc_infer:: infer:: type_variable:: { TypeVariableOrigin , TypeVariableOriginKind } ;
30
29
use rustc_infer:: infer:: { InferCtxt , TyCtxtInferExt } ;
31
30
use rustc_infer:: traits:: ObligationCause ;
32
- use rustc_middle:: infer:: unify_key:: { ConstVariableOrigin , ConstVariableOriginKind } ;
33
31
use rustc_middle:: middle:: stability:: AllowUnstable ;
34
32
use rustc_middle:: ty:: fold:: FnMutDelegate ;
35
33
use rustc_middle:: ty:: subst:: { self , GenericArgKind , InternalSubsts , SubstsRef } ;
@@ -1215,6 +1213,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1215
1213
}
1216
1214
1217
1215
let projection_ty = if return_type_notation {
1216
+ let mut emitted_bad_param_err = false ;
1218
1217
// If we have an method return type bound, then we need to substitute
1219
1218
// the method's early bound params with suitable late-bound params.
1220
1219
let mut num_bound_vars = candidate. bound_vars ( ) . len ( ) ;
@@ -1230,16 +1229,35 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1230
1229
} ,
1231
1230
)
1232
1231
. 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 (
1235
1243
ty:: INNERMOST ,
1236
1244
ty:: BoundTy {
1237
1245
var : ty:: BoundVar :: from_usize ( num_bound_vars) ,
1238
1246
kind : ty:: BoundTyKind :: Param ( param. def_id , param. name ) ,
1239
1247
} ,
1240
1248
)
1241
- . into ( ) ,
1249
+ . into ( )
1250
+ }
1242
1251
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
+ }
1243
1261
let ty = tcx
1244
1262
. type_of ( param. def_id )
1245
1263
. no_bound_vars ( )
@@ -2472,7 +2490,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
2472
2490
infcx. probe ( |_| {
2473
2491
let ocx = ObligationCtxt :: new_in_snapshot ( & infcx) ;
2474
2492
2475
- let impl_substs = infcx. fresh_item_substs ( impl_) ;
2493
+ let impl_substs = infcx. fresh_substs_for_item ( span , impl_) ;
2476
2494
let impl_ty = tcx. type_of ( impl_) . subst ( tcx, impl_substs) ;
2477
2495
let impl_ty = ocx. normalize ( & cause, param_env, impl_ty) ;
2478
2496
@@ -3759,36 +3777,3 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
3759
3777
}
3760
3778
}
3761
3779
}
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