Use () for inherent_impls.
This commit is contained in:
parent
3aa6f3e8f5
commit
837f3e3e67
@ -944,13 +944,12 @@ impl EncodeContext<'a, 'tcx> {
|
|||||||
record!(self.tables.super_predicates[def_id] <- self.tcx.super_predicates_of(def_id));
|
record!(self.tables.super_predicates[def_id] <- self.tcx.super_predicates_of(def_id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let inherent_impls = tcx.crate_inherent_impls(LOCAL_CRATE);
|
let inherent_impls = tcx.crate_inherent_impls(());
|
||||||
for (def_id, implementations) in inherent_impls.inherent_impls.iter() {
|
for (def_id, implementations) in inherent_impls.inherent_impls.iter() {
|
||||||
assert!(def_id.is_local());
|
|
||||||
if implementations.is_empty() {
|
if implementations.is_empty() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
record!(self.tables.inherent_impls[def_id] <- implementations.iter().map(|&def_id| {
|
record!(self.tables.inherent_impls[def_id.to_def_id()] <- implementations.iter().map(|&def_id| {
|
||||||
assert!(def_id.is_local());
|
assert!(def_id.is_local());
|
||||||
def_id.index
|
def_id.index
|
||||||
}));
|
}));
|
||||||
|
@ -740,18 +740,15 @@ rustc_queries! {
|
|||||||
|
|
||||||
/// Gets a complete map from all types to their inherent impls.
|
/// Gets a complete map from all types to their inherent impls.
|
||||||
/// Not meant to be used directly outside of coherence.
|
/// Not meant to be used directly outside of coherence.
|
||||||
/// (Defined only for `LOCAL_CRATE`.)
|
query crate_inherent_impls(k: ()) -> CrateInherentImpls {
|
||||||
query crate_inherent_impls(k: CrateNum)
|
|
||||||
-> CrateInherentImpls {
|
|
||||||
storage(ArenaCacheSelector<'tcx>)
|
storage(ArenaCacheSelector<'tcx>)
|
||||||
eval_always
|
eval_always
|
||||||
desc { "all inherent impls defined in crate `{:?}`", k }
|
desc { "all inherent impls defined in crate" }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks all types in the crate for overlap in their inherent impls. Reports errors.
|
/// Checks all types in the crate for overlap in their inherent impls. Reports errors.
|
||||||
/// Not meant to be used directly outside of coherence.
|
/// Not meant to be used directly outside of coherence.
|
||||||
/// (Defined only for `LOCAL_CRATE`.)
|
query crate_inherent_impls_overlap_check(_: ())
|
||||||
query crate_inherent_impls_overlap_check(_: CrateNum)
|
|
||||||
-> () {
|
-> () {
|
||||||
eval_always
|
eval_always
|
||||||
desc { "check for overlap between inherent impls defined in this crate" }
|
desc { "check for overlap between inherent impls defined in this crate" }
|
||||||
|
@ -36,7 +36,7 @@ use rustc_data_structures::sync::{self, par_iter, ParallelIterator};
|
|||||||
use rustc_data_structures::tagged_ptr::CopyTaggedPtr;
|
use rustc_data_structures::tagged_ptr::CopyTaggedPtr;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
|
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
|
||||||
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, CRATE_DEF_INDEX};
|
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LocalDefIdMap, CRATE_DEF_INDEX};
|
||||||
use rustc_hir::{Constness, Node};
|
use rustc_hir::{Constness, Node};
|
||||||
use rustc_macros::HashStable;
|
use rustc_macros::HashStable;
|
||||||
use rustc_span::hygiene::ExpnId;
|
use rustc_span::hygiene::ExpnId;
|
||||||
@ -1983,7 +1983,7 @@ pub fn provide(providers: &mut ty::query::Providers) {
|
|||||||
/// (constructing this map requires touching the entire crate).
|
/// (constructing this map requires touching the entire crate).
|
||||||
#[derive(Clone, Debug, Default, HashStable)]
|
#[derive(Clone, Debug, Default, HashStable)]
|
||||||
pub struct CrateInherentImpls {
|
pub struct CrateInherentImpls {
|
||||||
pub inherent_impls: DefIdMap<Vec<DefId>>,
|
pub inherent_impls: LocalDefIdMap<Vec<DefId>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, HashStable)]
|
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, HashStable)]
|
||||||
|
@ -9,16 +9,14 @@
|
|||||||
|
|
||||||
use rustc_errors::struct_span_err;
|
use rustc_errors::struct_span_err;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
|
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||||
use rustc_hir::itemlikevisit::ItemLikeVisitor;
|
use rustc_hir::itemlikevisit::ItemLikeVisitor;
|
||||||
use rustc_middle::ty::{self, CrateInherentImpls, TyCtxt};
|
use rustc_middle::ty::{self, CrateInherentImpls, TyCtxt};
|
||||||
|
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
|
||||||
/// On-demand query: yields a map containing all types mapped to their inherent impls.
|
/// On-demand query: yields a map containing all types mapped to their inherent impls.
|
||||||
pub fn crate_inherent_impls(tcx: TyCtxt<'_>, crate_num: CrateNum) -> CrateInherentImpls {
|
pub fn crate_inherent_impls(tcx: TyCtxt<'_>, (): ()) -> CrateInherentImpls {
|
||||||
assert_eq!(crate_num, LOCAL_CRATE);
|
|
||||||
|
|
||||||
let krate = tcx.hir().krate();
|
let krate = tcx.hir().krate();
|
||||||
let mut collect = InherentCollect { tcx, impls_map: Default::default() };
|
let mut collect = InherentCollect { tcx, impls_map: Default::default() };
|
||||||
krate.visit_all_item_likes(&mut collect);
|
krate.visit_all_item_likes(&mut collect);
|
||||||
@ -27,9 +25,9 @@ pub fn crate_inherent_impls(tcx: TyCtxt<'_>, crate_num: CrateNum) -> CrateInhere
|
|||||||
|
|
||||||
/// On-demand query: yields a vector of the inherent impls for a specific type.
|
/// On-demand query: yields a vector of the inherent impls for a specific type.
|
||||||
pub fn inherent_impls(tcx: TyCtxt<'_>, ty_def_id: DefId) -> &[DefId] {
|
pub fn inherent_impls(tcx: TyCtxt<'_>, ty_def_id: DefId) -> &[DefId] {
|
||||||
assert!(ty_def_id.is_local());
|
let ty_def_id = ty_def_id.expect_local();
|
||||||
|
|
||||||
let crate_map = tcx.crate_inherent_impls(ty_def_id.krate);
|
let crate_map = tcx.crate_inherent_impls(());
|
||||||
match crate_map.inherent_impls.get(&ty_def_id) {
|
match crate_map.inherent_impls.get(&ty_def_id) {
|
||||||
Some(v) => &v[..],
|
Some(v) => &v[..],
|
||||||
None => &[],
|
None => &[],
|
||||||
@ -364,7 +362,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
|||||||
|
|
||||||
impl InherentCollect<'tcx> {
|
impl InherentCollect<'tcx> {
|
||||||
fn check_def_id(&mut self, item: &hir::Item<'_>, def_id: DefId) {
|
fn check_def_id(&mut self, item: &hir::Item<'_>, def_id: DefId) {
|
||||||
if def_id.is_local() {
|
if let Some(def_id) = def_id.as_local() {
|
||||||
// Add the implementation to the mapping from implementation to base
|
// Add the implementation to the mapping from implementation to base
|
||||||
// type def ID, if there is a base type for this implementation and
|
// type def ID, if there is a base type for this implementation and
|
||||||
// the implementation does not have any associated traits.
|
// the implementation does not have any associated traits.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
use rustc_errors::struct_span_err;
|
use rustc_errors::struct_span_err;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::itemlikevisit::ItemLikeVisitor;
|
use rustc_hir::itemlikevisit::ItemLikeVisitor;
|
||||||
use rustc_middle::ty::{self, TyCtxt};
|
use rustc_middle::ty::{self, TyCtxt};
|
||||||
use rustc_span::Symbol;
|
use rustc_span::Symbol;
|
||||||
@ -9,8 +9,7 @@ use rustc_trait_selection::traits::{self, SkipLeakCheck};
|
|||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use std::collections::hash_map::Entry;
|
use std::collections::hash_map::Entry;
|
||||||
|
|
||||||
pub fn crate_inherent_impls_overlap_check(tcx: TyCtxt<'_>, crate_num: CrateNum) {
|
pub fn crate_inherent_impls_overlap_check(tcx: TyCtxt<'_>, (): ()) {
|
||||||
assert_eq!(crate_num, LOCAL_CRATE);
|
|
||||||
let krate = tcx.hir().krate();
|
let krate = tcx.hir().krate();
|
||||||
krate.visit_all_item_likes(&mut InherentOverlapChecker { tcx });
|
krate.visit_all_item_likes(&mut InherentOverlapChecker { tcx });
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
// mappings. That mapping code resides here.
|
// mappings. That mapping code resides here.
|
||||||
|
|
||||||
use rustc_errors::struct_span_err;
|
use rustc_errors::struct_span_err;
|
||||||
use rustc_hir::def_id::{DefId, LocalDefId, LOCAL_CRATE};
|
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||||
use rustc_middle::ty::query::Providers;
|
use rustc_middle::ty::query::Providers;
|
||||||
use rustc_middle::ty::{self, TyCtxt, TypeFoldable};
|
use rustc_middle::ty::{self, TyCtxt, TypeFoldable};
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
@ -203,8 +203,8 @@ pub fn check_coherence(tcx: TyCtxt<'_>) {
|
|||||||
tcx.sess.time("orphan_checking", || orphan::check(tcx));
|
tcx.sess.time("orphan_checking", || orphan::check(tcx));
|
||||||
|
|
||||||
// these queries are executed for side-effects (error reporting):
|
// these queries are executed for side-effects (error reporting):
|
||||||
tcx.ensure().crate_inherent_impls(LOCAL_CRATE);
|
tcx.ensure().crate_inherent_impls(());
|
||||||
tcx.ensure().crate_inherent_impls_overlap_check(LOCAL_CRATE);
|
tcx.ensure().crate_inherent_impls_overlap_check(());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks whether an impl overlaps with the automatic `impl Trait for dyn Trait`.
|
/// Checks whether an impl overlaps with the automatic `impl Trait for dyn Trait`.
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
use clippy_utils::diagnostics::span_lint_and_then;
|
use clippy_utils::diagnostics::span_lint_and_then;
|
||||||
use clippy_utils::in_macro;
|
use clippy_utils::in_macro;
|
||||||
use rustc_hir::def_id::DefIdMap;
|
use rustc_hir::def_id::DefIdMap;
|
||||||
use rustc_hir::{def_id, Crate, Impl, Item, ItemKind};
|
use rustc_hir::{Crate, Impl, Item, ItemKind};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
@ -68,7 +68,7 @@ impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl {
|
|||||||
fn check_crate_post(&mut self, cx: &LateContext<'tcx>, krate: &'tcx Crate<'_>) {
|
fn check_crate_post(&mut self, cx: &LateContext<'tcx>, krate: &'tcx Crate<'_>) {
|
||||||
if !krate.items.is_empty() {
|
if !krate.items.is_empty() {
|
||||||
// Retrieve all inherent implementations from the crate, grouped by type
|
// Retrieve all inherent implementations from the crate, grouped by type
|
||||||
for impls in cx.tcx.crate_inherent_impls(def_id::LOCAL_CRATE).inherent_impls.values() {
|
for impls in cx.tcx.crate_inherent_impls(()).inherent_impls.values() {
|
||||||
// Filter out implementations that have generic params (type or lifetime)
|
// Filter out implementations that have generic params (type or lifetime)
|
||||||
let mut impl_spans = impls.iter().filter_map(|impl_def| self.impls.get(impl_def));
|
let mut impl_spans = impls.iter().filter_map(|impl_def| self.impls.get(impl_def));
|
||||||
if let Some(initial_span) = impl_spans.next() {
|
if let Some(initial_span) = impl_spans.next() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user