Rollup merge of #130252 - compiler-errors:const-gen, r=chenyukang
Properly report error on `const gen fn` Fixes #130232 Also removes some (what I thought were unused) functions, and fixes a bug in clippy where we considered `gen fn` to be the same as `fn` because it was only built to consider asyncness.
This commit is contained in:
commit
a3d9d13d7a
7 changed files with 66 additions and 28 deletions
|
@ -1418,21 +1418,16 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
|||
|
||||
// Functions cannot both be `const async` or `const gen`
|
||||
if let Some(&FnHeader {
|
||||
constness: Const::Yes(cspan),
|
||||
constness: Const::Yes(const_span),
|
||||
coroutine_kind: Some(coroutine_kind),
|
||||
..
|
||||
}) = fk.header()
|
||||
{
|
||||
let aspan = match coroutine_kind {
|
||||
CoroutineKind::Async { span: aspan, .. }
|
||||
| CoroutineKind::Gen { span: aspan, .. }
|
||||
| CoroutineKind::AsyncGen { span: aspan, .. } => aspan,
|
||||
};
|
||||
// FIXME(gen_blocks): Report a different error for `const gen`
|
||||
self.dcx().emit_err(errors::ConstAndAsync {
|
||||
spans: vec![cspan, aspan],
|
||||
cspan,
|
||||
aspan,
|
||||
self.dcx().emit_err(errors::ConstAndCoroutine {
|
||||
spans: vec![coroutine_kind.span(), const_span],
|
||||
const_span,
|
||||
coroutine_span: coroutine_kind.span(),
|
||||
coroutine_kind: coroutine_kind.as_str(),
|
||||
span,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -657,16 +657,17 @@ pub(crate) enum TildeConstReason {
|
|||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(ast_passes_const_and_async)]
|
||||
pub(crate) struct ConstAndAsync {
|
||||
#[diag(ast_passes_const_and_coroutine)]
|
||||
pub(crate) struct ConstAndCoroutine {
|
||||
#[primary_span]
|
||||
pub spans: Vec<Span>,
|
||||
#[label(ast_passes_const)]
|
||||
pub cspan: Span,
|
||||
#[label(ast_passes_async)]
|
||||
pub aspan: Span,
|
||||
pub const_span: Span,
|
||||
#[label(ast_passes_coroutine)]
|
||||
pub coroutine_span: Span,
|
||||
#[label]
|
||||
pub span: Span,
|
||||
pub coroutine_kind: &'static str,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue