diff options
| author | Michael Goulet <michael@errs.io> | 2024-01-26 17:33:42 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2024-01-31 16:59:19 +0000 |
| commit | 3913c9a0cacf4bacb4ca1c6255271d54ec995f02 (patch) | |
| tree | e86c1e10d0db17e1ca359b3e4a7887eb04562394 /compiler/rustc_ast_lowering/src | |
| parent | 54db272cc972f232cc50a7c6dff30140f904738a (diff) | |
| download | rust-3913c9a0cacf4bacb4ca1c6255271d54ec995f02.tar.gz rust-3913c9a0cacf4bacb4ca1c6255271d54ec995f02.zip | |
Error on incorrect item kind in async bound
Diffstat (limited to 'compiler/rustc_ast_lowering/src')
| -rw-r--r-- | compiler/rustc_ast_lowering/src/errors.rs | 15 | ||||
| -rw-r--r-- | compiler/rustc_ast_lowering/src/path.rs | 29 |
2 files changed, 35 insertions, 9 deletions
diff --git a/compiler/rustc_ast_lowering/src/errors.rs b/compiler/rustc_ast_lowering/src/errors.rs index 51bb8a96fad..7658dfa5d5f 100644 --- a/compiler/rustc_ast_lowering/src/errors.rs +++ b/compiler/rustc_ast_lowering/src/errors.rs @@ -395,3 +395,18 @@ pub(crate) struct GenericParamDefaultInBinder { #[primary_span] pub span: Span, } + +#[derive(Diagnostic)] +#[diag(ast_lowering_async_bound_not_on_trait)] +pub(crate) struct AsyncBoundNotOnTrait { + #[primary_span] + pub span: Span, + pub descr: &'static str, +} + +#[derive(Diagnostic)] +#[diag(ast_lowering_async_bound_only_for_fn_traits)] +pub(crate) struct AsyncBoundOnlyForFnTraits { + #[primary_span] + pub span: Span, +} diff --git a/compiler/rustc_ast_lowering/src/path.rs b/compiler/rustc_ast_lowering/src/path.rs index b4f1d7ce8c2..b58ac5c3dae 100644 --- a/compiler/rustc_ast_lowering/src/path.rs +++ b/compiler/rustc_ast_lowering/src/path.rs @@ -1,6 +1,8 @@ use crate::ImplTraitPosition; -use super::errors::{GenericTypeWithParentheses, UseAngleBrackets}; +use super::errors::{ + AsyncBoundNotOnTrait, AsyncBoundOnlyForFnTraits, GenericTypeWithParentheses, UseAngleBrackets, +}; use super::ResolverAstLoweringExt; use super::{GenericArgsCtor, LifetimeRes, ParenthesizedGenericArgs}; use super::{ImplTraitContext, LoweringContext, ParamMode}; @@ -42,15 +44,24 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { // When we have an `async` kw on a bound, map the trait it resolves to. let mut bound_modifier_allowed_features = None; if let Some(TraitBoundModifiers { asyncness: BoundAsyncness::Async(_), .. }) = modifiers { - if let Res::Def(DefKind::Trait, def_id) = res { - if let Some((async_def_id, features)) = self.map_trait_to_async_trait(def_id) { - res = Res::Def(DefKind::Trait, async_def_id); - bound_modifier_allowed_features = Some(features); - } else { - panic!(); + match res { + Res::Def(DefKind::Trait, def_id) => { + if let Some((async_def_id, features)) = self.map_trait_to_async_trait(def_id) { + res = Res::Def(DefKind::Trait, async_def_id); + bound_modifier_allowed_features = Some(features); + } else { + self.dcx().emit_err(AsyncBoundOnlyForFnTraits { span: p.span }); + } + } + Res::Err => { + // No additional error. + } + _ => { + // This error isn't actually emitted AFAICT, but it's best to keep + // it around in case the resolver doesn't always check the defkind + // of an item or something. + self.dcx().emit_err(AsyncBoundNotOnTrait { span: p.span, descr: res.descr() }); } - } else { - panic!(); } } |
