Skip to content

Commit a93c171

Browse files
committed
Auto merge of #132116 - matthiaskrgr:rollup-3a0ia4r, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - #131790 (Document textual format of SocketAddrV{4,6}) - #131983 (Stabilize shorter-tail-lifetimes) - #132097 (sanitizer.md: LeakSanitizer is not supported on aarch64 macOS) - #132107 (Remove visit_expr_post from ast Visitor) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1d4a767 + a8cea36 commit a93c171

22 files changed

+91
-66
lines changed

compiler/rustc_ast/src/visit.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,6 @@ pub trait Visitor<'ast>: Sized {
173173
fn visit_method_receiver_expr(&mut self, ex: &'ast Expr) -> Self::Result {
174174
self.visit_expr(ex)
175175
}
176-
fn visit_expr_post(&mut self, _ex: &'ast Expr) -> Self::Result {
177-
Self::Result::output()
178-
}
179176
fn visit_ty(&mut self, t: &'ast Ty) -> Self::Result {
180177
walk_ty(self, t)
181178
}
@@ -1185,7 +1182,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) -> V
11851182
ExprKind::Dummy => {}
11861183
}
11871184

1188-
visitor.visit_expr_post(expression)
1185+
V::Result::output()
11891186
}
11901187

11911188
pub fn walk_param<'a, V: Visitor<'a>>(visitor: &mut V, param: &'a Param) -> V::Result {

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.

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).

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);

compiler/rustc_lint/src/early.rs

+12-15
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,18 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
121121
self.with_lint_attrs(e.id, &e.attrs, |cx| {
122122
lint_callback!(cx, check_expr, e);
123123
ast_visit::walk_expr(cx, e);
124+
// Explicitly check for lints associated with 'closure_id', since
125+
// it does not have a corresponding AST node
126+
match e.kind {
127+
ast::ExprKind::Closure(box ast::Closure {
128+
coroutine_kind: Some(coroutine_kind),
129+
..
130+
}) => {
131+
cx.check_id(coroutine_kind.closure_id());
132+
}
133+
_ => {}
134+
}
135+
lint_callback!(cx, check_expr_post, e);
124136
})
125137
}
126138

@@ -214,21 +226,6 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
214226
})
215227
}
216228

217-
fn visit_expr_post(&mut self, e: &'a ast::Expr) {
218-
// Explicitly check for lints associated with 'closure_id', since
219-
// it does not have a corresponding AST node
220-
match e.kind {
221-
ast::ExprKind::Closure(box ast::Closure {
222-
coroutine_kind: Some(coroutine_kind),
223-
..
224-
}) => {
225-
self.check_id(coroutine_kind.closure_id());
226-
}
227-
_ => {}
228-
}
229-
lint_callback!(self, check_expr_post, e);
230-
}
231-
232229
fn visit_generic_arg(&mut self, arg: &'a ast::GenericArg) {
233230
lint_callback!(self, check_generic_arg, arg);
234231
ast_visit::walk_generic_arg(self, arg);

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 };

library/core/src/net/socket_addr.rs

+39
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ pub enum SocketAddr {
4949
/// [IETF RFC 793]: https://tools.ietf.org/html/rfc793
5050
/// [`IPv4` address]: Ipv4Addr
5151
///
52+
/// # Textual representation
53+
///
54+
/// `SocketAddrV4` provides a [`FromStr`](crate::str::FromStr) implementation.
55+
/// It accepts an IPv4 address in its [textual representation], followed by a
56+
/// single `:`, followed by the port encoded as a decimal integer. Other
57+
/// formats are not accepted.
58+
///
59+
/// [textual representation]: Ipv4Addr#textual-representation
60+
///
5261
/// # Examples
5362
///
5463
/// ```
@@ -82,6 +91,32 @@ pub struct SocketAddrV4 {
8291
/// [IETF RFC 2553, Section 3.3]: https://tools.ietf.org/html/rfc2553#section-3.3
8392
/// [`IPv6` address]: Ipv6Addr
8493
///
94+
/// # Textual representation
95+
///
96+
/// `SocketAddrV6` provides a [`FromStr`](crate::str::FromStr) implementation,
97+
/// based on the bracketed format recommended by [IETF RFC 5952],
98+
/// with scope identifiers based on those specified in [IETF RFC 4007].
99+
///
100+
/// It accepts addresses consisting of the following elements, in order:
101+
/// - A left square bracket (`[`)
102+
/// - The [textual representation] of an IPv6 address
103+
/// - _Optionally_, a percent sign (`%`) followed by the scope identifier
104+
/// encoded as a decimal integer
105+
/// - A right square bracket (`]`)
106+
/// - A colon (`:`)
107+
/// - The port, encoded as a decimal integer.
108+
///
109+
/// For example, the string `[2001:db8::413]:443` represents a `SocketAddrV6`
110+
/// with the address `2001:db8::413` and port `443`. The string
111+
/// `[2001:db8::413%612]:443` represents the same address and port, with a
112+
/// scope identifier of `612`.
113+
///
114+
/// Other formats are not accepted.
115+
///
116+
/// [IETF RFC 5952]: https://tools.ietf.org/html/rfc5952#section-6
117+
/// [IETF RFC 4007]: https://tools.ietf.org/html/rfc4007#section-11
118+
/// [textual representation]: Ipv6Addr#textual-representation
119+
///
85120
/// # Examples
86121
///
87122
/// ```
@@ -92,6 +127,10 @@ pub struct SocketAddrV4 {
92127
/// assert_eq!("[2001:db8::1]:8080".parse(), Ok(socket));
93128
/// assert_eq!(socket.ip(), &Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 1));
94129
/// assert_eq!(socket.port(), 8080);
130+
///
131+
/// let mut with_scope = socket.clone();
132+
/// with_scope.set_scope_id(3);
133+
/// assert_eq!("[2001:db8::1%3]:8080".parse(), Ok(with_scope));
95134
/// ```
96135
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
97136
#[stable(feature = "rust1", since = "1.0.0")]

src/doc/unstable-book/src/compiler-flags/sanitizer.md

-1
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,6 @@ LeakSanitizer is run-time memory leak detector.
690690
691691
LeakSanitizer is supported on the following targets:
692692
693-
* `aarch64-apple-darwin`
694693
* `aarch64-unknown-linux-gnu`
695694
* `x86_64-apple-darwin`
696695
* `x86_64-unknown-linux-gnu`

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 {

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 {

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 {

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

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

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`.

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)]

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

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

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

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

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

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
| ^^^^^^^^^^^^^---------

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)