Skip to content

Commit 9eae6ba

Browse files
committed
rustc: remove unnecessary ItemSubsts wrapper.
1 parent a65ced5 commit 9eae6ba

File tree

12 files changed

+27
-95
lines changed

12 files changed

+27
-95
lines changed

src/librustc/ich/impls_ty.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ use std::mem;
1919
use syntax_pos::symbol::InternedString;
2020
use ty;
2121

22-
impl_stable_hash_for!(struct ty::ItemSubsts<'tcx> { substs });
23-
2422
impl<'a, 'tcx, T> HashStable<StableHashingContext<'a, 'tcx>> for &'tcx ty::Slice<T>
2523
where T: HashStable<StableHashingContext<'a, 'tcx>> {
2624
fn hash_stable<W: StableHasherResult>(&self,
@@ -602,7 +600,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::TypeckTables<'
602600
let ty::TypeckTables {
603601
ref type_relative_path_defs,
604602
ref node_types,
605-
ref item_substs,
603+
ref node_substs,
606604
ref adjustments,
607605
ref method_map,
608606
ref upvar_capture_map,
@@ -623,7 +621,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::TypeckTables<'
623621
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
624622
ich::hash_stable_nodemap(hcx, hasher, type_relative_path_defs);
625623
ich::hash_stable_nodemap(hcx, hasher, node_types);
626-
ich::hash_stable_nodemap(hcx, hasher, item_substs);
624+
ich::hash_stable_nodemap(hcx, hasher, node_substs);
627625
ich::hash_stable_nodemap(hcx, hasher, adjustments);
628626
ich::hash_stable_nodemap(hcx, hasher, method_map);
629627
ich::hash_stable_hashmap(hcx, hasher, upvar_capture_map, |hcx, up_var_id| {

src/librustc/ty/context.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ pub struct TypeckTables<'tcx> {
218218
/// of this node. This only applies to nodes that refer to entities
219219
/// parameterized by type parameters, such as generic fns, types, or
220220
/// other items.
221-
pub item_substs: NodeMap<ty::ItemSubsts<'tcx>>,
221+
pub node_substs: NodeMap<&'tcx Substs<'tcx>>,
222222

223223
pub adjustments: NodeMap<ty::adjustment::Adjustment<'tcx>>,
224224

@@ -273,7 +273,7 @@ impl<'tcx> TypeckTables<'tcx> {
273273
TypeckTables {
274274
type_relative_path_defs: NodeMap(),
275275
node_types: FxHashMap(),
276-
item_substs: NodeMap(),
276+
node_substs: NodeMap(),
277277
adjustments: NodeMap(),
278278
method_map: FxHashMap(),
279279
upvar_capture_map: FxHashMap(),
@@ -313,8 +313,8 @@ impl<'tcx> TypeckTables<'tcx> {
313313
self.node_types.get(&id).cloned()
314314
}
315315

316-
pub fn node_id_item_substs(&self, id: NodeId) -> Option<&'tcx Substs<'tcx>> {
317-
self.item_substs.get(&id).map(|ts| ts.substs)
316+
pub fn node_substs(&self, id: NodeId) -> &'tcx Substs<'tcx> {
317+
self.node_substs.get(&id).cloned().unwrap_or(Substs::empty())
318318
}
319319

320320
// Returns the type of a pattern as a monotype. Like @expr_ty, this function

src/librustc/ty/mod.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,13 +1809,6 @@ impl<'a, 'gcx, 'tcx> FieldDef {
18091809
}
18101810
}
18111811

1812-
/// Records the substitutions used to translate the polytype for an
1813-
/// item into the monotype of an item reference.
1814-
#[derive(Clone, RustcEncodable, RustcDecodable)]
1815-
pub struct ItemSubsts<'tcx> {
1816-
pub substs: &'tcx Substs<'tcx>,
1817-
}
1818-
18191812
#[derive(Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)]
18201813
pub enum ClosureKind {
18211814
// Warning: Ordering is significant here! The ordering is chosen
@@ -1893,12 +1886,6 @@ impl<'tcx> TyS<'tcx> {
18931886
}
18941887
}
18951888

1896-
impl<'tcx> ItemSubsts<'tcx> {
1897-
pub fn is_noop(&self) -> bool {
1898-
self.substs.is_noop()
1899-
}
1900-
}
1901-
19021889
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
19031890
pub enum LvaluePreference {
19041891
PreferMutLvalue,

src/librustc/ty/structural_impls.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -220,17 +220,6 @@ impl<'a, 'tcx> Lift<'tcx> for ty::ClosureSubsts<'a> {
220220
}
221221
}
222222

223-
impl<'a, 'tcx> Lift<'tcx> for ty::ItemSubsts<'a> {
224-
type Lifted = ty::ItemSubsts<'tcx>;
225-
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
226-
tcx.lift(&self.substs).map(|substs| {
227-
ty::ItemSubsts {
228-
substs: substs
229-
}
230-
})
231-
}
232-
}
233-
234223
impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::AutoBorrow<'a> {
235224
type Lifted = ty::adjustment::AutoBorrow<'tcx>;
236225
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
@@ -654,18 +643,6 @@ impl<'tcx> TypeFoldable<'tcx> for ty::ClosureSubsts<'tcx> {
654643
}
655644
}
656645

657-
impl<'tcx> TypeFoldable<'tcx> for ty::ItemSubsts<'tcx> {
658-
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
659-
ty::ItemSubsts {
660-
substs: self.substs.fold_with(folder),
661-
}
662-
}
663-
664-
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
665-
self.substs.visit_with(visitor)
666-
}
667-
}
668-
669646
impl<'tcx> TypeFoldable<'tcx> for ty::adjustment::AutoBorrow<'tcx> {
670647
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
671648
match *self {

src/librustc/util/ppaux.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,6 @@ impl<'tcx> fmt::Display for ty::TypeAndMut<'tcx> {
361361
}
362362
}
363363

364-
impl<'tcx> fmt::Debug for ty::ItemSubsts<'tcx> {
365-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
366-
write!(f, "ItemSubsts({:?})", self.substs)
367-
}
368-
}
369-
370364
impl<'tcx> fmt::Debug for ty::TraitRef<'tcx> {
371365
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
372366
// when printing out the debug representation, we don't need

src/librustc_const_eval/eval.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,7 @@ fn eval_const_expr_partial<'a, 'tcx>(cx: &ConstContext<'a, 'tcx>,
286286
}
287287
}
288288
hir::ExprPath(ref qpath) => {
289-
let substs = cx.tables.node_id_item_substs(e.id)
290-
.unwrap_or_else(|| tcx.intern_substs(&[]));
289+
let substs = cx.tables.node_substs(e.id);
291290

292291
// Avoid applying substitutions if they're empty, that'd ICE.
293292
let substs = if cx.substs.is_empty() {

src/librustc_const_eval/pattern.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,7 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
585585
let kind = match def {
586586
Def::Const(def_id) | Def::AssociatedConst(def_id) => {
587587
let tcx = self.tcx.global_tcx();
588-
let substs = self.tables.node_id_item_substs(id)
589-
.unwrap_or_else(|| tcx.intern_substs(&[]));
588+
let substs = self.tables.node_substs(id);
590589
match eval::lookup_const_by_id(tcx, def_id, substs) {
591590
Some((def_id, _substs)) => {
592591
// Enter the inlined constant's tables temporarily.

src/librustc_lint/builtin.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -911,8 +911,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnconditionalRecursion {
911911
};
912912
match def {
913913
Def::Method(def_id) => {
914-
let substs = cx.tables.node_id_item_substs(callee.id)
915-
.unwrap_or_else(|| cx.tcx.intern_substs(&[]));
914+
let substs = cx.tables.node_substs(callee.id);
916915
method_call_refers_to_method(
917916
cx.tcx, method, def_id, substs, id)
918917
}

src/librustc_mir/hair/cx/expr.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
297297
None
298298
};
299299
if let Some((adt_def, index)) = adt_data {
300-
let substs = cx.tables().node_id_item_substs(fun.id)
301-
.unwrap_or_else(|| cx.tcx.intern_substs(&[]));
300+
let substs = cx.tables().node_substs(fun.id);
302301
let field_refs = args.iter()
303302
.enumerate()
304303
.map(|(idx, e)| {
@@ -735,8 +734,7 @@ fn convert_path_expr<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
735734
expr: &'tcx hir::Expr,
736735
def: Def)
737736
-> ExprKind<'tcx> {
738-
let substs = cx.tables().node_id_item_substs(expr.id)
739-
.unwrap_or_else(|| cx.tcx.intern_substs(&[]));
737+
let substs = cx.tables().node_substs(expr.id);
740738
match def {
741739
// A regular function, constructor function or a constant.
742740
Def::Fn(def_id) |

src/librustc_typeck/check/mod.rs

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ can be broken down into several distinct phases:
5252
5353
While type checking a function, the intermediate types for the
5454
expressions, blocks, and so forth contained within the function are
55-
stored in `fcx.node_types` and `fcx.item_substs`. These types
55+
stored in `fcx.node_types` and `fcx.node_substs`. These types
5656
may contain unresolved type variables. After type checking is
5757
complete, the functions in the writeback module are used to take the
5858
types from this table, resolve them, and then write them into their
@@ -1758,14 +1758,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
17581758
}
17591759
}
17601760

1761-
pub fn write_substs(&self, node_id: ast::NodeId, substs: ty::ItemSubsts<'tcx>) {
1762-
if !substs.substs.is_noop() {
1761+
pub fn write_substs(&self, node_id: ast::NodeId, substs: &'tcx Substs<'tcx>) {
1762+
if !substs.is_noop() {
17631763
debug!("write_substs({}, {:?}) in fcx {}",
17641764
node_id,
17651765
substs,
17661766
self.tag());
17671767

1768-
self.tables.borrow_mut().item_substs.insert(node_id, substs);
1768+
self.tables.borrow_mut().node_substs.insert(node_id, substs);
17691769
}
17701770
}
17711771

@@ -1959,16 +1959,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
19591959
}
19601960
}
19611961

1962-
pub fn opt_node_ty_substs<F>(&self,
1963-
id: ast::NodeId,
1964-
f: F) where
1965-
F: FnOnce(&ty::ItemSubsts<'tcx>),
1966-
{
1967-
if let Some(s) = self.tables.borrow().item_substs.get(&id) {
1968-
f(s);
1969-
}
1970-
}
1971-
19721962
/// Registers an obligation for checking later, during regionck, that the type `ty` must
19731963
/// outlive the region `r`.
19741964
pub fn register_region_obligation(&self,
@@ -3550,9 +3540,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
35503540

35513541
// We always require that the type provided as the value for
35523542
// a type parameter outlives the moment of instantiation.
3553-
self.opt_node_ty_substs(expr.id, |item_substs| {
3554-
self.add_wf_bounds(&item_substs.substs, expr);
3555-
});
3543+
let substs = self.tables.borrow().node_substs(expr.id);
3544+
self.add_wf_bounds(substs, expr);
35563545

35573546
ty
35583547
}
@@ -4375,9 +4364,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
43754364
let ty = self.local_ty(span, nid);
43764365
let ty = self.normalize_associated_types_in(span, &ty);
43774366
self.write_ty(node_id, ty);
4378-
self.write_substs(node_id, ty::ItemSubsts {
4379-
substs: self.tcx.intern_substs(&[])
4380-
});
43814367
return ty;
43824368
}
43834369
_ => {}
@@ -4509,9 +4495,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
45094495
debug!("instantiate_value_path: type of {:?} is {:?}",
45104496
node_id,
45114497
ty_substituted);
4512-
self.write_substs(node_id, ty::ItemSubsts {
4513-
substs: substs
4514-
});
4498+
self.write_substs(node_id, substs);
45154499
ty_substituted
45164500
}
45174501

0 commit comments

Comments
 (0)