Skip to content

Commit 971f7d3

Browse files
committed
Auto merge of #51815 - oli-obk:lowering_cleanups2, r=nikomatsakis
Lowering cleanups [2/N] Double indirections are unnecessary
2 parents 612c280 + e65947d commit 971f7d3

File tree

6 files changed

+32
-28
lines changed

6 files changed

+32
-28
lines changed

src/librustc/hir/lowering.rs

+21-17
Original file line numberDiff line numberDiff line change
@@ -1074,11 +1074,15 @@ impl<'a> LoweringContext<'a> {
10741074
-> hir::GenericArg {
10751075
match arg {
10761076
ast::GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.lower_lifetime(&lt)),
1077-
ast::GenericArg::Type(ty) => GenericArg::Type(self.lower_ty(&ty, itctx)),
1077+
ast::GenericArg::Type(ty) => GenericArg::Type(self.lower_ty_direct(&ty, itctx)),
10781078
}
10791079
}
10801080

10811081
fn lower_ty(&mut self, t: &Ty, itctx: ImplTraitContext) -> P<hir::Ty> {
1082+
P(self.lower_ty_direct(t, itctx))
1083+
}
1084+
1085+
fn lower_ty_direct(&mut self, t: &Ty, itctx: ImplTraitContext) -> hir::Ty {
10821086
let kind = match t.node {
10831087
TyKind::Infer => hir::TyInfer,
10841088
TyKind::Err => hir::TyErr,
@@ -1115,10 +1119,10 @@ impl<'a> LoweringContext<'a> {
11151119
),
11161120
TyKind::Never => hir::TyNever,
11171121
TyKind::Tup(ref tys) => {
1118-
hir::TyTup(tys.iter().map(|ty| self.lower_ty(ty, itctx)).collect())
1122+
hir::TyTup(tys.iter().map(|ty| self.lower_ty_direct(ty, itctx)).collect())
11191123
}
11201124
TyKind::Paren(ref ty) => {
1121-
return self.lower_ty(ty, itctx);
1125+
return self.lower_ty_direct(ty, itctx);
11221126
}
11231127
TyKind::Path(ref qself, ref path) => {
11241128
let id = self.lower_node_id(t.id);
@@ -1228,12 +1232,12 @@ impl<'a> LoweringContext<'a> {
12281232
};
12291233

12301234
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(t.id);
1231-
P(hir::Ty {
1235+
hir::Ty {
12321236
id: node_id,
12331237
node: kind,
12341238
span: t.span,
12351239
hir_id,
1236-
})
1240+
}
12371241
}
12381242

12391243
fn lower_existential_impl_trait(
@@ -1636,7 +1640,7 @@ impl<'a> LoweringContext<'a> {
16361640
// e.g. `Vec` in `Vec::new` or `<I as Iterator>::Item` in
16371641
// `<I as Iterator>::Item::default`.
16381642
let new_id = self.next_id();
1639-
self.ty_path(new_id, p.span, hir::QPath::Resolved(qself, path))
1643+
P(self.ty_path(new_id, p.span, hir::QPath::Resolved(qself, path)))
16401644
};
16411645

16421646
// Anything after the base path are associated "extensions",
@@ -1667,7 +1671,7 @@ impl<'a> LoweringContext<'a> {
16671671

16681672
// Wrap the associated extension in another type node.
16691673
let new_id = self.next_id();
1670-
ty = self.ty_path(new_id, p.span, qpath);
1674+
ty = P(self.ty_path(new_id, p.span, qpath));
16711675
}
16721676

16731677
// Should've returned in the for loop above.
@@ -1802,10 +1806,10 @@ impl<'a> LoweringContext<'a> {
18021806
|this| {
18031807
const DISALLOWED: ImplTraitContext = ImplTraitContext::Disallowed;
18041808
let &ParenthesisedArgs { ref inputs, ref output, span } = data;
1805-
let inputs = inputs.iter().map(|ty| this.lower_ty(ty, DISALLOWED)).collect();
1809+
let inputs = inputs.iter().map(|ty| this.lower_ty_direct(ty, DISALLOWED)).collect();
18061810
let mk_tup = |this: &mut Self, tys, span| {
18071811
let LoweredNodeId { node_id, hir_id } = this.next_id();
1808-
P(hir::Ty { node: hir::TyTup(tys), id: node_id, hir_id, span })
1812+
hir::Ty { node: hir::TyTup(tys), id: node_id, hir_id, span }
18091813
};
18101814

18111815
(
@@ -1818,7 +1822,7 @@ impl<'a> LoweringContext<'a> {
18181822
ty: output
18191823
.as_ref()
18201824
.map(|ty| this.lower_ty(&ty, DISALLOWED))
1821-
.unwrap_or_else(|| mk_tup(this, hir::HirVec::new(), span)),
1825+
.unwrap_or_else(|| P(mk_tup(this, hir::HirVec::new(), span))),
18221826
span: output.as_ref().map_or(span, |ty| ty.span),
18231827
}
18241828
],
@@ -1894,9 +1898,9 @@ impl<'a> LoweringContext<'a> {
18941898
.iter()
18951899
.map(|arg| {
18961900
if let Some(def_id) = fn_def_id {
1897-
self.lower_ty(&arg.ty, ImplTraitContext::Universal(def_id))
1901+
self.lower_ty_direct(&arg.ty, ImplTraitContext::Universal(def_id))
18981902
} else {
1899-
self.lower_ty(&arg.ty, ImplTraitContext::Disallowed)
1903+
self.lower_ty_direct(&arg.ty, ImplTraitContext::Disallowed)
19001904
}
19011905
})
19021906
.collect::<HirVec<_>>();
@@ -1936,7 +1940,7 @@ impl<'a> LoweringContext<'a> {
19361940
// fn_def_id: DefId of the parent function. Used to create child impl trait definition.
19371941
fn lower_async_fn_ret_ty(
19381942
&mut self,
1939-
inputs: &[P<hir::Ty>],
1943+
inputs: &[hir::Ty],
19401944
output: &FunctionRetTy,
19411945
fn_def_id: DefId,
19421946
) -> hir::FunctionRetTy {
@@ -3661,7 +3665,7 @@ impl<'a> LoweringContext<'a> {
36613665
let e1 = self.lower_expr(e1);
36623666
let e2 = self.lower_expr(e2);
36633667
let ty_path = P(self.std_path(span, &["ops", "RangeInclusive"], None, false));
3664-
let ty = self.ty_path(id, span, hir::QPath::Resolved(None, ty_path));
3668+
let ty = P(self.ty_path(id, span, hir::QPath::Resolved(None, ty_path)));
36653669
let new_seg = P(hir::PathSegment::from_name(Symbol::intern("new")));
36663670
let new_path = hir::QPath::TypeRelative(ty, new_seg);
36673671
let new = P(self.expr(span, hir::ExprPath(new_path), ThinVec::new()));
@@ -4549,7 +4553,7 @@ impl<'a> LoweringContext<'a> {
45494553
.resolve_str_path(span, self.crate_root, components, params, is_value)
45504554
}
45514555

4552-
fn ty_path(&mut self, id: LoweredNodeId, span: Span, qpath: hir::QPath) -> P<hir::Ty> {
4556+
fn ty_path(&mut self, id: LoweredNodeId, span: Span, qpath: hir::QPath) -> hir::Ty {
45534557
let mut id = id;
45544558
let node = match qpath {
45554559
hir::QPath::Resolved(None, path) => {
@@ -4574,12 +4578,12 @@ impl<'a> LoweringContext<'a> {
45744578
}
45754579
_ => hir::TyPath(qpath),
45764580
};
4577-
P(hir::Ty {
4581+
hir::Ty {
45784582
id: id.node_id,
45794583
hir_id: id.hir_id,
45804584
node,
45814585
span,
4582-
})
4586+
}
45834587
}
45844588

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

src/librustc/hir/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ impl PathSegment {
383383
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
384384
pub enum GenericArg {
385385
Lifetime(Lifetime),
386-
Type(P<Ty>),
386+
Type(Ty),
387387
}
388388

389389
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
@@ -412,7 +412,7 @@ impl GenericArgs {
412412
self.args.is_empty() && self.bindings.is_empty() && !self.parenthesized
413413
}
414414

415-
pub fn inputs(&self) -> &[P<Ty>] {
415+
pub fn inputs(&self) -> &[Ty] {
416416
if self.parenthesized {
417417
for arg in &self.args {
418418
match arg {
@@ -1658,7 +1658,7 @@ pub enum Ty_ {
16581658
/// The never type (`!`)
16591659
TyNever,
16601660
/// A tuple (`(A, B, C, D,...)`)
1661-
TyTup(HirVec<P<Ty>>),
1661+
TyTup(HirVec<Ty>),
16621662
/// A path to a type definition (`module::module::...::Type`), or an
16631663
/// associated type, e.g. `<Vec<T> as Trait>::Type` or `<T>::Target`.
16641664
///
@@ -1719,7 +1719,7 @@ pub struct Arg {
17191719
/// Represents the header (not the body) of a function declaration
17201720
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
17211721
pub struct FnDecl {
1722-
pub inputs: HirVec<P<Ty>>,
1722+
pub inputs: HirVec<Ty>,
17231723
pub output: FunctionRetTy,
17241724
pub variadic: bool,
17251725
/// True if this function has an `self`, `&self` or `&mut self` receiver

src/librustc/middle/resolve_lifetime.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1792,7 +1792,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
17921792

17931793
fn visit_fn_like_elision(
17941794
&mut self,
1795-
inputs: &'tcx [P<hir::Ty>],
1795+
inputs: &'tcx [hir::Ty],
17961796
output: Option<&'tcx P<hir::Ty>>,
17971797
) {
17981798
debug!("visit_fn_like_elision: enter");

src/librustc/traits/error_reporting.rs

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

src/librustdoc/clean/auto_trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
263263
}));
264264
}
265265
ty::GenericParamDefKind::Type {..} => {
266-
args.push(hir::GenericArg::Type(P(self.ty_param_to_ty(param.clone()))));
266+
args.push(hir::GenericArg::Type(self.ty_param_to_ty(param.clone())));
267267
}
268268
}
269269
}

src/librustdoc/clean/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2150,7 +2150,7 @@ pub struct Arguments {
21502150
pub values: Vec<Argument>,
21512151
}
21522152

2153-
impl<'a> Clean<Arguments> for (&'a [P<hir::Ty>], &'a [Spanned<ast::Name>]) {
2153+
impl<'a> Clean<Arguments> for (&'a [hir::Ty], &'a [Spanned<ast::Name>]) {
21542154
fn clean(&self, cx: &DocContext) -> Arguments {
21552155
Arguments {
21562156
values: self.0.iter().enumerate().map(|(i, ty)| {
@@ -2168,7 +2168,7 @@ impl<'a> Clean<Arguments> for (&'a [P<hir::Ty>], &'a [Spanned<ast::Name>]) {
21682168
}
21692169
}
21702170

2171-
impl<'a> Clean<Arguments> for (&'a [P<hir::Ty>], hir::BodyId) {
2171+
impl<'a> Clean<Arguments> for (&'a [hir::Ty], hir::BodyId) {
21722172
fn clean(&self, cx: &DocContext) -> Arguments {
21732173
let body = cx.tcx.hir.body(self.1);
21742174

@@ -2184,7 +2184,7 @@ impl<'a> Clean<Arguments> for (&'a [P<hir::Ty>], hir::BodyId) {
21842184
}
21852185

21862186
impl<'a, A: Copy> Clean<FnDecl> for (&'a hir::FnDecl, A)
2187-
where (&'a [P<hir::Ty>], A): Clean<Arguments>
2187+
where (&'a [hir::Ty], A): Clean<Arguments>
21882188
{
21892189
fn clean(&self, cx: &DocContext) -> FnDecl {
21902190
FnDecl {
@@ -2926,7 +2926,7 @@ impl Clean<Type> for hir::Ty {
29262926
}
29272927
});
29282928
if let Some(ty) = type_.cloned() {
2929-
ty_substs.insert(ty_param_def, ty.into_inner().clean(cx));
2929+
ty_substs.insert(ty_param_def, ty.clean(cx));
29302930
} else if let Some(default) = default.clone() {
29312931
ty_substs.insert(ty_param_def,
29322932
default.into_inner().clean(cx));

0 commit comments

Comments
 (0)