Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 273873a

Browse files
compiler-errorscuviper
authored andcommittedJan 10, 2025
Don't create cycles by normalizing opaques defined in the body we're checking
(cherry picked from commit 197f6d8)
1 parent 61c0bcf commit 273873a

5 files changed

+33
-19
lines changed
 

‎compiler/rustc_mir_transform/src/lint_tail_expr_drop_order.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -351,14 +351,19 @@ pub(crate) fn run_lint<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId, body: &Body<
351351
{
352352
return;
353353
}
354+
355+
// FIXME(typing_env): This should be able to reveal the opaques local to the
356+
// body using the typeck results.
357+
let typing_env = ty::TypingEnv::non_body_analysis(tcx, def_id);
358+
354359
// ## About BIDs in blocks ##
355360
// Track the set of blocks that contain a backwards-incompatible drop (BID)
356361
// and, for each block, the vector of locations.
357362
//
358363
// We group them per-block because they tend to scheduled in the same drop ladder block.
359364
let mut bid_per_block = IndexMap::default();
360365
let mut bid_places = UnordSet::new();
361-
let typing_env = ty::TypingEnv::post_analysis(tcx, def_id);
366+
362367
let mut ty_dropped_components = UnordMap::default();
363368
for (block, data) in body.basic_blocks.iter_enumerated() {
364369
for (statement_index, stmt) in data.statements.iter().enumerate() {

‎tests/ui/drop/lint-tail-expr-drop-order.rs

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ impl Drop for LoudDropper {
1717
//~| NOTE: `#1` invokes this custom destructor
1818
//~| NOTE: `x` invokes this custom destructor
1919
//~| NOTE: `#1` invokes this custom destructor
20-
//~| NOTE: `future` invokes this custom destructor
2120
//~| NOTE: `_x` invokes this custom destructor
2221
//~| NOTE: `#1` invokes this custom destructor
2322
fn drop(&mut self) {

‎tests/ui/drop/lint-tail-expr-drop-order.stderr

+10-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: relative drop order changing in Rust 2024
2-
--> $DIR/lint-tail-expr-drop-order.rs:41:15
2+
--> $DIR/lint-tail-expr-drop-order.rs:40:15
33
|
44
LL | let x = LoudDropper;
55
| -
@@ -40,7 +40,7 @@ LL | #![deny(tail_expr_drop_order)]
4040
| ^^^^^^^^^^^^^^^^^^^^
4141

4242
error: relative drop order changing in Rust 2024
43-
--> $DIR/lint-tail-expr-drop-order.rs:66:19
43+
--> $DIR/lint-tail-expr-drop-order.rs:65:19
4444
|
4545
LL | let x = LoudDropper;
4646
| -
@@ -76,7 +76,7 @@ LL | | }
7676
= note: most of the time, changing drop order is harmless; inspect the `impl Drop`s for side effects like releasing locks or sending messages
7777

7878
error: relative drop order changing in Rust 2024
79-
--> $DIR/lint-tail-expr-drop-order.rs:93:7
79+
--> $DIR/lint-tail-expr-drop-order.rs:92:7
8080
|
8181
LL | let x = LoudDropper;
8282
| -
@@ -112,7 +112,7 @@ LL | | }
112112
= note: most of the time, changing drop order is harmless; inspect the `impl Drop`s for side effects like releasing locks or sending messages
113113

114114
error: relative drop order changing in Rust 2024
115-
--> $DIR/lint-tail-expr-drop-order.rs:146:5
115+
--> $DIR/lint-tail-expr-drop-order.rs:145:5
116116
|
117117
LL | let future = f();
118118
| ------
@@ -136,19 +136,12 @@ note: `#1` invokes this custom destructor
136136
|
137137
LL | / impl Drop for LoudDropper {
138138
... |
139-
LL | | }
140-
| |_^
141-
note: `future` invokes this custom destructor
142-
--> $DIR/lint-tail-expr-drop-order.rs:10:1
143-
|
144-
LL | / impl Drop for LoudDropper {
145-
... |
146139
LL | | }
147140
| |_^
148141
= note: most of the time, changing drop order is harmless; inspect the `impl Drop`s for side effects like releasing locks or sending messages
149142

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

172165
error: relative drop order changing in Rust 2024
173-
--> $DIR/lint-tail-expr-drop-order.rs:177:5
166+
--> $DIR/lint-tail-expr-drop-order.rs:176:5
174167
|
175168
LL | let x: Result<LoudDropper, ()> = Ok(LoudDropper);
176169
| -
@@ -206,7 +199,7 @@ LL | | }
206199
= note: most of the time, changing drop order is harmless; inspect the `impl Drop`s for side effects like releasing locks or sending messages
207200

208201
error: relative drop order changing in Rust 2024
209-
--> $DIR/lint-tail-expr-drop-order.rs:221:5
202+
--> $DIR/lint-tail-expr-drop-order.rs:220:5
210203
|
211204
LL | let x = LoudDropper2;
212205
| -
@@ -226,7 +219,7 @@ LL | }
226219
= warning: this changes meaning in Rust 2024
227220
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-tail-expr-scope.html>
228221
note: `#1` invokes this custom destructor
229-
--> $DIR/lint-tail-expr-drop-order.rs:194:5
222+
--> $DIR/lint-tail-expr-drop-order.rs:193:5
230223
|
231224
LL | / impl Drop for LoudDropper3 {
232225
LL | |
@@ -236,7 +229,7 @@ LL | | }
236229
LL | | }
237230
| |_____^
238231
note: `x` invokes this custom destructor
239-
--> $DIR/lint-tail-expr-drop-order.rs:206:5
232+
--> $DIR/lint-tail-expr-drop-order.rs:205:5
240233
|
241234
LL | / impl Drop for LoudDropper2 {
242235
LL | |
@@ -248,7 +241,7 @@ LL | | }
248241
= note: most of the time, changing drop order is harmless; inspect the `impl Drop`s for side effects like releasing locks or sending messages
249242

250243
error: relative drop order changing in Rust 2024
251-
--> $DIR/lint-tail-expr-drop-order.rs:234:13
244+
--> $DIR/lint-tail-expr-drop-order.rs:233:13
252245
|
253246
LL | LoudDropper.get()
254247
| ^^^^^^^^^^^

‎tests/ui/drop/tail_expr_drop_order-on-coroutine-unwind.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ error: relative drop order changing in Rust 2024
44
LL | match func().await {
55
| ^^^^^^^-----
66
| | |
7+
| | this value will be stored in a temporary; let us call it `#3`
8+
| | up until Edition 2021 `#3` is dropped last but will be dropped earlier in Edition 2024
79
| | this value will be stored in a temporary; let us call it `#1`
810
| | `#1` will be dropped later as of Edition 2024
911
| this value will be stored in a temporary; let us call it `#2`
1012
| up until Edition 2021 `#2` is dropped last but will be dropped earlier in Edition 2024
13+
| `__awaitee` calls a custom destructor
14+
| `__awaitee` will be dropped later as of Edition 2024
1115
...
1216
LL | Err(e) => {}
1317
| -
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@ edition: 2021
2+
//@ check-pass
3+
4+
// Make sure we don't cycle error when normalizing types for tail expr drop order lint.
5+
6+
#![deny(tail_expr_drop_order)]
7+
8+
async fn test() -> Result<(), Box<dyn std::error::Error>> {
9+
Box::pin(test()).await?;
10+
Ok(())
11+
}
12+
13+
fn main() {}

0 commit comments

Comments
 (0)
Failed to load comments.