Skip to content

Commit 9361297

Browse files
authored
Rollup merge of #101493 - spastorino:borrow-mut-impl-trait-context, r=oli-obk
Pass ImplTraitContext as &mut to avoid the need of ImplTraitContext::reborrow `@oli-obk` requested this and other changes as a way of simplifying #101345. This is just going to make the diff of #101345 smaller. r? `@oli-obk` `@cjgillot`
2 parents 1d65e96 + 2166a36 commit 9361297

File tree

7 files changed

+125
-102
lines changed

7 files changed

+125
-102
lines changed

compiler/rustc_ast_lowering/src/asm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
220220
&sym.qself,
221221
&sym.path,
222222
ParamMode::Optional,
223-
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
223+
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Path),
224224
);
225225
hir::InlineAsmOperand::SymStatic { path, def_id }
226226
} else {

compiler/rustc_ast_lowering/src/block.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
8484
}
8585

8686
fn lower_local(&mut self, l: &Local) -> &'hir hir::Local<'hir> {
87-
let ty = l
88-
.ty
89-
.as_ref()
90-
.map(|t| self.lower_ty(t, ImplTraitContext::Disallowed(ImplTraitPosition::Variable)));
87+
let ty = l.ty.as_ref().map(|t| {
88+
self.lower_ty(t, &mut ImplTraitContext::Disallowed(ImplTraitPosition::Variable))
89+
});
9190
let init = l.kind.init().map(|init| self.lower_expr(init));
9291
let hir_id = self.lower_node_id(l.id);
9392
let pat = self.lower_pat(&l.pat);

compiler/rustc_ast_lowering/src/expr.rs

+18-16
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
6666
seg,
6767
ParamMode::Optional,
6868
ParenthesizedGenericArgs::Err,
69-
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
69+
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Path),
7070
));
7171
let receiver = self.lower_expr(receiver);
7272
let args =
@@ -89,14 +89,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
8989
}
9090
ExprKind::Cast(ref expr, ref ty) => {
9191
let expr = self.lower_expr(expr);
92-
let ty =
93-
self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type));
92+
let ty = self
93+
.lower_ty(ty, &mut ImplTraitContext::Disallowed(ImplTraitPosition::Type));
9494
hir::ExprKind::Cast(expr, ty)
9595
}
9696
ExprKind::Type(ref expr, ref ty) => {
9797
let expr = self.lower_expr(expr);
98-
let ty =
99-
self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type));
98+
let ty = self
99+
.lower_ty(ty, &mut ImplTraitContext::Disallowed(ImplTraitPosition::Type));
100100
hir::ExprKind::Type(expr, ty)
101101
}
102102
ExprKind::AddrOf(k, m, ref ohs) => {
@@ -219,7 +219,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
219219
qself,
220220
path,
221221
ParamMode::Optional,
222-
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
222+
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Path),
223223
);
224224
hir::ExprKind::Path(qpath)
225225
}
@@ -253,7 +253,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
253253
&se.qself,
254254
&se.path,
255255
ParamMode::Optional,
256-
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
256+
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Path),
257257
)),
258258
self.arena
259259
.alloc_from_iter(se.fields.iter().map(|x| self.lower_expr_field(x))),
@@ -550,12 +550,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
550550
async_gen_kind: hir::AsyncGeneratorKind,
551551
body: impl FnOnce(&mut Self) -> hir::Expr<'hir>,
552552
) -> hir::ExprKind<'hir> {
553-
let output = match ret_ty {
554-
Some(ty) => hir::FnRetTy::Return(
555-
self.lower_ty(&ty, ImplTraitContext::Disallowed(ImplTraitPosition::AsyncBlock)),
556-
),
557-
None => hir::FnRetTy::DefaultReturn(self.lower_span(span)),
558-
};
553+
let output =
554+
match ret_ty {
555+
Some(ty) => hir::FnRetTy::Return(self.lower_ty(
556+
&ty,
557+
&mut ImplTraitContext::Disallowed(ImplTraitPosition::AsyncBlock),
558+
)),
559+
None => hir::FnRetTy::DefaultReturn(self.lower_span(span)),
560+
};
559561

560562
// Resume argument type. We let the compiler infer this to simplify the lowering. It is
561563
// fully constrained by `future::from_generator`.
@@ -1123,7 +1125,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
11231125
qself,
11241126
path,
11251127
ParamMode::Optional,
1126-
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
1128+
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Path),
11271129
);
11281130
// Destructure like a tuple struct.
11291131
let tuple_struct_pat =
@@ -1139,7 +1141,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
11391141
qself,
11401142
path,
11411143
ParamMode::Optional,
1142-
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
1144+
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Path),
11431145
);
11441146
// Destructure like a unit struct.
11451147
let unit_struct_pat = hir::PatKind::Path(qpath);
@@ -1163,7 +1165,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
11631165
&se.qself,
11641166
&se.path,
11651167
ParamMode::Optional,
1166-
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
1168+
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Path),
11671169
);
11681170
let fields_omitted = match &se.rest {
11691171
StructRest::Base(e) => {

0 commit comments

Comments
 (0)