Skip to content

Commit e08944f

Browse files
committed
Do not ICE on unnamed future
1 parent de0abf7 commit e08944f

File tree

4 files changed

+57
-4
lines changed

4 files changed

+57
-4
lines changed

src/librustc/hir/map/mod.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -1016,8 +1016,8 @@ impl<'hir> Map<'hir> {
10161016
}
10171017
}
10181018

1019-
pub fn name(&self, id: HirId) -> Name {
1020-
match self.get(id) {
1019+
pub fn opt_name(&self, id: HirId) -> Option<Name> {
1020+
Some(match self.get(id) {
10211021
Node::Item(i) => i.ident.name,
10221022
Node::ForeignItem(fi) => fi.ident.name,
10231023
Node::ImplItem(ii) => ii.ident.name,
@@ -1028,7 +1028,14 @@ impl<'hir> Map<'hir> {
10281028
Node::GenericParam(param) => param.name.ident().name,
10291029
Node::Binding(&Pat { kind: PatKind::Binding(_, _, l, _), .. }) => l.name,
10301030
Node::Ctor(..) => self.name(self.get_parent_item(id)),
1031-
_ => bug!("no name for {}", self.node_to_string(id))
1031+
_ => return None,
1032+
})
1033+
}
1034+
1035+
pub fn name(&self, id: HirId) -> Name {
1036+
match self.opt_name(id) {
1037+
Some(name) => name,
1038+
None => bug!("no name for {}", self.node_to_string(id)),
10321039
}
10331040
}
10341041

src/librustc/traits/error_reporting.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2353,7 +2353,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
23532353
let message = if let Some(name) = last_generator
23542354
.and_then(|generator_did| self.tcx.parent(generator_did))
23552355
.and_then(|parent_did| self.tcx.hir().as_local_hir_id(parent_did))
2356-
.map(|parent_hir_id| self.tcx.hir().name(parent_hir_id))
2356+
.and_then(|parent_hir_id| self.tcx.hir().opt_name(parent_hir_id))
23572357
{
23582358
format!("future returned by `{}` is not {}", name, trait_name)
23592359
} else {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// edition:2018
2+
use std::future::Future;
3+
use std::pin::Pin;
4+
use std::task::{Context, Poll};
5+
6+
fn spawn<T: Send>(_: T) {}
7+
8+
pub struct AFuture;
9+
impl Future for AFuture{
10+
type Output = ();
11+
12+
fn poll(mut self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<()> {
13+
unimplemented!()
14+
}
15+
}
16+
17+
async fn foo() {
18+
spawn(async { //~ ERROR future cannot be sent between threads safely
19+
let _a = std::ptr::null_mut::<()>(); // `*mut ()` is not `Send`
20+
AFuture.await;
21+
});
22+
}
23+
24+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error: future cannot be sent between threads safely
2+
--> $DIR/issue-67252-unnamed-future.rs:18:5
3+
|
4+
LL | fn spawn<T: Send>(_: T) {}
5+
| ----- ---- required by this bound in `spawn`
6+
...
7+
LL | spawn(async {
8+
| ^^^^^ future is not `Send`
9+
|
10+
= help: within `impl std::future::Future`, the trait `std::marker::Send` is not implemented for `*mut ()`
11+
note: future is not `Send` as this value is used across an await
12+
--> $DIR/issue-67252-unnamed-future.rs:20:9
13+
|
14+
LL | let _a = std::ptr::null_mut::<()>(); // `*mut ()` is not `Send`
15+
| -- has type `*mut ()`
16+
LL | AFuture.await;
17+
| ^^^^^^^^^^^^^ await occurs here, with `_a` maybe used later
18+
LL | });
19+
| - `_a` is later dropped here
20+
21+
error: aborting due to previous error
22+

0 commit comments

Comments
 (0)