Skip to content

Commit c8649a3

Browse files
Stop calling source_span query in significant drop order code
1 parent fd4dc18 commit c8649a3

7 files changed

+100
-280
lines changed

Diff for: compiler/rustc_middle/src/ty/significant_drop_order.rs

+4-18
Original file line numberDiff line numberDiff line change
@@ -143,25 +143,11 @@ pub fn ty_dtor_span<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<Span> {
143143
| ty::UnsafeBinder(_) => None,
144144

145145
ty::Adt(adt_def, _) => {
146-
let did = adt_def.did();
147-
let try_local_did_span = |did: DefId| {
148-
if let Some(local) = did.as_local() {
149-
tcx.source_span(local)
150-
} else {
151-
tcx.def_span(did)
152-
}
153-
};
154-
let dtor = if let Some(dtor) = tcx.adt_destructor(did) {
155-
dtor.did
156-
} else if let Some(dtor) = tcx.adt_async_destructor(did) {
157-
return Some(tcx.source_span(dtor.impl_did));
146+
if let Some(dtor) = tcx.adt_destructor(adt_def.did()) {
147+
Some(tcx.def_span(tcx.parent(dtor.did)))
158148
} else {
159-
return Some(try_local_did_span(did));
160-
};
161-
let def_key = tcx.def_key(dtor);
162-
let Some(parent_index) = def_key.parent else { return Some(try_local_did_span(dtor)) };
163-
let parent_did = DefId { index: parent_index, krate: dtor.krate };
164-
Some(try_local_did_span(parent_did))
149+
Some(tcx.def_span(adt_def.did()))
150+
}
165151
}
166152
ty::Coroutine(did, _)
167153
| ty::CoroutineWitness(did, _)

Diff for: tests/ui/drop/drop-order-comparisons.e2021.stderr

+44-132
Original file line numberDiff line numberDiff line change
@@ -31,39 +31,23 @@ LL | | }, e.mark(3), e.ok(4));
3131
note: `#3` invokes this custom destructor
3232
--> $DIR/drop-order-comparisons.rs:571:1
3333
|
34-
LL | / impl<'b> Drop for LogDrop<'b> {
35-
LL | | fn drop(&mut self) {
36-
LL | | self.0.mark(self.1);
37-
LL | | }
38-
LL | | }
39-
| |_^
34+
LL | impl<'b> Drop for LogDrop<'b> {
35+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4036
note: `#1` invokes this custom destructor
4137
--> $DIR/drop-order-comparisons.rs:571:1
4238
|
43-
LL | / impl<'b> Drop for LogDrop<'b> {
44-
LL | | fn drop(&mut self) {
45-
LL | | self.0.mark(self.1);
46-
LL | | }
47-
LL | | }
48-
| |_^
39+
LL | impl<'b> Drop for LogDrop<'b> {
40+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4941
note: `_v` invokes this custom destructor
5042
--> $DIR/drop-order-comparisons.rs:571:1
5143
|
52-
LL | / impl<'b> Drop for LogDrop<'b> {
53-
LL | | fn drop(&mut self) {
54-
LL | | self.0.mark(self.1);
55-
LL | | }
56-
LL | | }
57-
| |_^
44+
LL | impl<'b> Drop for LogDrop<'b> {
45+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5846
note: `#2` invokes this custom destructor
5947
--> $DIR/drop-order-comparisons.rs:571:1
6048
|
61-
LL | / impl<'b> Drop for LogDrop<'b> {
62-
LL | | fn drop(&mut self) {
63-
LL | | self.0.mark(self.1);
64-
LL | | }
65-
LL | | }
66-
| |_^
49+
LL | impl<'b> Drop for LogDrop<'b> {
50+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6751
= note: most of the time, changing drop order is harmless; inspect the `impl Drop`s for side effects like releasing locks or sending messages
6852
note: the lint level is defined here
6953
--> $DIR/drop-order-comparisons.rs:28:25
@@ -95,21 +79,13 @@ LL | | }, e.mark(1), e.ok(4));
9579
note: `#2` invokes this custom destructor
9680
--> $DIR/drop-order-comparisons.rs:571:1
9781
|
98-
LL | / impl<'b> Drop for LogDrop<'b> {
99-
LL | | fn drop(&mut self) {
100-
LL | | self.0.mark(self.1);
101-
LL | | }
102-
LL | | }
103-
| |_^
82+
LL | impl<'b> Drop for LogDrop<'b> {
83+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10484
note: `#1` invokes this custom destructor
10585
--> $DIR/drop-order-comparisons.rs:571:1
10686
|
107-
LL | / impl<'b> Drop for LogDrop<'b> {
108-
LL | | fn drop(&mut self) {
109-
LL | | self.0.mark(self.1);
110-
LL | | }
111-
LL | | }
112-
| |_^
87+
LL | impl<'b> Drop for LogDrop<'b> {
88+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11389
= note: most of the time, changing drop order is harmless; inspect the `impl Drop`s for side effects like releasing locks or sending messages
11490

11591
warning: relative drop order changing in Rust 2024
@@ -135,21 +111,13 @@ LL | | }, e.mark(1), e.ok(4));
135111
note: `#2` invokes this custom destructor
136112
--> $DIR/drop-order-comparisons.rs:571:1
137113
|
138-
LL | / impl<'b> Drop for LogDrop<'b> {
139-
LL | | fn drop(&mut self) {
140-
LL | | self.0.mark(self.1);
141-
LL | | }
142-
LL | | }
143-
| |_^
114+
LL | impl<'b> Drop for LogDrop<'b> {
115+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
144116
note: `#1` invokes this custom destructor
145117
--> $DIR/drop-order-comparisons.rs:571:1
146118
|
147-
LL | / impl<'b> Drop for LogDrop<'b> {
148-
LL | | fn drop(&mut self) {
149-
LL | | self.0.mark(self.1);
150-
LL | | }
151-
LL | | }
152-
| |_^
119+
LL | impl<'b> Drop for LogDrop<'b> {
120+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
153121
= note: most of the time, changing drop order is harmless; inspect the `impl Drop`s for side effects like releasing locks or sending messages
154122

155123
warning: relative drop order changing in Rust 2024
@@ -175,21 +143,13 @@ LL | | }, e.mark(2), e.ok(3));
175143
note: `#2` invokes this custom destructor
176144
--> $DIR/drop-order-comparisons.rs:571:1
177145
|
178-
LL | / impl<'b> Drop for LogDrop<'b> {
179-
LL | | fn drop(&mut self) {
180-
LL | | self.0.mark(self.1);
181-
LL | | }
182-
LL | | }
183-
| |_^
146+
LL | impl<'b> Drop for LogDrop<'b> {
147+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
184148
note: `#1` invokes this custom destructor
185149
--> $DIR/drop-order-comparisons.rs:571:1
186150
|
187-
LL | / impl<'b> Drop for LogDrop<'b> {
188-
LL | | fn drop(&mut self) {
189-
LL | | self.0.mark(self.1);
190-
LL | | }
191-
LL | | }
192-
| |_^
151+
LL | impl<'b> Drop for LogDrop<'b> {
152+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
193153
= note: most of the time, changing drop order is harmless; inspect the `impl Drop`s for side effects like releasing locks or sending messages
194154

195155
warning: relative drop order changing in Rust 2024
@@ -215,21 +175,13 @@ LL | | }, e.mark(2), e.ok(3));
215175
note: `#2` invokes this custom destructor
216176
--> $DIR/drop-order-comparisons.rs:571:1
217177
|
218-
LL | / impl<'b> Drop for LogDrop<'b> {
219-
LL | | fn drop(&mut self) {
220-
LL | | self.0.mark(self.1);
221-
LL | | }
222-
LL | | }
223-
| |_^
178+
LL | impl<'b> Drop for LogDrop<'b> {
179+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
224180
note: `#1` invokes this custom destructor
225181
--> $DIR/drop-order-comparisons.rs:571:1
226182
|
227-
LL | / impl<'b> Drop for LogDrop<'b> {
228-
LL | | fn drop(&mut self) {
229-
LL | | self.0.mark(self.1);
230-
LL | | }
231-
LL | | }
232-
| |_^
183+
LL | impl<'b> Drop for LogDrop<'b> {
184+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
233185
= note: most of the time, changing drop order is harmless; inspect the `impl Drop`s for side effects like releasing locks or sending messages
234186

235187
warning: `if let` assigns a shorter lifetime since Edition 2024
@@ -245,12 +197,8 @@ LL | _ = (if let Ok(_) = e.ok(4).as_ref() {
245197
note: value invokes this custom destructor
246198
--> $DIR/drop-order-comparisons.rs:571:1
247199
|
248-
LL | / impl<'b> Drop for LogDrop<'b> {
249-
LL | | fn drop(&mut self) {
250-
LL | | self.0.mark(self.1);
251-
LL | | }
252-
LL | | }
253-
| |_^
200+
LL | impl<'b> Drop for LogDrop<'b> {
201+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
254202
help: the value is now dropped here in Edition 2024
255203
--> $DIR/drop-order-comparisons.rs:127:5
256204
|
@@ -279,12 +227,8 @@ LL | _ = (if let Ok(_) = e.err(4).as_ref() {} else {
279227
note: value invokes this custom destructor
280228
--> $DIR/drop-order-comparisons.rs:571:1
281229
|
282-
LL | / impl<'b> Drop for LogDrop<'b> {
283-
LL | | fn drop(&mut self) {
284-
LL | | self.0.mark(self.1);
285-
LL | | }
286-
LL | | }
287-
| |_^
230+
LL | impl<'b> Drop for LogDrop<'b> {
231+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
288232
help: the value is now dropped here in Edition 2024
289233
--> $DIR/drop-order-comparisons.rs:145:44
290234
|
@@ -312,12 +256,8 @@ LL | if let Ok(_) = e.err(4).as_ref() {} else {
312256
note: value invokes this custom destructor
313257
--> $DIR/drop-order-comparisons.rs:571:1
314258
|
315-
LL | / impl<'b> Drop for LogDrop<'b> {
316-
LL | | fn drop(&mut self) {
317-
LL | | self.0.mark(self.1);
318-
LL | | }
319-
LL | | }
320-
| |_^
259+
LL | impl<'b> Drop for LogDrop<'b> {
260+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
321261
help: the value is now dropped here in Edition 2024
322262
--> $DIR/drop-order-comparisons.rs:247:43
323263
|
@@ -345,12 +285,8 @@ LL | if let true = e.err(9).is_ok() {} else {
345285
note: value invokes this custom destructor
346286
--> $DIR/drop-order-comparisons.rs:571:1
347287
|
348-
LL | / impl<'b> Drop for LogDrop<'b> {
349-
LL | | fn drop(&mut self) {
350-
LL | | self.0.mark(self.1);
351-
LL | | }
352-
LL | | }
353-
| |_^
288+
LL | impl<'b> Drop for LogDrop<'b> {
289+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
354290
help: the value is now dropped here in Edition 2024
355291
--> $DIR/drop-order-comparisons.rs:352:41
356292
|
@@ -378,12 +314,8 @@ LL | if let Ok(_v) = e.err(8) {} else {
378314
note: value invokes this custom destructor
379315
--> $DIR/drop-order-comparisons.rs:571:1
380316
|
381-
LL | / impl<'b> Drop for LogDrop<'b> {
382-
LL | | fn drop(&mut self) {
383-
LL | | self.0.mark(self.1);
384-
LL | | }
385-
LL | | }
386-
| |_^
317+
LL | impl<'b> Drop for LogDrop<'b> {
318+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
387319
help: the value is now dropped here in Edition 2024
388320
--> $DIR/drop-order-comparisons.rs:355:35
389321
|
@@ -411,12 +343,8 @@ LL | if let Ok(_) = e.err(7) {} else {
411343
note: value invokes this custom destructor
412344
--> $DIR/drop-order-comparisons.rs:571:1
413345
|
414-
LL | / impl<'b> Drop for LogDrop<'b> {
415-
LL | | fn drop(&mut self) {
416-
LL | | self.0.mark(self.1);
417-
LL | | }
418-
LL | | }
419-
| |_^
346+
LL | impl<'b> Drop for LogDrop<'b> {
347+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
420348
help: the value is now dropped here in Edition 2024
421349
--> $DIR/drop-order-comparisons.rs:358:34
422350
|
@@ -444,12 +372,8 @@ LL | if let Ok(_) = e.err(6).as_ref() {} else {
444372
note: value invokes this custom destructor
445373
--> $DIR/drop-order-comparisons.rs:571:1
446374
|
447-
LL | / impl<'b> Drop for LogDrop<'b> {
448-
LL | | fn drop(&mut self) {
449-
LL | | self.0.mark(self.1);
450-
LL | | }
451-
LL | | }
452-
| |_^
375+
LL | impl<'b> Drop for LogDrop<'b> {
376+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
453377
help: the value is now dropped here in Edition 2024
454378
--> $DIR/drop-order-comparisons.rs:361:43
455379
|
@@ -477,12 +401,8 @@ LL | if let Ok(_v) = e.err(5) {} else {
477401
note: value invokes this custom destructor
478402
--> $DIR/drop-order-comparisons.rs:571:1
479403
|
480-
LL | / impl<'b> Drop for LogDrop<'b> {
481-
LL | | fn drop(&mut self) {
482-
LL | | self.0.mark(self.1);
483-
LL | | }
484-
LL | | }
485-
| |_^
404+
LL | impl<'b> Drop for LogDrop<'b> {
405+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
486406
help: the value is now dropped here in Edition 2024
487407
--> $DIR/drop-order-comparisons.rs:365:35
488408
|
@@ -510,12 +430,8 @@ LL | if let Ok(_) = e.err(4) {} else {
510430
note: value invokes this custom destructor
511431
--> $DIR/drop-order-comparisons.rs:571:1
512432
|
513-
LL | / impl<'b> Drop for LogDrop<'b> {
514-
LL | | fn drop(&mut self) {
515-
LL | | self.0.mark(self.1);
516-
LL | | }
517-
LL | | }
518-
| |_^
433+
LL | impl<'b> Drop for LogDrop<'b> {
434+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
519435
help: the value is now dropped here in Edition 2024
520436
--> $DIR/drop-order-comparisons.rs:368:34
521437
|
@@ -543,12 +459,8 @@ LL | if let Ok(_) = e.err(4).as_ref() {} else {
543459
note: value invokes this custom destructor
544460
--> $DIR/drop-order-comparisons.rs:571:1
545461
|
546-
LL | / impl<'b> Drop for LogDrop<'b> {
547-
LL | | fn drop(&mut self) {
548-
LL | | self.0.mark(self.1);
549-
LL | | }
550-
LL | | }
551-
| |_^
462+
LL | impl<'b> Drop for LogDrop<'b> {
463+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
552464
help: the value is now dropped here in Edition 2024
553465
--> $DIR/drop-order-comparisons.rs:404:43
554466
|

Diff for: tests/ui/drop/lint-if-let-rescope-gated.edition2021.stderr

+2-6
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,8 @@ LL | if let Some(_value) = Droppy.get() {
1111
note: value invokes this custom destructor
1212
--> $DIR/lint-if-let-rescope-gated.rs:14:1
1313
|
14-
LL | / impl Drop for Droppy {
15-
LL | | fn drop(&mut self) {
16-
LL | | println!("dropped");
17-
LL | | }
18-
LL | | }
19-
| |_^
14+
LL | impl Drop for Droppy {
15+
| ^^^^^^^^^^^^^^^^^^^^
2016
help: the value is now dropped here in Edition 2024
2117
--> $DIR/lint-if-let-rescope-gated.rs:30:5
2218
|

Diff for: tests/ui/drop/lint-if-let-rescope-with-macro.stderr

+2-6
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,8 @@ LL | | };
1818
note: value invokes this custom destructor
1919
--> $DIR/lint-if-let-rescope-with-macro.rs:22:1
2020
|
21-
LL | / impl Drop for Droppy {
22-
LL | | fn drop(&mut self) {
23-
LL | | println!("dropped");
24-
LL | | }
25-
LL | | }
26-
| |_^
21+
LL | impl Drop for Droppy {
22+
| ^^^^^^^^^^^^^^^^^^^^
2723
help: the value is now dropped here in Edition 2024
2824
--> $DIR/lint-if-let-rescope-with-macro.rs:12:38
2925
|

0 commit comments

Comments
 (0)