mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 11:48:30 +00:00
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
|
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;
|
.ty;
|
||||||
|
|
||||||
if !check_opaque_type_parameter_valid(
|
if !check_opaque_type_parameter_valid(
|
||||||
|
@ -536,7 +536,8 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
|||||||
let opaque_types =
|
let opaque_types =
|
||||||
self.fcx.infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
|
self.fcx.infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
|
||||||
for (opaque_type_key, decl) in 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 {
|
struct RecursionChecker {
|
||||||
def_id: LocalDefId,
|
def_id: LocalDefId,
|
||||||
@ -559,6 +560,14 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
|||||||
continue;
|
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);
|
self.typeck_results.concrete_opaque_types.insert(opaque_type_key.def_id, hidden_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1307,6 +1307,8 @@ impl<'tcx> OpaqueHiddenType<'tcx> {
|
|||||||
self,
|
self,
|
||||||
opaque_type_key: OpaqueTypeKey<'tcx>,
|
opaque_type_key: OpaqueTypeKey<'tcx>,
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
|
// typeck errors have subpar spans for opaque types, so delay error reporting until borrowck.
|
||||||
|
ignore_errors: bool,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let OpaqueTypeKey { def_id, substs } = opaque_type_key;
|
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
|
// Convert the type from the function into a type valid outside
|
||||||
// the function, by replacing invalid regions with 'static,
|
// the function, by replacing invalid regions with 'static,
|
||||||
// after producing an error for each of them.
|
// 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> {
|
pub(super) struct ReverseMapper<'tcx> {
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
map: FxHashMap<GenericArg<'tcx>, GenericArg<'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,
|
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 of function being checked.
|
||||||
span: Span,
|
span: Span,
|
||||||
}
|
}
|
||||||
@ -21,8 +29,9 @@ impl<'tcx> ReverseMapper<'tcx> {
|
|||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
map: FxHashMap<GenericArg<'tcx>, GenericArg<'tcx>>,
|
map: FxHashMap<GenericArg<'tcx>, GenericArg<'tcx>>,
|
||||||
span: Span,
|
span: Span,
|
||||||
|
ignore_errors: bool,
|
||||||
) -> Self {
|
) -> 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> {
|
fn fold_kind_no_missing_regions_error(&mut self, kind: GenericArg<'tcx>) -> GenericArg<'tcx> {
|
||||||
@ -156,17 +165,19 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> {
|
|||||||
Some(u) => panic!("type mapped to unexpected kind: {:?}", u),
|
Some(u) => panic!("type mapped to unexpected kind: {:?}", u),
|
||||||
None => {
|
None => {
|
||||||
debug!(?param, ?self.map);
|
debug!(?param, ?self.map);
|
||||||
self.tcx
|
if !self.ignore_errors {
|
||||||
.sess
|
self.tcx
|
||||||
.struct_span_err(
|
.sess
|
||||||
self.span,
|
.struct_span_err(
|
||||||
&format!(
|
self.span,
|
||||||
"type parameter `{}` is part of concrete type but not \
|
&format!(
|
||||||
|
"type parameter `{}` is part of concrete type but not \
|
||||||
used in parameter list for the `impl Trait` type alias",
|
used in parameter list for the `impl Trait` type alias",
|
||||||
ty
|
ty
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.emit();
|
.emit();
|
||||||
|
}
|
||||||
|
|
||||||
self.tcx().ty_error()
|
self.tcx().ty_error()
|
||||||
}
|
}
|
||||||
@ -189,10 +200,12 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> {
|
|||||||
Some(GenericArgKind::Const(c1)) => c1,
|
Some(GenericArgKind::Const(c1)) => c1,
|
||||||
Some(u) => panic!("const mapped to unexpected kind: {:?}", u),
|
Some(u) => panic!("const mapped to unexpected kind: {:?}", u),
|
||||||
None => {
|
None => {
|
||||||
self.tcx.sess.emit_err(ty::ConstNotUsedTraitAlias {
|
if !self.ignore_errors {
|
||||||
ct: ct.to_string(),
|
self.tcx.sess.emit_err(ty::ConstNotUsedTraitAlias {
|
||||||
span: self.span,
|
ct: ct.to_string(),
|
||||||
});
|
span: self.span,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
self.tcx().const_error(ct.ty())
|
self.tcx().const_error(ct.ty())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user