Remove DefId from AssocItemContainer.
This commit is contained in:
parent
8ee4446ee5
commit
d7ea161b7e
40 changed files with 190 additions and 220 deletions
|
@ -66,9 +66,12 @@ pub fn call_kind<'tcx>(
|
||||||
from_hir_call: bool,
|
from_hir_call: bool,
|
||||||
self_arg: Option<Ident>,
|
self_arg: Option<Ident>,
|
||||||
) -> CallKind<'tcx> {
|
) -> CallKind<'tcx> {
|
||||||
let parent = tcx.opt_associated_item(method_did).and_then(|assoc| match assoc.container {
|
let parent = tcx.opt_associated_item(method_did).and_then(|assoc| {
|
||||||
AssocItemContainer::ImplContainer(impl_did) => tcx.trait_id_of_impl(impl_did),
|
let container_id = assoc.container_id(tcx);
|
||||||
AssocItemContainer::TraitContainer(trait_did) => Some(trait_did),
|
match assoc.container {
|
||||||
|
AssocItemContainer::ImplContainer => tcx.trait_id_of_impl(container_id),
|
||||||
|
AssocItemContainer::TraitContainer => Some(container_id),
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let fn_call = parent
|
let fn_call = parent
|
||||||
|
|
|
@ -76,10 +76,11 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
||||||
"...is used and required to live as long as `'static` here \
|
"...is used and required to live as long as `'static` here \
|
||||||
because of an implicit lifetime bound on the {}",
|
because of an implicit lifetime bound on the {}",
|
||||||
match ctxt.assoc_item.container {
|
match ctxt.assoc_item.container {
|
||||||
AssocItemContainer::TraitContainer(id) =>
|
AssocItemContainer::TraitContainer => {
|
||||||
format!("`impl` of `{}`", tcx.def_path_str(id)),
|
let id = ctxt.assoc_item.container_id(tcx);
|
||||||
AssocItemContainer::ImplContainer(_) =>
|
format!("`impl` of `{}`", tcx.def_path_str(id))
|
||||||
"inherent `impl`".to_string(),
|
}
|
||||||
|
AssocItemContainer::ImplContainer => "inherent `impl`".to_string(),
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -22,8 +22,8 @@ pub fn method_context(cx: &LateContext<'_>, id: hir::HirId) -> MethodLateContext
|
||||||
let def_id = cx.tcx.hir().local_def_id(id);
|
let def_id = cx.tcx.hir().local_def_id(id);
|
||||||
let item = cx.tcx.associated_item(def_id);
|
let item = cx.tcx.associated_item(def_id);
|
||||||
match item.container {
|
match item.container {
|
||||||
ty::TraitContainer(..) => MethodLateContext::TraitAutoImpl,
|
ty::TraitContainer => MethodLateContext::TraitAutoImpl,
|
||||||
ty::ImplContainer(cid) => match cx.tcx.impl_trait_ref(cid) {
|
ty::ImplContainer => match cx.tcx.impl_trait_ref(item.container_id(cx.tcx)) {
|
||||||
Some(_) => MethodLateContext::TraitImpl,
|
Some(_) => MethodLateContext::TraitImpl,
|
||||||
None => MethodLateContext::PlainImpl,
|
None => MethodLateContext::PlainImpl,
|
||||||
},
|
},
|
||||||
|
|
|
@ -1114,7 +1114,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
||||||
|
|
||||||
fn get_fn_has_self_parameter(self, id: DefIndex) -> bool {
|
fn get_fn_has_self_parameter(self, id: DefIndex) -> bool {
|
||||||
match self.kind(id) {
|
match self.kind(id) {
|
||||||
EntryKind::AssocFn(data) => data.decode(self).has_self,
|
EntryKind::AssocFn { has_self, .. } => has_self,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1134,18 +1134,13 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_associated_item(self, id: DefIndex) -> ty::AssocItem {
|
fn get_associated_item(self, id: DefIndex) -> ty::AssocItem {
|
||||||
let def_key = self.def_key(id);
|
|
||||||
let parent = self.local_def_id(def_key.parent.unwrap());
|
|
||||||
let name = self.item_name(id);
|
let name = self.item_name(id);
|
||||||
|
|
||||||
let (kind, container, has_self) = match self.kind(id) {
|
let (kind, container, has_self) = match self.kind(id) {
|
||||||
EntryKind::AssocConst(container) => (ty::AssocKind::Const, container, false),
|
EntryKind::AssocConst(container) => (ty::AssocKind::Const, container, false),
|
||||||
EntryKind::AssocFn(data) => {
|
EntryKind::AssocFn { container, has_self } => (ty::AssocKind::Fn, container, has_self),
|
||||||
let data = data.decode(self);
|
|
||||||
(ty::AssocKind::Fn, data.container, data.has_self)
|
|
||||||
}
|
|
||||||
EntryKind::AssocType(container) => (ty::AssocKind::Type, container, false),
|
EntryKind::AssocType(container) => (ty::AssocKind::Type, container, false),
|
||||||
_ => bug!("cannot get associated-item of `{:?}`", def_key),
|
_ => bug!("cannot get associated-item of `{:?}`", id),
|
||||||
};
|
};
|
||||||
|
|
||||||
ty::AssocItem {
|
ty::AssocItem {
|
||||||
|
@ -1153,7 +1148,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
||||||
kind,
|
kind,
|
||||||
def_id: self.local_def_id(id),
|
def_id: self.local_def_id(id),
|
||||||
trait_item_def_id: self.get_trait_item_def_id(id),
|
trait_item_def_id: self.get_trait_item_def_id(id),
|
||||||
container: container.with_def_id(parent),
|
container,
|
||||||
fn_has_self_parameter: has_self,
|
fn_has_self_parameter: has_self,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1222,7 +1222,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||||
|s| s.print_trait_item(ast_item),
|
|s| s.print_trait_item(ast_item),
|
||||||
);
|
);
|
||||||
|
|
||||||
record!(self.tables.kind[def_id] <- EntryKind::AssocConst(AssocContainer::Trait));
|
record!(self.tables.kind[def_id] <- EntryKind::AssocConst(ty::AssocItemContainer::TraitContainer));
|
||||||
record!(self.tables.mir_const_qualif[def_id] <- mir::ConstQualifs::default());
|
record!(self.tables.mir_const_qualif[def_id] <- mir::ConstQualifs::default());
|
||||||
record!(self.tables.rendered_const[def_id] <- rendered);
|
record!(self.tables.rendered_const[def_id] <- rendered);
|
||||||
}
|
}
|
||||||
|
@ -1238,14 +1238,14 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||||
};
|
};
|
||||||
self.tables.asyncness.set(def_id.index, m_sig.header.asyncness);
|
self.tables.asyncness.set(def_id.index, m_sig.header.asyncness);
|
||||||
self.tables.constness.set(def_id.index, hir::Constness::NotConst);
|
self.tables.constness.set(def_id.index, hir::Constness::NotConst);
|
||||||
record!(self.tables.kind[def_id] <- EntryKind::AssocFn(self.lazy(AssocFnData {
|
record!(self.tables.kind[def_id] <- EntryKind::AssocFn {
|
||||||
container:AssocContainer::Trait,
|
container: ty::AssocItemContainer::TraitContainer,
|
||||||
has_self: trait_item.fn_has_self_parameter,
|
has_self: trait_item.fn_has_self_parameter,
|
||||||
})));
|
});
|
||||||
}
|
}
|
||||||
ty::AssocKind::Type => {
|
ty::AssocKind::Type => {
|
||||||
self.encode_explicit_item_bounds(def_id);
|
self.encode_explicit_item_bounds(def_id);
|
||||||
record!(self.tables.kind[def_id] <- EntryKind::AssocType(AssocContainer::Trait));
|
record!(self.tables.kind[def_id] <- EntryKind::AssocType(ty::AssocItemContainer::TraitContainer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
match trait_item.kind {
|
match trait_item.kind {
|
||||||
|
@ -1277,7 +1277,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||||
let qualifs = self.tcx.at(ast_item.span).mir_const_qualif(def_id);
|
let qualifs = self.tcx.at(ast_item.span).mir_const_qualif(def_id);
|
||||||
let const_data = self.encode_rendered_const_for_body(body_id);
|
let const_data = self.encode_rendered_const_for_body(body_id);
|
||||||
|
|
||||||
record!(self.tables.kind[def_id] <- EntryKind::AssocConst(AssocContainer::Impl));
|
record!(self.tables.kind[def_id] <- EntryKind::AssocConst(ty::AssocItemContainer::ImplContainer));
|
||||||
record!(self.tables.mir_const_qualif[def_id] <- qualifs);
|
record!(self.tables.mir_const_qualif[def_id] <- qualifs);
|
||||||
record!(self.tables.rendered_const[def_id] <- const_data);
|
record!(self.tables.rendered_const[def_id] <- const_data);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1295,13 +1295,13 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||||
hir::Constness::NotConst
|
hir::Constness::NotConst
|
||||||
};
|
};
|
||||||
self.tables.constness.set(def_id.index, constness);
|
self.tables.constness.set(def_id.index, constness);
|
||||||
record!(self.tables.kind[def_id] <- EntryKind::AssocFn(self.lazy(AssocFnData {
|
record!(self.tables.kind[def_id] <- EntryKind::AssocFn {
|
||||||
container:AssocContainer::Impl,
|
container: ty::AssocItemContainer::ImplContainer,
|
||||||
has_self: impl_item.fn_has_self_parameter,
|
has_self: impl_item.fn_has_self_parameter,
|
||||||
})));
|
});
|
||||||
}
|
}
|
||||||
ty::AssocKind::Type => {
|
ty::AssocKind::Type => {
|
||||||
record!(self.tables.kind[def_id] <- EntryKind::AssocType(AssocContainer::Impl));
|
record!(self.tables.kind[def_id] <- EntryKind::AssocType(ty::AssocItemContainer::ImplContainer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.encode_item_type(def_id);
|
self.encode_item_type(def_id);
|
||||||
|
|
|
@ -419,9 +419,9 @@ enum EntryKind {
|
||||||
Generator,
|
Generator,
|
||||||
Trait,
|
Trait,
|
||||||
Impl,
|
Impl,
|
||||||
AssocFn(LazyValue<AssocFnData>),
|
AssocFn { container: ty::AssocItemContainer, has_self: bool },
|
||||||
AssocType(AssocContainer),
|
AssocType(ty::AssocItemContainer),
|
||||||
AssocConst(AssocContainer),
|
AssocConst(ty::AssocItemContainer),
|
||||||
TraitAlias,
|
TraitAlias,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -434,30 +434,6 @@ struct VariantData {
|
||||||
is_non_exhaustive: bool,
|
is_non_exhaustive: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Describes whether the container of an associated item
|
|
||||||
/// is a trait or an impl and whether, in a trait, it has
|
|
||||||
/// a default, or an in impl, whether it's marked "default".
|
|
||||||
#[derive(Copy, Clone, TyEncodable, TyDecodable)]
|
|
||||||
enum AssocContainer {
|
|
||||||
Trait,
|
|
||||||
Impl,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AssocContainer {
|
|
||||||
fn with_def_id(&self, def_id: DefId) -> ty::AssocItemContainer {
|
|
||||||
match *self {
|
|
||||||
AssocContainer::Trait => ty::TraitContainer(def_id),
|
|
||||||
AssocContainer::Impl => ty::ImplContainer(def_id),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(MetadataEncodable, MetadataDecodable)]
|
|
||||||
struct AssocFnData {
|
|
||||||
container: AssocContainer,
|
|
||||||
has_self: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(TyEncodable, TyDecodable)]
|
#[derive(TyEncodable, TyDecodable)]
|
||||||
struct GeneratorData<'tcx> {
|
struct GeneratorData<'tcx> {
|
||||||
layout: mir::GeneratorLayout<'tcx>,
|
layout: mir::GeneratorLayout<'tcx>,
|
||||||
|
@ -475,7 +451,6 @@ pub fn provide(providers: &mut Providers) {
|
||||||
|
|
||||||
trivially_parameterized_over_tcx! {
|
trivially_parameterized_over_tcx! {
|
||||||
VariantData,
|
VariantData,
|
||||||
AssocFnData,
|
|
||||||
EntryKind,
|
EntryKind,
|
||||||
RawDefId,
|
RawDefId,
|
||||||
TraitImpls,
|
TraitImpls,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
pub use self::AssocItemContainer::*;
|
pub use self::AssocItemContainer::*;
|
||||||
|
|
||||||
use crate::ty;
|
use crate::ty::{self, DefIdTree};
|
||||||
use rustc_data_structures::sorted_map::SortedIndexMultiMap;
|
use rustc_data_structures::sorted_map::SortedIndexMultiMap;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{DefKind, Namespace};
|
use rustc_hir::def::{DefKind, Namespace};
|
||||||
|
@ -11,33 +11,8 @@ use super::{TyCtxt, Visibility};
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, HashStable, Hash, Encodable, Decodable)]
|
#[derive(Clone, Copy, PartialEq, Eq, Debug, HashStable, Hash, Encodable, Decodable)]
|
||||||
pub enum AssocItemContainer {
|
pub enum AssocItemContainer {
|
||||||
TraitContainer(DefId),
|
TraitContainer,
|
||||||
ImplContainer(DefId),
|
ImplContainer,
|
||||||
}
|
|
||||||
|
|
||||||
impl AssocItemContainer {
|
|
||||||
pub fn impl_def_id(&self) -> Option<DefId> {
|
|
||||||
match *self {
|
|
||||||
ImplContainer(id) => Some(id),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Asserts that this is the `DefId` of an associated item declared
|
|
||||||
/// in a trait, and returns the trait `DefId`.
|
|
||||||
pub fn assert_trait(&self) -> DefId {
|
|
||||||
match *self {
|
|
||||||
TraitContainer(id) => id,
|
|
||||||
_ => bug!("associated item has wrong container type: {:?}", self),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn id(&self) -> DefId {
|
|
||||||
match *self {
|
|
||||||
TraitContainer(id) => id,
|
|
||||||
ImplContainer(id) => id,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Information about an associated item
|
/// Information about an associated item
|
||||||
|
@ -71,6 +46,27 @@ impl AssocItem {
|
||||||
tcx.visibility(self.def_id)
|
tcx.visibility(self.def_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn container_id(&self, tcx: TyCtxt<'_>) -> DefId {
|
||||||
|
tcx.parent(self.def_id)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn trait_container(&self, tcx: TyCtxt<'_>) -> Option<DefId> {
|
||||||
|
match self.container {
|
||||||
|
AssocItemContainer::ImplContainer => None,
|
||||||
|
AssocItemContainer::TraitContainer => Some(tcx.parent(self.def_id)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn impl_container(&self, tcx: TyCtxt<'_>) -> Option<DefId> {
|
||||||
|
match self.container {
|
||||||
|
AssocItemContainer::ImplContainer => Some(tcx.parent(self.def_id)),
|
||||||
|
AssocItemContainer::TraitContainer => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn signature(&self, tcx: TyCtxt<'_>) -> String {
|
pub fn signature(&self, tcx: TyCtxt<'_>) -> String {
|
||||||
match self.kind {
|
match self.kind {
|
||||||
ty::AssocKind::Fn => {
|
ty::AssocKind::Fn => {
|
||||||
|
|
|
@ -1668,8 +1668,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
|
|
||||||
// Checks if the bound region is in Impl Item.
|
// Checks if the bound region is in Impl Item.
|
||||||
pub fn is_bound_region_in_impl_item(self, suitable_region_binding_scope: LocalDefId) -> bool {
|
pub fn is_bound_region_in_impl_item(self, suitable_region_binding_scope: LocalDefId) -> bool {
|
||||||
let container_id =
|
let container_id = self.parent(suitable_region_binding_scope.to_def_id());
|
||||||
self.associated_item(suitable_region_binding_scope.to_def_id()).container.id();
|
|
||||||
if self.impl_trait_ref(container_id).is_some() {
|
if self.impl_trait_ref(container_id).is_some() {
|
||||||
// For now, we do not try to target impls of traits. This is
|
// For now, we do not try to target impls of traits. This is
|
||||||
// because this message is going to suggest that the user
|
// because this message is going to suggest that the user
|
||||||
|
|
|
@ -673,7 +673,7 @@ impl<T> Trait<T> for X {
|
||||||
// the associated type or calling a method that returns the associated type".
|
// the associated type or calling a method that returns the associated type".
|
||||||
let point_at_assoc_fn = self.point_at_methods_that_satisfy_associated_type(
|
let point_at_assoc_fn = self.point_at_methods_that_satisfy_associated_type(
|
||||||
diag,
|
diag,
|
||||||
assoc.container.id(),
|
assoc.container_id(self),
|
||||||
current_method_ident,
|
current_method_ident,
|
||||||
proj_ty.item_def_id,
|
proj_ty.item_def_id,
|
||||||
values.expected,
|
values.expected,
|
||||||
|
|
|
@ -460,7 +460,7 @@ impl<'tcx> Instance<'tcx> {
|
||||||
&& !matches!(
|
&& !matches!(
|
||||||
tcx.opt_associated_item(def.did),
|
tcx.opt_associated_item(def.did),
|
||||||
Some(ty::AssocItem {
|
Some(ty::AssocItem {
|
||||||
container: ty::AssocItemContainer::TraitContainer(_),
|
container: ty::AssocItemContainer::TraitContainer,
|
||||||
..
|
..
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
|
@ -2194,10 +2194,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
/// If the given `DefId` describes a method belonging to an impl, returns the
|
/// If the given `DefId` describes a method belonging to an impl, returns the
|
||||||
/// `DefId` of the impl that the method belongs to; otherwise, returns `None`.
|
/// `DefId` of the impl that the method belongs to; otherwise, returns `None`.
|
||||||
pub fn impl_of_method(self, def_id: DefId) -> Option<DefId> {
|
pub fn impl_of_method(self, def_id: DefId) -> Option<DefId> {
|
||||||
self.opt_associated_item(def_id).and_then(|trait_item| match trait_item.container {
|
self.opt_associated_item(def_id).and_then(|trait_item| trait_item.impl_container(self))
|
||||||
TraitContainer(_) => None,
|
|
||||||
ImplContainer(def_id) => Some(def_id),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If the given `DefId` belongs to a trait that was automatically derived, returns `true`.
|
/// If the given `DefId` belongs to a trait that was automatically derived, returns `true`.
|
||||||
|
|
|
@ -1179,13 +1179,14 @@ pub struct ProjectionTy<'tcx> {
|
||||||
/// The `DefId` of the `TraitItem` for the associated type `N`.
|
/// The `DefId` of the `TraitItem` for the associated type `N`.
|
||||||
///
|
///
|
||||||
/// Note that this is not the `DefId` of the `TraitRef` containing this
|
/// Note that this is not the `DefId` of the `TraitRef` containing this
|
||||||
/// associated type, which is in `tcx.associated_item(item_def_id).container`.
|
/// associated type, which is in `tcx.associated_item(item_def_id).container`,
|
||||||
|
/// aka. `tcx.parent(item_def_id).unwrap()`.
|
||||||
pub item_def_id: DefId,
|
pub item_def_id: DefId,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> ProjectionTy<'tcx> {
|
impl<'tcx> ProjectionTy<'tcx> {
|
||||||
pub fn trait_def_id(&self, tcx: TyCtxt<'tcx>) -> DefId {
|
pub fn trait_def_id(&self, tcx: TyCtxt<'tcx>) -> DefId {
|
||||||
tcx.associated_item(self.item_def_id).container.id()
|
tcx.parent(self.item_def_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extracts the underlying trait reference and own substs from this projection.
|
/// Extracts the underlying trait reference and own substs from this projection.
|
||||||
|
@ -1195,7 +1196,7 @@ impl<'tcx> ProjectionTy<'tcx> {
|
||||||
&self,
|
&self,
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
) -> (ty::TraitRef<'tcx>, &'tcx [ty::GenericArg<'tcx>]) {
|
) -> (ty::TraitRef<'tcx>, &'tcx [ty::GenericArg<'tcx>]) {
|
||||||
let def_id = tcx.associated_item(self.item_def_id).container.id();
|
let def_id = tcx.parent(self.item_def_id);
|
||||||
let trait_generics = tcx.generics_of(def_id);
|
let trait_generics = tcx.generics_of(def_id);
|
||||||
(
|
(
|
||||||
ty::TraitRef { def_id, substs: self.substs.truncate_to(tcx, trait_generics) },
|
ty::TraitRef { def_id, substs: self.substs.truncate_to(tcx, trait_generics) },
|
||||||
|
@ -1433,7 +1434,7 @@ impl<'tcx> ExistentialProjection<'tcx> {
|
||||||
/// then this function would return an `exists T. T: Iterator` existential trait
|
/// then this function would return an `exists T. T: Iterator` existential trait
|
||||||
/// reference.
|
/// reference.
|
||||||
pub fn trait_ref(&self, tcx: TyCtxt<'tcx>) -> ty::ExistentialTraitRef<'tcx> {
|
pub fn trait_ref(&self, tcx: TyCtxt<'tcx>) -> ty::ExistentialTraitRef<'tcx> {
|
||||||
let def_id = tcx.associated_item(self.item_def_id).container.id();
|
let def_id = tcx.parent(self.item_def_id);
|
||||||
let subst_count = tcx.generics_of(def_id).count() - 1;
|
let subst_count = tcx.generics_of(def_id).count() - 1;
|
||||||
let substs = tcx.intern_substs(&self.substs[..subst_count]);
|
let substs = tcx.intern_substs(&self.substs[..subst_count]);
|
||||||
ty::ExistentialTraitRef { def_id, substs }
|
ty::ExistentialTraitRef { def_id, substs }
|
||||||
|
|
|
@ -402,7 +402,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
Some(dtor) => dtor.did,
|
Some(dtor) => dtor.did,
|
||||||
};
|
};
|
||||||
|
|
||||||
let impl_def_id = self.associated_item(dtor).container.id();
|
let impl_def_id = self.parent(dtor);
|
||||||
let impl_generics = self.generics_of(impl_def_id);
|
let impl_generics = self.generics_of(impl_def_id);
|
||||||
|
|
||||||
// We have a destructor - all the parameters that are not
|
// We have a destructor - all the parameters that are not
|
||||||
|
|
|
@ -4,7 +4,7 @@ use rustc_data_structures::graph::iterate::{
|
||||||
use rustc_hir::def::DefKind;
|
use rustc_hir::def::DefKind;
|
||||||
use rustc_middle::mir::{BasicBlock, BasicBlocks, Body, Operand, TerminatorKind};
|
use rustc_middle::mir::{BasicBlock, BasicBlocks, Body, Operand, TerminatorKind};
|
||||||
use rustc_middle::ty::subst::{GenericArg, InternalSubsts};
|
use rustc_middle::ty::subst::{GenericArg, InternalSubsts};
|
||||||
use rustc_middle::ty::{self, AssocItem, AssocItemContainer, Instance, TyCtxt};
|
use rustc_middle::ty::{self, Instance, TyCtxt};
|
||||||
use rustc_session::lint::builtin::UNCONDITIONAL_RECURSION;
|
use rustc_session::lint::builtin::UNCONDITIONAL_RECURSION;
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
use std::ops::ControlFlow;
|
use std::ops::ControlFlow;
|
||||||
|
@ -14,11 +14,9 @@ pub(crate) fn check<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
|
||||||
|
|
||||||
if let DefKind::Fn | DefKind::AssocFn = tcx.def_kind(def_id) {
|
if let DefKind::Fn | DefKind::AssocFn = tcx.def_kind(def_id) {
|
||||||
// If this is trait/impl method, extract the trait's substs.
|
// If this is trait/impl method, extract the trait's substs.
|
||||||
let trait_substs = match tcx.opt_associated_item(def_id.to_def_id()) {
|
let trait_substs = match tcx.trait_of_item(def_id) {
|
||||||
Some(AssocItem {
|
Some(trait_def_id) => {
|
||||||
container: AssocItemContainer::TraitContainer(trait_def_id), ..
|
let trait_substs_count = tcx.generics_of(trait_def_id).count();
|
||||||
}) => {
|
|
||||||
let trait_substs_count = tcx.generics_of(*trait_def_id).count();
|
|
||||||
&InternalSubsts::identity_for_item(tcx, def_id.to_def_id())[..trait_substs_count]
|
&InternalSubsts::identity_for_item(tcx, def_id.to_def_id())[..trait_substs_count]
|
||||||
}
|
}
|
||||||
_ => &[],
|
_ => &[],
|
||||||
|
|
|
@ -212,7 +212,7 @@ where
|
||||||
// `impl Pub<Priv> { pub fn my_method() {} }` is considered a private type,
|
// `impl Pub<Priv> { pub fn my_method() {} }` is considered a private type,
|
||||||
// so we need to visit the self type additionally.
|
// so we need to visit the self type additionally.
|
||||||
if let Some(assoc_item) = tcx.opt_associated_item(def_id) {
|
if let Some(assoc_item) = tcx.opt_associated_item(def_id) {
|
||||||
if let ty::ImplContainer(impl_def_id) = assoc_item.container {
|
if let Some(impl_def_id) = assoc_item.impl_container(tcx) {
|
||||||
tcx.type_of(impl_def_id).visit_with(self)?;
|
tcx.type_of(impl_def_id).visit_with(self)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -564,8 +564,8 @@ impl<'tcx> SaveContext<'tcx> {
|
||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
let (def_id, decl_id) = match self.tcx.associated_item(method_id).container {
|
let (def_id, decl_id) = match self.tcx.associated_item(method_id).container {
|
||||||
ty::ImplContainer(_) => (Some(method_id), None),
|
ty::ImplContainer => (Some(method_id), None),
|
||||||
ty::TraitContainer(_) => (None, Some(method_id)),
|
ty::TraitContainer => (None, Some(method_id)),
|
||||||
};
|
};
|
||||||
let sub_span = seg.ident.span;
|
let sub_span = seg.ident.span;
|
||||||
filter!(self.span_utils, sub_span);
|
filter!(self.span_utils, sub_span);
|
||||||
|
|
|
@ -2714,7 +2714,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
if let Some(ident) = self
|
if let Some(ident) = self
|
||||||
.tcx
|
.tcx
|
||||||
.opt_associated_item(trait_item_def_id)
|
.opt_associated_item(trait_item_def_id)
|
||||||
.and_then(|i| self.tcx.opt_item_ident(i.container.id()))
|
.and_then(|i| self.tcx.opt_item_ident(i.container_id(self.tcx)))
|
||||||
{
|
{
|
||||||
assoc_span.push_span_label(ident.span, "in this trait");
|
assoc_span.push_span_label(ident.span, "in this trait");
|
||||||
}
|
}
|
||||||
|
|
|
@ -690,7 +690,7 @@ fn receiver_is_dispatchable<'tcx>(
|
||||||
// U: Trait<Arg1, ..., ArgN>
|
// U: Trait<Arg1, ..., ArgN>
|
||||||
let trait_predicate = {
|
let trait_predicate = {
|
||||||
let substs =
|
let substs =
|
||||||
InternalSubsts::for_item(tcx, method.container.assert_trait(), |param, _| {
|
InternalSubsts::for_item(tcx, method.trait_container(tcx).unwrap(), |param, _| {
|
||||||
if param.index == 0 {
|
if param.index == 0 {
|
||||||
unsized_self_ty.into()
|
unsized_self_ty.into()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -359,7 +359,7 @@ pub fn generator_trait_ref_and_outputs<'tcx>(
|
||||||
|
|
||||||
pub fn impl_item_is_final(tcx: TyCtxt<'_>, assoc_item: &ty::AssocItem) -> bool {
|
pub fn impl_item_is_final(tcx: TyCtxt<'_>, assoc_item: &ty::AssocItem) -> bool {
|
||||||
assoc_item.defaultness(tcx).is_final()
|
assoc_item.defaultness(tcx).is_final()
|
||||||
&& tcx.impl_defaultness(assoc_item.container.id()).is_final()
|
&& tcx.impl_defaultness(assoc_item.container_id(tcx)).is_final()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum TupleArgumentsFlag {
|
pub enum TupleArgumentsFlag {
|
||||||
|
|
|
@ -8,9 +8,7 @@
|
||||||
|
|
||||||
use rustc_middle::traits::ChalkRustInterner as RustInterner;
|
use rustc_middle::traits::ChalkRustInterner as RustInterner;
|
||||||
use rustc_middle::ty::subst::{InternalSubsts, Subst, SubstsRef};
|
use rustc_middle::ty::subst::{InternalSubsts, Subst, SubstsRef};
|
||||||
use rustc_middle::ty::{
|
use rustc_middle::ty::{self, AssocKind, EarlyBinder, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable};
|
||||||
self, AssocItemContainer, AssocKind, EarlyBinder, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable,
|
|
||||||
};
|
|
||||||
|
|
||||||
use rustc_ast::ast;
|
use rustc_ast::ast;
|
||||||
use rustc_attr as attr;
|
use rustc_attr as attr;
|
||||||
|
@ -74,7 +72,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
|
||||||
) -> Arc<chalk_solve::rust_ir::AssociatedTyDatum<RustInterner<'tcx>>> {
|
) -> Arc<chalk_solve::rust_ir::AssociatedTyDatum<RustInterner<'tcx>>> {
|
||||||
let def_id = assoc_type_id.0;
|
let def_id = assoc_type_id.0;
|
||||||
let assoc_item = self.interner.tcx.associated_item(def_id);
|
let assoc_item = self.interner.tcx.associated_item(def_id);
|
||||||
let AssocItemContainer::TraitContainer(trait_def_id) = assoc_item.container else {
|
let Some(trait_def_id) = assoc_item.trait_container(self.interner.tcx) else {
|
||||||
unimplemented!("Not possible??");
|
unimplemented!("Not possible??");
|
||||||
};
|
};
|
||||||
match assoc_item.kind {
|
match assoc_item.kind {
|
||||||
|
@ -455,7 +453,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
|
||||||
) -> Arc<chalk_solve::rust_ir::AssociatedTyValue<RustInterner<'tcx>>> {
|
) -> Arc<chalk_solve::rust_ir::AssociatedTyValue<RustInterner<'tcx>>> {
|
||||||
let def_id = associated_ty_id.0;
|
let def_id = associated_ty_id.0;
|
||||||
let assoc_item = self.interner.tcx.associated_item(def_id);
|
let assoc_item = self.interner.tcx.associated_item(def_id);
|
||||||
let impl_id = assoc_item.container.id();
|
let impl_id = assoc_item.container_id(self.interner.tcx);
|
||||||
match assoc_item.kind {
|
match assoc_item.kind {
|
||||||
AssocKind::Type => {}
|
AssocKind::Type => {}
|
||||||
_ => unimplemented!("Not possible??"),
|
_ => unimplemented!("Not possible??"),
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_middle::ty::{self, TyCtxt};
|
use rustc_middle::ty::{self, TyCtxt};
|
||||||
|
|
||||||
pub fn provide(providers: &mut ty::query::Providers) {
|
pub fn provide(providers: &mut ty::query::Providers) {
|
||||||
|
@ -44,10 +44,7 @@ fn impl_item_implementor_ids(tcx: TyCtxt<'_>, impl_id: DefId) -> FxHashMap<DefId
|
||||||
/// returns the `DefId` of the trait that the trait item belongs to;
|
/// returns the `DefId` of the trait that the trait item belongs to;
|
||||||
/// otherwise, returns `None`.
|
/// otherwise, returns `None`.
|
||||||
fn trait_of_item(tcx: TyCtxt<'_>, def_id: DefId) -> Option<DefId> {
|
fn trait_of_item(tcx: TyCtxt<'_>, def_id: DefId) -> Option<DefId> {
|
||||||
tcx.opt_associated_item(def_id).and_then(|associated_item| match associated_item.container {
|
tcx.opt_associated_item(def_id).and_then(|associated_item| associated_item.trait_container(tcx))
|
||||||
ty::TraitContainer(def_id) => Some(def_id),
|
|
||||||
ty::ImplContainer(_) => None,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn associated_item(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AssocItem {
|
fn associated_item(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AssocItem {
|
||||||
|
@ -59,7 +56,7 @@ fn associated_item(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AssocItem {
|
||||||
if let Some(impl_item_ref) =
|
if let Some(impl_item_ref) =
|
||||||
impl_.items.iter().find(|i| i.id.def_id.to_def_id() == def_id)
|
impl_.items.iter().find(|i| i.id.def_id.to_def_id() == def_id)
|
||||||
{
|
{
|
||||||
let assoc_item = associated_item_from_impl_item_ref(parent_def_id, impl_item_ref);
|
let assoc_item = associated_item_from_impl_item_ref(impl_item_ref);
|
||||||
debug_assert_eq!(assoc_item.def_id, def_id);
|
debug_assert_eq!(assoc_item.def_id, def_id);
|
||||||
return assoc_item;
|
return assoc_item;
|
||||||
}
|
}
|
||||||
|
@ -69,7 +66,7 @@ fn associated_item(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AssocItem {
|
||||||
if let Some(trait_item_ref) =
|
if let Some(trait_item_ref) =
|
||||||
trait_item_refs.iter().find(|i| i.id.def_id.to_def_id() == def_id)
|
trait_item_refs.iter().find(|i| i.id.def_id.to_def_id() == def_id)
|
||||||
{
|
{
|
||||||
let assoc_item = associated_item_from_trait_item_ref(parent_def_id, trait_item_ref);
|
let assoc_item = associated_item_from_trait_item_ref(trait_item_ref);
|
||||||
debug_assert_eq!(assoc_item.def_id, def_id);
|
debug_assert_eq!(assoc_item.def_id, def_id);
|
||||||
return assoc_item;
|
return assoc_item;
|
||||||
}
|
}
|
||||||
|
@ -85,10 +82,7 @@ fn associated_item(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AssocItem {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn associated_item_from_trait_item_ref(
|
fn associated_item_from_trait_item_ref(trait_item_ref: &hir::TraitItemRef) -> ty::AssocItem {
|
||||||
parent_def_id: LocalDefId,
|
|
||||||
trait_item_ref: &hir::TraitItemRef,
|
|
||||||
) -> ty::AssocItem {
|
|
||||||
let def_id = trait_item_ref.id.def_id;
|
let def_id = trait_item_ref.id.def_id;
|
||||||
let (kind, has_self) = match trait_item_ref.kind {
|
let (kind, has_self) = match trait_item_ref.kind {
|
||||||
hir::AssocItemKind::Const => (ty::AssocKind::Const, false),
|
hir::AssocItemKind::Const => (ty::AssocKind::Const, false),
|
||||||
|
@ -101,15 +95,12 @@ fn associated_item_from_trait_item_ref(
|
||||||
kind,
|
kind,
|
||||||
def_id: def_id.to_def_id(),
|
def_id: def_id.to_def_id(),
|
||||||
trait_item_def_id: Some(def_id.to_def_id()),
|
trait_item_def_id: Some(def_id.to_def_id()),
|
||||||
container: ty::TraitContainer(parent_def_id.to_def_id()),
|
container: ty::TraitContainer,
|
||||||
fn_has_self_parameter: has_self,
|
fn_has_self_parameter: has_self,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn associated_item_from_impl_item_ref(
|
fn associated_item_from_impl_item_ref(impl_item_ref: &hir::ImplItemRef) -> ty::AssocItem {
|
||||||
parent_def_id: LocalDefId,
|
|
||||||
impl_item_ref: &hir::ImplItemRef,
|
|
||||||
) -> ty::AssocItem {
|
|
||||||
let def_id = impl_item_ref.id.def_id;
|
let def_id = impl_item_ref.id.def_id;
|
||||||
let (kind, has_self) = match impl_item_ref.kind {
|
let (kind, has_self) = match impl_item_ref.kind {
|
||||||
hir::AssocItemKind::Const => (ty::AssocKind::Const, false),
|
hir::AssocItemKind::Const => (ty::AssocKind::Const, false),
|
||||||
|
@ -122,7 +113,7 @@ fn associated_item_from_impl_item_ref(
|
||||||
kind,
|
kind,
|
||||||
def_id: def_id.to_def_id(),
|
def_id: def_id.to_def_id(),
|
||||||
trait_item_def_id: impl_item_ref.trait_item_def_id,
|
trait_item_def_id: impl_item_ref.trait_item_def_id,
|
||||||
container: ty::ImplContainer(parent_def_id.to_def_id()),
|
container: ty::ImplContainer,
|
||||||
fn_has_self_parameter: has_self,
|
fn_has_self_parameter: has_self,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -255,7 +255,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
trait_bound_spans.push(*span);
|
trait_bound_spans.push(*span);
|
||||||
}
|
}
|
||||||
for assoc_item in items {
|
for assoc_item in items {
|
||||||
let trait_def_id = assoc_item.container.id();
|
let trait_def_id = assoc_item.container_id(tcx);
|
||||||
names.push(format!(
|
names.push(format!(
|
||||||
"`{}` (from trait `{}`)",
|
"`{}` (from trait `{}`)",
|
||||||
assoc_item.name,
|
assoc_item.name,
|
||||||
|
@ -321,7 +321,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
let mut dupes = false;
|
let mut dupes = false;
|
||||||
for item in assoc_items {
|
for item in assoc_items {
|
||||||
let prefix = if names[&item.name] > 1 {
|
let prefix = if names[&item.name] > 1 {
|
||||||
let trait_def_id = item.container.id();
|
let trait_def_id = item.container_id(tcx);
|
||||||
dupes = true;
|
dupes = true;
|
||||||
format!("{}::", tcx.def_path_str(trait_def_id))
|
format!("{}::", tcx.def_path_str(trait_def_id))
|
||||||
} else {
|
} else {
|
||||||
|
@ -376,7 +376,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
let mut label = vec![];
|
let mut label = vec![];
|
||||||
for item in assoc_items {
|
for item in assoc_items {
|
||||||
let postfix = if names[&item.name] > 1 {
|
let postfix = if names[&item.name] > 1 {
|
||||||
let trait_def_id = item.container.id();
|
let trait_def_id = item.container_id(tcx);
|
||||||
format!(" (from trait `{}`)", tcx.def_path_str(trait_def_id))
|
format!(" (from trait `{}`)", tcx.def_path_str(trait_def_id))
|
||||||
} else {
|
} else {
|
||||||
String::new()
|
String::new()
|
||||||
|
|
|
@ -1160,7 +1160,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
span: binding.span,
|
span: binding.span,
|
||||||
prev_span: *prev_span,
|
prev_span: *prev_span,
|
||||||
item_name: binding.item_name,
|
item_name: binding.item_name,
|
||||||
def_path: tcx.def_path_str(assoc_item.container.id()),
|
def_path: tcx.def_path_str(assoc_item.container_id(tcx)),
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.or_insert(binding.span);
|
.or_insert(binding.span);
|
||||||
|
|
|
@ -165,7 +165,7 @@ fn compare_predicate_entailment<'tcx>(
|
||||||
|
|
||||||
// Create mapping from trait to placeholder.
|
// Create mapping from trait to placeholder.
|
||||||
let trait_to_placeholder_substs =
|
let trait_to_placeholder_substs =
|
||||||
impl_to_placeholder_substs.rebase_onto(tcx, impl_m.container.id(), trait_to_impl_substs);
|
impl_to_placeholder_substs.rebase_onto(tcx, impl_m.container_id(tcx), trait_to_impl_substs);
|
||||||
debug!("compare_impl_method: trait_to_placeholder_substs={:?}", trait_to_placeholder_substs);
|
debug!("compare_impl_method: trait_to_placeholder_substs={:?}", trait_to_placeholder_substs);
|
||||||
|
|
||||||
let impl_m_generics = tcx.generics_of(impl_m.def_id);
|
let impl_m_generics = tcx.generics_of(impl_m.def_id);
|
||||||
|
@ -511,8 +511,8 @@ fn compare_self_type<'tcx>(
|
||||||
|
|
||||||
let self_string = |method: &ty::AssocItem| {
|
let self_string = |method: &ty::AssocItem| {
|
||||||
let untransformed_self_ty = match method.container {
|
let untransformed_self_ty = match method.container {
|
||||||
ty::ImplContainer(_) => impl_trait_ref.self_ty(),
|
ty::ImplContainer => impl_trait_ref.self_ty(),
|
||||||
ty::TraitContainer(_) => tcx.types.self_param,
|
ty::TraitContainer => tcx.types.self_param,
|
||||||
};
|
};
|
||||||
let self_arg_ty = tcx.fn_sig(method.def_id).input(0);
|
let self_arg_ty = tcx.fn_sig(method.def_id).input(0);
|
||||||
let param_env = ty::ParamEnv::reveal_all();
|
let param_env = ty::ParamEnv::reveal_all();
|
||||||
|
@ -1194,7 +1194,7 @@ fn compare_type_predicate_entailment<'tcx>(
|
||||||
) -> Result<(), ErrorGuaranteed> {
|
) -> Result<(), ErrorGuaranteed> {
|
||||||
let impl_substs = InternalSubsts::identity_for_item(tcx, impl_ty.def_id);
|
let impl_substs = InternalSubsts::identity_for_item(tcx, impl_ty.def_id);
|
||||||
let trait_to_impl_substs =
|
let trait_to_impl_substs =
|
||||||
impl_substs.rebase_onto(tcx, impl_ty.container.id(), impl_trait_ref.substs);
|
impl_substs.rebase_onto(tcx, impl_ty.container_id(tcx), impl_trait_ref.substs);
|
||||||
|
|
||||||
let impl_ty_generics = tcx.generics_of(impl_ty.def_id);
|
let impl_ty_generics = tcx.generics_of(impl_ty.def_id);
|
||||||
let trait_ty_generics = tcx.generics_of(trait_ty.def_id);
|
let trait_ty_generics = tcx.generics_of(trait_ty.def_id);
|
||||||
|
@ -1390,9 +1390,9 @@ pub fn check_type_bounds<'tcx>(
|
||||||
});
|
});
|
||||||
let bound_vars = tcx.mk_bound_variable_kinds(bound_vars.into_iter());
|
let bound_vars = tcx.mk_bound_variable_kinds(bound_vars.into_iter());
|
||||||
let impl_ty_substs = tcx.intern_substs(&substs);
|
let impl_ty_substs = tcx.intern_substs(&substs);
|
||||||
|
let container_id = impl_ty.container_id(tcx);
|
||||||
|
|
||||||
let rebased_substs =
|
let rebased_substs = impl_ty_substs.rebase_onto(tcx, container_id, impl_trait_ref.substs);
|
||||||
impl_ty_substs.rebase_onto(tcx, impl_ty.container.id(), impl_trait_ref.substs);
|
|
||||||
let impl_ty_value = tcx.type_of(impl_ty.def_id);
|
let impl_ty_value = tcx.type_of(impl_ty.def_id);
|
||||||
|
|
||||||
let param_env = tcx.param_env(impl_ty.def_id);
|
let param_env = tcx.param_env(impl_ty.def_id);
|
||||||
|
@ -1441,8 +1441,7 @@ pub fn check_type_bounds<'tcx>(
|
||||||
debug!(?normalize_param_env);
|
debug!(?normalize_param_env);
|
||||||
|
|
||||||
let impl_ty_substs = InternalSubsts::identity_for_item(tcx, impl_ty.def_id);
|
let impl_ty_substs = InternalSubsts::identity_for_item(tcx, impl_ty.def_id);
|
||||||
let rebased_substs =
|
let rebased_substs = impl_ty_substs.rebase_onto(tcx, container_id, impl_trait_ref.substs);
|
||||||
impl_ty_substs.rebase_onto(tcx, impl_ty.container.id(), impl_trait_ref.substs);
|
|
||||||
|
|
||||||
tcx.infer_ctxt().enter(move |infcx| {
|
tcx.infer_ctxt().enter(move |infcx| {
|
||||||
let ocx = ObligationCtxt::new(&infcx);
|
let ocx = ObligationCtxt::new(&infcx);
|
||||||
|
@ -1505,10 +1504,13 @@ pub fn check_type_bounds<'tcx>(
|
||||||
// Finally, resolve all regions. This catches wily misuses of
|
// Finally, resolve all regions. This catches wily misuses of
|
||||||
// lifetime parameters.
|
// lifetime parameters.
|
||||||
let implied_bounds = match impl_ty.container {
|
let implied_bounds = match impl_ty.container {
|
||||||
ty::TraitContainer(_) => FxHashSet::default(),
|
ty::TraitContainer => FxHashSet::default(),
|
||||||
ty::ImplContainer(def_id) => {
|
ty::ImplContainer => wfcheck::impl_implied_bounds(
|
||||||
wfcheck::impl_implied_bounds(tcx, param_env, def_id.expect_local(), impl_ty_span)
|
tcx,
|
||||||
}
|
param_env,
|
||||||
|
container_id.expect_local(),
|
||||||
|
impl_ty_span,
|
||||||
|
),
|
||||||
};
|
};
|
||||||
let mut outlives_environment = OutlivesEnvironment::new(param_env);
|
let mut outlives_environment = OutlivesEnvironment::new(param_env);
|
||||||
outlives_environment.add_implied_bounds(&infcx, implied_bounds, impl_ty_hir_id);
|
outlives_environment.add_implied_bounds(&infcx, implied_bounds, impl_ty_hir_id);
|
||||||
|
|
|
@ -775,7 +775,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
self.typeck_results.borrow().type_dependent_def_id(expr.hir_id).map(
|
self.typeck_results.borrow().type_dependent_def_id(expr.hir_id).map(
|
||||||
|did| {
|
|did| {
|
||||||
let ai = self.tcx.associated_item(did);
|
let ai = self.tcx.associated_item(did);
|
||||||
ai.container == ty::TraitContainer(clone_trait)
|
ai.trait_container(self.tcx) == Some(clone_trait)
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
segment.ident.name,
|
segment.ident.name,
|
||||||
|
|
|
@ -1090,13 +1090,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
is_alias_variant_ctor = true;
|
is_alias_variant_ctor = true;
|
||||||
}
|
}
|
||||||
Res::Def(DefKind::AssocFn | DefKind::AssocConst, def_id) => {
|
Res::Def(DefKind::AssocFn | DefKind::AssocConst, def_id) => {
|
||||||
let container = tcx.associated_item(def_id).container;
|
let assoc_item = tcx.associated_item(def_id);
|
||||||
debug!(?def_id, ?container);
|
let container = assoc_item.container;
|
||||||
|
let container_id = assoc_item.container_id(tcx);
|
||||||
|
debug!(?def_id, ?container, ?container_id);
|
||||||
match container {
|
match container {
|
||||||
ty::TraitContainer(trait_did) => {
|
ty::TraitContainer => {
|
||||||
callee::check_legal_trait_for_method_call(tcx, span, None, span, trait_did)
|
callee::check_legal_trait_for_method_call(tcx, span, None, span, container_id)
|
||||||
}
|
}
|
||||||
ty::ImplContainer(impl_def_id) => {
|
ty::ImplContainer => {
|
||||||
if segments.len() == 1 {
|
if segments.len() == 1 {
|
||||||
// `<T>::assoc` will end up here, and so
|
// `<T>::assoc` will end up here, and so
|
||||||
// can `T::assoc`. It this came from an
|
// can `T::assoc`. It this came from an
|
||||||
|
@ -1104,7 +1106,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
// `T` for posterity (see `UserSelfTy` for
|
// `T` for posterity (see `UserSelfTy` for
|
||||||
// details).
|
// details).
|
||||||
let self_ty = self_ty.expect("UFCS sugared assoc missing Self");
|
let self_ty = self_ty.expect("UFCS sugared assoc missing Self");
|
||||||
user_self_ty = Some(UserSelfTy { impl_def_id, self_ty });
|
user_self_ty = Some(UserSelfTy { impl_def_id: container_id, self_ty });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -839,8 +839,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
&& results.type_dependent_def_id(expr.hir_id).map_or(
|
&& results.type_dependent_def_id(expr.hir_id).map_or(
|
||||||
false,
|
false,
|
||||||
|did| {
|
|did| {
|
||||||
self.tcx.associated_item(did).container
|
let assoc_item = self.tcx.associated_item(did);
|
||||||
== ty::AssocItemContainer::TraitContainer(clone_trait_did)
|
assoc_item.container == ty::AssocItemContainer::TraitContainer
|
||||||
|
&& assoc_item.container_id(self.tcx) == clone_trait_did
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
// If that clone call hasn't already dereferenced the self type (i.e. don't give this
|
// If that clone call hasn't already dereferenced the self type (i.e. don't give this
|
||||||
|
|
|
@ -238,7 +238,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
|
||||||
) -> SubstsRef<'tcx> {
|
) -> SubstsRef<'tcx> {
|
||||||
match pick.kind {
|
match pick.kind {
|
||||||
probe::InherentImplPick => {
|
probe::InherentImplPick => {
|
||||||
let impl_def_id = pick.item.container.id();
|
let impl_def_id = pick.item.container_id(self.tcx);
|
||||||
assert!(
|
assert!(
|
||||||
self.tcx.impl_trait_ref(impl_def_id).is_none(),
|
self.tcx.impl_trait_ref(impl_def_id).is_none(),
|
||||||
"impl {:?} is not an inherent impl",
|
"impl {:?} is not an inherent impl",
|
||||||
|
@ -248,7 +248,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
probe::ObjectPick => {
|
probe::ObjectPick => {
|
||||||
let trait_def_id = pick.item.container.id();
|
let trait_def_id = pick.item.container_id(self.tcx);
|
||||||
self.extract_existential_trait_ref(self_ty, |this, object_ty, principal| {
|
self.extract_existential_trait_ref(self_ty, |this, object_ty, principal| {
|
||||||
// The object data has no entry for the Self
|
// The object data has no entry for the Self
|
||||||
// Type. For the purposes of this method call, we
|
// Type. For the purposes of this method call, we
|
||||||
|
@ -273,7 +273,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
probe::TraitPick => {
|
probe::TraitPick => {
|
||||||
let trait_def_id = pick.item.container.id();
|
let trait_def_id = pick.item.container_id(self.tcx);
|
||||||
|
|
||||||
// Make a trait reference `$0 : Trait<$1...$n>`
|
// Make a trait reference `$0 : Trait<$1...$n>`
|
||||||
// consisting entirely of type variables. Later on in
|
// consisting entirely of type variables. Later on in
|
||||||
|
@ -540,15 +540,14 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
|
||||||
|
|
||||||
fn enforce_illegal_method_limitations(&self, pick: &probe::Pick<'_>) {
|
fn enforce_illegal_method_limitations(&self, pick: &probe::Pick<'_>) {
|
||||||
// Disallow calls to the method `drop` defined in the `Drop` trait.
|
// Disallow calls to the method `drop` defined in the `Drop` trait.
|
||||||
match pick.item.container {
|
if let Some(trait_def_id) = pick.item.trait_container(self.tcx) {
|
||||||
ty::TraitContainer(trait_def_id) => callee::check_legal_trait_for_method_call(
|
callee::check_legal_trait_for_method_call(
|
||||||
self.tcx,
|
self.tcx,
|
||||||
self.span,
|
self.span,
|
||||||
Some(self.self_expr.span),
|
Some(self.self_expr.span),
|
||||||
self.call_expr.span,
|
self.call_expr.span,
|
||||||
trait_def_id,
|
trait_def_id,
|
||||||
),
|
)
|
||||||
ty::ImplContainer(..) => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -231,7 +231,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
ProbeScope::AllTraits,
|
ProbeScope::AllTraits,
|
||||||
) {
|
) {
|
||||||
// If we find a different result the caller probably forgot to import a trait.
|
// If we find a different result the caller probably forgot to import a trait.
|
||||||
Ok(ref new_pick) if *new_pick != pick => vec![new_pick.item.container.id()],
|
Ok(ref new_pick) if *new_pick != pick => vec![new_pick.item.container_id(self.tcx)],
|
||||||
Err(Ambiguity(ref sources)) => sources
|
Err(Ambiguity(ref sources)) => sources
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|source| {
|
.filter_map(|source| {
|
||||||
|
|
|
@ -148,7 +148,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
let trait_name = self.trait_path_or_bare_name(
|
let trait_name = self.trait_path_or_bare_name(
|
||||||
span,
|
span,
|
||||||
call_expr.hir_id,
|
call_expr.hir_id,
|
||||||
pick.item.container.id(),
|
pick.item.container_id(self.tcx),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut lint = lint.build(&format!(
|
let mut lint = lint.build(&format!(
|
||||||
|
@ -261,8 +261,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
self.tcx.struct_span_lint_hir(RUST_2021_PRELUDE_COLLISIONS, expr_id, span, |lint| {
|
self.tcx.struct_span_lint_hir(RUST_2021_PRELUDE_COLLISIONS, expr_id, span, |lint| {
|
||||||
// "type" refers to either a type or, more likely, a trait from which
|
// "type" refers to either a type or, more likely, a trait from which
|
||||||
// the associated function or method is from.
|
// the associated function or method is from.
|
||||||
let trait_path = self.trait_path_or_bare_name(span, expr_id, pick.item.container.id());
|
let container_id = pick.item.container_id(self.tcx);
|
||||||
let trait_generics = self.tcx.generics_of(pick.item.container.id());
|
let trait_path = self.trait_path_or_bare_name(span, expr_id, container_id);
|
||||||
|
let trait_generics = self.tcx.generics_of(container_id);
|
||||||
|
|
||||||
let trait_name =
|
let trait_name =
|
||||||
if trait_generics.params.len() <= trait_generics.has_self as usize {
|
if trait_generics.params.len() <= trait_generics.has_self as usize {
|
||||||
|
|
|
@ -592,8 +592,10 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
||||||
fn push_candidate(&mut self, candidate: Candidate<'tcx>, is_inherent: bool) {
|
fn push_candidate(&mut self, candidate: Candidate<'tcx>, is_inherent: bool) {
|
||||||
let is_accessible = if let Some(name) = self.method_name {
|
let is_accessible = if let Some(name) = self.method_name {
|
||||||
let item = candidate.item;
|
let item = candidate.item;
|
||||||
let def_scope =
|
let def_scope = self
|
||||||
self.tcx.adjust_ident_and_get_scope(name, item.container.id(), self.body_id).1;
|
.tcx
|
||||||
|
.adjust_ident_and_get_scope(name, item.container_id(self.tcx), self.body_id)
|
||||||
|
.1;
|
||||||
item.visibility(self.tcx).is_accessible_from(def_scope, self.tcx)
|
item.visibility(self.tcx).is_accessible_from(def_scope, self.tcx)
|
||||||
} else {
|
} else {
|
||||||
true
|
true
|
||||||
|
@ -1025,7 +1027,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
||||||
self.assemble_extension_candidates_for_all_traits();
|
self.assemble_extension_candidates_for_all_traits();
|
||||||
|
|
||||||
let out_of_scope_traits = match self.pick_core() {
|
let out_of_scope_traits = match self.pick_core() {
|
||||||
Some(Ok(p)) => vec![p.item.container.id()],
|
Some(Ok(p)) => vec![p.item.container_id(self.tcx)],
|
||||||
//Some(Ok(p)) => p.iter().map(|p| p.item.container().id()).collect(),
|
//Some(Ok(p)) => p.iter().map(|p| p.item.container().id()).collect(),
|
||||||
Some(Err(MethodError::Ambiguity(v))) => v
|
Some(Err(MethodError::Ambiguity(v))) => v
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -1387,7 +1389,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
||||||
self.tcx.def_path_str(stable_pick.item.def_id),
|
self.tcx.def_path_str(stable_pick.item.def_id),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
(ty::AssocKind::Const, ty::AssocItemContainer::TraitContainer(def_id)) => {
|
(ty::AssocKind::Const, ty::AssocItemContainer::TraitContainer) => {
|
||||||
|
let def_id = stable_pick.item.container_id(self.tcx);
|
||||||
diag.span_suggestion(
|
diag.span_suggestion(
|
||||||
self.span,
|
self.span,
|
||||||
"use the fully qualified path to the associated const",
|
"use the fully qualified path to the associated const",
|
||||||
|
@ -1429,9 +1432,11 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
||||||
|
|
||||||
fn candidate_source(&self, candidate: &Candidate<'tcx>, self_ty: Ty<'tcx>) -> CandidateSource {
|
fn candidate_source(&self, candidate: &Candidate<'tcx>, self_ty: Ty<'tcx>) -> CandidateSource {
|
||||||
match candidate.kind {
|
match candidate.kind {
|
||||||
InherentImplCandidate(..) => CandidateSource::Impl(candidate.item.container.id()),
|
InherentImplCandidate(..) => {
|
||||||
|
CandidateSource::Impl(candidate.item.container_id(self.tcx))
|
||||||
|
}
|
||||||
ObjectCandidate | WhereClauseCandidate(_) => {
|
ObjectCandidate | WhereClauseCandidate(_) => {
|
||||||
CandidateSource::Trait(candidate.item.container.id())
|
CandidateSource::Trait(candidate.item.container_id(self.tcx))
|
||||||
}
|
}
|
||||||
TraitCandidate(trait_ref) => self.probe(|_| {
|
TraitCandidate(trait_ref) => self.probe(|_| {
|
||||||
let _ = self
|
let _ = self
|
||||||
|
@ -1444,7 +1449,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
||||||
// to that impl.
|
// to that impl.
|
||||||
CandidateSource::Impl(impl_data.impl_def_id)
|
CandidateSource::Impl(impl_data.impl_def_id)
|
||||||
}
|
}
|
||||||
_ => CandidateSource::Trait(candidate.item.container.id()),
|
_ => CandidateSource::Trait(candidate.item.container_id(self.tcx)),
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
@ -1502,7 +1507,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
||||||
debug!("xform_ret_ty after normalization: {:?}", xform_ret_ty);
|
debug!("xform_ret_ty after normalization: {:?}", xform_ret_ty);
|
||||||
|
|
||||||
// Check whether the impl imposes obligations we have to worry about.
|
// Check whether the impl imposes obligations we have to worry about.
|
||||||
let impl_def_id = probe.item.container.id();
|
let impl_def_id = probe.item.container_id(self.tcx);
|
||||||
let impl_bounds = self.tcx.predicates_of(impl_def_id);
|
let impl_bounds = self.tcx.predicates_of(impl_def_id);
|
||||||
let impl_bounds = impl_bounds.instantiate(self.tcx, substs);
|
let impl_bounds = impl_bounds.instantiate(self.tcx, substs);
|
||||||
let traits::Normalized { value: impl_bounds, obligations: norm_obligations } =
|
let traits::Normalized { value: impl_bounds, obligations: norm_obligations } =
|
||||||
|
@ -1653,12 +1658,12 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
||||||
probes: &[(&Candidate<'tcx>, ProbeResult)],
|
probes: &[(&Candidate<'tcx>, ProbeResult)],
|
||||||
) -> Option<Pick<'tcx>> {
|
) -> Option<Pick<'tcx>> {
|
||||||
// Do all probes correspond to the same trait?
|
// Do all probes correspond to the same trait?
|
||||||
let container = probes[0].0.item.container;
|
let container = probes[0].0.item.trait_container(self.tcx)?;
|
||||||
if let ty::ImplContainer(_) = container {
|
for (p, _) in &probes[1..] {
|
||||||
return None;
|
let p_container = p.item.trait_container(self.tcx)?;
|
||||||
}
|
if p_container != container {
|
||||||
if probes[1..].iter().any(|&(p, _)| p.item.container != container) {
|
return None;
|
||||||
return None;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: check the return type here somehow.
|
// FIXME: check the return type here somehow.
|
||||||
|
|
|
@ -1789,7 +1789,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
// We point at the method, but we just skip the rest of the check for arbitrary
|
// We point at the method, but we just skip the rest of the check for arbitrary
|
||||||
// self types and rely on the suggestion to `use` the trait from
|
// self types and rely on the suggestion to `use` the trait from
|
||||||
// `suggest_valid_traits`.
|
// `suggest_valid_traits`.
|
||||||
let did = Some(pick.item.container.id());
|
let did = Some(pick.item.container_id(self.tcx));
|
||||||
let skip = skippable.contains(&did);
|
let skip = skippable.contains(&did);
|
||||||
if pick.autoderefs == 0 && !skip {
|
if pick.autoderefs == 0 && !skip {
|
||||||
err.span_label(
|
err.span_label(
|
||||||
|
@ -1825,7 +1825,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
debug!("try_alt_rcvr: pick candidate {:?}", pick);
|
debug!("try_alt_rcvr: pick candidate {:?}", pick);
|
||||||
let did = Some(pick.item.container.id());
|
let did = Some(pick.item.container_id(self.tcx));
|
||||||
// We don't want to suggest a container type when the missing
|
// We don't want to suggest a container type when the missing
|
||||||
// method is `.clone()` or `.deref()` otherwise we'd suggest
|
// method is `.clone()` or `.deref()` otherwise we'd suggest
|
||||||
// `Arc::new(foo).clone()`, which is far from what the user wants.
|
// `Arc::new(foo).clone()`, which is far from what the user wants.
|
||||||
|
|
|
@ -977,11 +977,14 @@ fn check_associated_item(
|
||||||
let item = tcx.associated_item(item_id);
|
let item = tcx.associated_item(item_id);
|
||||||
|
|
||||||
let (mut implied_bounds, self_ty) = match item.container {
|
let (mut implied_bounds, self_ty) = match item.container {
|
||||||
ty::TraitContainer(_) => (FxHashSet::default(), tcx.types.self_param),
|
ty::TraitContainer => (FxHashSet::default(), tcx.types.self_param),
|
||||||
ty::ImplContainer(def_id) => (
|
ty::ImplContainer => {
|
||||||
impl_implied_bounds(tcx, wfcx.param_env, def_id.expect_local(), span),
|
let def_id = item.container_id(tcx);
|
||||||
tcx.type_of(def_id),
|
(
|
||||||
),
|
impl_implied_bounds(tcx, wfcx.param_env, def_id.expect_local(), span),
|
||||||
|
tcx.type_of(def_id),
|
||||||
|
)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
match item.kind {
|
match item.kind {
|
||||||
|
@ -1004,7 +1007,7 @@ fn check_associated_item(
|
||||||
check_method_receiver(wfcx, hir_sig, item, self_ty);
|
check_method_receiver(wfcx, hir_sig, item, self_ty);
|
||||||
}
|
}
|
||||||
ty::AssocKind::Type => {
|
ty::AssocKind::Type => {
|
||||||
if let ty::AssocItemContainer::TraitContainer(_) = item.container {
|
if let ty::AssocItemContainer::TraitContainer = item.container {
|
||||||
check_associated_type_bounds(wfcx, item, span)
|
check_associated_type_bounds(wfcx, item, span)
|
||||||
}
|
}
|
||||||
if item.defaultness(tcx).has_value() {
|
if item.defaultness(tcx).has_value() {
|
||||||
|
|
|
@ -2433,7 +2433,7 @@ fn explicit_predicates_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> ty::Generic
|
||||||
// supertrait).
|
// supertrait).
|
||||||
if let ty::Projection(projection) = ty.kind() {
|
if let ty::Projection(projection) = ty.kind() {
|
||||||
projection.substs == trait_identity_substs
|
projection.substs == trait_identity_substs
|
||||||
&& tcx.associated_item(projection.item_def_id).container.id() == def_id
|
&& tcx.associated_item(projection.item_def_id).container_id(tcx) == def_id
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
@ -3264,7 +3264,7 @@ fn asm_target_features<'tcx>(tcx: TyCtxt<'tcx>, did: DefId) -> &'tcx FxHashSet<S
|
||||||
/// applied to the method prototype.
|
/// applied to the method prototype.
|
||||||
fn should_inherit_track_caller(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
|
fn should_inherit_track_caller(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
|
||||||
if let Some(impl_item) = tcx.opt_associated_item(def_id)
|
if let Some(impl_item) = tcx.opt_associated_item(def_id)
|
||||||
&& let ty::AssocItemContainer::ImplContainer(_) = impl_item.container
|
&& let ty::AssocItemContainer::ImplContainer = impl_item.container
|
||||||
&& let Some(trait_item) = impl_item.trait_item_def_id
|
&& let Some(trait_item) = impl_item.trait_item_def_id
|
||||||
{
|
{
|
||||||
return tcx
|
return tcx
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::astconv::AstConv;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_infer::traits::util;
|
use rustc_infer::traits::util;
|
||||||
use rustc_middle::ty::subst::InternalSubsts;
|
use rustc_middle::ty::subst::InternalSubsts;
|
||||||
use rustc_middle::ty::{self, TyCtxt};
|
use rustc_middle::ty::{self, DefIdTree, TyCtxt};
|
||||||
use rustc_span::def_id::DefId;
|
use rustc_span::def_id::DefId;
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ fn associated_type_bounds<'tcx>(
|
||||||
// Associated types are implicitly sized unless a `?Sized` bound is found
|
// Associated types are implicitly sized unless a `?Sized` bound is found
|
||||||
<dyn AstConv<'_>>::add_implicitly_sized(&icx, &mut bounds, ast_bounds, None, span);
|
<dyn AstConv<'_>>::add_implicitly_sized(&icx, &mut bounds, ast_bounds, None, span);
|
||||||
|
|
||||||
let trait_def_id = tcx.associated_item(assoc_item_def_id).container.id();
|
let trait_def_id = tcx.parent(assoc_item_def_id);
|
||||||
let trait_predicates = tcx.trait_explicit_predicates_and_bounds(trait_def_id.expect_local());
|
let trait_predicates = tcx.trait_explicit_predicates_and_bounds(trait_def_id.expect_local());
|
||||||
|
|
||||||
let bounds_from_parent = trait_predicates.predicates.iter().copied().filter(|(pred, _)| {
|
let bounds_from_parent = trait_predicates.predicates.iter().copied().filter(|(pred, _)| {
|
||||||
|
|
|
@ -2,7 +2,7 @@ use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_hir::def::DefKind;
|
use rustc_hir::def::DefKind;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst};
|
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst};
|
||||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
use rustc_middle::ty::{self, DefIdTree, Ty, TyCtxt};
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
|
||||||
use super::explicit::ExplicitPredicatesMap;
|
use super::explicit::ExplicitPredicatesMap;
|
||||||
|
@ -202,7 +202,7 @@ fn insert_required_predicates_to_be_wf<'tcx>(
|
||||||
debug!("Projection");
|
debug!("Projection");
|
||||||
check_explicit_predicates(
|
check_explicit_predicates(
|
||||||
tcx,
|
tcx,
|
||||||
tcx.associated_item(obj.item_def_id).container.id(),
|
tcx.parent(obj.item_def_id),
|
||||||
obj.substs,
|
obj.substs,
|
||||||
required_predicates,
|
required_predicates,
|
||||||
explicit_map,
|
explicit_map,
|
||||||
|
|
|
@ -1139,8 +1139,8 @@ impl<'tcx> Clean<'tcx, Item> for ty::AssocItem {
|
||||||
let ty = clean_middle_ty(tcx.type_of(self.def_id), cx, Some(self.def_id));
|
let ty = clean_middle_ty(tcx.type_of(self.def_id), cx, Some(self.def_id));
|
||||||
|
|
||||||
let provided = match self.container {
|
let provided = match self.container {
|
||||||
ty::ImplContainer(_) => true,
|
ty::ImplContainer => true,
|
||||||
ty::TraitContainer(_) => tcx.impl_defaultness(self.def_id).has_value(),
|
ty::TraitContainer => tcx.impl_defaultness(self.def_id).has_value(),
|
||||||
};
|
};
|
||||||
if provided {
|
if provided {
|
||||||
AssocConstItem(ty, ConstantKind::Extern { def_id: self.def_id })
|
AssocConstItem(ty, ConstantKind::Extern { def_id: self.def_id })
|
||||||
|
@ -1159,8 +1159,8 @@ impl<'tcx> Clean<'tcx, Item> for ty::AssocItem {
|
||||||
|
|
||||||
if self.fn_has_self_parameter {
|
if self.fn_has_self_parameter {
|
||||||
let self_ty = match self.container {
|
let self_ty = match self.container {
|
||||||
ty::ImplContainer(def_id) => tcx.type_of(def_id),
|
ty::ImplContainer => tcx.type_of(self.container_id(tcx)),
|
||||||
ty::TraitContainer(_) => tcx.types.self_param,
|
ty::TraitContainer => tcx.types.self_param,
|
||||||
};
|
};
|
||||||
let self_arg_ty = sig.input(0).skip_binder();
|
let self_arg_ty = sig.input(0).skip_binder();
|
||||||
if self_arg_ty == self_ty {
|
if self_arg_ty == self_ty {
|
||||||
|
@ -1178,13 +1178,13 @@ impl<'tcx> Clean<'tcx, Item> for ty::AssocItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
let provided = match self.container {
|
let provided = match self.container {
|
||||||
ty::ImplContainer(_) => true,
|
ty::ImplContainer => true,
|
||||||
ty::TraitContainer(_) => self.defaultness(tcx).has_value(),
|
ty::TraitContainer => self.defaultness(tcx).has_value(),
|
||||||
};
|
};
|
||||||
if provided {
|
if provided {
|
||||||
let defaultness = match self.container {
|
let defaultness = match self.container {
|
||||||
ty::ImplContainer(_) => Some(self.defaultness(tcx)),
|
ty::ImplContainer => Some(self.defaultness(tcx)),
|
||||||
ty::TraitContainer(_) => None,
|
ty::TraitContainer => None,
|
||||||
};
|
};
|
||||||
MethodItem(Box::new(Function { generics, decl }), defaultness)
|
MethodItem(Box::new(Function { generics, decl }), defaultness)
|
||||||
} else {
|
} else {
|
||||||
|
@ -1215,7 +1215,7 @@ impl<'tcx> Clean<'tcx, Item> for ty::AssocItem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let ty::TraitContainer(_) = self.container {
|
if let ty::TraitContainer = self.container {
|
||||||
let bounds = tcx.explicit_item_bounds(self.def_id);
|
let bounds = tcx.explicit_item_bounds(self.def_id);
|
||||||
let predicates = ty::GenericPredicates { parent: None, predicates: bounds };
|
let predicates = ty::GenericPredicates { parent: None, predicates: bounds };
|
||||||
let mut generics =
|
let mut generics =
|
||||||
|
@ -1232,7 +1232,7 @@ impl<'tcx> Clean<'tcx, Item> for ty::AssocItem {
|
||||||
if assoc.name != my_name {
|
if assoc.name != my_name {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if trait_.def_id() != self.container.id() {
|
if trait_.def_id() != self.container_id(tcx) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
match **self_type {
|
match **self_type {
|
||||||
|
@ -1356,7 +1356,7 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type
|
||||||
}
|
}
|
||||||
|
|
||||||
let trait_segments = &p.segments[..p.segments.len() - 1];
|
let trait_segments = &p.segments[..p.segments.len() - 1];
|
||||||
let trait_def = cx.tcx.associated_item(p.res.def_id()).container.id();
|
let trait_def = cx.tcx.associated_item(p.res.def_id()).container_id(cx.tcx);
|
||||||
let trait_ = self::Path {
|
let trait_ = self::Path {
|
||||||
res: Res::Def(DefKind::Trait, trait_def),
|
res: Res::Def(DefKind::Trait, trait_def),
|
||||||
segments: trait_segments.iter().map(|x| x.clean(cx)).collect(),
|
segments: trait_segments.iter().map(|x| x.clean(cx)).collect(),
|
||||||
|
|
|
@ -220,9 +220,11 @@ fn check_sig<'tcx>(cx: &LateContext<'tcx>, closure_ty: Ty<'tcx>, call_ty: Ty<'tc
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_ufcs_type_name(cx: &LateContext<'_>, method_def_id: DefId) -> String {
|
fn get_ufcs_type_name(cx: &LateContext<'_>, method_def_id: DefId) -> String {
|
||||||
match cx.tcx.associated_item(method_def_id).container {
|
let assoc_item = cx.tcx.associated_item(method_def_id);
|
||||||
ty::TraitContainer(def_id) => cx.tcx.def_path_str(def_id),
|
let def_id = assoc_item.container_id(cx.tcx);
|
||||||
ty::ImplContainer(def_id) => {
|
match assoc_item.container {
|
||||||
|
ty::TraitContainer => cx.tcx.def_path_str(def_id),
|
||||||
|
ty::ImplContainer => {
|
||||||
let ty = cx.tcx.type_of(def_id);
|
let ty = cx.tcx.type_of(def_id);
|
||||||
match ty.kind() {
|
match ty.kind() {
|
||||||
ty::Adt(adt, _) => cx.tcx.def_path_str(adt.did()),
|
ty::Adt(adt, _) => cx.tcx.def_path_str(adt.did()),
|
||||||
|
|
|
@ -10,7 +10,7 @@ use clippy_utils::diagnostics::span_lint;
|
||||||
use rustc_ast::ast;
|
use rustc_ast::ast;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||||
use rustc_middle::ty::{self, DefIdTree};
|
use rustc_middle::ty::DefIdTree;
|
||||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||||
use rustc_span::def_id::CRATE_DEF_ID;
|
use rustc_span::def_id::CRATE_DEF_ID;
|
||||||
use rustc_span::source_map::Span;
|
use rustc_span::source_map::Span;
|
||||||
|
@ -153,13 +153,12 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
|
||||||
|
|
||||||
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) {
|
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) {
|
||||||
// If the method is an impl for a trait, don't doc.
|
// If the method is an impl for a trait, don't doc.
|
||||||
match cx.tcx.associated_item(impl_item.def_id).container {
|
if let Some(cid) = cx.tcx.associated_item(impl_item.def_id).impl_container(cx.tcx) {
|
||||||
ty::TraitContainer(_) => return,
|
if cx.tcx.impl_trait_ref(cid).is_some() {
|
||||||
ty::ImplContainer(cid) => {
|
return;
|
||||||
if cx.tcx.impl_trait_ref(cid).is_some() {
|
}
|
||||||
return;
|
} else {
|
||||||
}
|
return;
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let (article, desc) = cx.tcx.article_and_description(impl_item.def_id.to_def_id());
|
let (article, desc) = cx.tcx.article_and_description(impl_item.def_id.to_def_id());
|
||||||
|
|
|
@ -151,9 +151,11 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
|
||||||
hir::ImplItemKind::Const(..) | hir::ImplItemKind::TyAlias(_) => return,
|
hir::ImplItemKind::Const(..) | hir::ImplItemKind::TyAlias(_) => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
let trait_def_id = match cx.tcx.associated_item(impl_item.def_id).container {
|
let assoc_item = cx.tcx.associated_item(impl_item.def_id);
|
||||||
TraitContainer(cid) => Some(cid),
|
let container_id = assoc_item.container_id(cx.tcx);
|
||||||
ImplContainer(cid) => cx.tcx.impl_trait_ref(cid).map(|t| t.def_id),
|
let trait_def_id = match assoc_item.container {
|
||||||
|
TraitContainer => Some(container_id),
|
||||||
|
ImplContainer => cx.tcx.impl_trait_ref(container_id).map(|t| t.def_id),
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(trait_def_id) = trait_def_id {
|
if let Some(trait_def_id) = trait_def_id {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue