Skip to content

Commit

Permalink
Don't create cycles by normalizing opaques defined in the body we're …
Browse files Browse the repository at this point in the history
…checking
  • Loading branch information
compiler-errors committed Jan 8, 2025
1 parent 13c7122 commit 197f6d8
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,19 @@ pub(crate) fn run_lint<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId, body: &Body<
{
return;
}

// FIXME(typing_env): This should be able to reveal the opaques local to the
// body using the typeck results.
let typing_env = ty::TypingEnv::non_body_analysis(tcx, def_id);

// ## About BIDs in blocks ##
// Track the set of blocks that contain a backwards-incompatible drop (BID)
// and, for each block, the vector of locations.
//
// We group them per-block because they tend to scheduled in the same drop ladder block.
let mut bid_per_block = IndexMap::default();
let mut bid_places = UnordSet::new();
let typing_env = ty::TypingEnv::post_analysis(tcx, def_id);

let mut ty_dropped_components = UnordMap::default();
for (block, data) in body.basic_blocks.iter_enumerated() {
for (statement_index, stmt) in data.statements.iter().enumerate() {
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 @@ -17,7 +17,6 @@ impl Drop for LoudDropper {
//~| NOTE: `#1` invokes this custom destructor
//~| NOTE: `x` invokes this custom destructor
//~| NOTE: `#1` invokes this custom destructor
//~| NOTE: `future` invokes this custom destructor
//~| NOTE: `_x` invokes this custom destructor
//~| NOTE: `#1` invokes this custom destructor
fn drop(&mut self) {
Expand Down
27 changes: 10 additions & 17 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:41:15
--> $DIR/lint-tail-expr-drop-order.rs:40:15
|
LL | let x = LoudDropper;
| -
Expand Down Expand Up @@ -40,7 +40,7 @@ LL | #![deny(tail_expr_drop_order)]
| ^^^^^^^^^^^^^^^^^^^^

error: relative drop order changing in Rust 2024
--> $DIR/lint-tail-expr-drop-order.rs:66:19
--> $DIR/lint-tail-expr-drop-order.rs:65:19
|
LL | let x = LoudDropper;
| -
Expand Down Expand Up @@ -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:93:7
--> $DIR/lint-tail-expr-drop-order.rs:92:7
|
LL | let x = LoudDropper;
| -
Expand Down Expand Up @@ -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:146:5
--> $DIR/lint-tail-expr-drop-order.rs:145:5
|
LL | let future = f();
| ------
Expand All @@ -136,19 +136,12 @@ note: `#1` invokes this custom destructor
|
LL | / impl Drop for LoudDropper {
... |
LL | | }
| |_^
note: `future` invokes this custom destructor
--> $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

error: relative drop order changing in Rust 2024
--> $DIR/lint-tail-expr-drop-order.rs:163:14
--> $DIR/lint-tail-expr-drop-order.rs:162:14
|
LL | let x = T::default();
| -
Expand All @@ -170,7 +163,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:177:5
--> $DIR/lint-tail-expr-drop-order.rs:176:5
|
LL | let x: Result<LoudDropper, ()> = Ok(LoudDropper);
| -
Expand Down Expand Up @@ -206,7 +199,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:221:5
--> $DIR/lint-tail-expr-drop-order.rs:220:5
|
LL | let x = LoudDropper2;
| -
Expand All @@ -226,7 +219,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:194:5
--> $DIR/lint-tail-expr-drop-order.rs:193:5
|
LL | / impl Drop for LoudDropper3 {
LL | |
Expand All @@ -236,7 +229,7 @@ LL | | }
LL | | }
| |_____^
note: `x` invokes this custom destructor
--> $DIR/lint-tail-expr-drop-order.rs:206:5
--> $DIR/lint-tail-expr-drop-order.rs:205:5
|
LL | / impl Drop for LoudDropper2 {
LL | |
Expand All @@ -248,7 +241,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:234:13
--> $DIR/lint-tail-expr-drop-order.rs:233:13
|
LL | LoudDropper.get()
| ^^^^^^^^^^^
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/drop/tail_expr_drop_order-on-coroutine-unwind.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ error: relative drop order changing in Rust 2024
LL | match func().await {
| ^^^^^^^-----
| | |
| | this value will be stored in a temporary; let us call it `#3`
| | up until Edition 2021 `#3` is dropped last but will be dropped earlier in Edition 2024
| | this value will be stored in a temporary; let us call it `#1`
| | `#1` will be dropped later as of Edition 2024
| this value will be stored in a temporary; let us call it `#2`
| up until Edition 2021 `#2` is dropped last but will be dropped earlier in Edition 2024
| `__awaitee` calls a custom destructor
| `__awaitee` will be dropped later as of Edition 2024
...
LL | Err(e) => {}
| -
Expand Down
13 changes: 13 additions & 0 deletions tests/ui/drop/tail_expr_drop_order-on-recursive-boxed-fut.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//@ edition: 2021
//@ check-pass

// Make sure we don't cycle error when normalizing types for tail expr drop order lint.

#![deny(tail_expr_drop_order)]

async fn test() -> Result<(), Box<dyn std::error::Error>> {
Box::pin(test()).await?;
Ok(())
}

fn main() {}

0 comments on commit 197f6d8

Please sign in to comment.