Run UI tests in edition 2024 mode (#14602)
The `ui_test` package runs test in edition 2021 mode by default. This PR switches our tests to edition 2024. The commits progressively make our test suite compatible with both edition 2021 and edition 2024, then switches the testing mode to edition 2024, which is compatible with what `cargo dev lint` also uses by default. The changes are (without functionality changes in tests): - Add `unsafe` when [calling unsafe constructs inside `unsafe fn`](https://doc.rust-lang.org/edition-guide/rust-2024/unsafe-op-in-unsafe-fn.html), to [unsafe attributes](https://doc.rust-lang.org/edition-guide/rust-2024/unsafe-attributes.html), and to [`extern` blocks](https://doc.rust-lang.org/edition-guide/rust-2024/unsafe-extern.html). - Use stricter reference patterns to accomodate with the [new match ergonomics rules](https://doc.rust-lang.org/edition-guide/rust-2024/match-ergonomics.html). - Add some `use<>` markers where required to keep the same semantics under the [new RPIT lifetime rules](https://doc.rust-lang.org/edition-guide/rust-2024/rpit-lifetime-capture.html). Some other changes ensure that non-regression tests are still enforced: - Add edition 2021 specific tests when switching rules would make some explicitly tested constructs untested, or when the test require using the older [temporary tail expression scoping rules](https://doc.rust-lang.org/edition-guide/rust-2024/temporary-tail-expr-scope.html). - In `misnamed_getters`, check that getters containing an `unsafe` block (for example a getter on an `Union` field) trigger the lint. The last commit switches the default edition for running UI tests to edition 2024. changelog: [`misnamed_getters`]: getters containing an `unsafe` block are also linted
This commit is contained in:
commit
9663da39d2
95 changed files with 1058 additions and 780 deletions
|
|
@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_then;
|
|||
use clippy_utils::source::snippet;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::intravisit::FnKind;
|
||||
use rustc_hir::{Body, ExprKind, FnDecl, ImplicitSelfKind};
|
||||
use rustc_hir::{BlockCheckMode, Body, ExprKind, FnDecl, ImplicitSelfKind, UnsafeSource};
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::ty;
|
||||
use rustc_span::Span;
|
||||
|
|
@ -40,14 +40,25 @@ pub fn check_fn(cx: &LateContext<'_>, kind: FnKind<'_>, decl: &FnDecl<'_>, body:
|
|||
name
|
||||
};
|
||||
|
||||
// Body must be &(mut) <self_data>.name
|
||||
// Body must be `&(mut) <self_data>.name`, potentially in an `unsafe` block
|
||||
// self_data is not necessarily self, to also lint sub-getters, etc…
|
||||
|
||||
let block_expr = if let ExprKind::Block(block, _) = body.value.kind
|
||||
&& block.stmts.is_empty()
|
||||
&& let Some(block_expr) = block.expr
|
||||
{
|
||||
block_expr
|
||||
if let ExprKind::Block(unsafe_block, _) = block_expr.kind
|
||||
&& unsafe_block.stmts.is_empty()
|
||||
&& matches!(
|
||||
unsafe_block.rules,
|
||||
BlockCheckMode::UnsafeBlock(UnsafeSource::UserProvided)
|
||||
)
|
||||
&& let Some(unsafe_block_expr) = unsafe_block.expr
|
||||
{
|
||||
unsafe_block_expr
|
||||
} else {
|
||||
block_expr
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue