Skip to content

Commit cac3426

Browse files
committed
fix tidy errors
replace TODO with FIXME
1 parent 71d9fed commit cac3426

7 files changed

Lines changed: 30 additions & 21 deletions

File tree

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,7 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
251251
ExprKind::Await(expr, await_kw_span) => self.lower_expr_await(*await_kw_span, expr),
252252
ExprKind::Move(_, move_kw_span) => {
253253
if !self.tcx.features().move_expr() {
254-
return self.expr_err(
255-
*move_kw_span,
256-
self.dcx().span_delayed_bug(*move_kw_span, "invalid move(expr)"),
257-
);
254+
return self.expr_err(*move_kw_span, self.dcx().has_errors().unwrap());
258255
}
259256
if let Some((ident, binding)) = self
260257
.move_expr_bindings
@@ -277,10 +274,10 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
277274
}),
278275
))
279276
} else {
280-
self.dcx().emit_err(MoveExprOnlyInPlainClosures { span: *move_kw_span });
281-
hir::ExprKind::Err(
282-
self.dcx().span_delayed_bug(*move_kw_span, "invalid move(expr)"),
283-
)
277+
let guar = self
278+
.dcx()
279+
.emit_err(MoveExprOnlyInPlainClosures { span: *move_kw_span });
280+
hir::ExprKind::Err(guar)
284281
}
285282
}
286283
ExprKind::Use(expr, use_kw_span) => self.lower_expr_use(*use_kw_span, expr),
@@ -1096,6 +1093,8 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
10961093
let attrs = self.lower_attrs(expr_hir_id, &e.attrs, e.span, Target::from_expr(e));
10971094

10981095
match closure.coroutine_kind {
1096+
// FIXME(TaKO8Ki): Support `move(expr)` in coroutine closures too.
1097+
// For the first step, we only support plain closures.
10991098
Some(coroutine_kind) => hir::Expr {
11001099
hir_id: expr_hir_id,
11011100
kind: self.lower_expr_coroutine_closure(
@@ -1188,12 +1187,11 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
11881187
));
11891188
}
11901189

1191-
let explicit_captures = self.arena.alloc_from_iter(lowered_occurrences.iter().map(
1192-
|(occurrence, _, binding)| hir::ExplicitCapture {
1193-
var_hir_id: *binding,
1194-
origin_span: self.lower_span(occurrence.move_kw_span),
1195-
},
1196-
));
1190+
let explicit_captures = self.arena.alloc_from_iter(
1191+
lowered_occurrences
1192+
.iter()
1193+
.map(|(_, _, binding)| hir::ExplicitCapture { var_hir_id: *binding }),
1194+
);
11971195

11981196
let closure_expr = self.arena.alloc(hir::Expr {
11991197
hir_id: expr_hir_id,
@@ -1395,9 +1393,10 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
13951393
// knows that a `FnDecl` output type like `-> &str` actually means
13961394
// "coroutine that returns &str", rather than directly returning a `&str`.
13971395
kind: hir::ClosureKind::CoroutineClosure(coroutine_desugaring),
1398-
constness: hir::Constness::NotConst,
1396+
constness: self.lower_constness(constness),
13991397
explicit_captures: &[],
14001398
});
1399+
14011400
hir::ExprKind::Closure(c)
14021401
}
14031402

compiler/rustc_feature/src/unstable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,8 @@ declare_features! (
594594
(unstable, mips_target_feature, "1.27.0", Some(150253)),
595595
/// Allows qualified paths in struct expressions, struct patterns and tuple struct patterns.
596596
(unstable, more_qualified_paths, "1.54.0", Some(86935)),
597+
/// Allows `move(expr)` in closures.
598+
(incomplete, move_expr, "CURRENT_RUSTC_VERSION", Some(155050)),
597599
/// The `movrs` target feature on x86.
598600
(unstable, movrs_target_feature, "1.88.0", Some(137976)),
599601
/// Allows the `multiple_supertrait_upcastable` lint.
@@ -602,8 +604,6 @@ declare_features! (
602604
(unstable, must_not_suspend, "1.57.0", Some(83310)),
603605
/// Allows `mut ref` and `mut ref mut` identifier patterns.
604606
(incomplete, mut_ref, "1.79.0", Some(123076)),
605-
/// Allows `move(expr)` in closures.
606-
(incomplete, move_expr, "CURRENT_RUSTC_VERSION", None),
607607
/// Allows using `#[naked]` on `extern "Rust"` functions.
608608
(unstable, naked_functions_rustic_abi, "1.88.0", Some(138997)),
609609
/// Allows using `#[target_feature(enable = "...")]` on `#[naked]` on functions.

compiler/rustc_hir/src/hir.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1696,7 +1696,6 @@ pub struct Closure<'hir> {
16961696
#[derive(Debug, Clone, Copy, HashStable_Generic)]
16971697
pub struct ExplicitCapture {
16981698
pub var_hir_id: HirId,
1699-
pub origin_span: Span,
17001699
}
17011700

17021701
#[derive(Clone, PartialEq, Eq, Debug, Copy, Hash, HashStable_Generic, Encodable, Decodable)]

compiler/rustc_hir_typeck/src/upvar.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
219219
delegate.capture_information.push((
220220
place,
221221
ty::CaptureInfo {
222-
capture_kind_expr_id: Some(capture.var_hir_id),
223-
path_expr_id: Some(capture.var_hir_id),
222+
capture_kind_expr_id: Some(closure_hir_id),
223+
path_expr_id: Some(closure_hir_id),
224224
capture_kind: UpvarCapture::ByValue,
225225
},
226226
));

src/tools/rustfmt/src/expr.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,13 @@ pub(crate) fn format_expr(
127127
}
128128
ast::ExprKind::Move(ref subexpr, move_kw_span) => {
129129
let inner_span = mk_sp(move_kw_span.hi(), expr.span.hi());
130-
rewrite_call(context, "move", std::slice::from_ref(subexpr), inner_span, shape)
130+
rewrite_call(
131+
context,
132+
"move",
133+
std::slice::from_ref(subexpr),
134+
inner_span,
135+
shape,
136+
)
131137
}
132138
ast::ExprKind::Paren(ref subexpr) => rewrite_paren(context, subexpr, shape, expr.span),
133139
ast::ExprKind::Binary(op, ref lhs, ref rhs) => {

tests/ui/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,10 @@ Tests on the module system.
933933

934934
**FIXME**: `tests/ui/imports/` should probably be merged with this.
935935

936+
## `tests/ui/move-expr/`
937+
938+
Tests for `#![feature(move_expr)]`.
939+
936940
## `tests/ui/moves`
937941

938942
Tests on moves (destructive moves).

tests/ui/feature-gates/feature-gate-move_expr.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ error[E0658]: `move(expr)` syntax is experimental
44
LL | let _ = || move(2);
55
| ^^^^
66
|
7+
= note: see issue #155050 <https://github.com/rust-lang/rust/issues/155050> for more information
78
= help: add `#![feature(move_expr)]` to the crate attributes to enable
89
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
910

0 commit comments

Comments
 (0)