Skip to content

Don't fire rust_2021_incompatible_closure_captures in edition = 2021 crates #101409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
@@ -3407,7 +3407,7 @@ declare_lint! {
///
/// ### Example of drop reorder
///
/// ```rust,compile_fail
/// ```rust,edition2018,compile_fail
/// #![deny(rust_2021_incompatible_closure_captures)]
/// # #![allow(unused)]
///
@@ -3443,7 +3443,7 @@ declare_lint! {
///
/// ### Example of auto-trait
///
/// ```rust,compile_fail
/// ```rust,edition2018,compile_fail
/// #![deny(rust_2021_incompatible_closure_captures)]
/// use std::thread;
///
4 changes: 4 additions & 0 deletions compiler/rustc_typeck/src/check/upvar.rs
Original file line number Diff line number Diff line change
@@ -2024,6 +2024,10 @@ fn should_do_rust_2021_incompatible_closure_captures_analysis(
tcx: TyCtxt<'_>,
closure_id: hir::HirId,
) -> bool {
if tcx.sess.rust_2021() {
return false;
}

let (level, _) =
tcx.lint_level_at_node(lint::builtin::RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES, closure_id);

15 changes: 15 additions & 0 deletions src/test/ui/lint/issue-101284.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// check-pass
// edition:2021
#![deny(rust_2021_compatibility)]

pub struct Warns {
// `Arc` has significant drop
_significant_drop: std::sync::Arc<()>,
field: String,
}

pub fn test(w: Warns) {
_ = || drop(w.field);
}

fn main() {}