| 
1 | 1 | use crate::ImplTraitPosition;  | 
2 | 2 | 
 
  | 
3 |  | -use super::errors::{GenericTypeWithParentheses, UseAngleBrackets};  | 
 | 3 | +use super::errors::{  | 
 | 4 | +    AsyncBoundNotOnTrait, AsyncBoundOnlyForFnTraits, GenericTypeWithParentheses, UseAngleBrackets,  | 
 | 5 | +};  | 
4 | 6 | use super::ResolverAstLoweringExt;  | 
5 | 7 | use super::{GenericArgsCtor, LifetimeRes, ParenthesizedGenericArgs};  | 
6 | 8 | use super::{ImplTraitContext, LoweringContext, ParamMode};  | 
@@ -42,15 +44,24 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {  | 
42 | 44 |         // When we have an `async` kw on a bound, map the trait it resolves to.  | 
43 | 45 |         let mut bound_modifier_allowed_features = None;  | 
44 | 46 |         if let Some(TraitBoundModifiers { asyncness: BoundAsyncness::Async(_), .. }) = modifiers {  | 
45 |  | -            if let Res::Def(DefKind::Trait, def_id) = res {  | 
46 |  | -                if let Some((async_def_id, features)) = self.map_trait_to_async_trait(def_id) {  | 
47 |  | -                    res = Res::Def(DefKind::Trait, async_def_id);  | 
48 |  | -                    bound_modifier_allowed_features = Some(features);  | 
49 |  | -                } else {  | 
50 |  | -                    panic!();  | 
 | 47 | +            match res {  | 
 | 48 | +                Res::Def(DefKind::Trait, def_id) => {  | 
 | 49 | +                    if let Some((async_def_id, features)) = self.map_trait_to_async_trait(def_id) {  | 
 | 50 | +                        res = Res::Def(DefKind::Trait, async_def_id);  | 
 | 51 | +                        bound_modifier_allowed_features = Some(features);  | 
 | 52 | +                    } else {  | 
 | 53 | +                        self.dcx().emit_err(AsyncBoundOnlyForFnTraits { span: p.span });  | 
 | 54 | +                    }  | 
 | 55 | +                }  | 
 | 56 | +                Res::Err => {  | 
 | 57 | +                    // No additional error.  | 
 | 58 | +                }  | 
 | 59 | +                _ => {  | 
 | 60 | +                    // This error isn't actually emitted AFAICT, but it's best to keep  | 
 | 61 | +                    // it around in case the resolver doesn't always check the defkind  | 
 | 62 | +                    // of an item or something.  | 
 | 63 | +                    self.dcx().emit_err(AsyncBoundNotOnTrait { span: p.span, descr: res.descr() });  | 
51 | 64 |                 }  | 
52 |  | -            } else {  | 
53 |  | -                panic!();  | 
54 | 65 |             }  | 
55 | 66 |         }  | 
56 | 67 | 
 
  | 
 | 
0 commit comments