Remap hidden types from typeck before storing them in the TypeckResult
This commit is contained in:
parent
9eb69e82e0
commit
70d39abbc2
@ -226,7 +226,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
|
||||
}
|
||||
|
||||
let definition_ty = instantiated_ty
|
||||
.remap_generic_params_to_declaration_params(opaque_type_key, self.tcx)
|
||||
.remap_generic_params_to_declaration_params(opaque_type_key, self.tcx, false)
|
||||
.ty;
|
||||
|
||||
if !check_opaque_type_parameter_valid(
|
||||
|
@ -536,7 +536,8 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
||||
let opaque_types =
|
||||
self.fcx.infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
|
||||
for (opaque_type_key, decl) in opaque_types {
|
||||
let hidden_type = self.resolve(decl.hidden_type.ty, &decl.hidden_type.span);
|
||||
let hidden_type = self.resolve(decl.hidden_type, &decl.hidden_type.span);
|
||||
let opaque_type_key = self.resolve(opaque_type_key, &decl.hidden_type.span);
|
||||
|
||||
struct RecursionChecker {
|
||||
def_id: LocalDefId,
|
||||
@ -559,6 +560,14 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
||||
continue;
|
||||
}
|
||||
|
||||
let hidden_type = hidden_type
|
||||
.remap_generic_params_to_declaration_params(
|
||||
opaque_type_key,
|
||||
self.fcx.infcx.tcx,
|
||||
true,
|
||||
)
|
||||
.ty;
|
||||
|
||||
self.typeck_results.concrete_opaque_types.insert(opaque_type_key.def_id, hidden_type);
|
||||
}
|
||||
}
|
||||
|
@ -1307,6 +1307,8 @@ impl<'tcx> OpaqueHiddenType<'tcx> {
|
||||
self,
|
||||
opaque_type_key: OpaqueTypeKey<'tcx>,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
// typeck errors have subpar spans for opaque types, so delay error reporting until borrowck.
|
||||
ignore_errors: bool,
|
||||
) -> Self {
|
||||
let OpaqueTypeKey { def_id, substs } = opaque_type_key;
|
||||
|
||||
@ -1325,7 +1327,7 @@ impl<'tcx> OpaqueHiddenType<'tcx> {
|
||||
// Convert the type from the function into a type valid outside
|
||||
// the function, by replacing invalid regions with 'static,
|
||||
// after producing an error for each of them.
|
||||
self.fold_with(&mut opaque_types::ReverseMapper::new(tcx, map, self.span))
|
||||
self.fold_with(&mut opaque_types::ReverseMapper::new(tcx, map, self.span, ignore_errors))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,8 +10,16 @@ use rustc_span::Span;
|
||||
pub(super) struct ReverseMapper<'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
map: FxHashMap<GenericArg<'tcx>, GenericArg<'tcx>>,
|
||||
/// see call sites to fold_kind_no_missing_regions_error
|
||||
/// for an explanation of this field.
|
||||
do_not_error: bool,
|
||||
|
||||
/// We do not want to emit any errors in typeck because
|
||||
/// the spans in typeck are subpar at the moment.
|
||||
/// Borrowck will do the same work again (this time with
|
||||
/// lifetime information) and thus report better errors.
|
||||
ignore_errors: bool,
|
||||
|
||||
/// Span of function being checked.
|
||||
span: Span,
|
||||
}
|
||||
@ -21,8 +29,9 @@ impl<'tcx> ReverseMapper<'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
map: FxHashMap<GenericArg<'tcx>, GenericArg<'tcx>>,
|
||||
span: Span,
|
||||
ignore_errors: bool,
|
||||
) -> Self {
|
||||
Self { tcx, map, do_not_error: false, span }
|
||||
Self { tcx, map, do_not_error: false, ignore_errors, span }
|
||||
}
|
||||
|
||||
fn fold_kind_no_missing_regions_error(&mut self, kind: GenericArg<'tcx>) -> GenericArg<'tcx> {
|
||||
@ -156,6 +165,7 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> {
|
||||
Some(u) => panic!("type mapped to unexpected kind: {:?}", u),
|
||||
None => {
|
||||
debug!(?param, ?self.map);
|
||||
if !self.ignore_errors {
|
||||
self.tcx
|
||||
.sess
|
||||
.struct_span_err(
|
||||
@ -167,6 +177,7 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> {
|
||||
),
|
||||
)
|
||||
.emit();
|
||||
}
|
||||
|
||||
self.tcx().ty_error()
|
||||
}
|
||||
@ -189,10 +200,12 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> {
|
||||
Some(GenericArgKind::Const(c1)) => c1,
|
||||
Some(u) => panic!("const mapped to unexpected kind: {:?}", u),
|
||||
None => {
|
||||
if !self.ignore_errors {
|
||||
self.tcx.sess.emit_err(ty::ConstNotUsedTraitAlias {
|
||||
ct: ct.to_string(),
|
||||
span: self.span,
|
||||
});
|
||||
}
|
||||
|
||||
self.tcx().const_error(ct.ty())
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user