mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 19:17:43 +00:00
Rollup merge of #99347 - compiler-errors:opaque-type-key-local-def-id, r=oli-obk
Use `LocalDefId` in `OpaqueTypeKey` Addresses a `// FIXME(oli-obk): make this a LocalDefId` r? ``@oli-obk``
This commit is contained in:
commit
d00646b821
@ -1,7 +1,7 @@
|
|||||||
//! The entry point of the NLL borrow checker.
|
//! The entry point of the NLL borrow checker.
|
||||||
|
|
||||||
use rustc_data_structures::vec_map::VecMap;
|
use rustc_data_structures::vec_map::VecMap;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::LocalDefId;
|
||||||
use rustc_index::vec::IndexVec;
|
use rustc_index::vec::IndexVec;
|
||||||
use rustc_infer::infer::InferCtxt;
|
use rustc_infer::infer::InferCtxt;
|
||||||
use rustc_middle::mir::{create_dump_file, dump_enabled, dump_mir, PassWhere};
|
use rustc_middle::mir::{create_dump_file, dump_enabled, dump_mir, PassWhere};
|
||||||
@ -44,7 +44,7 @@ pub type PoloniusOutput = Output<RustcFacts>;
|
|||||||
/// closure requirements to propagate, and any generated errors.
|
/// closure requirements to propagate, and any generated errors.
|
||||||
pub(crate) struct NllOutput<'tcx> {
|
pub(crate) struct NllOutput<'tcx> {
|
||||||
pub regioncx: RegionInferenceContext<'tcx>,
|
pub regioncx: RegionInferenceContext<'tcx>,
|
||||||
pub opaque_type_values: VecMap<DefId, OpaqueHiddenType<'tcx>>,
|
pub opaque_type_values: VecMap<LocalDefId, OpaqueHiddenType<'tcx>>,
|
||||||
pub polonius_input: Option<Box<AllFacts>>,
|
pub polonius_input: Option<Box<AllFacts>>,
|
||||||
pub polonius_output: Option<Rc<PoloniusOutput>>,
|
pub polonius_output: Option<Rc<PoloniusOutput>>,
|
||||||
pub opt_closure_req: Option<ClosureRegionRequirements<'tcx>>,
|
pub opt_closure_req: Option<ClosureRegionRequirements<'tcx>>,
|
||||||
@ -373,7 +373,7 @@ pub(super) fn dump_annotation<'a, 'tcx>(
|
|||||||
body: &Body<'tcx>,
|
body: &Body<'tcx>,
|
||||||
regioncx: &RegionInferenceContext<'tcx>,
|
regioncx: &RegionInferenceContext<'tcx>,
|
||||||
closure_region_requirements: &Option<ClosureRegionRequirements<'_>>,
|
closure_region_requirements: &Option<ClosureRegionRequirements<'_>>,
|
||||||
opaque_type_values: &VecMap<DefId, OpaqueHiddenType<'tcx>>,
|
opaque_type_values: &VecMap<LocalDefId, OpaqueHiddenType<'tcx>>,
|
||||||
errors: &mut crate::error::BorrowckErrors<'tcx>,
|
errors: &mut crate::error::BorrowckErrors<'tcx>,
|
||||||
) {
|
) {
|
||||||
let tcx = infcx.tcx;
|
let tcx = infcx.tcx;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_data_structures::vec_map::VecMap;
|
use rustc_data_structures::vec_map::VecMap;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::LocalDefId;
|
||||||
use rustc_hir::OpaqueTyOrigin;
|
use rustc_hir::OpaqueTyOrigin;
|
||||||
use rustc_infer::infer::error_reporting::unexpected_hidden_region_diagnostic;
|
use rustc_infer::infer::error_reporting::unexpected_hidden_region_diagnostic;
|
||||||
use rustc_infer::infer::InferCtxt;
|
use rustc_infer::infer::InferCtxt;
|
||||||
@ -63,8 +63,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||||||
&self,
|
&self,
|
||||||
infcx: &InferCtxt<'_, 'tcx>,
|
infcx: &InferCtxt<'_, 'tcx>,
|
||||||
opaque_ty_decls: VecMap<OpaqueTypeKey<'tcx>, (OpaqueHiddenType<'tcx>, OpaqueTyOrigin)>,
|
opaque_ty_decls: VecMap<OpaqueTypeKey<'tcx>, (OpaqueHiddenType<'tcx>, OpaqueTyOrigin)>,
|
||||||
) -> VecMap<DefId, OpaqueHiddenType<'tcx>> {
|
) -> VecMap<LocalDefId, OpaqueHiddenType<'tcx>> {
|
||||||
let mut result: VecMap<DefId, OpaqueHiddenType<'tcx>> = VecMap::new();
|
let mut result: VecMap<LocalDefId, OpaqueHiddenType<'tcx>> = VecMap::new();
|
||||||
for (opaque_type_key, (concrete_type, origin)) in opaque_ty_decls {
|
for (opaque_type_key, (concrete_type, origin)) in opaque_ty_decls {
|
||||||
let substs = opaque_type_key.substs;
|
let substs = opaque_type_key.substs;
|
||||||
debug!(?concrete_type, ?substs);
|
debug!(?concrete_type, ?substs);
|
||||||
@ -235,7 +235,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||||||
// lifetimes with 'static and remapping only those used in the
|
// lifetimes with 'static and remapping only those used in the
|
||||||
// `impl Trait` return type, resulting in the parameters
|
// `impl Trait` return type, resulting in the parameters
|
||||||
// shifting.
|
// shifting.
|
||||||
let id_substs = InternalSubsts::identity_for_item(self.tcx, def_id);
|
let id_substs = InternalSubsts::identity_for_item(self.tcx, def_id.to_def_id());
|
||||||
debug!(?id_substs);
|
debug!(?id_substs);
|
||||||
let map: FxHashMap<GenericArg<'tcx>, GenericArg<'tcx>> =
|
let map: FxHashMap<GenericArg<'tcx>, GenericArg<'tcx>> =
|
||||||
substs.iter().enumerate().map(|(index, subst)| (subst, id_substs[index])).collect();
|
substs.iter().enumerate().map(|(index, subst)| (subst, id_substs[index])).collect();
|
||||||
@ -268,7 +268,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||||||
// This logic duplicates most of `check_opaque_meets_bounds`.
|
// This logic duplicates most of `check_opaque_meets_bounds`.
|
||||||
// FIXME(oli-obk): Also do region checks here and then consider removing `check_opaque_meets_bounds` entirely.
|
// FIXME(oli-obk): Also do region checks here and then consider removing `check_opaque_meets_bounds` entirely.
|
||||||
let param_env = self.tcx.param_env(def_id);
|
let param_env = self.tcx.param_env(def_id);
|
||||||
let body_id = self.tcx.local_def_id_to_hir_id(def_id.as_local().unwrap());
|
let body_id = self.tcx.local_def_id_to_hir_id(def_id);
|
||||||
self.tcx.infer_ctxt().enter(move |infcx| {
|
self.tcx.infer_ctxt().enter(move |infcx| {
|
||||||
// Require the hidden type to be well-formed with only the generics of the opaque type.
|
// Require the hidden type to be well-formed with only the generics of the opaque type.
|
||||||
// Defining use functions may have more bounds than the opaque type, which is ok, as long as the
|
// Defining use functions may have more bounds than the opaque type, which is ok, as long as the
|
||||||
@ -296,7 +296,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||||||
infcx
|
infcx
|
||||||
.report_mismatched_types(
|
.report_mismatched_types(
|
||||||
&ObligationCause::misc(instantiated_ty.span, body_id),
|
&ObligationCause::misc(instantiated_ty.span, body_id),
|
||||||
self.tcx.mk_opaque(def_id, id_substs),
|
self.tcx.mk_opaque(def_id.to_def_id(), id_substs),
|
||||||
definition_ty,
|
definition_ty,
|
||||||
err,
|
err,
|
||||||
)
|
)
|
||||||
@ -423,7 +423,7 @@ fn check_opaque_type_parameter_valid(
|
|||||||
struct ReverseMapper<'tcx> {
|
struct ReverseMapper<'tcx> {
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
|
|
||||||
opaque_type_def_id: DefId,
|
opaque_type_def_id: LocalDefId,
|
||||||
map: FxHashMap<GenericArg<'tcx>, GenericArg<'tcx>>,
|
map: FxHashMap<GenericArg<'tcx>, GenericArg<'tcx>>,
|
||||||
map_missing_regions_to_empty: bool,
|
map_missing_regions_to_empty: bool,
|
||||||
|
|
||||||
@ -437,7 +437,7 @@ struct ReverseMapper<'tcx> {
|
|||||||
impl<'tcx> ReverseMapper<'tcx> {
|
impl<'tcx> ReverseMapper<'tcx> {
|
||||||
fn new(
|
fn new(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
opaque_type_def_id: DefId,
|
opaque_type_def_id: LocalDefId,
|
||||||
map: FxHashMap<GenericArg<'tcx>, GenericArg<'tcx>>,
|
map: FxHashMap<GenericArg<'tcx>, GenericArg<'tcx>>,
|
||||||
hidden_ty: Ty<'tcx>,
|
hidden_ty: Ty<'tcx>,
|
||||||
span: Span,
|
span: Span,
|
||||||
|
@ -153,7 +153,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
|
|||||||
.opaque_type_storage
|
.opaque_type_storage
|
||||||
.take_opaque_types()
|
.take_opaque_types()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(k, v)| (self.tcx.mk_opaque(k.def_id, k.substs), v.hidden_type.ty))
|
.map(|(k, v)| (self.tcx.mk_opaque(k.def_id.to_def_id(), k.substs), v.hidden_type.ty))
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -938,7 +938,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||||||
#[instrument(skip(self), level = "debug")]
|
#[instrument(skip(self), level = "debug")]
|
||||||
pub fn member_constraint(
|
pub fn member_constraint(
|
||||||
&self,
|
&self,
|
||||||
opaque_type_def_id: DefId,
|
opaque_type_def_id: LocalDefId,
|
||||||
definition_span: Span,
|
definition_span: Span,
|
||||||
hidden_ty: Ty<'tcx>,
|
hidden_ty: Ty<'tcx>,
|
||||||
region: ty::Region<'tcx>,
|
region: ty::Region<'tcx>,
|
||||||
|
@ -51,7 +51,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||||||
return InferOk { value: ty, obligations: vec![] };
|
return InferOk { value: ty, obligations: vec![] };
|
||||||
}
|
}
|
||||||
let mut obligations = vec![];
|
let mut obligations = vec![];
|
||||||
let replace_opaque_type = |def_id| self.opaque_type_origin(def_id, span).is_some();
|
let replace_opaque_type = |def_id: DefId| {
|
||||||
|
def_id
|
||||||
|
.as_local()
|
||||||
|
.map_or(false, |def_id| self.opaque_type_origin(def_id, span).is_some())
|
||||||
|
};
|
||||||
let value = ty.fold_with(&mut ty::fold::BottomUpFolder {
|
let value = ty.fold_with(&mut ty::fold::BottomUpFolder {
|
||||||
tcx: self.tcx,
|
tcx: self.tcx,
|
||||||
lt_op: |lt| lt,
|
lt_op: |lt| lt,
|
||||||
@ -96,6 +100,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||||||
let (a, b) = if a_is_expected { (a, b) } else { (b, a) };
|
let (a, b) = if a_is_expected { (a, b) } else { (b, a) };
|
||||||
let process = |a: Ty<'tcx>, b: Ty<'tcx>| match *a.kind() {
|
let process = |a: Ty<'tcx>, b: Ty<'tcx>| match *a.kind() {
|
||||||
ty::Opaque(def_id, substs) if def_id.is_local() => {
|
ty::Opaque(def_id, substs) if def_id.is_local() => {
|
||||||
|
let def_id = def_id.expect_local();
|
||||||
let origin = if self.defining_use_anchor.is_some() {
|
let origin = if self.defining_use_anchor.is_some() {
|
||||||
// Check that this is `impl Trait` type is
|
// Check that this is `impl Trait` type is
|
||||||
// declared by `parent_def_id` -- i.e., one whose
|
// declared by `parent_def_id` -- i.e., one whose
|
||||||
@ -141,7 +146,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||||||
// no one encounters it in practice.
|
// no one encounters it in practice.
|
||||||
// It does occur however in `fn fut() -> impl Future<Output = i32> { async { 42 } }`,
|
// It does occur however in `fn fut() -> impl Future<Output = i32> { async { 42 } }`,
|
||||||
// where it is of no concern, so we only check for TAITs.
|
// where it is of no concern, so we only check for TAITs.
|
||||||
if let Some(OpaqueTyOrigin::TyAlias) = self.opaque_type_origin(did2, cause.span)
|
if let Some(OpaqueTyOrigin::TyAlias) =
|
||||||
|
did2.as_local().and_then(|did2| self.opaque_type_origin(did2, cause.span))
|
||||||
{
|
{
|
||||||
self.tcx
|
self.tcx
|
||||||
.sess
|
.sess
|
||||||
@ -399,8 +405,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip(self), level = "trace")]
|
#[instrument(skip(self), level = "trace")]
|
||||||
pub fn opaque_type_origin(&self, opaque_def_id: DefId, span: Span) -> Option<OpaqueTyOrigin> {
|
pub fn opaque_type_origin(&self, def_id: LocalDefId, span: Span) -> Option<OpaqueTyOrigin> {
|
||||||
let def_id = opaque_def_id.as_local()?;
|
|
||||||
let opaque_hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id);
|
let opaque_hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id);
|
||||||
let parent_def_id = self.defining_use_anchor?;
|
let parent_def_id = self.defining_use_anchor?;
|
||||||
let item_kind = &self.tcx.hir().expect_item(def_id).kind;
|
let item_kind = &self.tcx.hir().expect_item(def_id).kind;
|
||||||
@ -409,7 +414,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||||||
span_bug!(
|
span_bug!(
|
||||||
span,
|
span,
|
||||||
"weird opaque type: {:#?}, {:#?}",
|
"weird opaque type: {:#?}, {:#?}",
|
||||||
opaque_def_id,
|
def_id,
|
||||||
item_kind
|
item_kind
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
@ -428,12 +433,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip(self), level = "trace")]
|
#[instrument(skip(self), level = "trace")]
|
||||||
fn opaque_ty_origin_unchecked(&self, opaque_def_id: DefId, span: Span) -> OpaqueTyOrigin {
|
fn opaque_ty_origin_unchecked(&self, def_id: LocalDefId, span: Span) -> OpaqueTyOrigin {
|
||||||
let def_id = opaque_def_id.as_local().unwrap();
|
|
||||||
let origin = match self.tcx.hir().expect_item(def_id).kind {
|
let origin = match self.tcx.hir().expect_item(def_id).kind {
|
||||||
hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) => origin,
|
hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) => origin,
|
||||||
ref itemkind => {
|
ref itemkind => {
|
||||||
span_bug!(span, "weird opaque type: {:?}, {:#?}", opaque_def_id, itemkind)
|
span_bug!(span, "weird opaque type: {:?}, {:#?}", def_id, itemkind)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
trace!(?origin);
|
trace!(?origin);
|
||||||
@ -557,7 +561,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||||||
obligations = self.at(&cause, param_env).eq(prev, hidden_ty)?.obligations;
|
obligations = self.at(&cause, param_env).eq(prev, hidden_ty)?.obligations;
|
||||||
}
|
}
|
||||||
|
|
||||||
let item_bounds = tcx.bound_explicit_item_bounds(def_id);
|
let item_bounds = tcx.bound_explicit_item_bounds(def_id.to_def_id());
|
||||||
|
|
||||||
for predicate in item_bounds.transpose_iter().map(|e| e.map_bound(|(p, _)| *p)) {
|
for predicate in item_bounds.transpose_iter().map(|e| e.map_bound(|(p, _)| *p)) {
|
||||||
debug!(?predicate);
|
debug!(?predicate);
|
||||||
@ -579,7 +583,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
// Replace all other mentions of the same opaque type with the hidden type,
|
// Replace all other mentions of the same opaque type with the hidden type,
|
||||||
// as the bounds must hold on the hidden type after all.
|
// as the bounds must hold on the hidden type after all.
|
||||||
ty::Opaque(def_id2, substs2) if def_id == def_id2 && substs == substs2 => {
|
ty::Opaque(def_id2, substs2)
|
||||||
|
if def_id.to_def_id() == def_id2 && substs == substs2 =>
|
||||||
|
{
|
||||||
hidden_ty
|
hidden_ty
|
||||||
}
|
}
|
||||||
_ => ty,
|
_ => ty,
|
||||||
|
@ -12,7 +12,7 @@ use rustc_data_structures::intern::Interned;
|
|||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
use rustc_data_structures::undo_log::UndoLogs;
|
use rustc_data_structures::undo_log::UndoLogs;
|
||||||
use rustc_data_structures::unify as ut;
|
use rustc_data_structures::unify as ut;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::LocalDefId;
|
||||||
use rustc_index::vec::IndexVec;
|
use rustc_index::vec::IndexVec;
|
||||||
use rustc_middle::infer::unify_key::{RegionVidKey, UnifiedRegion};
|
use rustc_middle::infer::unify_key::{RegionVidKey, UnifiedRegion};
|
||||||
use rustc_middle::ty::ReStatic;
|
use rustc_middle::ty::ReStatic;
|
||||||
@ -533,7 +533,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
|
|||||||
|
|
||||||
pub fn member_constraint(
|
pub fn member_constraint(
|
||||||
&mut self,
|
&mut self,
|
||||||
opaque_type_def_id: DefId,
|
opaque_type_def_id: LocalDefId,
|
||||||
definition_span: Span,
|
definition_span: Span,
|
||||||
hidden_ty: Ty<'tcx>,
|
hidden_ty: Ty<'tcx>,
|
||||||
member_region: ty::Region<'tcx>,
|
member_region: ty::Region<'tcx>,
|
||||||
|
@ -4,7 +4,7 @@ pub mod unify_key;
|
|||||||
use crate::ty::Region;
|
use crate::ty::Region;
|
||||||
use crate::ty::Ty;
|
use crate::ty::Ty;
|
||||||
use rustc_data_structures::sync::Lrc;
|
use rustc_data_structures::sync::Lrc;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::LocalDefId;
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
|
||||||
/// Requires that `region` must be equal to one of the regions in `choice_regions`.
|
/// Requires that `region` must be equal to one of the regions in `choice_regions`.
|
||||||
@ -16,7 +16,7 @@ use rustc_span::Span;
|
|||||||
#[derive(Debug, Clone, HashStable, TypeFoldable, TypeVisitable, Lift)]
|
#[derive(Debug, Clone, HashStable, TypeFoldable, TypeVisitable, Lift)]
|
||||||
pub struct MemberConstraint<'tcx> {
|
pub struct MemberConstraint<'tcx> {
|
||||||
/// The `DefId` of the opaque type causing this constraint: used for error reporting.
|
/// The `DefId` of the opaque type causing this constraint: used for error reporting.
|
||||||
pub opaque_type_def_id: DefId,
|
pub opaque_type_def_id: LocalDefId,
|
||||||
|
|
||||||
/// The span where the hidden type was instantiated.
|
/// The span where the hidden type was instantiated.
|
||||||
pub definition_span: Span,
|
pub definition_span: Span,
|
||||||
|
@ -235,7 +235,7 @@ pub struct BorrowCheckResult<'tcx> {
|
|||||||
/// All the opaque types that are restricted to concrete types
|
/// All the opaque types that are restricted to concrete types
|
||||||
/// by this function. Unlike the value in `TypeckResults`, this has
|
/// by this function. Unlike the value in `TypeckResults`, this has
|
||||||
/// unerased regions.
|
/// unerased regions.
|
||||||
pub concrete_opaque_types: VecMap<DefId, OpaqueHiddenType<'tcx>>,
|
pub concrete_opaque_types: VecMap<LocalDefId, OpaqueHiddenType<'tcx>>,
|
||||||
pub closure_requirements: Option<ClosureRegionRequirements<'tcx>>,
|
pub closure_requirements: Option<ClosureRegionRequirements<'tcx>>,
|
||||||
pub used_mut_upvars: SmallVec<[Field; 8]>,
|
pub used_mut_upvars: SmallVec<[Field; 8]>,
|
||||||
pub tainted_by_errors: Option<ErrorGuaranteed>,
|
pub tainted_by_errors: Option<ErrorGuaranteed>,
|
||||||
|
@ -542,7 +542,7 @@ pub struct TypeckResults<'tcx> {
|
|||||||
/// even if they are only set in dead code (which doesn't show up in MIR).
|
/// even if they are only set in dead code (which doesn't show up in MIR).
|
||||||
/// For type-alias-impl-trait, this map is only used to prevent query cycles,
|
/// For type-alias-impl-trait, this map is only used to prevent query cycles,
|
||||||
/// so the hidden types are all `None`.
|
/// so the hidden types are all `None`.
|
||||||
pub concrete_opaque_types: VecMap<DefId, Option<Ty<'tcx>>>,
|
pub concrete_opaque_types: VecMap<LocalDefId, Option<Ty<'tcx>>>,
|
||||||
|
|
||||||
/// Tracks the minimum captures required for a closure;
|
/// Tracks the minimum captures required for a closure;
|
||||||
/// see `MinCaptureInformationMap` for more details.
|
/// see `MinCaptureInformationMap` for more details.
|
||||||
|
@ -1108,8 +1108,7 @@ impl<'tcx> InstantiatedPredicates<'tcx> {
|
|||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, HashStable, TyEncodable, TyDecodable, Lift)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, HashStable, TyEncodable, TyDecodable, Lift)]
|
||||||
#[derive(TypeFoldable, TypeVisitable)]
|
#[derive(TypeFoldable, TypeVisitable)]
|
||||||
pub struct OpaqueTypeKey<'tcx> {
|
pub struct OpaqueTypeKey<'tcx> {
|
||||||
// FIXME(oli-obk): make this a LocalDefId
|
pub def_id: LocalDefId,
|
||||||
pub def_id: DefId,
|
|
||||||
pub substs: SubstsRef<'tcx>,
|
pub substs: SubstsRef<'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1707,13 +1707,6 @@ impl<'tcx> Ty<'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn expect_opaque_type(self) -> ty::OpaqueTypeKey<'tcx> {
|
|
||||||
match *self.kind() {
|
|
||||||
Opaque(def_id, substs) => ty::OpaqueTypeKey { def_id, substs },
|
|
||||||
_ => bug!("`expect_opaque_type` called on non-opaque type: {}", self),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn simd_size_and_type(self, tcx: TyCtxt<'tcx>) -> (u64, Ty<'tcx>) {
|
pub fn simd_size_and_type(self, tcx: TyCtxt<'tcx>) -> (u64, Ty<'tcx>) {
|
||||||
match self.kind() {
|
match self.kind() {
|
||||||
Adt(def, substs) => {
|
Adt(def, substs) => {
|
||||||
|
@ -1513,7 +1513,7 @@ pub fn check_type_bounds<'tcx>(
|
|||||||
value.hidden_type.span,
|
value.hidden_type.span,
|
||||||
tcx.hir().local_def_id_to_hir_id(impl_ty.def_id.expect_local()),
|
tcx.hir().local_def_id_to_hir_id(impl_ty.def_id.expect_local()),
|
||||||
),
|
),
|
||||||
tcx.mk_opaque(key.def_id, key.substs),
|
tcx.mk_opaque(key.def_id.to_def_id(), key.substs),
|
||||||
value.hidden_type.ty,
|
value.hidden_type.ty,
|
||||||
TypeError::Mismatch,
|
TypeError::Mismatch,
|
||||||
)
|
)
|
||||||
|
@ -763,12 +763,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
// src/test/ui/impl-trait/hidden-type-is-opaque-2.rs for examples that hit this path.
|
// src/test/ui/impl-trait/hidden-type-is-opaque-2.rs for examples that hit this path.
|
||||||
if formal_ret.has_infer_types() {
|
if formal_ret.has_infer_types() {
|
||||||
for ty in ret_ty.walk() {
|
for ty in ret_ty.walk() {
|
||||||
if let ty::subst::GenericArgKind::Type(ty) = ty.unpack() {
|
if let ty::subst::GenericArgKind::Type(ty) = ty.unpack()
|
||||||
if let ty::Opaque(def_id, _) = *ty.kind() {
|
&& let ty::Opaque(def_id, _) = *ty.kind()
|
||||||
if self.infcx.opaque_type_origin(def_id, DUMMY_SP).is_some() {
|
&& let Some(def_id) = def_id.as_local()
|
||||||
return None;
|
&& self.infcx.opaque_type_origin(def_id, DUMMY_SP).is_some() {
|
||||||
}
|
return None;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
use crate::check::FnCtxt;
|
use crate::check::FnCtxt;
|
||||||
|
|
||||||
|
use hir::def_id::LocalDefId;
|
||||||
use rustc_data_structures::stable_map::FxHashMap;
|
use rustc_data_structures::stable_map::FxHashMap;
|
||||||
use rustc_errors::ErrorGuaranteed;
|
use rustc_errors::ErrorGuaranteed;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
@ -509,13 +510,13 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
|||||||
hir::OpaqueTyOrigin::FnReturn(_) | hir::OpaqueTyOrigin::AsyncFn(_) => {
|
hir::OpaqueTyOrigin::FnReturn(_) | hir::OpaqueTyOrigin::AsyncFn(_) => {
|
||||||
let ty = self.resolve(decl.hidden_type.ty, &decl.hidden_type.span);
|
let ty = self.resolve(decl.hidden_type.ty, &decl.hidden_type.span);
|
||||||
struct RecursionChecker {
|
struct RecursionChecker {
|
||||||
def_id: DefId,
|
def_id: LocalDefId,
|
||||||
}
|
}
|
||||||
impl<'tcx> ty::TypeVisitor<'tcx> for RecursionChecker {
|
impl<'tcx> ty::TypeVisitor<'tcx> for RecursionChecker {
|
||||||
type BreakTy = ();
|
type BreakTy = ();
|
||||||
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
|
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||||
if let ty::Opaque(def_id, _) = *t.kind() {
|
if let ty::Opaque(def_id, _) = *t.kind() {
|
||||||
if def_id == self.def_id {
|
if def_id == self.def_id.to_def_id() {
|
||||||
return ControlFlow::Break(());
|
return ControlFlow::Break(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -342,7 +342,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
|
|||||||
let concrete_ty = tcx
|
let concrete_ty = tcx
|
||||||
.mir_borrowck(owner)
|
.mir_borrowck(owner)
|
||||||
.concrete_opaque_types
|
.concrete_opaque_types
|
||||||
.get(&def_id.to_def_id())
|
.get(&def_id)
|
||||||
.copied()
|
.copied()
|
||||||
.map(|concrete| concrete.ty)
|
.map(|concrete| concrete.ty)
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
@ -353,7 +353,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
|
|||||||
// the `concrete_opaque_types` table.
|
// the `concrete_opaque_types` table.
|
||||||
tcx.ty_error()
|
tcx.ty_error()
|
||||||
} else {
|
} else {
|
||||||
table.concrete_opaque_types.get(&def_id.to_def_id()).copied().unwrap_or_else(|| {
|
table.concrete_opaque_types.get(&def_id).copied().unwrap_or_else(|| {
|
||||||
// We failed to resolve the opaque type or it
|
// We failed to resolve the opaque type or it
|
||||||
// resolves to itself. We interpret this as the
|
// resolves to itself. We interpret this as the
|
||||||
// no values of the hidden type ever being constructed,
|
// no values of the hidden type ever being constructed,
|
||||||
@ -526,7 +526,7 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
|
|||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
|
|
||||||
/// def_id of the opaque type whose defining uses are being checked
|
/// def_id of the opaque type whose defining uses are being checked
|
||||||
def_id: DefId,
|
def_id: LocalDefId,
|
||||||
|
|
||||||
/// as we walk the defining uses, we are checking that all of them
|
/// as we walk the defining uses, we are checking that all of them
|
||||||
/// define the same hidden type. This variable is set to `Some`
|
/// define the same hidden type. This variable is set to `Some`
|
||||||
@ -602,7 +602,7 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
|
|||||||
fn visit_item(&mut self, it: &'tcx Item<'tcx>) {
|
fn visit_item(&mut self, it: &'tcx Item<'tcx>) {
|
||||||
trace!(?it.def_id);
|
trace!(?it.def_id);
|
||||||
// The opaque type itself or its children are not within its reveal scope.
|
// The opaque type itself or its children are not within its reveal scope.
|
||||||
if it.def_id.to_def_id() != self.def_id {
|
if it.def_id != self.def_id {
|
||||||
self.check(it.def_id);
|
self.check(it.def_id);
|
||||||
intravisit::walk_item(self, it);
|
intravisit::walk_item(self, it);
|
||||||
}
|
}
|
||||||
@ -610,7 +610,7 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
|
|||||||
fn visit_impl_item(&mut self, it: &'tcx ImplItem<'tcx>) {
|
fn visit_impl_item(&mut self, it: &'tcx ImplItem<'tcx>) {
|
||||||
trace!(?it.def_id);
|
trace!(?it.def_id);
|
||||||
// The opaque type itself or its children are not within its reveal scope.
|
// The opaque type itself or its children are not within its reveal scope.
|
||||||
if it.def_id.to_def_id() != self.def_id {
|
if it.def_id != self.def_id {
|
||||||
self.check(it.def_id);
|
self.check(it.def_id);
|
||||||
intravisit::walk_impl_item(self, it);
|
intravisit::walk_impl_item(self, it);
|
||||||
}
|
}
|
||||||
@ -624,7 +624,7 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
|
|||||||
|
|
||||||
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
|
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
|
||||||
let scope = tcx.hir().get_defining_scope(hir_id);
|
let scope = tcx.hir().get_defining_scope(hir_id);
|
||||||
let mut locator = ConstraintLocator { def_id: def_id.to_def_id(), tcx, found: None };
|
let mut locator = ConstraintLocator { def_id: def_id, tcx, found: None };
|
||||||
|
|
||||||
debug!(?scope);
|
debug!(?scope);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user