|
1 | 1 | use crate::infer::type_variable::TypeVariableOriginKind; |
2 | | -use crate::infer::InferCtxt; |
| 2 | +use crate::infer::{InferCtxt, Symbol}; |
3 | 3 | use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder}; |
4 | 4 | use rustc_hir as hir; |
5 | 5 | use rustc_hir::def::{DefKind, Namespace}; |
@@ -898,8 +898,17 @@ impl<'tcx> TypeFolder<'tcx> for ResolvedTypeParamEraser<'tcx> { |
898 | 898 | let substs: Vec<_> = substs |
899 | 899 | .iter() |
900 | 900 | .zip(generics.params.iter()) |
901 | | - .map(|(subst, param)| match ¶m.kind { |
902 | | - ty::GenericParamDefKind::Type { has_default: true, .. } => subst, |
| 901 | + .map(|(subst, param)| match &(subst.unpack(), ¶m.kind) { |
| 902 | + (_, ty::GenericParamDefKind::Type { has_default: true, .. }) => subst, |
| 903 | + (crate::infer::GenericArgKind::Const(c), _) => { |
| 904 | + match c.val { |
| 905 | + ty::ConstKind::Infer(..) => { |
| 906 | + // Replace not yet inferred const params with their def name. |
| 907 | + self.tcx().mk_const_param(param.index, param.name, c.ty).into() |
| 908 | + } |
| 909 | + _ => subst, |
| 910 | + } |
| 911 | + } |
903 | 912 | _ => subst.super_fold_with(self), |
904 | 913 | }) |
905 | 914 | .collect(); |
@@ -937,8 +946,19 @@ impl<'tcx> TypeFolder<'tcx> for ResolvedTypeParamEraser<'tcx> { |
937 | 946 | | ty::FnPtr(_) |
938 | 947 | | ty::Opaque(..) |
939 | 948 | | ty::Projection(_) |
940 | | - | ty::Never |
941 | | - | ty::Array(..) => t.super_fold_with(self), |
| 949 | + | ty::Never => t.super_fold_with(self), |
| 950 | + ty::Array(ty, c) => { |
| 951 | + self.tcx().mk_ty(ty::Array( |
| 952 | + self.fold_ty(ty), |
| 953 | + match c.val { |
| 954 | + ty::ConstKind::Infer(..) => { |
| 955 | + // Replace not yet inferred const params with their def name. |
| 956 | + self.tcx().mk_const_param(0, Symbol::intern("N"), c.ty).into() |
| 957 | + } |
| 958 | + _ => c, |
| 959 | + }, |
| 960 | + )) |
| 961 | + } |
942 | 962 | // We don't want to hide type params that haven't been resolved yet. |
943 | 963 | // This would be the type that will be written out with the type param |
944 | 964 | // name in the output. |
|
0 commit comments