Skip to content

Commit 5d30201

Browse files
authored
Unrolled build for #131983
Rollup merge of #131983 - dingxiangfei2009:stabilize-shorter-tail-lifetimes, r=lcnr Stabilize shorter-tail-lifetimes Close #131445 Tracked by #123739 We found a test case `tests/ui/drop/drop_order.rs` that had not been covered by the change. The test fixture is fixed now with the correct expectation.
2 parents 1d4a767 + 0689b21 commit 5d30201

18 files changed

+39
-46
lines changed

Diff for: compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,8 @@ declare_features! (
364364
(accepted, self_in_typedefs, "1.32.0", Some(49303)),
365365
/// Allows `Self` struct constructor (RFC 2302).
366366
(accepted, self_struct_ctor, "1.32.0", Some(51994)),
367+
/// Shortern the tail expression lifetime
368+
(accepted, shorter_tail_lifetimes, "CURRENT_RUSTC_VERSION", Some(123739)),
367369
/// Allows using subslice patterns, `[a, .., b]` and `[a, xs @ .., b]`.
368370
(accepted, slice_patterns, "1.42.0", Some(62254)),
369371
/// Allows use of `&foo[a..b]` as a slicing syntax.

Diff for: compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,6 @@ declare_features! (
577577
(unstable, rust_cold_cc, "1.63.0", Some(97544)),
578578
/// Allows use of x86 SHA512, SM3 and SM4 target-features and intrinsics
579579
(unstable, sha512_sm_x86, "1.82.0", Some(126624)),
580-
/// Shortern the tail expression lifetime
581-
(unstable, shorter_tail_lifetimes, "1.79.0", Some(123739)),
582580
/// Allows the use of SIMD types in functions declared in `extern` blocks.
583581
(unstable, simd_ffi, "1.0.0", Some(27731)),
584582
/// Allows specialization of implementations (RFC 1210).

Diff for: compiler/rustc_hir_analysis/src/check/region.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,7 @@ fn resolve_block<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, blk: &'tcx h
167167
}
168168
}
169169
if let Some(tail_expr) = blk.expr {
170-
if visitor.tcx.features().shorter_tail_lifetimes()
171-
&& blk.span.edition().at_least_rust_2024()
172-
{
170+
if blk.span.edition().at_least_rust_2024() {
173171
visitor.terminating_scopes.insert(tail_expr.hir_id.local_id);
174172
}
175173
visitor.visit_expr(tail_expr);

Diff for: compiler/rustc_lint/src/tail_expr_drop_order.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@ use rustc_span::edition::Edition;
1414
use crate::{LateContext, LateLintPass};
1515

1616
declare_lint! {
17-
/// The `tail_expr_drop_order` lint looks for those values generated at the tail expression location, that of type
18-
/// with a significant `Drop` implementation, such as locks.
19-
/// In case there are also local variables of type with significant `Drop` implementation as well,
20-
/// this lint warns you of a potential transposition in the drop order.
21-
/// Your discretion on the new drop order introduced by Edition 2024 is required.
17+
/// The `tail_expr_drop_order` lint looks for those values generated at the tail expression location,
18+
/// that runs a custom `Drop` destructor.
19+
/// Some of them may be dropped earlier in Edition 2024 that they used to in Edition 2021 and prior.
20+
/// This lint detects those cases and provides you information on those values and their custom destructor implementations.
21+
/// Your discretion on this information is required.
2222
///
2323
/// ### Example
24-
/// ```rust,edition2024
25-
/// #![feature(shorter_tail_lifetimes)]
24+
/// ```rust,edition2021
2625
/// #![warn(tail_expr_drop_order)]
2726
/// struct Droppy(i32);
2827
/// impl Droppy {
@@ -37,12 +36,12 @@ declare_lint! {
3736
/// println!("loud drop {}", self.0);
3837
/// }
3938
/// }
40-
/// fn edition_2024() -> i32 {
39+
/// fn edition_2021() -> i32 {
4140
/// let another_droppy = Droppy(0);
4241
/// Droppy(1).get()
4342
/// }
4443
/// fn main() {
45-
/// edition_2024();
44+
/// edition_2021();
4645
/// }
4746
/// ```
4847
///
@@ -137,7 +136,7 @@ impl<'tcx> LateLintPass<'tcx> for TailExprDropOrder {
137136
_: Span,
138137
def_id: rustc_span::def_id::LocalDefId,
139138
) {
140-
if cx.tcx.sess.at_least_rust_2024() && cx.tcx.features().shorter_tail_lifetimes() {
139+
if !body.value.span.edition().at_least_rust_2024() {
141140
Self::check_fn_or_closure(cx, fn_kind, body, def_id);
142141
}
143142
}
@@ -185,8 +184,8 @@ impl<'a, 'tcx> Visitor<'tcx> for LintVisitor<'a, 'tcx> {
185184

186185
impl<'a, 'tcx> LintVisitor<'a, 'tcx> {
187186
fn check_block_inner(&mut self, block: &Block<'tcx>) {
188-
if !block.span.at_least_rust_2024() {
189-
// We only lint for Edition 2024 onwards
187+
if block.span.at_least_rust_2024() {
188+
// We only lint up to Edition 2021
190189
return;
191190
}
192191
let Some(tail_expr) = block.expr else { return };

Diff for: tests/ui/drop/drop_order.rs

+12
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ impl DropOrderCollector {
105105
() => self.print(10),
106106
}
107107

108+
#[cfg(edition2021)]
108109
match {
109110
match self.option_loud_drop(14) {
110111
_ => {
@@ -115,6 +116,17 @@ impl DropOrderCollector {
115116
} {
116117
_ => self.print(12),
117118
}
119+
#[cfg(edition2024)]
120+
match {
121+
match self.option_loud_drop(12) {
122+
_ => {
123+
self.print(11);
124+
self.option_loud_drop(14)
125+
}
126+
}
127+
} {
128+
_ => self.print(13),
129+
}
118130

119131
match {
120132
loop {

Diff for: tests/ui/drop/lint-tail-expr-drop-order-gated.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
// This test ensures that `tail_expr_drop_order` does not activate in case Edition 2024 is not used
2-
// or the feature gate `shorter_tail_lifetimes` is disabled.
1+
// This test is to demonstrate that the lint is gated behind Edition and
2+
// is triggered only for Edition 2021 and before.
33

4-
//@ revisions: neither no_feature_gate edition_less_than_2024
54
//@ check-pass
6-
//@ [neither] edition: 2021
7-
//@ [no_feature_gate] compile-flags: -Z unstable-options
8-
//@ [no_feature_gate] edition: 2024
9-
//@ [edition_less_than_2024] edition: 2021
5+
//@ edition: 2024
6+
//@ compile-flags: -Z unstable-options
107

118
#![deny(tail_expr_drop_order)]
12-
#![cfg_attr(edition_less_than_2024, feature(shorter_tail_lifetimes))]
139

1410
struct LoudDropper;
1511
impl Drop for LoudDropper {

Diff for: tests/ui/drop/lint-tail-expr-drop-order.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
//@ compile-flags: -Z unstable-options
2-
//@ edition: 2024
1+
//@ edition: 2021
32

43
// Edition 2024 lint for change in drop order at tail expression
54
// This lint is to capture potential change in program semantics
65
// due to implementation of RFC 3606 <https://github.com/rust-lang/rfcs/pull/3606>
76

87
#![deny(tail_expr_drop_order)]
9-
#![feature(shorter_tail_lifetimes)]
108

119
struct LoudDropper;
1210
impl Drop for LoudDropper {

Diff for: tests/ui/drop/lint-tail-expr-drop-order.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: these values and local bindings have significant drop implementation that will have a different drop order from that of Edition 2021
2-
--> $DIR/lint-tail-expr-drop-order.rs:29:15
2+
--> $DIR/lint-tail-expr-drop-order.rs:27:15
33
|
44
LL | let x = LoudDropper;
55
| - these values have significant drop implementation and will observe changes in drop order under Edition 2024
@@ -10,13 +10,13 @@ LL | x.get() + LoudDropper.get()
1010
= warning: this changes meaning in Rust 2024
1111
= note: for more information, see issue #123739 <https://github.com/rust-lang/rust/issues/123739>
1212
note: the lint level is defined here
13-
--> $DIR/lint-tail-expr-drop-order.rs:8:9
13+
--> $DIR/lint-tail-expr-drop-order.rs:7:9
1414
|
1515
LL | #![deny(tail_expr_drop_order)]
1616
| ^^^^^^^^^^^^^^^^^^^^
1717

1818
error: these values and local bindings have significant drop implementation that will have a different drop order from that of Edition 2021
19-
--> $DIR/lint-tail-expr-drop-order.rs:36:23
19+
--> $DIR/lint-tail-expr-drop-order.rs:34:23
2020
|
2121
LL | let x = LoudDropper;
2222
| - these values have significant drop implementation and will observe changes in drop order under Edition 2024
@@ -27,7 +27,7 @@ LL | move || x.get() + LoudDropper.get()
2727
= note: for more information, see issue #123739 <https://github.com/rust-lang/rust/issues/123739>
2828

2929
error: these values and local bindings have significant drop implementation that will have a different drop order from that of Edition 2021
30-
--> $DIR/lint-tail-expr-drop-order.rs:65:19
30+
--> $DIR/lint-tail-expr-drop-order.rs:63:19
3131
|
3232
LL | let x = LoudDropper;
3333
| - these values have significant drop implementation and will observe changes in drop order under Edition 2024

Diff for: tests/ui/drop/tail-expr-drop-order-negative.edition2024.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0716]: temporary value dropped while borrowed
2-
--> $DIR/tail-expr-drop-order-negative.rs:11:15
2+
--> $DIR/tail-expr-drop-order-negative.rs:9:15
33
|
44
LL | x.replace(std::cell::RefCell::new(123).borrow()).is_some()
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - temporary value is freed at the end of this statement

Diff for: tests/ui/drop/tail-expr-drop-order-negative.rs

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
//@ [edition2024] edition: 2024
44
//@ [edition2021] check-pass
55

6-
#![feature(shorter_tail_lifetimes)]
7-
86
fn why_would_you_do_this() -> bool {
97
let mut x = None;
108
// Make a temporary `RefCell` and put a `Ref` that borrows it in `x`.

Diff for: tests/ui/drop/tail-expr-drop-order.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
//@ edition: 2024
55
//@ run-pass
66

7-
#![feature(shorter_tail_lifetimes)]
87
#![allow(unused_imports)]
98
#![allow(dead_code)]
109
#![allow(unused_variables)]

Diff for: tests/ui/lifetimes/refcell-in-tail-expr.edition2021.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0597]: `cell` does not live long enough
2-
--> $DIR/refcell-in-tail-expr.rs:12:27
2+
--> $DIR/refcell-in-tail-expr.rs:10:27
33
|
44
LL | let cell = std::cell::RefCell::new(0u8);
55
| ---- binding `cell` declared here

Diff for: tests/ui/lifetimes/refcell-in-tail-expr.rs

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
//@ [edition2024] compile-flags: -Zunstable-options
55
//@ [edition2024] check-pass
66

7-
#![cfg_attr(edition2024, feature(shorter_tail_lifetimes))]
8-
97
fn main() {
108
let cell = std::cell::RefCell::new(0u8);
119

Diff for: tests/ui/lifetimes/shorter-tail-expr-lifetime.edition2021.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0597]: `c` does not live long enough
2-
--> $DIR/shorter-tail-expr-lifetime.rs:10:5
2+
--> $DIR/shorter-tail-expr-lifetime.rs:8:5
33
|
44
LL | let c = std::cell::RefCell::new("..");
55
| - binding `c` declared here

Diff for: tests/ui/lifetimes/shorter-tail-expr-lifetime.rs

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
//@ [edition2024] edition: 2024
44
//@ [edition2024] run-pass
55

6-
#![cfg_attr(edition2024, feature(shorter_tail_lifetimes))]
7-
86
fn f() -> usize {
97
let c = std::cell::RefCell::new("..");
108
c.borrow().len() //[edition2021]~ ERROR: `c` does not live long enough

Diff for: tests/ui/lifetimes/tail-expr-in-nested-expr.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//@ edition: 2024
22
//@ compile-flags: -Zunstable-options
33

4-
#![feature(shorter_tail_lifetimes)]
5-
64
fn main() {
75
let _ = { String::new().as_str() }.len();
86
//~^ ERROR temporary value dropped while borrowed

Diff for: tests/ui/lifetimes/tail-expr-in-nested-expr.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0716]: temporary value dropped while borrowed
2-
--> $DIR/tail-expr-in-nested-expr.rs:7:15
2+
--> $DIR/tail-expr-in-nested-expr.rs:5:15
33
|
44
LL | let _ = { String::new().as_str() }.len();
55
| ^^^^^^^^^^^^^---------

Diff for: tests/ui/lifetimes/tail-expr-lock-poisoning.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
//@ [edition2024] edition: 2024
55
//@ run-pass
66
//@ needs-unwind
7-
#![cfg_attr(edition2024, feature(shorter_tail_lifetimes))]
87

98
use std::sync::Mutex;
109

0 commit comments

Comments
 (0)