Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not ICE on unnamed future #67289

Merged
merged 1 commit into from
Dec 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1016,8 +1016,8 @@ impl<'hir> Map<'hir> {
}
}

pub fn name(&self, id: HirId) -> Name {
match self.get(id) {
pub fn opt_name(&self, id: HirId) -> Option<Name> {
Some(match self.get(id) {
Node::Item(i) => i.ident.name,
Node::ForeignItem(fi) => fi.ident.name,
Node::ImplItem(ii) => ii.ident.name,
Expand All @@ -1028,7 +1028,14 @@ impl<'hir> Map<'hir> {
Node::GenericParam(param) => param.name.ident().name,
Node::Binding(&Pat { kind: PatKind::Binding(_, _, l, _), .. }) => l.name,
Node::Ctor(..) => self.name(self.get_parent_item(id)),
_ => bug!("no name for {}", self.node_to_string(id))
_ => return None,
})
}

pub fn name(&self, id: HirId) -> Name {
match self.opt_name(id) {
Some(name) => name,
None => bug!("no name for {}", self.node_to_string(id)),
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2353,7 +2353,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
let message = if let Some(name) = last_generator
.and_then(|generator_did| self.tcx.parent(generator_did))
.and_then(|parent_did| self.tcx.hir().as_local_hir_id(parent_did))
.map(|parent_hir_id| self.tcx.hir().name(parent_hir_id))
.and_then(|parent_hir_id| self.tcx.hir().opt_name(parent_hir_id))
{
format!("future returned by `{}` is not {}", name, trait_name)
} else {
Expand Down
24 changes: 24 additions & 0 deletions src/test/ui/async-await/issue-67252-unnamed-future.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// edition:2018
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};

fn spawn<T: Send>(_: T) {}

pub struct AFuture;
impl Future for AFuture{
type Output = ();

fn poll(mut self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<()> {
unimplemented!()
}
}

async fn foo() {
spawn(async { //~ ERROR future cannot be sent between threads safely
let _a = std::ptr::null_mut::<()>(); // `*mut ()` is not `Send`
AFuture.await;
});
}

fn main() {}
22 changes: 22 additions & 0 deletions src/test/ui/async-await/issue-67252-unnamed-future.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
error: future cannot be sent between threads safely
--> $DIR/issue-67252-unnamed-future.rs:18:5
|
LL | fn spawn<T: Send>(_: T) {}
| ----- ---- required by this bound in `spawn`
...
LL | spawn(async {
| ^^^^^ future is not `Send`
|
= help: within `impl std::future::Future`, the trait `std::marker::Send` is not implemented for `*mut ()`
note: future is not `Send` as this value is used across an await
--> $DIR/issue-67252-unnamed-future.rs:20:9
|
LL | let _a = std::ptr::null_mut::<()>(); // `*mut ()` is not `Send`
| -- has type `*mut ()`
LL | AFuture.await;
| ^^^^^^^^^^^^^ await occurs here, with `_a` maybe used later
LL | });
| - `_a` is later dropped here

error: aborting due to previous error