Skip to content

Commit 90b296d

Browse files
authored
Rollup merge of #98644 - matthiaskrgr:drp_loc_span_err__2021_inc_clos_cap, r=lcnr
fix ICE with -Wrust-2021-incompatible-closure-captures Fixes #93117 Fixes #96258
2 parents 9dd3288 + 7dc0489 commit 90b296d

5 files changed

+154
-2
lines changed

compiler/rustc_typeck/src/check/upvar.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1707,12 +1707,14 @@ fn drop_location_span<'tcx>(tcx: TyCtxt<'tcx>, hir_id: hir::HirId) -> Span {
17071707
hir::Node::Item(item) => match item.kind {
17081708
hir::ItemKind::Fn(_, _, owner_id) => tcx.hir().span(owner_id.hir_id),
17091709
_ => {
1710-
bug!("Drop location span error: need to handle more ItemKind {:?}", item.kind);
1710+
bug!("Drop location span error: need to handle more ItemKind '{:?}'", item.kind);
17111711
}
17121712
},
17131713
hir::Node::Block(block) => tcx.hir().span(block.hir_id),
1714+
hir::Node::TraitItem(item) => tcx.hir().span(item.hir_id()),
1715+
hir::Node::ImplItem(item) => tcx.hir().span(item.hir_id()),
17141716
_ => {
1715-
bug!("Drop location span error: need to handle more Node {:?}", owner_node);
1717+
bug!("Drop location span error: need to handle more Node '{:?}'", owner_node);
17161718
}
17171719
};
17181720
tcx.sess.source_map().end_point(owner_span)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// compile-flags: -Wrust-2021-incompatible-closure-captures
2+
3+
pub struct A {}
4+
5+
impl A {
6+
async fn create(path: impl AsRef<std::path::Path>) { //~ ERROR `async fn` is not permitted in Rust 2015
7+
//~^ WARN changes to closure capture in Rust 2021 will affect drop order [rust_2021_incompatible_closure_captures]
8+
;
9+
crate(move || {} ).await //~ ERROR expected function, found module `crate`
10+
}
11+
}
12+
13+
trait C{async fn new(val: T) {} //~ ERROR `async fn` is not permitted in Rust 2015
14+
//~^ ERROR functions in traits cannot be declared `async`
15+
//~^^ ERROR cannot find type `T` in this scope
16+
//~^^^ WARN changes to closure capture in Rust 2021 will affect drop order [rust_2021_incompatible_closure_captures]
17+
18+
//~ ERROR this file contains an unclosed delimiter
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
error: this file contains an unclosed delimiter
2+
--> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:18:53
3+
|
4+
LL | trait C{async fn new(val: T) {}
5+
| - unclosed delimiter
6+
...
7+
LL |
8+
| ^
9+
10+
error[E0670]: `async fn` is not permitted in Rust 2015
11+
--> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:6:5
12+
|
13+
LL | async fn create(path: impl AsRef<std::path::Path>) {
14+
| ^^^^^ to use `async fn`, switch to Rust 2018 or later
15+
|
16+
= help: pass `--edition 2021` to `rustc`
17+
= note: for more on editions, read https://doc.rust-lang.org/edition-guide
18+
19+
error[E0670]: `async fn` is not permitted in Rust 2015
20+
--> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:13:9
21+
|
22+
LL | trait C{async fn new(val: T) {}
23+
| ^^^^^ to use `async fn`, switch to Rust 2018 or later
24+
|
25+
= help: pass `--edition 2021` to `rustc`
26+
= note: for more on editions, read https://doc.rust-lang.org/edition-guide
27+
28+
error[E0706]: functions in traits cannot be declared `async`
29+
--> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:13:9
30+
|
31+
LL | trait C{async fn new(val: T) {}
32+
| -----^^^^^^^^^^^^^^^^^^
33+
| |
34+
| `async` because of this
35+
|
36+
= note: `async` trait functions are not currently supported
37+
= note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
38+
39+
error[E0423]: expected function, found module `crate`
40+
--> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:9:5
41+
|
42+
LL | crate(move || {} ).await
43+
| ^^^^^ not a function
44+
45+
error[E0412]: cannot find type `T` in this scope
46+
--> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:13:27
47+
|
48+
LL | pub struct A {}
49+
| ------------ similarly named struct `A` defined here
50+
...
51+
LL | trait C{async fn new(val: T) {}
52+
| ^ help: a struct with a similar name exists: `A`
53+
54+
warning: changes to closure capture in Rust 2021 will affect drop order
55+
--> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:6:57
56+
|
57+
LL | async fn create(path: impl AsRef<std::path::Path>) {
58+
| _____________________----_____________________________-__^
59+
| | | |
60+
| | | in Rust 2018, `path` is dropped here along with the closure, but in Rust 2021 `path` is not part of the closure
61+
| | in Rust 2018, this causes the closure to capture `path`, but in Rust 2021, it has no effect
62+
LL | |
63+
LL | | ;
64+
LL | | crate(move || {} ).await
65+
LL | | }
66+
| |_____^
67+
|
68+
= note: requested on the command line with `-W rust-2021-incompatible-closure-captures`
69+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
70+
help: add a dummy let to cause `path` to be fully captured
71+
|
72+
LL | async fn create(path: impl AsRef<std::path::Path>) { let _ = &path;
73+
| ++++++++++++++
74+
75+
warning: changes to closure capture in Rust 2021 will affect drop order
76+
--> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:13:30
77+
|
78+
LL | trait C{async fn new(val: T) {}
79+
| --- - ^^
80+
| | |
81+
| | in Rust 2018, `val` is dropped here along with the closure, but in Rust 2021 `val` is not part of the closure
82+
| in Rust 2018, this causes the closure to capture `val`, but in Rust 2021, it has no effect
83+
|
84+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
85+
help: add a dummy let to cause `val` to be fully captured
86+
|
87+
LL | trait C{async fn new(val: T) { let _ = &val;}
88+
| +++++++++++++
89+
90+
error: aborting due to 6 previous errors; 2 warnings emitted
91+
92+
Some errors have detailed explanations: E0412, E0423, E0670, E0706.
93+
For more information about an error, try `rustc --explain E0412`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// compile-flags -Wrust-2021-incompatible-closure-captures
2+
3+
fn main() {}
4+
5+
pub(crate) struct Numberer {}
6+
7+
impl Numberer {
8+
pub(crate) async fn new(
9+
//~^ ERROR `async fn` is not permitted in Rust 2015
10+
interval: Duration,
11+
//~^ ERROR cannot find type `Duration` in this scope
12+
) -> Numberer {
13+
Numberer {}
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error[E0670]: `async fn` is not permitted in Rust 2015
2+
--> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-96258.rs:8:16
3+
|
4+
LL | pub(crate) async fn new(
5+
| ^^^^^ to use `async fn`, switch to Rust 2018 or later
6+
|
7+
= help: pass `--edition 2021` to `rustc`
8+
= note: for more on editions, read https://doc.rust-lang.org/edition-guide
9+
10+
error[E0412]: cannot find type `Duration` in this scope
11+
--> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-96258.rs:10:19
12+
|
13+
LL | interval: Duration,
14+
| ^^^^^^^^ not found in this scope
15+
|
16+
help: consider importing this struct
17+
|
18+
LL | use std::time::Duration;
19+
|
20+
21+
error: aborting due to 2 previous errors
22+
23+
Some errors have detailed explanations: E0412, E0670.
24+
For more information about an error, try `rustc --explain E0412`.

0 commit comments

Comments
 (0)