Skip to content

Commit 92c974d

Browse files
committed
Flatten some occurrences of [P<T>] to [T]
1 parent f949e10 commit 92c974d

File tree

4 files changed

+33
-24
lines changed

4 files changed

+33
-24
lines changed

src/librustc/hir/lowering.rs

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,11 @@ impl<'a> LoweringContext<'a> {
10471047
}
10481048
}
10491049

1050-
fn lower_ty(&mut self, t: &Ty, mut itctx: ImplTraitContext) -> P<hir::Ty> {
1050+
fn lower_ty(&mut self, t: &Ty, itctx: ImplTraitContext) -> P<hir::Ty> {
1051+
P(self.lower_ty_direct(t, itctx))
1052+
}
1053+
1054+
fn lower_ty_direct(&mut self, t: &Ty, mut itctx: ImplTraitContext) -> hir::Ty {
10511055
let kind = match t.node {
10521056
TyKind::Infer => hir::TyInfer,
10531057
TyKind::Err => hir::TyErr,
@@ -1087,10 +1091,15 @@ impl<'a> LoweringContext<'a> {
10871091
),
10881092
TyKind::Never => hir::TyNever,
10891093
TyKind::Tup(ref tys) => {
1090-
hir::TyTup(tys.iter().map(|ty| self.lower_ty(ty, itctx.reborrow())).collect())
1094+
hir::TyTup(
1095+
tys
1096+
.iter()
1097+
.map(|ty| self.lower_ty_direct(ty, itctx.reborrow()))
1098+
.collect()
1099+
)
10911100
}
10921101
TyKind::Paren(ref ty) => {
1093-
return self.lower_ty(ty, itctx);
1102+
return self.lower_ty_direct(ty, itctx);
10941103
}
10951104
TyKind::Path(ref qself, ref path) => {
10961105
let id = self.lower_node_id(t.id);
@@ -1269,12 +1278,12 @@ impl<'a> LoweringContext<'a> {
12691278
};
12701279

12711280
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(t.id);
1272-
P(hir::Ty {
1281+
hir::Ty {
12731282
id: node_id,
12741283
node: kind,
12751284
span: t.span,
12761285
hir_id,
1277-
})
1286+
}
12781287
}
12791288

12801289
fn generics_from_impl_trait_bounds(
@@ -1588,7 +1597,7 @@ impl<'a> LoweringContext<'a> {
15881597
// e.g. `Vec` in `Vec::new` or `<I as Iterator>::Item` in
15891598
// `<I as Iterator>::Item::default`.
15901599
let new_id = self.next_id();
1591-
self.ty_path(new_id, p.span, hir::QPath::Resolved(qself, path))
1600+
P(self.ty_path(new_id, p.span, hir::QPath::Resolved(qself, path)))
15921601
};
15931602

15941603
// Anything after the base path are associated "extensions",
@@ -1619,7 +1628,7 @@ impl<'a> LoweringContext<'a> {
16191628

16201629
// Wrap the associated extension in another type node.
16211630
let new_id = self.next_id();
1622-
ty = self.ty_path(new_id, p.span, qpath);
1631+
ty = P(self.ty_path(new_id, p.span, qpath));
16231632
}
16241633

16251634
// Should've returned in the for loop above.
@@ -1727,7 +1736,7 @@ impl<'a> LoweringContext<'a> {
17271736
(
17281737
hir::PathParameters {
17291738
lifetimes: self.lower_lifetimes(lifetimes),
1730-
types: types.iter().map(|ty| self.lower_ty(ty, itctx.reborrow())).collect(),
1739+
types: types.iter().map(|ty| self.lower_ty_direct(ty, itctx.reborrow())).collect(),
17311740
bindings: bindings
17321741
.iter()
17331742
.map(|b| self.lower_ty_binding(b, itctx.reborrow()))
@@ -1758,16 +1767,16 @@ impl<'a> LoweringContext<'a> {
17581767
} = data;
17591768
let inputs = inputs
17601769
.iter()
1761-
.map(|ty| this.lower_ty(ty, DISALLOWED))
1770+
.map(|ty| this.lower_ty_direct(ty, DISALLOWED))
17621771
.collect();
17631772
let mk_tup = |this: &mut Self, tys, span| {
17641773
let LoweredNodeId { node_id, hir_id } = this.next_id();
1765-
P(hir::Ty {
1774+
hir::Ty {
17661775
node: hir::TyTup(tys),
17671776
id: node_id,
17681777
hir_id,
17691778
span,
1770-
})
1779+
}
17711780
};
17721781

17731782
(
@@ -1781,7 +1790,7 @@ impl<'a> LoweringContext<'a> {
17811790
ty: output
17821791
.as_ref()
17831792
.map(|ty| this.lower_ty(&ty, DISALLOWED))
1784-
.unwrap_or_else(|| mk_tup(this, hir::HirVec::new(), span)),
1793+
.unwrap_or_else(|| P(mk_tup(this, hir::HirVec::new(), span))),
17851794
span: output.as_ref().map_or(span, |ty| ty.span),
17861795
}
17871796
],
@@ -1853,9 +1862,9 @@ impl<'a> LoweringContext<'a> {
18531862
.iter()
18541863
.map(|arg| {
18551864
if let Some((def_id, ibty, _)) = in_band_ty_params.as_mut() {
1856-
self.lower_ty(&arg.ty, ImplTraitContext::Universal(*def_id, ibty))
1865+
self.lower_ty_direct(&arg.ty, ImplTraitContext::Universal(*def_id, ibty))
18571866
} else {
1858-
self.lower_ty(&arg.ty, ImplTraitContext::Disallowed)
1867+
self.lower_ty_direct(&arg.ty, ImplTraitContext::Disallowed)
18591868
}
18601869
})
18611870
.collect(),
@@ -3316,7 +3325,7 @@ impl<'a> LoweringContext<'a> {
33163325
let e1 = self.lower_expr(e1);
33173326
let e2 = self.lower_expr(e2);
33183327
let ty_path = P(self.std_path(span, &["ops", "RangeInclusive"], false));
3319-
let ty = self.ty_path(id, span, hir::QPath::Resolved(None, ty_path));
3328+
let ty = P(self.ty_path(id, span, hir::QPath::Resolved(None, ty_path)));
33203329
let new_seg = P(hir::PathSegment::from_name(Symbol::intern("new")));
33213330
let new_path = hir::QPath::TypeRelative(ty, new_seg);
33223331
let new = P(self.expr(span, hir::ExprPath(new_path), ThinVec::new()));
@@ -4194,7 +4203,7 @@ impl<'a> LoweringContext<'a> {
41944203
.resolve_str_path(span, self.crate_root, components, is_value)
41954204
}
41964205

4197-
fn ty_path(&mut self, id: LoweredNodeId, span: Span, qpath: hir::QPath) -> P<hir::Ty> {
4206+
fn ty_path(&mut self, id: LoweredNodeId, span: Span, qpath: hir::QPath) -> hir::Ty {
41984207
let mut id = id;
41994208
let node = match qpath {
42004209
hir::QPath::Resolved(None, path) => {
@@ -4219,12 +4228,12 @@ impl<'a> LoweringContext<'a> {
42194228
}
42204229
_ => hir::TyPath(qpath),
42214230
};
4222-
P(hir::Ty {
4231+
hir::Ty {
42234232
id: id.node_id,
42244233
hir_id: id.hir_id,
42254234
node,
42264235
span,
4227-
})
4236+
}
42284237
}
42294238

42304239
/// Invoked to create the lifetime argument for a type `&T`

src/librustc/hir/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ pub struct PathParameters {
377377
/// The lifetime parameters for this path segment.
378378
pub lifetimes: HirVec<Lifetime>,
379379
/// The type parameters for this path segment, if present.
380-
pub types: HirVec<P<Ty>>,
380+
pub types: HirVec<Ty>,
381381
/// Bindings (equality constraints) on associated types, if present.
382382
/// E.g., `Foo<A=Bar>`.
383383
pub bindings: HirVec<TypeBinding>,
@@ -402,7 +402,7 @@ impl PathParameters {
402402
self.bindings.is_empty() && !self.parenthesized
403403
}
404404

405-
pub fn inputs(&self) -> &[P<Ty>] {
405+
pub fn inputs(&self) -> &[Ty] {
406406
if self.parenthesized {
407407
if let Some(ref ty) = self.types.get(0) {
408408
if let TyTup(ref tys) = ty.node {
@@ -1712,7 +1712,7 @@ pub enum Ty_ {
17121712
/// The never type (`!`)
17131713
TyNever,
17141714
/// A tuple (`(A, B, C, D,...)`)
1715-
TyTup(HirVec<P<Ty>>),
1715+
TyTup(HirVec<Ty>),
17161716
/// A path to a type definition (`module::module::...::Type`), or an
17171717
/// associated type, e.g. `<Vec<T> as Trait>::Type` or `<T>::Target`.
17181718
///
@@ -1773,7 +1773,7 @@ pub struct Arg {
17731773
/// Represents the header (not the body) of a function declaration
17741774
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
17751775
pub struct FnDecl {
1776-
pub inputs: HirVec<P<Ty>>,
1776+
pub inputs: HirVec<Ty>,
17771777
pub output: FunctionRetTy,
17781778
pub variadic: bool,
17791779
/// True if this function has an `self`, `&self` or `&mut self` receiver

src/librustc/middle/resolve_lifetime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1713,7 +1713,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
17131713

17141714
fn visit_fn_like_elision(
17151715
&mut self,
1716-
inputs: &'tcx [P<hir::Ty>],
1716+
inputs: &'tcx [hir::Ty],
17171717
output: Option<&'tcx P<hir::Ty>>,
17181718
) {
17191719
debug!("visit_fn_like_elision: enter");

src/librustc/traits/error_reporting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
964964
..
965965
}) => {
966966
(self.tcx.sess.codemap().def_span(span), decl.inputs.iter()
967-
.map(|arg| match arg.clone().into_inner().node {
967+
.map(|arg| match arg.clone().node {
968968
hir::TyTup(ref tys) => ArgKind::Tuple(
969969
Some(arg.span),
970970
tys.iter()

0 commit comments

Comments
 (0)