Skip to content

Always run tail_expr_drop_order lint in promoted MIR query #134493

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
merged 1 commit into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,8 @@ fn mir_promoted(
Some(MirPhase::Analysis(AnalysisPhase::Initial)),
);

lint_tail_expr_drop_order::run_lint(tcx, def, &body);

let promoted = promote_pass.promoted_fragments.into_inner();
(tcx.alloc_steal_mir(body), tcx.alloc_steal_promoted(promoted))
}
Expand Down Expand Up @@ -492,7 +494,6 @@ fn mir_drops_elaborated_and_const_checked(tcx: TyCtxt<'_>, def: LocalDefId) -> &
}

let (body, _) = tcx.mir_promoted(def);
lint_tail_expr_drop_order::run_lint(tcx, def, &body.borrow());
let mut body = body.steal();

if let Some(error_reported) = tainted_by_errors {
Expand Down
1 change: 0 additions & 1 deletion tests/ui/drop/lint-tail-expr-drop-order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// This lint is to capture potential change in program semantics
// due to implementation of RFC 3606 <https://github.com/rust-lang/rfcs/pull/3606>
//@ edition: 2021
//@ build-fail
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A build-fail became a check-fail, which is evidence enough of this being a sufficient fix.


#![deny(tail_expr_drop_order)] //~ NOTE: the lint level is defined here
#![allow(dropping_copy_types)]
Expand Down
46 changes: 23 additions & 23 deletions tests/ui/drop/lint-tail-expr-drop-order.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: relative drop order changing in Rust 2024
--> $DIR/lint-tail-expr-drop-order.rs:42:15
--> $DIR/lint-tail-expr-drop-order.rs:41:15
|
LL | let x = LoudDropper;
| -
Expand All @@ -19,28 +19,28 @@ LL | }
= warning: this changes meaning in Rust 2024
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-tail-expr-scope.html>
note: `#1` invokes this custom destructor
--> $DIR/lint-tail-expr-drop-order.rs:11:1
--> $DIR/lint-tail-expr-drop-order.rs:10:1
|
LL | / impl Drop for LoudDropper {
... |
LL | | }
| |_^
note: `x` invokes this custom destructor
--> $DIR/lint-tail-expr-drop-order.rs:11:1
--> $DIR/lint-tail-expr-drop-order.rs:10:1
|
LL | / impl Drop for LoudDropper {
... |
LL | | }
| |_^
= note: most of the time, changing drop order is harmless; inspect the `impl Drop`s for side effects like releasing locks or sending messages
note: the lint level is defined here
--> $DIR/lint-tail-expr-drop-order.rs:7:9
--> $DIR/lint-tail-expr-drop-order.rs:6:9
|
LL | #![deny(tail_expr_drop_order)]
| ^^^^^^^^^^^^^^^^^^^^

error: relative drop order changing in Rust 2024
--> $DIR/lint-tail-expr-drop-order.rs:67:19
--> $DIR/lint-tail-expr-drop-order.rs:66:19
|
LL | let x = LoudDropper;
| -
Expand All @@ -60,14 +60,14 @@ LL | }
= warning: this changes meaning in Rust 2024
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-tail-expr-scope.html>
note: `#1` invokes this custom destructor
--> $DIR/lint-tail-expr-drop-order.rs:11:1
--> $DIR/lint-tail-expr-drop-order.rs:10:1
|
LL | / impl Drop for LoudDropper {
... |
LL | | }
| |_^
note: `x` invokes this custom destructor
--> $DIR/lint-tail-expr-drop-order.rs:11:1
--> $DIR/lint-tail-expr-drop-order.rs:10:1
|
LL | / impl Drop for LoudDropper {
... |
Expand All @@ -76,7 +76,7 @@ LL | | }
= note: most of the time, changing drop order is harmless; inspect the `impl Drop`s for side effects like releasing locks or sending messages

error: relative drop order changing in Rust 2024
--> $DIR/lint-tail-expr-drop-order.rs:94:7
--> $DIR/lint-tail-expr-drop-order.rs:93:7
|
LL | let x = LoudDropper;
| -
Expand All @@ -96,14 +96,14 @@ LL | }
= warning: this changes meaning in Rust 2024
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-tail-expr-scope.html>
note: `#1` invokes this custom destructor
--> $DIR/lint-tail-expr-drop-order.rs:11:1
--> $DIR/lint-tail-expr-drop-order.rs:10:1
|
LL | / impl Drop for LoudDropper {
... |
LL | | }
| |_^
note: `x` invokes this custom destructor
--> $DIR/lint-tail-expr-drop-order.rs:11:1
--> $DIR/lint-tail-expr-drop-order.rs:10:1
|
LL | / impl Drop for LoudDropper {
... |
Expand All @@ -112,7 +112,7 @@ LL | | }
= note: most of the time, changing drop order is harmless; inspect the `impl Drop`s for side effects like releasing locks or sending messages

error: relative drop order changing in Rust 2024
--> $DIR/lint-tail-expr-drop-order.rs:147:5
--> $DIR/lint-tail-expr-drop-order.rs:146:5
|
LL | let future = f();
| ------
Expand All @@ -132,14 +132,14 @@ LL | }
= warning: this changes meaning in Rust 2024
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-tail-expr-scope.html>
note: `#1` invokes this custom destructor
--> $DIR/lint-tail-expr-drop-order.rs:11:1
--> $DIR/lint-tail-expr-drop-order.rs:10:1
|
LL | / impl Drop for LoudDropper {
... |
LL | | }
| |_^
note: `future` invokes this custom destructor
--> $DIR/lint-tail-expr-drop-order.rs:11:1
--> $DIR/lint-tail-expr-drop-order.rs:10:1
|
LL | / impl Drop for LoudDropper {
... |
Expand All @@ -148,7 +148,7 @@ LL | | }
= note: most of the time, changing drop order is harmless; inspect the `impl Drop`s for side effects like releasing locks or sending messages

error: relative drop order changing in Rust 2024
--> $DIR/lint-tail-expr-drop-order.rs:164:14
--> $DIR/lint-tail-expr-drop-order.rs:163:14
|
LL | let x = T::default();
| -
Expand All @@ -170,7 +170,7 @@ LL | }
= note: most of the time, changing drop order is harmless; inspect the `impl Drop`s for side effects like releasing locks or sending messages

error: relative drop order changing in Rust 2024
--> $DIR/lint-tail-expr-drop-order.rs:178:5
--> $DIR/lint-tail-expr-drop-order.rs:177:5
|
LL | let x: Result<LoudDropper, ()> = Ok(LoudDropper);
| -
Expand All @@ -190,14 +190,14 @@ LL | }
= warning: this changes meaning in Rust 2024
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-tail-expr-scope.html>
note: `#1` invokes this custom destructor
--> $DIR/lint-tail-expr-drop-order.rs:11:1
--> $DIR/lint-tail-expr-drop-order.rs:10:1
|
LL | / impl Drop for LoudDropper {
... |
LL | | }
| |_^
note: `x` invokes this custom destructor
--> $DIR/lint-tail-expr-drop-order.rs:11:1
--> $DIR/lint-tail-expr-drop-order.rs:10:1
|
LL | / impl Drop for LoudDropper {
... |
Expand All @@ -206,7 +206,7 @@ LL | | }
= note: most of the time, changing drop order is harmless; inspect the `impl Drop`s for side effects like releasing locks or sending messages

error: relative drop order changing in Rust 2024
--> $DIR/lint-tail-expr-drop-order.rs:222:5
--> $DIR/lint-tail-expr-drop-order.rs:221:5
|
LL | let x = LoudDropper2;
| -
Expand All @@ -226,7 +226,7 @@ LL | }
= warning: this changes meaning in Rust 2024
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-tail-expr-scope.html>
note: `#1` invokes this custom destructor
--> $DIR/lint-tail-expr-drop-order.rs:195:5
--> $DIR/lint-tail-expr-drop-order.rs:194:5
|
LL | / impl Drop for LoudDropper3 {
LL | |
Expand All @@ -236,7 +236,7 @@ LL | | }
LL | | }
| |_____^
note: `x` invokes this custom destructor
--> $DIR/lint-tail-expr-drop-order.rs:207:5
--> $DIR/lint-tail-expr-drop-order.rs:206:5
|
LL | / impl Drop for LoudDropper2 {
LL | |
Expand All @@ -248,7 +248,7 @@ LL | | }
= note: most of the time, changing drop order is harmless; inspect the `impl Drop`s for side effects like releasing locks or sending messages

error: relative drop order changing in Rust 2024
--> $DIR/lint-tail-expr-drop-order.rs:235:13
--> $DIR/lint-tail-expr-drop-order.rs:234:13
|
LL | LoudDropper.get()
| ^^^^^^^^^^^
Expand All @@ -268,14 +268,14 @@ LL | ));
= warning: this changes meaning in Rust 2024
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-tail-expr-scope.html>
note: `#1` invokes this custom destructor
--> $DIR/lint-tail-expr-drop-order.rs:11:1
--> $DIR/lint-tail-expr-drop-order.rs:10:1
|
LL | / impl Drop for LoudDropper {
... |
LL | | }
| |_^
note: `_x` invokes this custom destructor
--> $DIR/lint-tail-expr-drop-order.rs:11:1
--> $DIR/lint-tail-expr-drop-order.rs:10:1
|
LL | / impl Drop for LoudDropper {
... |
Expand Down
1 change: 0 additions & 1 deletion tests/ui/drop/tail_expr_drop_order-on-coroutine-unwind.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//@ edition: 2021
//@ build-fail

// Make sure we don't ICE when emitting the "lint" drop statement
// used for tail_expr_drop_order.
Expand Down
10 changes: 5 additions & 5 deletions tests/ui/drop/tail_expr_drop_order-on-coroutine-unwind.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: relative drop order changing in Rust 2024
--> $DIR/tail_expr_drop_order-on-coroutine-unwind.rs:20:15
--> $DIR/tail_expr_drop_order-on-coroutine-unwind.rs:19:15
|
LL | match func().await {
| ^^^^^^^-----
Expand All @@ -21,29 +21,29 @@ LL | }
= warning: this changes meaning in Rust 2024
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-tail-expr-scope.html>
note: `#2` invokes this custom destructor
--> $DIR/tail_expr_drop_order-on-coroutine-unwind.rs:10:1
--> $DIR/tail_expr_drop_order-on-coroutine-unwind.rs:9:1
|
LL | / impl std::ops::Drop for Drop {
LL | | fn drop(&mut self) {}
LL | | }
| |_^
note: `#1` invokes this custom destructor
--> $DIR/tail_expr_drop_order-on-coroutine-unwind.rs:10:1
--> $DIR/tail_expr_drop_order-on-coroutine-unwind.rs:9:1
|
LL | / impl std::ops::Drop for Drop {
LL | | fn drop(&mut self) {}
LL | | }
| |_^
note: `e` invokes this custom destructor
--> $DIR/tail_expr_drop_order-on-coroutine-unwind.rs:10:1
--> $DIR/tail_expr_drop_order-on-coroutine-unwind.rs:9:1
|
LL | / impl std::ops::Drop for Drop {
LL | | fn drop(&mut self) {}
LL | | }
| |_^
= note: most of the time, changing drop order is harmless; inspect the `impl Drop`s for side effects like releasing locks or sending messages
note: the lint level is defined here
--> $DIR/tail_expr_drop_order-on-coroutine-unwind.rs:7:9
--> $DIR/tail_expr_drop_order-on-coroutine-unwind.rs:6:9
|
LL | #![deny(tail_expr_drop_order)]
| ^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/error-codes/E0452.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
//~| ERROR E0452
//~| ERROR E0452
//~| ERROR E0452
//~| ERROR E0452
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated attr errors is due to a call to lints_that_dont_need_to_run in check-builds. This is deduplicated to the user, so it doesn't matter.

//~| ERROR E0452
fn main() {
}
18 changes: 17 additions & 1 deletion tests/ui/error-codes/E0452.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ LL | #![allow(foo = "")]
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 4 previous errors
error[E0452]: malformed lint attribute input
--> $DIR/E0452.rs:1:10
|
LL | #![allow(foo = "")]
| ^^^^^^^^ bad attribute argument
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error[E0452]: malformed lint attribute input
--> $DIR/E0452.rs:1:10
|
LL | #![allow(foo = "")]
| ^^^^^^^^ bad attribute argument
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 6 previous errors

For more information about this error, try `rustc --explain E0452`.
7 changes: 6 additions & 1 deletion tests/ui/lint/command-line-register-unknown-lint-tool.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ error[E0602]: unknown lint tool: `unknown_tool`
= note: requested on the command line with `-A unknown_tool::foo`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 2 previous errors
error[E0602]: unknown lint tool: `unknown_tool`
|
= note: requested on the command line with `-A unknown_tool::foo`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0602`.
6 changes: 5 additions & 1 deletion tests/ui/lint/force-warn/warnings-lint-group.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ error[E0602]: `warnings` lint group is not supported with ´--force-warn´
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 2 previous errors
error[E0602]: `warnings` lint group is not supported with ´--force-warn´
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0602`.
2 changes: 2 additions & 0 deletions tests/ui/lint/lint-malformed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
//~| ERROR malformed lint attribute
//~| ERROR malformed lint attribute
//~| ERROR malformed lint attribute
//~| ERROR malformed lint attribute
//~| ERROR malformed lint attribute
fn main() { }
18 changes: 17 additions & 1 deletion tests/ui/lint/lint-malformed.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ LL | #![allow(bar = "baz")]
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 5 previous errors
error[E0452]: malformed lint attribute input
--> $DIR/lint-malformed.rs:2:10
|
LL | #![allow(bar = "baz")]
| ^^^^^^^^^^^ bad attribute argument
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error[E0452]: malformed lint attribute input
--> $DIR/lint-malformed.rs:2:10
|
LL | #![allow(bar = "baz")]
| ^^^^^^^^^^^ bad attribute argument
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 7 previous errors

For more information about this error, try `rustc --explain E0452`.
1 change: 1 addition & 0 deletions tests/ui/tool-attributes/unknown-lint-tool-name.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![deny(foo::bar)] //~ ERROR unknown tool name `foo` found in scoped lint: `foo::bar`
//~| ERROR unknown tool name `foo` found in scoped lint: `foo::bar`
//~| ERROR unknown tool name `foo` found in scoped lint: `foo::bar`

#[allow(foo::bar)] //~ ERROR unknown tool name `foo` found in scoped lint: `foo::bar`
//~| ERROR unknown tool name `foo` found in scoped lint: `foo::bar`
Expand Down
15 changes: 12 additions & 3 deletions tests/ui/tool-attributes/unknown-lint-tool-name.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | #![deny(foo::bar)]
= help: add `#![register_tool(foo)]` to the crate root

error[E0710]: unknown tool name `foo` found in scoped lint: `foo::bar`
--> $DIR/unknown-lint-tool-name.rs:4:9
--> $DIR/unknown-lint-tool-name.rs:5:9
|
LL | #[allow(foo::bar)]
| ^^^
Expand All @@ -24,14 +24,23 @@ LL | #![deny(foo::bar)]
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error[E0710]: unknown tool name `foo` found in scoped lint: `foo::bar`
--> $DIR/unknown-lint-tool-name.rs:4:9
--> $DIR/unknown-lint-tool-name.rs:5:9
|
LL | #[allow(foo::bar)]
| ^^^
|
= help: add `#![register_tool(foo)]` to the crate root
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 4 previous errors
error[E0710]: unknown tool name `foo` found in scoped lint: `foo::bar`
--> $DIR/unknown-lint-tool-name.rs:1:9
|
LL | #![deny(foo::bar)]
| ^^^
|
= help: add `#![register_tool(foo)]` to the crate root
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 5 previous errors

For more information about this error, try `rustc --explain E0710`.
Loading