Skip to content

Commit 6d569f7

Browse files
stabilize if_let_rescope
1 parent be01dab commit 6d569f7

20 files changed

+30
-84
lines changed

compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ declare_features! (
224224
(accepted, i128_type, "1.26.0", Some(35118)),
225225
/// Allows the use of `if let` expressions.
226226
(accepted, if_let, "1.0.0", None),
227+
/// Rescoping temporaries in `if let` to align with Rust 2024.
228+
(accepted, if_let_rescope, "CURRENT_RUSTC_VERSION", Some(124085)),
227229
/// Allows top level or-patterns (`p | q`) in `if let` and `while let`.
228230
(accepted, if_while_or_patterns, "1.33.0", Some(48215)),
229231
/// Allows lifetime elision in `impl` headers. For example:

compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,6 @@ declare_features! (
482482
(unstable, half_open_range_patterns_in_slices, "1.66.0", Some(67264)),
483483
/// Allows `if let` guard in match arms.
484484
(unstable, if_let_guard, "1.47.0", Some(51114)),
485-
/// Rescoping temporaries in `if let` to align with Rust 2024.
486-
(unstable, if_let_rescope, "1.83.0", Some(124085)),
487485
/// Allows `impl Trait` to be used inside associated types (RFC 2515).
488486
(unstable, impl_trait_in_assoc_type, "1.70.0", Some(63063)),
489487
/// Allows `impl Trait` as output type in `Fn` traits in return position of functions.

compiler/rustc_hir_analysis/src/check/region.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,7 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h
466466

467467
hir::ExprKind::If(cond, then, Some(otherwise)) => {
468468
let expr_cx = visitor.cx;
469-
let data = if expr.span.at_least_rust_2024() && visitor.tcx.features().if_let_rescope()
470-
{
469+
let data = if expr.span.at_least_rust_2024() {
471470
ScopeData::IfThenRescope
472471
} else {
473472
ScopeData::IfThen
@@ -482,8 +481,7 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h
482481

483482
hir::ExprKind::If(cond, then, None) => {
484483
let expr_cx = visitor.cx;
485-
let data = if expr.span.at_least_rust_2024() && visitor.tcx.features().if_let_rescope()
486-
{
484+
let data = if expr.span.at_least_rust_2024() {
487485
ScopeData::IfThenRescope
488486
} else {
489487
ScopeData::IfThen

compiler/rustc_lint/src/if_let_rescope.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ declare_lint! {
2424
/// ### Example
2525
///
2626
/// ```rust,edition2021
27-
/// #![feature(if_let_rescope)]
2827
/// #![warn(if_let_rescope)]
2928
/// #![allow(unused_variables)]
3029
///
@@ -243,7 +242,7 @@ impl_lint_pass!(
243242

244243
impl<'tcx> LateLintPass<'tcx> for IfLetRescope {
245244
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>) {
246-
if expr.span.edition().at_least_rust_2024() || !cx.tcx.features().if_let_rescope() {
245+
if expr.span.edition().at_least_rust_2024() {
247246
return;
248247
}
249248
if let (Level::Allow, _) = cx.tcx.lint_level_at_node(IF_LET_RESCOPE, expr.hir_id) {

compiler/rustc_mir_build/src/thir/cx/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ impl<'tcx> Cx<'tcx> {
777777
if_then_scope: region::Scope {
778778
id: then.hir_id.local_id,
779779
data: {
780-
if expr.span.at_least_rust_2024() && tcx.features().if_let_rescope() {
780+
if expr.span.at_least_rust_2024() {
781781
region::ScopeData::IfThenRescope
782782
} else {
783783
region::ScopeData::IfThen

tests/ui/drop/drop_order.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
//@ [edition2021] edition: 2021
55
//@ [edition2024] compile-flags: -Z unstable-options
66
//@ [edition2024] edition: 2024
7+
78
#![feature(let_chains)]
8-
#![cfg_attr(edition2024, feature(if_let_rescope))]
99

1010
use std::cell::RefCell;
1111
use std::convert::TryInto;

tests/ui/drop/drop_order_if_let_rescope.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//@ compile-flags: -Z validate-mir -Zunstable-options
44

55
#![feature(let_chains)]
6-
#![feature(if_let_rescope)]
76

87
use std::cell::RefCell;
98
use std::convert::TryInto;

tests/ui/drop/if-let-rescope-borrowck-suggestions.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//@ edition: 2024
22
//@ compile-flags: -Z validate-mir -Zunstable-options
33

4-
#![feature(if_let_rescope)]
54
#![deny(if_let_rescope)]
65

76
struct Droppy;

tests/ui/drop/if-let-rescope-borrowck-suggestions.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error[E0716]: temporary value dropped while borrowed
2-
--> $DIR/if-let-rescope-borrowck-suggestions.rs:22:39
2+
--> $DIR/if-let-rescope-borrowck-suggestions.rs:21:39
33
|
44
LL | do_something(if let Some(value) = Droppy.get_ref() { value } else { &0 });
55
| ^^^^^^ - temporary value is freed at the end of this statement
66
| |
77
| creates a temporary value which is freed while still in use
88
|
99
note: lifetimes for temporaries generated in `if let`s have been shortened in Edition 2024 so that they are dropped here instead
10-
--> $DIR/if-let-rescope-borrowck-suggestions.rs:22:64
10+
--> $DIR/if-let-rescope-borrowck-suggestions.rs:21:64
1111
|
1212
LL | do_something(if let Some(value) = Droppy.get_ref() { value } else { &0 });
1313
| ^
@@ -22,7 +22,7 @@ LL | do_something({ match Droppy.get_ref() { Some(value) => { value } _ =>
2222
| ~~~~~~~ ++++++++++++++++ ~~~~ ++
2323

2424
error[E0716]: temporary value dropped while borrowed
25-
--> $DIR/if-let-rescope-borrowck-suggestions.rs:24:39
25+
--> $DIR/if-let-rescope-borrowck-suggestions.rs:23:39
2626
|
2727
LL | do_something(if let Some(value) = Droppy.get_ref() {
2828
| ^^^^^^ creates a temporary value which is freed while still in use
@@ -31,7 +31,7 @@ LL | } else if let Some(value) = Droppy.get_ref() {
3131
| - temporary value is freed at the end of this statement
3232
|
3333
note: lifetimes for temporaries generated in `if let`s have been shortened in Edition 2024 so that they are dropped here instead
34-
--> $DIR/if-let-rescope-borrowck-suggestions.rs:27:5
34+
--> $DIR/if-let-rescope-borrowck-suggestions.rs:26:5
3535
|
3636
LL | } else if let Some(value) = Droppy.get_ref() {
3737
| ^
@@ -53,7 +53,7 @@ LL ~ }}});
5353
|
5454

5555
error[E0716]: temporary value dropped while borrowed
56-
--> $DIR/if-let-rescope-borrowck-suggestions.rs:27:33
56+
--> $DIR/if-let-rescope-borrowck-suggestions.rs:26:33
5757
|
5858
LL | } else if let Some(value) = Droppy.get_ref() {
5959
| ^^^^^^ creates a temporary value which is freed while still in use
@@ -62,7 +62,7 @@ LL | } else {
6262
| - temporary value is freed at the end of this statement
6363
|
6464
note: lifetimes for temporaries generated in `if let`s have been shortened in Edition 2024 so that they are dropped here instead
65-
--> $DIR/if-let-rescope-borrowck-suggestions.rs:30:5
65+
--> $DIR/if-let-rescope-borrowck-suggestions.rs:29:5
6666
|
6767
LL | } else {
6868
| ^
+11-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// This test checks that the lint `if_let_rescope` only actions
2-
// when the feature gate is enabled.
3-
// Edition 2021 is used here because the lint should work especially
4-
// when edition migration towards 2024 is run.
2+
// when Edition 2021 or prior is targeted here because the lint should work especially
3+
// when edition migration towards 2024 is executed.
54

6-
//@ revisions: with_feature_gate without_feature_gate
7-
//@ [without_feature_gate] check-pass
8-
//@ edition: 2021
5+
//@ revisions: edition2021 edition2024
6+
//@ [edition2021] edition: 2021
7+
//@ [edition2024] edition: 2024
8+
//@ [edition2024] compile-flags: -Zunstable-options
9+
//@ [edition2024] check-pass
910

10-
#![cfg_attr(with_feature_gate, feature(if_let_rescope))]
1111
#![deny(if_let_rescope)]
1212
#![allow(irrefutable_let_patterns)]
1313

@@ -25,10 +25,10 @@ impl Droppy {
2525

2626
fn main() {
2727
if let Some(_value) = Droppy.get() {
28-
//[with_feature_gate]~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024
29-
//[with_feature_gate]~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
30-
//[with_feature_gate]~| WARN: this changes meaning in Rust 2024
28+
//[edition2021]~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024
29+
//[edition2021]~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
30+
//[edition2021]~| WARN: this changes meaning in Rust 2024
3131
} else {
32-
//[with_feature_gate]~^ HELP: the value is now dropped here in Edition 2024
32+
//[edition2021]~^ HELP: the value is now dropped here in Edition 2024
3333
}
3434
}

tests/ui/drop/lint-if-let-rescope-with-macro.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
//@ edition:2021
55
//@ compile-flags: -Z unstable-options
66

7-
#![feature(if_let_rescope)]
87
#![deny(if_let_rescope)]
98
#![allow(irrefutable_let_patterns)]
109

tests/ui/drop/lint-if-let-rescope-with-macro.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: `if let` assigns a shorter lifetime since Edition 2024
2-
--> $DIR/lint-if-let-rescope-with-macro.rs:13:12
2+
--> $DIR/lint-if-let-rescope-with-macro.rs:12:12
33
|
44
LL | if let $p = $e { $($conseq)* } else { $($alt)* }
55
| ^^^
@@ -16,7 +16,7 @@ LL | | };
1616
= warning: this changes meaning in Rust 2024
1717
= note: for more information, see issue #124085 <https://github.com/rust-lang/rust/issues/124085>
1818
help: the value is now dropped here in Edition 2024
19-
--> $DIR/lint-if-let-rescope-with-macro.rs:13:38
19+
--> $DIR/lint-if-let-rescope-with-macro.rs:12:38
2020
|
2121
LL | if let $p = $e { $($conseq)* } else { $($alt)* }
2222
| ^
@@ -29,7 +29,7 @@ LL | | {}
2929
LL | | };
3030
| |_____- in this macro invocation
3131
note: the lint level is defined here
32-
--> $DIR/lint-if-let-rescope-with-macro.rs:8:9
32+
--> $DIR/lint-if-let-rescope-with-macro.rs:7:9
3333
|
3434
LL | #![deny(if_let_rescope)]
3535
| ^^^^^^^^^^^^^^

tests/ui/drop/lint-if-let-rescope.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@ run-rustfix
22

33
#![deny(if_let_rescope)]
4-
#![feature(if_let_rescope, stmt_expr_attributes)]
4+
#![feature(stmt_expr_attributes)]
55
#![allow(irrefutable_let_patterns, unused_parens)]
66

77
fn droppy() -> Droppy {

tests/ui/drop/lint-if-let-rescope.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@ run-rustfix
22

33
#![deny(if_let_rescope)]
4-
#![feature(if_let_rescope, stmt_expr_attributes)]
4+
#![feature(stmt_expr_attributes)]
55
#![allow(irrefutable_let_patterns, unused_parens)]
66

77
fn droppy() -> Droppy {

tests/ui/feature-gates/feature-gate-if-let-rescope.rs

-27
This file was deleted.

tests/ui/feature-gates/feature-gate-if-let-rescope.stderr

-18
This file was deleted.

tests/ui/mir/mir_let_chains_drop_order.rs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// See `mir_drop_order.rs` for more information
99

1010
#![feature(let_chains)]
11-
#![cfg_attr(edition2024, feature(if_let_rescope))]
1211
#![allow(irrefutable_let_patterns)]
1312

1413
use std::cell::RefCell;

tests/ui/nll/issue-54556-niconii.edition2021.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0597]: `counter` does not live long enough
2-
--> $DIR/issue-54556-niconii.rs:30:20
2+
--> $DIR/issue-54556-niconii.rs:28:20
33
|
44
LL | let counter = Mutex;
55
| ------- binding `counter` declared here

tests/ui/nll/issue-54556-niconii.rs

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
//@ [edition2024] compile-flags: -Z unstable-options
1313
//@ [edition2024] check-pass
1414

15-
#![cfg_attr(edition2024, feature(if_let_rescope))]
16-
1715
struct Mutex;
1816
struct MutexGuard<'a>(&'a Mutex);
1917

0 commit comments

Comments
 (0)