Skip to content

Commit

Permalink
warn about rust_2021_compatibility and fix warning
Browse files Browse the repository at this point in the history
warning: changes to closure capture in Rust 2021 will affect drop order
   --> clippy_utils/src/lib.rs:995:26
    |
995 |     v.allow_closure.then(|| v.captures)
    |                          ^^^----------
    |                             |
    |                             in Rust 2018, this closure captures all of `v`, but in Rust 2021, it will only capture `v.captures`
996 | }
    | - in Rust 2018, `v` is dropped here, but in Rust 2021, only `v.captures` will be dropped here as part of the closure
    |
note: the lint level is defined here
   --> clippy_utils/src/lib.rs:16:9
    |
16  | #![warn(rust_2021_compatibility)]
    |         ^^^^^^^^^^^^^^^^^^^^^^^
    = note: `#[warn(rust_2021_incompatible_closure_captures)]` implied by `#[warn(rust_2021_compatibility)]`
    = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
help: add a dummy let to cause `v` to be fully captured
    |
995 |     v.allow_closure.then(|| { let _ = &v; v.captures })
    |                             +++++++++++++            +
  • Loading branch information
matthiaskrgr committed Sep 13, 2021
1 parent 311e25c commit bd7fe40
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions clippy_dev/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![feature(once_cell)]
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
#![warn(rust_2021_compatibility)]
// warn on lints, that are included in `rust-lang/rust`s bootstrap
#![warn(rust_2018_idioms, unused_lifetimes)]

Expand Down
1 change: 1 addition & 0 deletions clippy_dev/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
#![warn(rust_2021_compatibility)]
// warn on lints, that are included in `rust-lang/rust`s bootstrap
#![warn(rust_2018_idioms, unused_lifetimes)]

Expand Down
1 change: 1 addition & 0 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
#![allow(clippy::missing_docs_in_private_items, clippy::must_use_candidate)]
#![warn(trivial_casts, trivial_numeric_casts)]
#![warn(rust_2021_compatibility)]
// warn on lints, that are included in `rust-lang/rust`s bootstrap
#![warn(rust_2018_idioms, unused_lifetimes)]
// warn on rustc internal lints
Expand Down
7 changes: 6 additions & 1 deletion clippy_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
#![allow(clippy::missing_errors_doc, clippy::missing_panics_doc, clippy::must_use_candidate)]
// warn on the same lints as `clippy_lints`
#![warn(trivial_casts, trivial_numeric_casts)]
#![warn(rust_2021_compatibility)]
// warn on lints, that are included in `rust-lang/rust`s bootstrap
#![warn(rust_2018_idioms, unused_lifetimes)]
// warn on rustc internal lints
#![warn(rustc::internal)]
#![warn(rust_2021_compatibility)]

// FIXME: switch to something more ergonomic here, once available.
// (Currently there is no way to opt into sysroot crates without `extern crate`.)
Expand Down Expand Up @@ -990,7 +992,10 @@ pub fn can_move_expr_to_closure(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) ->
captures: HirIdMap::default(),
};
v.visit_expr(expr);
v.allow_closure.then(|| v.captures)
v.allow_closure.then(|| {
let _ = &v;
v.captures
})
}

/// Returns the method names and argument list of nested method call expressions that make up
Expand Down
1 change: 1 addition & 0 deletions src/driver.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![feature(rustc_private)]
#![feature(once_cell)]
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
#![warn(rust_2021_compatibility)]
// warn on lints, that are included in `rust-lang/rust`s bootstrap
#![warn(rust_2018_idioms, unused_lifetimes)]
// warn on rustc internal lints
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
#![warn(rust_2021_compatibility)]
// warn on lints, that are included in `rust-lang/rust`s bootstrap
#![warn(rust_2018_idioms, unused_lifetimes)]

Expand Down
1 change: 1 addition & 0 deletions tests/compile-test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![feature(test)] // compiletest_rs requires this attribute
#![feature(once_cell)]
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
#![warn(rust_2021_compatibility)]
#![warn(rust_2018_idioms, unused_lifetimes)]

use compiletest_rs as compiletest;
Expand Down
1 change: 1 addition & 0 deletions tests/dogfood.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#![cfg(not(windows))]
#![feature(once_cell)]
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
#![warn(rust_2021_compatibility)]
#![warn(rust_2018_idioms, unused_lifetimes)]

use std::lazy::SyncLazy;
Expand Down
1 change: 1 addition & 0 deletions tests/fmt.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
#![warn(rust_2021_compatibility)]
#![warn(rust_2018_idioms, unused_lifetimes)]

use std::path::PathBuf;
Expand Down
1 change: 1 addition & 0 deletions tests/integration.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![cfg(feature = "integration")]
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
#![warn(rust_2021_compatibility)]
#![warn(rust_2018_idioms, unused_lifetimes)]

use std::env;
Expand Down
1 change: 1 addition & 0 deletions tests/lint_message_convention.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
#![warn(rust_2021_compatibility)]
#![warn(rust_2018_idioms, unused_lifetimes)]

use std::ffi::OsStr;
Expand Down
1 change: 1 addition & 0 deletions tests/missing-test-files.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
#![warn(rust_2021_compatibility)]
#![warn(rust_2018_idioms, unused_lifetimes)]
#![allow(clippy::assertions_on_constants)]

Expand Down
1 change: 1 addition & 0 deletions tests/versioncheck.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
#![warn(rust_2021_compatibility)]
#![warn(rust_2018_idioms, unused_lifetimes)]
#![allow(clippy::single_match_else)]

Expand Down

0 comments on commit bd7fe40

Please sign in to comment.