Skip to content

Commit 8daa523

Browse files
stabilize if_let_rescope
1 parent de977a5 commit 8daa523

21 files changed

+59
-81
lines changed

compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ declare_features! (
244244
(accepted, irrefutable_let_patterns, "1.33.0", Some(44495)),
245245
/// Allows `#[instruction_set(_)]` attribute.
246246
(accepted, isa_attribute, "1.67.0", Some(74727)),
247+
/// Rescoping temporaries in `if let` to align with Rust 2024.
248+
(accepted, if_let_rescope, "1.83.0", Some(124085)),
247249
/// Allows some increased flexibility in the name resolution rules,
248250
/// especially around globs and shadowing (RFC 1560).
249251
(accepted, item_like_imports, "1.15.0", Some(35120)),

compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,6 @@ declare_features! (
497497
(unstable, half_open_range_patterns_in_slices, "1.66.0", Some(67264)),
498498
/// Allows `if let` guard in match arms.
499499
(unstable, if_let_guard, "1.47.0", Some(51114)),
500-
/// Rescoping temporaries in `if let` to align with Rust 2024.
501-
(unstable, if_let_rescope, "1.83.0", Some(124085)),
502500
/// Allows `impl Trait` to be used inside associated types (RFC 2515).
503501
(unstable, impl_trait_in_assoc_type, "1.70.0", Some(63063)),
504502
/// Allows `impl Trait` as output type in `Fn` traits in return position of functions.

compiler/rustc_hir_analysis/src/check/region.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -466,7 +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 {
469+
let data = if expr.span.at_least_rust_2024() {
470470
ScopeData::IfThenRescope
471471
} else {
472472
ScopeData::IfThen
@@ -481,7 +481,7 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h
481481

482482
hir::ExprKind::If(cond, then, None) => {
483483
let expr_cx = visitor.cx;
484-
let data = if expr.span.at_least_rust_2024() && visitor.tcx.features().if_let_rescope {
484+
let data = if expr.span.at_least_rust_2024() {
485485
ScopeData::IfThenRescope
486486
} else {
487487
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
| ^

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

+4-7
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33
// Edition 2021 is used here because the lint should work especially
44
// when edition migration towards 2024 is run.
55

6-
//@ revisions: with_feature_gate without_feature_gate
7-
//@ [without_feature_gate] check-pass
86
//@ edition: 2021
97

10-
#![cfg_attr(with_feature_gate, feature(if_let_rescope))]
118
#![deny(if_let_rescope)]
129
#![allow(irrefutable_let_patterns)]
1310

@@ -25,10 +22,10 @@ impl Droppy {
2522

2623
fn main() {
2724
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
25+
//~^ ERROR: `if let` assigns a shorter lifetime since Edition 2024
26+
//~| HELP: a `match` with a single arm can preserve the drop order up to Edition 2021
27+
//~| WARN: this changes meaning in Rust 2024
3128
} else {
32-
//[with_feature_gate]~^ HELP: the value is now dropped here in Edition 2024
29+
//~^ HELP: the value is now dropped here in Edition 2024
3330
}
3431
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
error: `if let` assigns a shorter lifetime since Edition 2024
2+
--> $DIR/lint-if-let-rescope-gated.rs:24:8
3+
|
4+
LL | if let Some(_value) = Droppy.get() {
5+
| ^^^^^^^^^^^^^^^^^^^------^^^^^^
6+
| |
7+
| this value has a significant drop implementation which may observe a major change in drop order and requires your discretion
8+
|
9+
= warning: this changes meaning in Rust 2024
10+
= note: for more information, see issue #124085 <https://github.com/rust-lang/rust/issues/124085>
11+
help: the value is now dropped here in Edition 2024
12+
--> $DIR/lint-if-let-rescope-gated.rs:28:5
13+
|
14+
LL | } else {
15+
| ^
16+
note: the lint level is defined here
17+
--> $DIR/lint-if-let-rescope-gated.rs:8:9
18+
|
19+
LL | #![deny(if_let_rescope)]
20+
| ^^^^^^^^^^^^^^
21+
help: a `match` with a single arm can preserve the drop order up to Edition 2021
22+
|
23+
LL ~ match Droppy.get() { Some(_value) => {
24+
LL |
25+
LL |
26+
LL |
27+
LL ~ } _ => {
28+
LL |
29+
LL ~ }}
30+
|
31+
32+
error: aborting due to 1 previous error
33+

tests/ui/drop/lint-if-let-rescope-gated.with_feature_gate.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-gated.rs:27:8
2+
--> $DIR/lint-if-let-rescope-gated.rs:26:8
33
|
44
LL | if let Some(_value) = Droppy.get() {
55
| ^^^^^^^^^^^^^^^^^^^------^^^^^^
@@ -9,12 +9,12 @@ LL | if let Some(_value) = Droppy.get() {
99
= warning: this changes meaning in Rust 2024
1010
= note: for more information, see issue #124085 <https://github.com/rust-lang/rust/issues/124085>
1111
help: the value is now dropped here in Edition 2024
12-
--> $DIR/lint-if-let-rescope-gated.rs:31:5
12+
--> $DIR/lint-if-let-rescope-gated.rs:30:5
1313
|
1414
LL | } else {
1515
| ^
1616
note: the lint level is defined here
17-
--> $DIR/lint-if-let-rescope-gated.rs:11:9
17+
--> $DIR/lint-if-let-rescope-gated.rs:10:9
1818
|
1919
LL | #![deny(if_let_rescope)]
2020
| ^^^^^^^^^^^^^^

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)