From 0689b2139fa90aeb6f42930ee783cc2f322cd265 Mon Sep 17 00:00:00 2001 From: Ding Xiang Fei Date: Mon, 21 Oct 2024 04:47:02 +0800 Subject: [PATCH 1/4] stabilize shorter-tail-lifetimes --- compiler/rustc_feature/src/accepted.rs | 2 ++ compiler/rustc_feature/src/unstable.rs | 2 -- .../rustc_hir_analysis/src/check/region.rs | 4 +--- .../rustc_lint/src/tail_expr_drop_order.rs | 23 +++++++++---------- tests/ui/drop/drop_order.rs | 12 ++++++++++ .../drop/lint-tail-expr-drop-order-gated.rs | 12 ++++------ tests/ui/drop/lint-tail-expr-drop-order.rs | 4 +--- .../ui/drop/lint-tail-expr-drop-order.stderr | 8 +++---- ...xpr-drop-order-negative.edition2024.stderr | 2 +- .../ui/drop/tail-expr-drop-order-negative.rs | 2 -- tests/ui/drop/tail-expr-drop-order.rs | 1 - .../refcell-in-tail-expr.edition2021.stderr | 2 +- tests/ui/lifetimes/refcell-in-tail-expr.rs | 2 -- ...rter-tail-expr-lifetime.edition2021.stderr | 2 +- .../lifetimes/shorter-tail-expr-lifetime.rs | 2 -- .../ui/lifetimes/tail-expr-in-nested-expr.rs | 2 -- .../lifetimes/tail-expr-in-nested-expr.stderr | 2 +- .../ui/lifetimes/tail-expr-lock-poisoning.rs | 1 - 18 files changed, 39 insertions(+), 46 deletions(-) diff --git a/compiler/rustc_feature/src/accepted.rs b/compiler/rustc_feature/src/accepted.rs index 4f71bdaca1b13..ac922f184dd8c 100644 --- a/compiler/rustc_feature/src/accepted.rs +++ b/compiler/rustc_feature/src/accepted.rs @@ -364,6 +364,8 @@ declare_features! ( (accepted, self_in_typedefs, "1.32.0", Some(49303)), /// Allows `Self` struct constructor (RFC 2302). (accepted, self_struct_ctor, "1.32.0", Some(51994)), + /// Shortern the tail expression lifetime + (accepted, shorter_tail_lifetimes, "CURRENT_RUSTC_VERSION", Some(123739)), /// Allows using subslice patterns, `[a, .., b]` and `[a, xs @ .., b]`. (accepted, slice_patterns, "1.42.0", Some(62254)), /// Allows use of `&foo[a..b]` as a slicing syntax. diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index 8f4c208f1fbb5..152eb2edb0502 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -571,8 +571,6 @@ declare_features! ( (unstable, rust_cold_cc, "1.63.0", Some(97544)), /// Allows use of x86 SHA512, SM3 and SM4 target-features and intrinsics (unstable, sha512_sm_x86, "1.82.0", Some(126624)), - /// Shortern the tail expression lifetime - (unstable, shorter_tail_lifetimes, "1.79.0", Some(123739)), /// Allows the use of SIMD types in functions declared in `extern` blocks. (unstable, simd_ffi, "1.0.0", Some(27731)), /// Allows specialization of implementations (RFC 1210). diff --git a/compiler/rustc_hir_analysis/src/check/region.rs b/compiler/rustc_hir_analysis/src/check/region.rs index 312fb16c93aae..bfa088fdefc96 100644 --- a/compiler/rustc_hir_analysis/src/check/region.rs +++ b/compiler/rustc_hir_analysis/src/check/region.rs @@ -167,9 +167,7 @@ fn resolve_block<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, blk: &'tcx h } } if let Some(tail_expr) = blk.expr { - if visitor.tcx.features().shorter_tail_lifetimes() - && blk.span.edition().at_least_rust_2024() - { + if blk.span.edition().at_least_rust_2024() { visitor.terminating_scopes.insert(tail_expr.hir_id.local_id); } visitor.visit_expr(tail_expr); diff --git a/compiler/rustc_lint/src/tail_expr_drop_order.rs b/compiler/rustc_lint/src/tail_expr_drop_order.rs index 04f769bf5517f..89763059877c0 100644 --- a/compiler/rustc_lint/src/tail_expr_drop_order.rs +++ b/compiler/rustc_lint/src/tail_expr_drop_order.rs @@ -14,15 +14,14 @@ use rustc_span::edition::Edition; use crate::{LateContext, LateLintPass}; declare_lint! { - /// The `tail_expr_drop_order` lint looks for those values generated at the tail expression location, that of type - /// with a significant `Drop` implementation, such as locks. - /// In case there are also local variables of type with significant `Drop` implementation as well, - /// this lint warns you of a potential transposition in the drop order. - /// Your discretion on the new drop order introduced by Edition 2024 is required. + /// The `tail_expr_drop_order` lint looks for those values generated at the tail expression location, + /// that runs a custom `Drop` destructor. + /// Some of them may be dropped earlier in Edition 2024 that they used to in Edition 2021 and prior. + /// This lint detects those cases and provides you information on those values and their custom destructor implementations. + /// Your discretion on this information is required. /// /// ### Example - /// ```rust,edition2024 - /// #![feature(shorter_tail_lifetimes)] + /// ```rust,edition2021 /// #![warn(tail_expr_drop_order)] /// struct Droppy(i32); /// impl Droppy { @@ -37,12 +36,12 @@ declare_lint! { /// println!("loud drop {}", self.0); /// } /// } - /// fn edition_2024() -> i32 { + /// fn edition_2021() -> i32 { /// let another_droppy = Droppy(0); /// Droppy(1).get() /// } /// fn main() { - /// edition_2024(); + /// edition_2021(); /// } /// ``` /// @@ -137,7 +136,7 @@ impl<'tcx> LateLintPass<'tcx> for TailExprDropOrder { _: Span, def_id: rustc_span::def_id::LocalDefId, ) { - if cx.tcx.sess.at_least_rust_2024() && cx.tcx.features().shorter_tail_lifetimes() { + if !body.value.span.edition().at_least_rust_2024() { Self::check_fn_or_closure(cx, fn_kind, body, def_id); } } @@ -185,8 +184,8 @@ impl<'a, 'tcx> Visitor<'tcx> for LintVisitor<'a, 'tcx> { impl<'a, 'tcx> LintVisitor<'a, 'tcx> { fn check_block_inner(&mut self, block: &Block<'tcx>) { - if !block.span.at_least_rust_2024() { - // We only lint for Edition 2024 onwards + if block.span.at_least_rust_2024() { + // We only lint up to Edition 2021 return; } let Some(tail_expr) = block.expr else { return }; diff --git a/tests/ui/drop/drop_order.rs b/tests/ui/drop/drop_order.rs index cf06253800745..29b68d666fc6e 100644 --- a/tests/ui/drop/drop_order.rs +++ b/tests/ui/drop/drop_order.rs @@ -105,6 +105,7 @@ impl DropOrderCollector { () => self.print(10), } + #[cfg(edition2021)] match { match self.option_loud_drop(14) { _ => { @@ -115,6 +116,17 @@ impl DropOrderCollector { } { _ => self.print(12), } + #[cfg(edition2024)] + match { + match self.option_loud_drop(12) { + _ => { + self.print(11); + self.option_loud_drop(14) + } + } + } { + _ => self.print(13), + } match { loop { diff --git a/tests/ui/drop/lint-tail-expr-drop-order-gated.rs b/tests/ui/drop/lint-tail-expr-drop-order-gated.rs index b22e72bcfad22..fde542c756f2e 100644 --- a/tests/ui/drop/lint-tail-expr-drop-order-gated.rs +++ b/tests/ui/drop/lint-tail-expr-drop-order-gated.rs @@ -1,15 +1,11 @@ -// This test ensures that `tail_expr_drop_order` does not activate in case Edition 2024 is not used -// or the feature gate `shorter_tail_lifetimes` is disabled. +// This test is to demonstrate that the lint is gated behind Edition and +// is triggered only for Edition 2021 and before. -//@ revisions: neither no_feature_gate edition_less_than_2024 //@ check-pass -//@ [neither] edition: 2021 -//@ [no_feature_gate] compile-flags: -Z unstable-options -//@ [no_feature_gate] edition: 2024 -//@ [edition_less_than_2024] edition: 2021 +//@ edition: 2024 +//@ compile-flags: -Z unstable-options #![deny(tail_expr_drop_order)] -#![cfg_attr(edition_less_than_2024, feature(shorter_tail_lifetimes))] struct LoudDropper; impl Drop for LoudDropper { diff --git a/tests/ui/drop/lint-tail-expr-drop-order.rs b/tests/ui/drop/lint-tail-expr-drop-order.rs index 0aa0ef026101a..d61abae518707 100644 --- a/tests/ui/drop/lint-tail-expr-drop-order.rs +++ b/tests/ui/drop/lint-tail-expr-drop-order.rs @@ -1,12 +1,10 @@ -//@ compile-flags: -Z unstable-options -//@ edition: 2024 +//@ edition: 2021 // Edition 2024 lint for change in drop order at tail expression // This lint is to capture potential change in program semantics // due to implementation of RFC 3606 #![deny(tail_expr_drop_order)] -#![feature(shorter_tail_lifetimes)] struct LoudDropper; impl Drop for LoudDropper { diff --git a/tests/ui/drop/lint-tail-expr-drop-order.stderr b/tests/ui/drop/lint-tail-expr-drop-order.stderr index 630f0a80f092b..6775c4ce6d15a 100644 --- a/tests/ui/drop/lint-tail-expr-drop-order.stderr +++ b/tests/ui/drop/lint-tail-expr-drop-order.stderr @@ -1,5 +1,5 @@ error: these values and local bindings have significant drop implementation that will have a different drop order from that of Edition 2021 - --> $DIR/lint-tail-expr-drop-order.rs:29:15 + --> $DIR/lint-tail-expr-drop-order.rs:27:15 | LL | let x = LoudDropper; | - 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() = warning: this changes meaning in Rust 2024 = note: for more information, see issue #123739 note: the lint level is defined here - --> $DIR/lint-tail-expr-drop-order.rs:8:9 + --> $DIR/lint-tail-expr-drop-order.rs:7:9 | LL | #![deny(tail_expr_drop_order)] | ^^^^^^^^^^^^^^^^^^^^ error: these values and local bindings have significant drop implementation that will have a different drop order from that of Edition 2021 - --> $DIR/lint-tail-expr-drop-order.rs:36:23 + --> $DIR/lint-tail-expr-drop-order.rs:34:23 | LL | let x = LoudDropper; | - 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() = note: for more information, see issue #123739 error: these values and local bindings have significant drop implementation that will have a different drop order from that of Edition 2021 - --> $DIR/lint-tail-expr-drop-order.rs:65:19 + --> $DIR/lint-tail-expr-drop-order.rs:63:19 | LL | let x = LoudDropper; | - these values have significant drop implementation and will observe changes in drop order under Edition 2024 diff --git a/tests/ui/drop/tail-expr-drop-order-negative.edition2024.stderr b/tests/ui/drop/tail-expr-drop-order-negative.edition2024.stderr index 75fc34e409b54..bcce796570e29 100644 --- a/tests/ui/drop/tail-expr-drop-order-negative.edition2024.stderr +++ b/tests/ui/drop/tail-expr-drop-order-negative.edition2024.stderr @@ -1,5 +1,5 @@ error[E0716]: temporary value dropped while borrowed - --> $DIR/tail-expr-drop-order-negative.rs:11:15 + --> $DIR/tail-expr-drop-order-negative.rs:9:15 | LL | x.replace(std::cell::RefCell::new(123).borrow()).is_some() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - temporary value is freed at the end of this statement diff --git a/tests/ui/drop/tail-expr-drop-order-negative.rs b/tests/ui/drop/tail-expr-drop-order-negative.rs index c570b3a1ee235..5ad04d0a67ef6 100644 --- a/tests/ui/drop/tail-expr-drop-order-negative.rs +++ b/tests/ui/drop/tail-expr-drop-order-negative.rs @@ -3,8 +3,6 @@ //@ [edition2024] edition: 2024 //@ [edition2021] check-pass -#![feature(shorter_tail_lifetimes)] - fn why_would_you_do_this() -> bool { let mut x = None; // Make a temporary `RefCell` and put a `Ref` that borrows it in `x`. diff --git a/tests/ui/drop/tail-expr-drop-order.rs b/tests/ui/drop/tail-expr-drop-order.rs index 5d87f980b1563..80968b823f9a7 100644 --- a/tests/ui/drop/tail-expr-drop-order.rs +++ b/tests/ui/drop/tail-expr-drop-order.rs @@ -4,7 +4,6 @@ //@ edition: 2024 //@ run-pass -#![feature(shorter_tail_lifetimes)] #![allow(unused_imports)] #![allow(dead_code)] #![allow(unused_variables)] diff --git a/tests/ui/lifetimes/refcell-in-tail-expr.edition2021.stderr b/tests/ui/lifetimes/refcell-in-tail-expr.edition2021.stderr index 858be42d54094..157a1c5e09b07 100644 --- a/tests/ui/lifetimes/refcell-in-tail-expr.edition2021.stderr +++ b/tests/ui/lifetimes/refcell-in-tail-expr.edition2021.stderr @@ -1,5 +1,5 @@ error[E0597]: `cell` does not live long enough - --> $DIR/refcell-in-tail-expr.rs:12:27 + --> $DIR/refcell-in-tail-expr.rs:10:27 | LL | let cell = std::cell::RefCell::new(0u8); | ---- binding `cell` declared here diff --git a/tests/ui/lifetimes/refcell-in-tail-expr.rs b/tests/ui/lifetimes/refcell-in-tail-expr.rs index b1814c1e32713..595e951f3731b 100644 --- a/tests/ui/lifetimes/refcell-in-tail-expr.rs +++ b/tests/ui/lifetimes/refcell-in-tail-expr.rs @@ -4,8 +4,6 @@ //@ [edition2024] compile-flags: -Zunstable-options //@ [edition2024] check-pass -#![cfg_attr(edition2024, feature(shorter_tail_lifetimes))] - fn main() { let cell = std::cell::RefCell::new(0u8); diff --git a/tests/ui/lifetimes/shorter-tail-expr-lifetime.edition2021.stderr b/tests/ui/lifetimes/shorter-tail-expr-lifetime.edition2021.stderr index ad28ae2f80d66..3c074c5c3a2cb 100644 --- a/tests/ui/lifetimes/shorter-tail-expr-lifetime.edition2021.stderr +++ b/tests/ui/lifetimes/shorter-tail-expr-lifetime.edition2021.stderr @@ -1,5 +1,5 @@ error[E0597]: `c` does not live long enough - --> $DIR/shorter-tail-expr-lifetime.rs:10:5 + --> $DIR/shorter-tail-expr-lifetime.rs:8:5 | LL | let c = std::cell::RefCell::new(".."); | - binding `c` declared here diff --git a/tests/ui/lifetimes/shorter-tail-expr-lifetime.rs b/tests/ui/lifetimes/shorter-tail-expr-lifetime.rs index 0392b6c6d9ada..4195a8b6c32bd 100644 --- a/tests/ui/lifetimes/shorter-tail-expr-lifetime.rs +++ b/tests/ui/lifetimes/shorter-tail-expr-lifetime.rs @@ -3,8 +3,6 @@ //@ [edition2024] edition: 2024 //@ [edition2024] run-pass -#![cfg_attr(edition2024, feature(shorter_tail_lifetimes))] - fn f() -> usize { let c = std::cell::RefCell::new(".."); c.borrow().len() //[edition2021]~ ERROR: `c` does not live long enough diff --git a/tests/ui/lifetimes/tail-expr-in-nested-expr.rs b/tests/ui/lifetimes/tail-expr-in-nested-expr.rs index a8989f22f4b5b..2ac97aff2b098 100644 --- a/tests/ui/lifetimes/tail-expr-in-nested-expr.rs +++ b/tests/ui/lifetimes/tail-expr-in-nested-expr.rs @@ -1,8 +1,6 @@ //@ edition: 2024 //@ compile-flags: -Zunstable-options -#![feature(shorter_tail_lifetimes)] - fn main() { let _ = { String::new().as_str() }.len(); //~^ ERROR temporary value dropped while borrowed diff --git a/tests/ui/lifetimes/tail-expr-in-nested-expr.stderr b/tests/ui/lifetimes/tail-expr-in-nested-expr.stderr index f699d184bdb1d..96e88eaca9225 100644 --- a/tests/ui/lifetimes/tail-expr-in-nested-expr.stderr +++ b/tests/ui/lifetimes/tail-expr-in-nested-expr.stderr @@ -1,5 +1,5 @@ error[E0716]: temporary value dropped while borrowed - --> $DIR/tail-expr-in-nested-expr.rs:7:15 + --> $DIR/tail-expr-in-nested-expr.rs:5:15 | LL | let _ = { String::new().as_str() }.len(); | ^^^^^^^^^^^^^--------- diff --git a/tests/ui/lifetimes/tail-expr-lock-poisoning.rs b/tests/ui/lifetimes/tail-expr-lock-poisoning.rs index cdfd35304b44e..ec74596a08da4 100644 --- a/tests/ui/lifetimes/tail-expr-lock-poisoning.rs +++ b/tests/ui/lifetimes/tail-expr-lock-poisoning.rs @@ -4,7 +4,6 @@ //@ [edition2024] edition: 2024 //@ run-pass //@ needs-unwind -#![cfg_attr(edition2024, feature(shorter_tail_lifetimes))] use std::sync::Mutex; From 33941d3ba5aa2e9beed85130a27833f3de853d9b Mon Sep 17 00:00:00 2001 From: David Date: Thu, 24 Oct 2024 11:42:11 +0530 Subject: [PATCH 2/4] sanitizer.md: LeakSanitizer is not supported on aarch64 macOS --- src/doc/unstable-book/src/compiler-flags/sanitizer.md | 1 - 1 file changed, 1 deletion(-) diff --git a/src/doc/unstable-book/src/compiler-flags/sanitizer.md b/src/doc/unstable-book/src/compiler-flags/sanitizer.md index 24940f0d6fb96..4679acf0a6a15 100644 --- a/src/doc/unstable-book/src/compiler-flags/sanitizer.md +++ b/src/doc/unstable-book/src/compiler-flags/sanitizer.md @@ -690,7 +690,6 @@ LeakSanitizer is run-time memory leak detector. LeakSanitizer is supported on the following targets: -* `aarch64-apple-darwin` * `aarch64-unknown-linux-gnu` * `x86_64-apple-darwin` * `x86_64-unknown-linux-gnu` From 0e5c5a25961a94d866a65bb956d5ae9bf7c84eef Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 16 Oct 2024 09:34:34 -0400 Subject: [PATCH 3/4] Document textual format of SocketAddrV{4,6} This commit adds new "Textual representation" documentation sections to SocketAddrV4 and SocketAddrV6, by analogy to the existing "textual representation" sections of Ipv4Addr and Ipv6Addr. Rationale: Without documentation about which formats are actually accepted, it's hard for a programmer to be sure that their code will actually behave as expected when implementing protocols that require support (or rejection) for particular representations. This lack of clarity can in turn can lead to ambiguities and security problems like those discussed in RFC 6942. (I've tried to describe the governing RFCs or standards where I could, but it's possible that the actual implementers had something else in mind. I could not find any standards that corresponded _exactly_ to the one implemented in SocketAddrv6, but I have linked the relevant documents that I could find.) --- library/core/src/net/socket_addr.rs | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/library/core/src/net/socket_addr.rs b/library/core/src/net/socket_addr.rs index 4e339172b682f..a46495add6a19 100644 --- a/library/core/src/net/socket_addr.rs +++ b/library/core/src/net/socket_addr.rs @@ -49,6 +49,15 @@ pub enum SocketAddr { /// [IETF RFC 793]: https://tools.ietf.org/html/rfc793 /// [`IPv4` address]: Ipv4Addr /// +/// # Textual representation +/// +/// `SocketAddrV4` provides a [`FromStr`](crate::str::FromStr) implementation. +/// It accepts an IPv4 address in its [textual representation], followed by a +/// single `:`, followed by the port encoded as a decimal integer. Other +/// formats are not accepted. +/// +/// [textual representation]: Ipv4Addr#textual-representation +/// /// # Examples /// /// ``` @@ -82,6 +91,32 @@ pub struct SocketAddrV4 { /// [IETF RFC 2553, Section 3.3]: https://tools.ietf.org/html/rfc2553#section-3.3 /// [`IPv6` address]: Ipv6Addr /// +/// # Textual representation +/// +/// `SocketAddrV6` provides a [`FromStr`](crate::str::FromStr) implementation, +/// based on the bracketed format recommended by [IETF RFC 5952], +/// with scope identifiers based on those specified in [IETF RFC 4007]. +/// +/// It accepts addresses consisting of the following elements, in order: +/// - A left square bracket (`[`) +/// - The [textual representation] of an IPv6 address +/// - _Optionally_, a percent sign (`%`) followed by the scope identifier +/// encoded as a decimal integer +/// - A right square bracket (`]`) +/// - A colon (`:`) +/// - The port, encoded as a decimal integer. +/// +/// For example, the string `[2001:db8::413]:443` represents a `SocketAddrV6` +/// with the address `2001:db8::413` and port `443`. The string +/// `[2001:db8::413%612]:443` represents the same address and port, with a +/// scope identifier of `612`. +/// +/// Other formats are not accepted. +/// +/// [IETF RFC 5952]: https://tools.ietf.org/html/rfc5952#section-6 +/// [IETF RFC 4007]: https://tools.ietf.org/html/rfc4007#section-11 +/// [textual representation]: Ipv6Addr#textual-representation +/// /// # Examples /// /// ``` @@ -92,6 +127,10 @@ pub struct SocketAddrV4 { /// assert_eq!("[2001:db8::1]:8080".parse(), Ok(socket)); /// assert_eq!(socket.ip(), &Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 1)); /// assert_eq!(socket.port(), 8080); +/// +/// let mut with_scope = socket.clone(); +/// with_scope.set_scope_id(3); +/// assert_eq!("[2001:db8::1%3]:8080".parse(), Ok(with_scope)); /// ``` #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] #[stable(feature = "rust1", since = "1.0.0")] From 0635916cbe22b96708abe40499d03aef4901ad6a Mon Sep 17 00:00:00 2001 From: maxcabrajac Date: Thu, 24 Oct 2024 10:59:40 -0300 Subject: [PATCH 4/4] Remove visit_expr_post --- compiler/rustc_ast/src/visit.rs | 5 +---- compiler/rustc_lint/src/early.rs | 27 ++++++++++++--------------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index 207ec71065051..57ebab2abdf7a 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -173,9 +173,6 @@ pub trait Visitor<'ast>: Sized { fn visit_method_receiver_expr(&mut self, ex: &'ast Expr) -> Self::Result { self.visit_expr(ex) } - fn visit_expr_post(&mut self, _ex: &'ast Expr) -> Self::Result { - Self::Result::output() - } fn visit_ty(&mut self, t: &'ast Ty) -> Self::Result { walk_ty(self, t) } @@ -1185,7 +1182,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) -> V ExprKind::Dummy => {} } - visitor.visit_expr_post(expression) + V::Result::output() } pub fn walk_param<'a, V: Visitor<'a>>(visitor: &mut V, param: &'a Param) -> V::Result { diff --git a/compiler/rustc_lint/src/early.rs b/compiler/rustc_lint/src/early.rs index 2285877c9ef26..c095199a47116 100644 --- a/compiler/rustc_lint/src/early.rs +++ b/compiler/rustc_lint/src/early.rs @@ -121,6 +121,18 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T> self.with_lint_attrs(e.id, &e.attrs, |cx| { lint_callback!(cx, check_expr, e); ast_visit::walk_expr(cx, e); + // Explicitly check for lints associated with 'closure_id', since + // it does not have a corresponding AST node + match e.kind { + ast::ExprKind::Closure(box ast::Closure { + coroutine_kind: Some(coroutine_kind), + .. + }) => { + cx.check_id(coroutine_kind.closure_id()); + } + _ => {} + } + lint_callback!(cx, check_expr_post, e); }) } @@ -214,21 +226,6 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T> }) } - fn visit_expr_post(&mut self, e: &'a ast::Expr) { - // Explicitly check for lints associated with 'closure_id', since - // it does not have a corresponding AST node - match e.kind { - ast::ExprKind::Closure(box ast::Closure { - coroutine_kind: Some(coroutine_kind), - .. - }) => { - self.check_id(coroutine_kind.closure_id()); - } - _ => {} - } - lint_callback!(self, check_expr_post, e); - } - fn visit_generic_arg(&mut self, arg: &'a ast::GenericArg) { lint_callback!(self, check_generic_arg, arg); ast_visit::walk_generic_arg(self, arg);