Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Use HirId in TraitCandidate.
  • Loading branch information
cjgillot committed Feb 13, 2020
commit 4706c38e17349793b2713947f81cfa1fd1f75ba3
1 change: 0 additions & 1 deletion src/librustc/ich/impls_hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ impl<'a> ToStableHashKey<StableHashingContext<'a>> for hir::TraitCandidate {

let import_keys = import_ids
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this method can just return the fields of TraitCandidate now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just leave it like this for now.

.iter()
.map(|node_id| hcx.node_to_hir_id(*node_id))
.map(|hir_id| (hcx.local_def_path_hash(hir_id.owner), hir_id.local_id))
.collect();
(hcx.def_path_hash(*def_id), import_keys)
Expand Down
1 change: 1 addition & 0 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,7 @@ impl<'tcx> TyCtxt<'tcx> {
for (k, v) in resolutions.trait_map {
let hir_id = hir.node_to_hir_id(k);
let map = trait_map.entry(hir_id.owner).or_default();
let v = v.into_iter().map(|tc| tc.node_to_hir_id(&hir.definitions())).collect();
map.insert(hir_id.local_id, StableVec::new(v));
}

Expand Down
20 changes: 19 additions & 1 deletion src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use rustc_data_structures::sync::{self, par_iter, Lrc, ParallelIterator};
use rustc_hir as hir;
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc_hir::{Constness, GlobMap, Node, TraitMap};
use rustc_hir::{Constness, GlobMap, Node};
use rustc_index::vec::{Idx, IndexVec};
use rustc_macros::HashStable;
use rustc_serialize::{self, Encodable, Encoder};
Expand All @@ -46,6 +46,7 @@ use rustc_target::abi::Align;
use syntax::ast::{self, Ident, Name};
use syntax::node_id::{NodeId, NodeMap, NodeSet};

use smallvec::SmallVec;
use std::cell::RefCell;
use std::cmp::{self, Ordering};
use std::fmt;
Expand Down Expand Up @@ -122,6 +123,23 @@ mod sty;

// Data types

#[derive(Clone, Debug)]
pub struct TraitCandidate {
pub def_id: DefId,
pub import_ids: SmallVec<[NodeId; 1]>,
}

impl TraitCandidate {
fn node_to_hir_id(self, definitions: &hir_map::Definitions) -> hir::TraitCandidate {
let TraitCandidate { def_id, import_ids } = self;
let import_ids =
import_ids.into_iter().map(|node_id| definitions.node_to_hir_id(node_id)).collect();
hir::TraitCandidate { def_id, import_ids }
}
}

pub type TraitMap = NodeMap<Vec<TraitCandidate>>;

pub struct ResolverOutputs {
pub definitions: hir_map::Definitions,
pub cstore: Box<CrateStoreDyn>,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_hir/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rustc_span::source_map::{SourceMap, Spanned};
use rustc_span::symbol::{kw, sym, Symbol};
use rustc_span::{MultiSpan, Span, DUMMY_SP};
use rustc_target::spec::abi::Abi;
use syntax::ast::{self, AsmDialect, CrateSugar, Ident, Name, NodeId};
use syntax::ast::{self, AsmDialect, CrateSugar, Ident, Name};
use syntax::ast::{AttrVec, Attribute, FloatTy, IntTy, Label, LitKind, StrStyle, UintTy};
pub use syntax::ast::{BorrowKind, ImplPolarity, IsAuto};
pub use syntax::ast::{CaptureBy, Movability, Mutability};
Expand Down Expand Up @@ -2610,7 +2610,7 @@ pub type CaptureModeMap = NodeMap<CaptureBy>;
#[derive(Clone, Debug)]
pub struct TraitCandidate {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could make this generic over the id instead of duplicating it.

pub def_id: DefId,
pub import_ids: SmallVec<[NodeId; 1]>,
pub import_ids: SmallVec<[HirId; 1]>,
}

// Trait method resolution
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ use crate::{path_names_to_string, BindingError, CrateLint, LexicalScopeBinding};
use crate::{Module, ModuleOrUniformRoot, NameBindingKind, ParentScope, PathResult};
use crate::{ResolutionError, Resolver, Segment, UseError};

use rustc::ty::TraitCandidate;
use rustc::{bug, lint, span_bug};
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_errors::DiagnosticId;
use rustc_hir::def::Namespace::{self, *};
use rustc_hir::def::{self, CtorKind, DefKind, PartialRes, PerNS};
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX};
use rustc_hir::TraitCandidate;
use rustc_span::symbol::{kw, sym};
use rustc_span::Span;
use smallvec::{smallvec, SmallVec};
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use rustc::lint;
use rustc::middle::cstore::{CrateStore, MetadataLoaderDyn};
use rustc::span_bug;
use rustc::ty::query::Providers;
use rustc::ty::{self, DefIdTree, ResolverOutputs};
use rustc::ty::{self, DefIdTree, ResolverOutputs, TraitMap};
use rustc_ast_pretty::pprust;
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
use rustc_data_structures::ptr_key::PtrKey;
Expand All @@ -32,8 +32,8 @@ use rustc_expand::base::SyntaxExtension;
use rustc_hir::def::Namespace::*;
use rustc_hir::def::{self, CtorOf, DefKind, NonMacroAttrKind, PartialRes};
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc_hir::GlobMap;
use rustc_hir::PrimTy::{self, Bool, Char, Float, Int, Str, Uint};
use rustc_hir::{GlobMap, TraitMap};
use rustc_metadata::creader::{CStore, CrateLoader};
use rustc_session::lint::{BuiltinLintDiagnostics, LintBuffer};
use rustc_session::Session;
Expand Down
15 changes: 6 additions & 9 deletions src/librustc_typeck/check/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -902,13 +902,10 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
for trait_candidate in applicable_traits.iter() {
let trait_did = trait_candidate.def_id;
if duplicates.insert(trait_did) {
let import_ids = trait_candidate
.import_ids
.iter()
.map(|node_id| self.fcx.tcx.hir().node_to_hir_id(*node_id))
.collect();
let result =
self.assemble_extension_candidates_for_trait(import_ids, trait_did);
let result = self.assemble_extension_candidates_for_trait(
&trait_candidate.import_ids,
trait_did,
);
result?;
}
}
Expand All @@ -920,7 +917,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
let mut duplicates = FxHashSet::default();
for trait_info in suggest::all_traits(self.tcx) {
if duplicates.insert(trait_info.def_id) {
self.assemble_extension_candidates_for_trait(smallvec![], trait_info.def_id)?;
self.assemble_extension_candidates_for_trait(&smallvec![], trait_info.def_id)?;
}
}
Ok(())
Expand Down Expand Up @@ -959,7 +956,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {

fn assemble_extension_candidates_for_trait(
&mut self,
import_ids: SmallVec<[hir::HirId; 1]>,
import_ids: &SmallVec<[hir::HirId; 1]>,
trait_def_id: DefId,
) -> Result<(), MethodError<'tcx>> {
debug!("assemble_extension_candidates_for_trait(trait_def_id={:?})", trait_def_id);
Expand Down