Skip to content

Commit 56237d7

Browse files
committed
Auto merge of #66252 - cjgillot:trees, r=oli-obk
Merge repeated definitions Step forward on #66149 I may need further context to understand the need for a separate crate. Also, please tell me if you think of other definitions to merge.
2 parents 9248b01 + 76128f8 commit 56237d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+298
-404
lines changed

src/librustc/hir/lowering.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,7 @@ impl<'a> LoweringContext<'a> {
12171217
&NodeMap::default(),
12181218
ImplTraitContext::disallowed(),
12191219
),
1220-
unsafety: this.lower_unsafety(f.unsafety),
1220+
unsafety: f.unsafety,
12211221
abi: this.lower_abi(f.abi),
12221222
decl: this.lower_fn_decl(&f.decl, None, false, None),
12231223
param_names: this.lower_fn_params_to_names(&f.decl),
@@ -2081,13 +2081,6 @@ impl<'a> LoweringContext<'a> {
20812081
}, ids)
20822082
}
20832083

2084-
fn lower_mutability(&mut self, m: Mutability) -> hir::Mutability {
2085-
match m {
2086-
Mutability::Mutable => hir::MutMutable,
2087-
Mutability::Immutable => hir::MutImmutable,
2088-
}
2089-
}
2090-
20912084
fn lower_fn_params_to_names(&mut self, decl: &FnDecl) -> hir::HirVec<Ident> {
20922085
// Skip the `...` (`CVarArgs`) trailing arguments from the AST,
20932086
// as they are not explicit in HIR/Ty function signatures.
@@ -2657,7 +2650,7 @@ impl<'a> LoweringContext<'a> {
26572650
fn lower_mt(&mut self, mt: &MutTy, itctx: ImplTraitContext<'_>) -> hir::MutTy {
26582651
hir::MutTy {
26592652
ty: self.lower_ty(&mt.ty, itctx),
2660-
mutbl: self.lower_mutability(mt.mutbl),
2653+
mutbl: mt.mutbl,
26612654
}
26622655
}
26632656

@@ -2758,7 +2751,7 @@ impl<'a> LoweringContext<'a> {
27582751
}
27592752
PatKind::Box(ref inner) => hir::PatKind::Box(self.lower_pat(inner)),
27602753
PatKind::Ref(ref inner, mutbl) => {
2761-
hir::PatKind::Ref(self.lower_pat(inner), self.lower_mutability(mutbl))
2754+
hir::PatKind::Ref(self.lower_pat(inner), mutbl)
27622755
}
27632756
PatKind::Range(ref e1, ref e2, Spanned { node: ref end, .. }) => hir::PatKind::Range(
27642757
P(self.lower_expr(e1)),

src/librustc/hir/lowering/expr.rs

+5-18
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ impl LoweringContext<'_> {
6464
hir::ExprKind::Type(expr, self.lower_ty(ty, ImplTraitContext::disallowed()))
6565
}
6666
ExprKind::AddrOf(m, ref ohs) => {
67-
let m = self.lower_mutability(m);
6867
let ohs = P(self.lower_expr(ohs));
6968
hir::ExprKind::AddrOf(m, ohs)
7069
}
@@ -474,7 +473,6 @@ impl LoweringContext<'_> {
474473
async_gen_kind: hir::AsyncGeneratorKind,
475474
body: impl FnOnce(&mut LoweringContext<'_>) -> hir::Expr,
476475
) -> hir::ExprKind {
477-
let capture_clause = self.lower_capture_clause(capture_clause);
478476
let output = match ret_ty {
479477
Some(ty) => FunctionRetTy::Ty(ty),
480478
None => FunctionRetTy::Default(span),
@@ -495,7 +493,7 @@ impl LoweringContext<'_> {
495493
decl,
496494
body_id,
497495
span,
498-
Some(hir::GeneratorMovability::Static)
496+
Some(hir::Movability::Static)
499497
);
500498
let generator = hir::Expr {
501499
hir_id: self.lower_node_id(closure_node_id),
@@ -701,7 +699,6 @@ impl LoweringContext<'_> {
701699
generator_kind,
702700
movability,
703701
);
704-
let capture_clause = this.lower_capture_clause(capture_clause);
705702
this.current_item = prev;
706703
hir::ExprKind::Closure(
707704
capture_clause,
@@ -713,20 +710,13 @@ impl LoweringContext<'_> {
713710
})
714711
}
715712

716-
fn lower_capture_clause(&mut self, c: CaptureBy) -> hir::CaptureClause {
717-
match c {
718-
CaptureBy::Value => hir::CaptureByValue,
719-
CaptureBy::Ref => hir::CaptureByRef,
720-
}
721-
}
722-
723713
fn generator_movability_for_fn(
724714
&mut self,
725715
decl: &FnDecl,
726716
fn_decl_span: Span,
727717
generator_kind: Option<hir::GeneratorKind>,
728718
movability: Movability,
729-
) -> Option<hir::GeneratorMovability> {
719+
) -> Option<hir::Movability> {
730720
match generator_kind {
731721
Some(hir::GeneratorKind::Gen) => {
732722
if !decl.inputs.is_empty() {
@@ -737,10 +727,7 @@ impl LoweringContext<'_> {
737727
"generators cannot have explicit parameters"
738728
);
739729
}
740-
Some(match movability {
741-
Movability::Movable => hir::GeneratorMovability::Movable,
742-
Movability::Static => hir::GeneratorMovability::Static,
743-
})
730+
Some(movability)
744731
},
745732
Some(hir::GeneratorKind::Async(_)) => {
746733
bug!("non-`async` closure body turned `async` during lowering");
@@ -811,7 +798,7 @@ impl LoweringContext<'_> {
811798
this.expr(fn_decl_span, async_body, ThinVec::new())
812799
});
813800
hir::ExprKind::Closure(
814-
this.lower_capture_clause(capture_clause),
801+
capture_clause,
815802
fn_decl,
816803
body_id,
817804
fn_decl_span,
@@ -1350,7 +1337,7 @@ impl LoweringContext<'_> {
13501337
}
13511338

13521339
fn expr_mut_addr_of(&mut self, span: Span, e: P<hir::Expr>) -> hir::Expr {
1353-
self.expr(span, hir::ExprKind::AddrOf(hir::MutMutable, e), ThinVec::new())
1340+
self.expr(span, hir::ExprKind::AddrOf(hir::Mutability::Mutable, e), ThinVec::new())
13541341
}
13551342

13561343
fn expr_unit(&mut self, sp: Span) -> hir::Expr {

src/librustc/hir/lowering/item.rs

+9-37
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use smallvec::SmallVec;
1919
use syntax::attr;
2020
use syntax::ast::*;
2121
use syntax::visit::{self, Visitor};
22-
use syntax::source_map::{respan, DesugaringKind, Spanned};
22+
use syntax::source_map::{respan, DesugaringKind};
2323
use syntax::symbol::{kw, sym};
2424
use syntax_pos::Span;
2525

@@ -289,7 +289,7 @@ impl LoweringContext<'_> {
289289
ImplTraitContext::Disallowed(ImplTraitPosition::Binding)
290290
}
291291
),
292-
self.lower_mutability(m),
292+
m,
293293
self.lower_const_body(e),
294294
)
295295
}
@@ -433,8 +433,8 @@ impl LoweringContext<'_> {
433433
);
434434

435435
hir::ItemKind::Impl(
436-
self.lower_unsafety(unsafety),
437-
self.lower_impl_polarity(polarity),
436+
unsafety,
437+
polarity,
438438
self.lower_defaultness(defaultness, true /* [1] */),
439439
generics,
440440
trait_ref,
@@ -449,8 +449,8 @@ impl LoweringContext<'_> {
449449
.map(|item| self.lower_trait_item_ref(item))
450450
.collect();
451451
hir::ItemKind::Trait(
452-
self.lower_is_auto(is_auto),
453-
self.lower_unsafety(unsafety),
452+
is_auto,
453+
unsafety,
454454
self.lower_generics(generics, ImplTraitContext::disallowed()),
455455
bounds,
456456
items,
@@ -719,7 +719,7 @@ impl LoweringContext<'_> {
719719
}
720720
ForeignItemKind::Static(ref t, m) => {
721721
hir::ForeignItemKind::Static(
722-
self.lower_ty(t, ImplTraitContext::disallowed()), self.lower_mutability(m))
722+
self.lower_ty(t, ImplTraitContext::disallowed()), m)
723723
}
724724
ForeignItemKind::Ty => hir::ForeignItemKind::Type,
725725
ForeignItemKind::Macro(_) => panic!("macro shouldn't exist here"),
@@ -1011,13 +1011,6 @@ impl LoweringContext<'_> {
10111011
}
10121012
}
10131013

1014-
fn lower_impl_polarity(&mut self, i: ImplPolarity) -> hir::ImplPolarity {
1015-
match i {
1016-
ImplPolarity::Positive => hir::ImplPolarity::Positive,
1017-
ImplPolarity::Negative => hir::ImplPolarity::Negative,
1018-
}
1019-
}
1020-
10211014
fn record_body(&mut self, params: HirVec<hir::Param>, value: hir::Expr) -> hir::BodyId {
10221015
let body = hir::Body {
10231016
generator_kind: self.generator_kind,
@@ -1275,18 +1268,11 @@ impl LoweringContext<'_> {
12751268
(generics, hir::FnSig { header, decl })
12761269
}
12771270

1278-
fn lower_is_auto(&mut self, a: IsAuto) -> hir::IsAuto {
1279-
match a {
1280-
IsAuto::Yes => hir::IsAuto::Yes,
1281-
IsAuto::No => hir::IsAuto::No,
1282-
}
1283-
}
1284-
12851271
fn lower_fn_header(&mut self, h: FnHeader) -> hir::FnHeader {
12861272
hir::FnHeader {
1287-
unsafety: self.lower_unsafety(h.unsafety),
1273+
unsafety: h.unsafety,
12881274
asyncness: self.lower_asyncness(h.asyncness.node),
1289-
constness: self.lower_constness(h.constness),
1275+
constness: h.constness.node,
12901276
abi: self.lower_abi(h.abi),
12911277
}
12921278
}
@@ -1311,20 +1297,6 @@ impl LoweringContext<'_> {
13111297
.emit();
13121298
}
13131299

1314-
pub(super) fn lower_unsafety(&mut self, u: Unsafety) -> hir::Unsafety {
1315-
match u {
1316-
Unsafety::Unsafe => hir::Unsafety::Unsafe,
1317-
Unsafety::Normal => hir::Unsafety::Normal,
1318-
}
1319-
}
1320-
1321-
fn lower_constness(&mut self, c: Spanned<Constness>) -> hir::Constness {
1322-
match c.node {
1323-
Constness::Const => hir::Constness::Const,
1324-
Constness::NotConst => hir::Constness::NotConst,
1325-
}
1326-
}
1327-
13281300
fn lower_asyncness(&mut self, a: IsAsync) -> hir::IsAsync {
13291301
match a {
13301302
IsAsync::Async { .. } => hir::IsAsync::Async,

0 commit comments

Comments
 (0)