Skip to content

Commit 9bde6b6

Browse files
committed
rustc: expose the common DUMMY_SP query case as tcx methods.
1 parent 612bb1f commit 9bde6b6

File tree

18 files changed

+39
-108
lines changed

18 files changed

+39
-108
lines changed

src/librustc/lint/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use std::fmt;
4343
use syntax::attr;
4444
use syntax::ast;
4545
use syntax::symbol::Symbol;
46-
use syntax_pos::{DUMMY_SP, MultiSpan, Span};
46+
use syntax_pos::{MultiSpan, Span};
4747
use errors::{self, Diagnostic, DiagnosticBuilder};
4848
use hir;
4949
use hir::def_id::LOCAL_CRATE;
@@ -1234,7 +1234,7 @@ fn check_lint_name_cmdline(sess: &Session, lint_cx: &LintStore,
12341234
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
12351235
let _task = tcx.dep_graph.in_task(DepNode::LateLintCheck);
12361236

1237-
let access_levels = &ty::queries::privacy_access_levels::get(tcx, DUMMY_SP, LOCAL_CRATE);
1237+
let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE);
12381238

12391239
let krate = tcx.hir.krate();
12401240

src/librustc/middle/dead.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use util::nodemap::FxHashSet;
2626

2727
use syntax::{ast, codemap};
2828
use syntax::attr;
29-
use syntax::codemap::DUMMY_SP;
3029
use syntax_pos;
3130

3231
// Any local node that may call something in its body block should be
@@ -593,7 +592,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> {
593592
}
594593

595594
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
596-
let access_levels = &ty::queries::privacy_access_levels::get(tcx, DUMMY_SP, LOCAL_CRATE);
595+
let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE);
597596
let krate = tcx.hir.krate();
598597
let live_symbols = find_live(tcx, access_levels, krate);
599598
let mut visitor = DeadVisitor { tcx: tcx, live_symbols: live_symbols };

src/librustc/middle/reachable.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ use util::nodemap::{NodeSet, FxHashSet};
2828
use syntax::abi::Abi;
2929
use syntax::ast;
3030
use syntax::attr;
31-
use syntax::codemap::DUMMY_SP;
3231
use hir;
3332
use hir::def_id::LOCAL_CRATE;
3433
use hir::intravisit::{Visitor, NestedVisitorMap};
@@ -364,13 +363,13 @@ impl<'a, 'tcx: 'a> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a,
364363
}
365364

366365
pub fn find_reachable<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Rc<NodeSet> {
367-
ty::queries::reachable_set::get(tcx, DUMMY_SP, LOCAL_CRATE)
366+
tcx.reachable_set(LOCAL_CRATE)
368367
}
369368

370369
fn reachable_set<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) -> Rc<NodeSet> {
371370
debug_assert!(crate_num == LOCAL_CRATE);
372371

373-
let access_levels = &ty::queries::privacy_access_levels::get(tcx, DUMMY_SP, LOCAL_CRATE);
372+
let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE);
374373

375374
let any_library = tcx.sess.crate_types.borrow().iter().any(|ty| {
376375
*ty == config::CrateTypeRlib || *ty == config::CrateTypeDylib ||

src/librustc/middle/stability.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
656656
pub fn check_unused_or_stable_features<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
657657
let sess = &tcx.sess;
658658

659-
let access_levels = &ty::queries::privacy_access_levels::get(tcx, DUMMY_SP, LOCAL_CRATE);
659+
let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE);
660660

661661
if tcx.stability.borrow().staged_api[&LOCAL_CRATE] && tcx.sess.features.borrow().staged_api {
662662
let krate = tcx.hir.krate();

src/librustc/ty/maps.rs

+7
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,13 @@ macro_rules! define_maps {
351351
}
352352
})*
353353

354+
impl<'a, $tcx, 'lcx> TyCtxt<'a, $tcx, 'lcx> {
355+
$($(#[$attr])*
356+
pub fn $name(self, key: $K) -> $V {
357+
queries::$name::get(self, DUMMY_SP, key)
358+
})*
359+
}
360+
354361
pub struct Providers<$tcx> {
355362
$(pub $name: for<'a> fn(TyCtxt<'a, $tcx, $tcx>, $K) -> $V),*
356363
}

src/librustc/ty/mod.rs

+5-74
Original file line numberDiff line numberDiff line change
@@ -1686,7 +1686,7 @@ impl<'a, 'gcx, 'tcx> AdtDef {
16861686
let mut discr = prev_discr.map_or(initial, |d| d.wrap_incr());
16871687
if let VariantDiscr::Explicit(expr_did) = v.discr {
16881688
let substs = Substs::empty();
1689-
match queries::const_eval::get(tcx, DUMMY_SP, (expr_did, substs)) {
1689+
match tcx.const_eval((expr_did, substs)) {
16901690
Ok(ConstVal::Integral(v)) => {
16911691
discr = v;
16921692
}
@@ -1725,7 +1725,7 @@ impl<'a, 'gcx, 'tcx> AdtDef {
17251725
}
17261726
ty::VariantDiscr::Explicit(expr_did) => {
17271727
let substs = Substs::empty();
1728-
match queries::const_eval::get(tcx, DUMMY_SP, (expr_did, substs)) {
1728+
match tcx.const_eval((expr_did, substs)) {
17291729
Ok(ConstVal::Integral(v)) => {
17301730
explicit_value = v;
17311731
break;
@@ -1760,7 +1760,7 @@ impl<'a, 'gcx, 'tcx> AdtDef {
17601760
}
17611761

17621762
pub fn destructor(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Destructor> {
1763-
queries::adt_destructor::get(tcx, DUMMY_SP, self.did)
1763+
tcx.adt_destructor(self.did)
17641764
}
17651765

17661766
/// Returns a list of types such that `Self: Sized` if and only
@@ -2045,10 +2045,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
20452045
self.typeck_tables_of(self.hir.body_owner_def_id(body))
20462046
}
20472047

2048-
pub fn typeck_tables_of(self, def_id: DefId) -> &'gcx TypeckTables<'gcx> {
2049-
queries::typeck_tables_of::get(self, DUMMY_SP, def_id)
2050-
}
2051-
20522048
pub fn expr_span(self, id: NodeId) -> Span {
20532049
match self.hir.find(id) {
20542050
Some(hir_map::NodeExpr(e)) => {
@@ -2136,24 +2132,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
21362132
.collect()
21372133
}
21382134

2139-
pub fn impl_polarity(self, id: DefId) -> hir::ImplPolarity {
2140-
queries::impl_polarity::get(self, DUMMY_SP, id)
2141-
}
2142-
21432135
pub fn trait_relevant_for_never(self, did: DefId) -> bool {
21442136
self.associated_items(did).any(|item| {
21452137
item.relevant_for_never()
21462138
})
21472139
}
21482140

2149-
pub fn coerce_unsized_info(self, did: DefId) -> adjustment::CoerceUnsizedInfo {
2150-
queries::coerce_unsized_info::get(self, DUMMY_SP, did)
2151-
}
2152-
2153-
pub fn associated_item(self, def_id: DefId) -> AssociatedItem {
2154-
queries::associated_item::get(self, DUMMY_SP, def_id)
2155-
}
2156-
21572141
fn associated_item_from_trait_item_ref(self,
21582142
parent_def_id: DefId,
21592143
trait_item_ref: &hir::TraitItemRef)
@@ -2207,23 +2191,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
22072191
}
22082192
}
22092193

2210-
pub fn associated_item_def_ids(self, def_id: DefId) -> Rc<Vec<DefId>> {
2211-
queries::associated_item_def_ids::get(self, DUMMY_SP, def_id)
2212-
}
2213-
22142194
#[inline] // FIXME(#35870) Avoid closures being unexported due to impl Trait.
22152195
pub fn associated_items(self, def_id: DefId)
22162196
-> impl Iterator<Item = ty::AssociatedItem> + 'a {
22172197
let def_ids = self.associated_item_def_ids(def_id);
22182198
(0..def_ids.len()).map(move |i| self.associated_item(def_ids[i]))
22192199
}
22202200

2221-
/// Returns the trait-ref corresponding to a given impl, or None if it is
2222-
/// an inherent impl.
2223-
pub fn impl_trait_ref(self, id: DefId) -> Option<TraitRef<'gcx>> {
2224-
queries::impl_trait_ref::get(self, DUMMY_SP, id)
2225-
}
2226-
22272201
/// Returns true if the impls are the same polarity and are implementing
22282202
/// a trait which contains no items
22292203
pub fn impls_are_allowed_to_overlap(self, def_id1: DefId, def_id2: DefId) -> bool {
@@ -2325,40 +2299,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
23252299
}
23262300
}
23272301

2328-
// If the given item is in an external crate, looks up its type and adds it to
2329-
// the type cache. Returns the type parameters and type.
2330-
pub fn type_of(self, did: DefId) -> Ty<'gcx> {
2331-
queries::type_of::get(self, DUMMY_SP, did)
2332-
}
2333-
2334-
/// Given the did of a trait, returns its canonical trait ref.
2335-
pub fn trait_def(self, did: DefId) -> &'gcx TraitDef {
2336-
queries::trait_def::get(self, DUMMY_SP, did)
2337-
}
2338-
2339-
/// Given the did of an ADT, return a reference to its definition.
2340-
pub fn adt_def(self, did: DefId) -> &'gcx AdtDef {
2341-
queries::adt_def::get(self, DUMMY_SP, did)
2342-
}
2343-
2344-
/// Given the did of an item, returns its generics.
2345-
pub fn generics_of(self, did: DefId) -> &'gcx Generics {
2346-
queries::generics_of::get(self, DUMMY_SP, did)
2347-
}
2348-
2349-
/// Given the did of an item, returns its full set of predicates.
2350-
pub fn predicates_of(self, did: DefId) -> GenericPredicates<'gcx> {
2351-
queries::predicates_of::get(self, DUMMY_SP, did)
2352-
}
2353-
2354-
/// Given the did of a trait, returns its superpredicates.
2355-
pub fn super_predicates_of(self, did: DefId) -> GenericPredicates<'gcx> {
2356-
queries::super_predicates_of::get(self, DUMMY_SP, did)
2357-
}
2358-
23592302
/// Given the did of an item, returns its MIR, borrowed immutably.
23602303
pub fn item_mir(self, did: DefId) -> Ref<'gcx, Mir<'gcx>> {
2361-
queries::mir::get(self, DUMMY_SP, did).borrow()
2304+
self.mir(did).borrow()
23622305
}
23632306

23642307
/// Return the possibly-auto-generated MIR of a (DefId, Subst) pair.
@@ -2367,7 +2310,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
23672310
{
23682311
match instance {
23692312
ty::InstanceDef::Item(did) if true => self.item_mir(did),
2370-
_ => queries::mir_shims::get(self, DUMMY_SP, instance).borrow(),
2313+
_ => self.mir_shims(instance).borrow(),
23712314
}
23722315
}
23732316

@@ -2399,10 +2342,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
23992342
self.get_attrs(did).iter().any(|item| item.check_name(attr))
24002343
}
24012344

2402-
pub fn variances_of(self, item_id: DefId) -> Rc<Vec<ty::Variance>> {
2403-
queries::variances_of::get(self, DUMMY_SP, item_id)
2404-
}
2405-
24062345
pub fn trait_has_default_impl(self, trait_def_id: DefId) -> bool {
24072346
let def = self.trait_def(trait_def_id);
24082347
def.flags.get().intersects(TraitFlags::HAS_DEFAULT_IMPL)
@@ -2437,14 +2376,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
24372376
def.flags.set(def.flags.get() | TraitFlags::HAS_REMOTE_IMPLS);
24382377
}
24392378

2440-
pub fn closure_kind(self, def_id: DefId) -> ty::ClosureKind {
2441-
queries::closure_kind::get(self, DUMMY_SP, def_id)
2442-
}
2443-
2444-
pub fn closure_type(self, def_id: DefId) -> ty::PolyFnSig<'tcx> {
2445-
queries::closure_type::get(self, DUMMY_SP, def_id)
2446-
}
2447-
24482379
/// Given the def_id of an impl, return the def_id of the trait it implements.
24492380
/// If it implements no trait, return `None`.
24502381
pub fn trait_id_of_impl(self, def_id: DefId) -> Option<DefId> {

src/librustc/ty/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
369369
return None;
370370
};
371371

372-
ty::queries::coherent_trait::get(self, DUMMY_SP, (LOCAL_CRATE, drop_trait));
372+
self.coherent_trait((LOCAL_CRATE, drop_trait));
373373

374374
let mut dtor_did = None;
375375
let ty = self.type_of(adt_did);

src/librustc_borrowck/borrowck/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use std::fmt;
4242
use std::rc::Rc;
4343
use std::hash::{Hash, Hasher};
4444
use syntax::ast;
45-
use syntax_pos::{DUMMY_SP, MultiSpan, Span};
45+
use syntax_pos::{MultiSpan, Span};
4646
use errors::DiagnosticBuilder;
4747

4848
use rustc::hir;
@@ -63,7 +63,7 @@ pub type LoanDataFlow<'a, 'tcx> = DataFlowContext<'a, 'tcx, LoanDataFlowOperator
6363

6464
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
6565
tcx.visit_all_bodies_in_krate(|body_owner_def_id, _body_id| {
66-
ty::queries::borrowck::get(tcx, DUMMY_SP, body_owner_def_id);
66+
tcx.borrowck(body_owner_def_id);
6767
});
6868
}
6969

src/librustc_const_eval/eval.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use rustc::util::nodemap::DefIdMap;
2727

2828
use syntax::ast;
2929
use rustc::hir::{self, Expr};
30-
use syntax_pos::{Span, DUMMY_SP};
30+
use syntax_pos::Span;
3131

3232
use std::cmp::Ordering;
3333

@@ -773,7 +773,7 @@ fn const_eval<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
773773
};
774774

775775
let body = if let Some(id) = tcx.hir.as_local_node_id(def_id) {
776-
ty::queries::mir_const_qualif::get(tcx, DUMMY_SP, def_id);
776+
tcx.mir_const_qualif(def_id);
777777
tcx.hir.body(tcx.hir.body_owned_by(id))
778778
} else {
779779
tcx.sess.cstore.item_body(tcx, def_id)

src/librustc_metadata/encoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use syntax::ast::{self, CRATE_NODE_ID};
3636
use syntax::codemap::Spanned;
3737
use syntax::attr;
3838
use syntax::symbol::Symbol;
39-
use syntax_pos::{self, DUMMY_SP};
39+
use syntax_pos;
4040

4141
use rustc::hir::{self, PatKind};
4242
use rustc::hir::itemlikevisit::ItemLikeVisitor;
@@ -1169,7 +1169,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> EntryBuilder<'a, 'b, 'tcx> {
11691169
let body = tcx.hir.body_owned_by(id);
11701170

11711171
Entry {
1172-
kind: EntryKind::Const(ty::queries::mir_const_qualif::get(tcx, DUMMY_SP, def_id)),
1172+
kind: EntryKind::Const(tcx.mir_const_qualif(def_id)),
11731173
visibility: self.lazy(&ty::Visibility::Public),
11741174
span: self.lazy(&tcx.def_span(def_id)),
11751175
attributes: LazySeq::empty(),

src/librustc_mir/transform/qualify_consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ impl<'tcx> MirMapPass<'tcx> for QualifyAndPromoteConstants {
959959
let src = MirSource::from_node(tcx, id);
960960

961961
if let MirSource::Const(_) = src {
962-
ty::queries::mir_const_qualif::get(tcx, DUMMY_SP, def_id);
962+
tcx.mir_const_qualif(def_id);
963963
continue;
964964
}
965965

src/librustc_privacy/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use rustc::ty::fold::TypeVisitor;
3838
use rustc::ty::maps::Providers;
3939
use rustc::util::nodemap::NodeSet;
4040
use syntax::ast;
41-
use syntax_pos::{DUMMY_SP, Span};
41+
use syntax_pos::Span;
4242

4343
use std::cmp;
4444
use std::mem::replace;
@@ -1222,7 +1222,7 @@ pub fn provide(providers: &mut Providers) {
12221222

12231223
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Rc<AccessLevels> {
12241224
tcx.dep_graph.with_ignore(|| { // FIXME
1225-
ty::queries::privacy_access_levels::get(tcx, DUMMY_SP, LOCAL_CRATE)
1225+
tcx.privacy_access_levels(LOCAL_CRATE)
12261226
})
12271227
}
12281228

src/librustc_trans/callee.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ use declare;
2121
use llvm::{self, ValueRef};
2222
use monomorphize::{self, Instance};
2323
use rustc::hir::def_id::DefId;
24-
use rustc::ty::{self, TypeFoldable};
24+
use rustc::ty::TypeFoldable;
2525
use rustc::ty::subst::Substs;
26-
use syntax_pos::DUMMY_SP;
2726
use trans_item::TransItem;
2827
use type_of;
2928

@@ -105,7 +104,7 @@ pub fn get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
105104
// *in Rust code* may unwind. Foreign items like `extern "C" {
106105
// fn foo(); }` are assumed not to unwind **unless** they have
107106
// a `#[unwind]` attribute.
108-
if !ty::queries::is_foreign_item::get(tcx, DUMMY_SP, instance.def_id()) {
107+
if !tcx.is_foreign_item(instance.def_id()) {
109108
attributes::unwind(llfn, true);
110109
unsafe {
111110
llvm::LLVMRustSetLinkage(llfn, llvm::Linkage::ExternalLinkage);

src/librustc_typeck/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ pub fn check_item_types<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> CompileResult
621621
}
622622

623623
pub fn check_item_bodies<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> CompileResult {
624-
ty::queries::typeck_item_bodies::get(tcx, DUMMY_SP, LOCAL_CRATE)
624+
tcx.typeck_item_bodies(LOCAL_CRATE)
625625
}
626626

627627
fn typeck_item_bodies<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) -> CompileResult {

src/librustc_typeck/coherence/inherent_impls.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc::util::nodemap::DefIdMap;
2626

2727
use std::rc::Rc;
2828
use syntax::ast;
29-
use syntax_pos::{DUMMY_SP, Span};
29+
use syntax_pos::Span;
3030

3131
/// On-demand query: yields a map containing all types mapped to their inherent impls.
3232
pub fn crate_inherent_impls<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
@@ -67,7 +67,7 @@ pub fn inherent_impls<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
6767
// [the plan]: https://github.com/rust-lang/rust-roadmap/issues/4
6868

6969
let result = tcx.dep_graph.with_ignore(|| {
70-
let crate_map = ty::queries::crate_inherent_impls::get(tcx, DUMMY_SP, ty_def_id.krate);
70+
let crate_map = tcx.crate_inherent_impls(ty_def_id.krate);
7171
match crate_map.inherent_impls.get(&ty_def_id) {
7272
Some(v) => v.clone(),
7373
None => Rc::new(vec![]),

0 commit comments

Comments
 (0)