Rollup merge of #59789 - eddyb:typeck-reverts, r=nikomatsakis
Revert two unapproved changes to rustc_typeck. There was a breakdown in process (https://github.com/rust-lang/rust/pull/59004#issuecomment-477600735, https://github.com/rust-lang/rust/pull/58894#discussion_r272795560) and two changes were made to `rustc_typeck`'s "collect" queries, for rustdoc, that were neither needed *nor* correct. I'm reverting them here, and will fix up rustdoc *somehow*, if necessary. cc @rust-lang/compiler How do we ensure this doesn't happen again? r? @nikomatsakis or @oli-obk
This commit is contained in:
commit
d7f1406378
7 changed files with 71 additions and 109 deletions
|
@ -95,8 +95,8 @@ provide! { <'tcx> tcx, def_id, other, cdata,
|
|||
generics_of => {
|
||||
tcx.arena.alloc(cdata.get_generics(def_id.index, tcx.sess))
|
||||
}
|
||||
predicates_of => { cdata.get_predicates(def_id.index, tcx) }
|
||||
predicates_defined_on => { cdata.get_predicates_defined_on(def_id.index, tcx) }
|
||||
explicit_predicates_of => { cdata.get_explicit_predicates(def_id.index, tcx) }
|
||||
inferred_outlives_of => { cdata.get_inferred_outlives(def_id.index, tcx) }
|
||||
super_predicates_of => { cdata.get_super_predicates(def_id.index, tcx) }
|
||||
trait_def => {
|
||||
tcx.arena.alloc(cdata.get_trait_def(def_id.index, tcx.sess))
|
||||
|
|
|
@ -658,20 +658,22 @@ impl<'a, 'tcx> CrateMetadata {
|
|||
tcx.alloc_adt_def(did, adt_kind, variants, repr)
|
||||
}
|
||||
|
||||
crate fn get_predicates(
|
||||
crate fn get_explicit_predicates(
|
||||
&self,
|
||||
item_id: DefIndex,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
) -> ty::GenericPredicates<'tcx> {
|
||||
self.root.per_def.predicates.get(self, item_id).unwrap().decode((self, tcx))
|
||||
self.root.per_def.explicit_predicates.get(self, item_id).unwrap().decode((self, tcx))
|
||||
}
|
||||
|
||||
crate fn get_predicates_defined_on(
|
||||
crate fn get_inferred_outlives(
|
||||
&self,
|
||||
item_id: DefIndex,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
) -> ty::GenericPredicates<'tcx> {
|
||||
self.root.per_def.predicates_defined_on.get(self, item_id).unwrap().decode((self, tcx))
|
||||
) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
|
||||
self.root.per_def.inferred_outlives.get(self, item_id).map(|predicates| {
|
||||
predicates.decode((self, tcx))
|
||||
}).unwrap_or_default()
|
||||
}
|
||||
|
||||
crate fn get_super_predicates(
|
||||
|
|
|
@ -76,8 +76,8 @@ struct PerDefTables<'tcx> {
|
|||
inherent_impls: PerDefTable<Lazy<[DefIndex]>>,
|
||||
variances: PerDefTable<Lazy<[ty::Variance]>>,
|
||||
generics: PerDefTable<Lazy<ty::Generics>>,
|
||||
predicates: PerDefTable<Lazy<ty::GenericPredicates<'tcx>>>,
|
||||
predicates_defined_on: PerDefTable<Lazy<ty::GenericPredicates<'tcx>>>,
|
||||
explicit_predicates: PerDefTable<Lazy<ty::GenericPredicates<'tcx>>>,
|
||||
inferred_outlives: PerDefTable<Lazy<&'tcx [(ty::Predicate<'tcx>, Span)]>>,
|
||||
super_predicates: PerDefTable<Lazy<ty::GenericPredicates<'tcx>>>,
|
||||
|
||||
mir: PerDefTable<Lazy<mir::Body<'tcx>>>,
|
||||
|
@ -524,8 +524,8 @@ impl<'tcx> EncodeContext<'tcx> {
|
|||
inherent_impls: self.per_def.inherent_impls.encode(&mut self.opaque),
|
||||
variances: self.per_def.variances.encode(&mut self.opaque),
|
||||
generics: self.per_def.generics.encode(&mut self.opaque),
|
||||
predicates: self.per_def.predicates.encode(&mut self.opaque),
|
||||
predicates_defined_on: self.per_def.predicates_defined_on.encode(&mut self.opaque),
|
||||
explicit_predicates: self.per_def.explicit_predicates.encode(&mut self.opaque),
|
||||
inferred_outlives: self.per_def.inferred_outlives.encode(&mut self.opaque),
|
||||
super_predicates: self.per_def.super_predicates.encode(&mut self.opaque),
|
||||
|
||||
mir: self.per_def.mir.encode(&mut self.opaque),
|
||||
|
@ -675,7 +675,8 @@ impl EncodeContext<'tcx> {
|
|||
self.encode_variances_of(def_id);
|
||||
}
|
||||
self.encode_generics(def_id);
|
||||
self.encode_predicates(def_id);
|
||||
self.encode_explicit_predicates(def_id);
|
||||
self.encode_inferred_outlives(def_id);
|
||||
self.encode_optimized_mir(def_id);
|
||||
self.encode_promoted_mir(def_id);
|
||||
}
|
||||
|
@ -718,7 +719,8 @@ impl EncodeContext<'tcx> {
|
|||
self.encode_variances_of(def_id);
|
||||
}
|
||||
self.encode_generics(def_id);
|
||||
self.encode_predicates(def_id);
|
||||
self.encode_explicit_predicates(def_id);
|
||||
self.encode_inferred_outlives(def_id);
|
||||
self.encode_optimized_mir(def_id);
|
||||
self.encode_promoted_mir(def_id);
|
||||
}
|
||||
|
@ -776,7 +778,8 @@ impl EncodeContext<'tcx> {
|
|||
self.encode_deprecation(def_id);
|
||||
self.encode_item_type(def_id);
|
||||
self.encode_generics(def_id);
|
||||
self.encode_predicates(def_id);
|
||||
self.encode_explicit_predicates(def_id);
|
||||
self.encode_inferred_outlives(def_id);
|
||||
}
|
||||
|
||||
fn encode_struct_ctor(&mut self, adt_def_id: DefId, def_id: DefId) {
|
||||
|
@ -819,7 +822,8 @@ impl EncodeContext<'tcx> {
|
|||
self.encode_variances_of(def_id);
|
||||
}
|
||||
self.encode_generics(def_id);
|
||||
self.encode_predicates(def_id);
|
||||
self.encode_explicit_predicates(def_id);
|
||||
self.encode_inferred_outlives(def_id);
|
||||
self.encode_optimized_mir(def_id);
|
||||
self.encode_promoted_mir(def_id);
|
||||
}
|
||||
|
@ -829,15 +833,18 @@ impl EncodeContext<'tcx> {
|
|||
record!(self.per_def.generics[def_id] <- self.tcx.generics_of(def_id));
|
||||
}
|
||||
|
||||
fn encode_predicates(&mut self, def_id: DefId) {
|
||||
debug!("EncodeContext::encode_predicates({:?})", def_id);
|
||||
record!(self.per_def.predicates[def_id] <- self.tcx.predicates_of(def_id));
|
||||
fn encode_explicit_predicates(&mut self, def_id: DefId) {
|
||||
debug!("EncodeContext::encode_explicit_predicates({:?})", def_id);
|
||||
record!(self.per_def.explicit_predicates[def_id] <-
|
||||
self.tcx.explicit_predicates_of(def_id));
|
||||
}
|
||||
|
||||
fn encode_predicates_defined_on(&mut self, def_id: DefId) {
|
||||
debug!("EncodeContext::encode_predicates_defined_on({:?})", def_id);
|
||||
record!(self.per_def.predicates_defined_on[def_id] <-
|
||||
self.tcx.predicates_defined_on(def_id))
|
||||
fn encode_inferred_outlives(&mut self, def_id: DefId) {
|
||||
debug!("EncodeContext::encode_inferred_outlives({:?})", def_id);
|
||||
let inferred_outlives = self.tcx.inferred_outlives_of(def_id);
|
||||
if !inferred_outlives.is_empty() {
|
||||
record!(self.per_def.inferred_outlives[def_id] <- inferred_outlives);
|
||||
}
|
||||
}
|
||||
|
||||
fn encode_super_predicates(&mut self, def_id: DefId) {
|
||||
|
@ -919,7 +926,8 @@ impl EncodeContext<'tcx> {
|
|||
self.encode_variances_of(def_id);
|
||||
}
|
||||
self.encode_generics(def_id);
|
||||
self.encode_predicates(def_id);
|
||||
self.encode_explicit_predicates(def_id);
|
||||
self.encode_inferred_outlives(def_id);
|
||||
self.encode_optimized_mir(def_id);
|
||||
self.encode_promoted_mir(def_id);
|
||||
}
|
||||
|
@ -986,7 +994,8 @@ impl EncodeContext<'tcx> {
|
|||
self.encode_variances_of(def_id);
|
||||
}
|
||||
self.encode_generics(def_id);
|
||||
self.encode_predicates(def_id);
|
||||
self.encode_explicit_predicates(def_id);
|
||||
self.encode_inferred_outlives(def_id);
|
||||
let mir = match ast_item.kind {
|
||||
hir::ImplItemKind::Const(..) => true,
|
||||
hir::ImplItemKind::Method(ref sig, _) => {
|
||||
|
@ -1260,22 +1269,11 @@ impl EncodeContext<'tcx> {
|
|||
hir::ItemKind::Trait(..) |
|
||||
hir::ItemKind::TraitAlias(..) => {
|
||||
self.encode_generics(def_id);
|
||||
self.encode_predicates(def_id);
|
||||
self.encode_explicit_predicates(def_id);
|
||||
self.encode_inferred_outlives(def_id);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
// The only time that `predicates_defined_on` is used (on
|
||||
// an external item) is for traits, during chalk lowering,
|
||||
// so only encode it in that case as an efficiency
|
||||
// hack. (No reason not to expand it in the future if
|
||||
// necessary.)
|
||||
match item.kind {
|
||||
hir::ItemKind::Trait(..) |
|
||||
hir::ItemKind::TraitAlias(..) => {
|
||||
self.encode_predicates_defined_on(def_id);
|
||||
}
|
||||
_ => {} // not *wrong* for other kinds of items, but not needed
|
||||
}
|
||||
match item.kind {
|
||||
hir::ItemKind::Trait(..) |
|
||||
hir::ItemKind::TraitAlias(..) => {
|
||||
|
@ -1377,7 +1375,8 @@ impl EncodeContext<'tcx> {
|
|||
record!(self.per_def.span[def_id] <- self.tcx.def_span(def_id));
|
||||
self.encode_item_type(def_id);
|
||||
self.encode_generics(def_id);
|
||||
self.encode_predicates(def_id);
|
||||
self.encode_explicit_predicates(def_id);
|
||||
self.encode_inferred_outlives(def_id);
|
||||
self.encode_optimized_mir(def_id);
|
||||
self.encode_promoted_mir(def_id);
|
||||
}
|
||||
|
@ -1588,7 +1587,8 @@ impl EncodeContext<'tcx> {
|
|||
self.encode_variances_of(def_id);
|
||||
}
|
||||
self.encode_generics(def_id);
|
||||
self.encode_predicates(def_id);
|
||||
self.encode_explicit_predicates(def_id);
|
||||
self.encode_inferred_outlives(def_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -244,8 +244,13 @@ crate struct LazyPerDefTables<'tcx> {
|
|||
pub inherent_impls: Lazy!(PerDefTable<Lazy<[DefIndex]>>),
|
||||
pub variances: Lazy!(PerDefTable<Lazy<[ty::Variance]>>),
|
||||
pub generics: Lazy!(PerDefTable<Lazy<ty::Generics>>),
|
||||
pub predicates: Lazy!(PerDefTable<Lazy!(ty::GenericPredicates<'tcx>)>),
|
||||
pub predicates_defined_on: Lazy!(PerDefTable<Lazy!(ty::GenericPredicates<'tcx>)>),
|
||||
pub explicit_predicates: Lazy!(PerDefTable<Lazy!(ty::GenericPredicates<'tcx>)>),
|
||||
// FIXME(eddyb) this would ideally be `Lazy<[...]>` but `ty::Predicate`
|
||||
// doesn't handle shorthands in its own (de)serialization impls,
|
||||
// as it's an `enum` for which we want to derive (de)serialization,
|
||||
// so the `ty::codec` APIs handle the whole `&'tcx [...]` at once.
|
||||
// Also, as an optimization, a missing entry indicates an empty `&[]`.
|
||||
pub inferred_outlives: Lazy!(PerDefTable<Lazy!(&'tcx [(ty::Predicate<'tcx>, Span)])>),
|
||||
pub super_predicates: Lazy!(PerDefTable<Lazy!(ty::GenericPredicates<'tcx>)>),
|
||||
|
||||
pub mir: Lazy!(PerDefTable<Lazy!(mir::Body<'tcx>)>),
|
||||
|
|
|
@ -1146,10 +1146,6 @@ fn report_assoc_ty_on_inherent_impl(tcx: TyCtxt<'_>, span: Span) {
|
|||
);
|
||||
}
|
||||
|
||||
fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
|
||||
checked_type_of(tcx, def_id, true).unwrap()
|
||||
}
|
||||
|
||||
fn infer_placeholder_type(
|
||||
tcx: TyCtxt<'_>,
|
||||
def_id: DefId,
|
||||
|
@ -1193,26 +1189,14 @@ fn infer_placeholder_type(
|
|||
ty
|
||||
}
|
||||
|
||||
/// Same as [`type_of`] but returns [`Option`] instead of failing.
|
||||
///
|
||||
/// If you want to fail anyway, you can set the `fail` parameter to true, but in this case,
|
||||
/// you'd better just call [`type_of`] directly.
|
||||
pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<'_>> {
|
||||
fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
|
||||
use rustc::hir::*;
|
||||
|
||||
let hir_id = match tcx.hir().as_local_hir_id(def_id) {
|
||||
Some(hir_id) => hir_id,
|
||||
None => {
|
||||
if !fail {
|
||||
return None;
|
||||
}
|
||||
bug!("invalid node");
|
||||
}
|
||||
};
|
||||
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
|
||||
|
||||
let icx = ItemCtxt::new(tcx, def_id);
|
||||
|
||||
Some(match tcx.hir().get(hir_id) {
|
||||
match tcx.hir().get(hir_id) {
|
||||
Node::TraitItem(item) => match item.kind {
|
||||
TraitItemKind::Method(..) => {
|
||||
let substs = InternalSubsts::identity_for_item(tcx, def_id);
|
||||
|
@ -1229,9 +1213,6 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
|
|||
},
|
||||
TraitItemKind::Type(_, Some(ref ty)) => icx.to_ty(ty),
|
||||
TraitItemKind::Type(_, None) => {
|
||||
if !fail {
|
||||
return None;
|
||||
}
|
||||
span_bug!(item.span, "associated type missing default");
|
||||
}
|
||||
},
|
||||
|
@ -1325,9 +1306,6 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
|
|||
| ItemKind::GlobalAsm(..)
|
||||
| ItemKind::ExternCrate(..)
|
||||
| ItemKind::Use(..) => {
|
||||
if !fail {
|
||||
return None;
|
||||
}
|
||||
span_bug!(
|
||||
item.span,
|
||||
"compute_type_of_item: unexpected item type: {:?}",
|
||||
|
@ -1365,7 +1343,7 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
|
|||
..
|
||||
}) => {
|
||||
if gen.is_some() {
|
||||
return Some(tcx.typeck_tables_of(def_id).node_type(hir_id));
|
||||
return tcx.typeck_tables_of(def_id).node_type(hir_id);
|
||||
}
|
||||
|
||||
let substs = InternalSubsts::identity_for_item(tcx, def_id);
|
||||
|
@ -1440,13 +1418,9 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
|
|||
.map(|(index, _)| index)
|
||||
.next()
|
||||
})
|
||||
.or_else(|| {
|
||||
if !fail {
|
||||
None
|
||||
} else {
|
||||
bug!("no arg matching AnonConst in path")
|
||||
}
|
||||
})?;
|
||||
.unwrap_or_else(|| {
|
||||
bug!("no arg matching AnonConst in path");
|
||||
});
|
||||
|
||||
// We've encountered an `AnonConst` in some path, so we need to
|
||||
// figure out which generic parameter it corresponds to and return
|
||||
|
@ -1456,8 +1430,7 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
|
|||
tcx.generics_of(tcx.parent(def_id).unwrap())
|
||||
}
|
||||
Res::Def(_, def_id) => tcx.generics_of(def_id),
|
||||
Res::Err => return Some(tcx.types.err),
|
||||
_ if !fail => return None,
|
||||
Res::Err => return tcx.types.err,
|
||||
res => {
|
||||
tcx.sess.delay_span_bug(
|
||||
DUMMY_SP,
|
||||
|
@ -1466,7 +1439,7 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
|
|||
res,
|
||||
),
|
||||
);
|
||||
return Some(tcx.types.err);
|
||||
return tcx.types.err;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1484,9 +1457,6 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
|
|||
// probably from an extra arg where one is not needed.
|
||||
.unwrap_or(tcx.types.err)
|
||||
} else {
|
||||
if !fail {
|
||||
return None;
|
||||
}
|
||||
tcx.sess.delay_span_bug(
|
||||
DUMMY_SP,
|
||||
&format!(
|
||||
|
@ -1494,14 +1464,11 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
|
|||
parent_node,
|
||||
),
|
||||
);
|
||||
return Some(tcx.types.err);
|
||||
return tcx.types.err;
|
||||
}
|
||||
}
|
||||
|
||||
x => {
|
||||
if !fail {
|
||||
return None;
|
||||
}
|
||||
tcx.sess.delay_span_bug(
|
||||
DUMMY_SP,
|
||||
&format!(
|
||||
|
@ -1551,21 +1518,13 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
|
|||
}
|
||||
ty
|
||||
}
|
||||
x => {
|
||||
if !fail {
|
||||
return None;
|
||||
}
|
||||
bug!("unexpected non-type Node::GenericParam: {:?}", x)
|
||||
},
|
||||
x => bug!("unexpected non-type Node::GenericParam: {:?}", x),
|
||||
},
|
||||
|
||||
x => {
|
||||
if !fail {
|
||||
return None;
|
||||
}
|
||||
bug!("unexpected sort of node in type_of_def_id(): {:?}", x);
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
|
||||
|
@ -2075,10 +2034,7 @@ fn explicit_predicates_of(
|
|||
}
|
||||
}
|
||||
|
||||
let hir_id = match tcx.hir().as_local_hir_id(def_id) {
|
||||
Some(hir_id) => hir_id,
|
||||
None => return tcx.predicates_of(def_id),
|
||||
};
|
||||
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
|
||||
let node = tcx.hir().get(hir_id);
|
||||
|
||||
let mut is_trait = None;
|
||||
|
|
|
@ -109,8 +109,6 @@ use util::common::time;
|
|||
use std::iter;
|
||||
|
||||
use astconv::{AstConv, Bounds};
|
||||
pub use collect::checked_type_of;
|
||||
|
||||
pub struct TypeAndSubsts<'tcx> {
|
||||
substs: SubstsRef<'tcx>,
|
||||
ty: Ty<'tcx>,
|
||||
|
|
|
@ -1492,12 +1492,13 @@ impl GenericParamDefKind {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_type(&self, cx: &DocContext<'_>) -> Option<Type> {
|
||||
match *self {
|
||||
GenericParamDefKind::Type { did, .. } => {
|
||||
rustc_typeck::checked_type_of(cx.tcx, did, false).map(|t| t.clean(cx))
|
||||
}
|
||||
GenericParamDefKind::Const { ref ty, .. } => Some(ty.clone()),
|
||||
// FIXME(eddyb) this either returns the default of a type parameter, or the
|
||||
// type of a `const` parameter. It seems that the intention is to *visit*
|
||||
// any embedded types, but `get_type` seems to be the wrong name for that.
|
||||
pub fn get_type(&self) -> Option<Type> {
|
||||
match self {
|
||||
GenericParamDefKind::Type { default, .. } => default.clone(),
|
||||
GenericParamDefKind::Const { ty, .. } => Some(ty.clone()),
|
||||
GenericParamDefKind::Lifetime => None,
|
||||
}
|
||||
}
|
||||
|
@ -1523,8 +1524,8 @@ impl GenericParamDef {
|
|||
self.kind.is_type()
|
||||
}
|
||||
|
||||
pub fn get_type(&self, cx: &DocContext<'_>) -> Option<Type> {
|
||||
self.kind.get_type(cx)
|
||||
pub fn get_type(&self) -> Option<Type> {
|
||||
self.kind.get_type()
|
||||
}
|
||||
|
||||
pub fn get_bounds(&self) -> Option<&[GenericBound]> {
|
||||
|
@ -1892,7 +1893,7 @@ fn get_real_types(
|
|||
if !x.is_type() {
|
||||
continue
|
||||
}
|
||||
if let Some(ty) = x.get_type(cx) {
|
||||
if let Some(ty) = x.get_type() {
|
||||
let adds = get_real_types(generics, &ty, cx, recurse + 1);
|
||||
if !adds.is_empty() {
|
||||
res.extend(adds);
|
||||
|
|
Loading…
Add table
Reference in a new issue