Give better const-checking error for async blocks

This commit is contained in:
Dylan MacKenzie
2020-10-01 09:28:25 -07:00
parent 782013564e
commit 50e0c0d97b
2 changed files with 12 additions and 3 deletions

View File

@@ -151,14 +151,15 @@ impl NonConstOp for FnPtrCast {
}
#[derive(Debug)]
pub struct Generator;
pub struct Generator(pub hir::GeneratorKind);
impl NonConstOp for Generator {
fn status_in_item(&self, _: &ConstCx<'_, '_>) -> Status {
Status::Forbidden
}
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
ccx.tcx.sess.struct_span_err(span, "Generators and `async` functions cannot be `const`")
let msg = format!("{}s are not allowed in {}s", self.0, ccx.const_kind());
ccx.tcx.sess.struct_span_err(span, &msg)
}
}