Skip to content

Commit

Permalink
Auto merge of rust-lang#134493 - compiler-errors:drops-elaborated, r=…
Browse files Browse the repository at this point in the history
…<try>

Always run `tail_expr_drop_order` lint in promoted MIR query

Rather than running the lint at the beginning of `mir_drops_elaborated_and_const_checked`, run it at the end of `mir_promoted`.  This should ensure that the lint gets picked up when running `cargo fix`, which runs with `--emit metadata` and therefore doesn't actually query `mir_drops_elaborated_and_const_checked`.

We could probably push this down into `mir_built` too? but I don't really see a good reason to do so.

rust-lang#132861 (comment)

cc `@ehuss`
  • Loading branch information
bors committed Dec 19, 2024
2 parents 3bf62cc + 8ccdd12 commit 07012ee
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 32 deletions.
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

#![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
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
//~| 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`.

0 comments on commit 07012ee

Please sign in to comment.