@@ -7,6 +7,7 @@ use rustc_ast::ptr::P;
77use rustc_ast:: visit:: AssocCtxt ;
88use rustc_ast:: * ;
99use rustc_data_structures:: sorted_map:: SortedMap ;
10+ use rustc_errors:: ErrorGuaranteed ;
1011use rustc_hir as hir;
1112use rustc_hir:: def:: { DefKind , Res } ;
1213use rustc_hir:: def_id:: { LocalDefId , CRATE_DEF_ID } ;
@@ -284,7 +285,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
284285 . alloc_from_iter ( fm. items . iter ( ) . map ( |x| self . lower_foreign_item_ref ( x) ) ) ,
285286 } ,
286287 ItemKind :: GlobalAsm ( asm) => hir:: ItemKind :: GlobalAsm ( self . lower_inline_asm ( span, asm) ) ,
287- ItemKind :: TyAlias ( box TyAlias { generics, where_clauses, ty : Some ( ty ) , .. } ) => {
288+ ItemKind :: TyAlias ( box TyAlias { generics, where_clauses, ty, .. } ) => {
288289 // We lower
289290 //
290291 // type Foo = impl Trait
@@ -299,18 +300,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
299300 & generics,
300301 id,
301302 & ImplTraitContext :: Disallowed ( ImplTraitPosition :: Generic ) ,
302- |this| this. lower_ty ( ty, & ImplTraitContext :: TypeAliasesOpaqueTy ) ,
303- ) ;
304- hir:: ItemKind :: TyAlias ( ty, generics)
305- }
306- ItemKind :: TyAlias ( box TyAlias { generics, where_clauses, ty : None , .. } ) => {
307- let mut generics = generics. clone ( ) ;
308- add_ty_alias_where_clause ( & mut generics, * where_clauses, true ) ;
309- let ( generics, ty) = self . lower_generics (
310- & generics,
311- id,
312- & ImplTraitContext :: Disallowed ( ImplTraitPosition :: Generic ) ,
313- |this| this. arena . alloc ( this. ty ( span, hir:: TyKind :: Err ) ) ,
303+ |this| match ty {
304+ None => {
305+ let guar = this. tcx . sess . delay_span_bug (
306+ span,
307+ "expected to lower type alias type, but it was missing" ,
308+ ) ;
309+ this. arena . alloc ( this. ty ( span, hir:: TyKind :: Err ( guar) ) )
310+ }
311+ Some ( ty) => this. lower_ty ( ty, & ImplTraitContext :: TypeAliasesOpaqueTy ) ,
312+ } ,
314313 ) ;
315314 hir:: ItemKind :: TyAlias ( ty, generics)
316315 }
@@ -798,8 +797,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
798797 }
799798
800799 /// Construct `ExprKind::Err` for the given `span`.
801- pub ( crate ) fn expr_err ( & mut self , span : Span ) -> hir:: Expr < ' hir > {
802- self . expr ( span, hir:: ExprKind :: Err )
800+ pub ( crate ) fn expr_err ( & mut self , span : Span , guar : ErrorGuaranteed ) -> hir:: Expr < ' hir > {
801+ self . expr ( span, hir:: ExprKind :: Err ( guar ) )
803802 }
804803
805804 fn lower_impl_item ( & mut self , i : & AssocItem ) -> & ' hir hir:: ImplItem < ' hir > {
@@ -847,7 +846,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
847846 & ImplTraitContext :: Disallowed ( ImplTraitPosition :: Generic ) ,
848847 |this| match ty {
849848 None => {
850- let ty = this. arena . alloc ( this. ty ( i. span , hir:: TyKind :: Err ) ) ;
849+ let guar = this. tcx . sess . delay_span_bug (
850+ i. span ,
851+ "expected to lower associated type, but it was missing" ,
852+ ) ;
853+ let ty = this. arena . alloc ( this. ty ( i. span , hir:: TyKind :: Err ( guar) ) ) ;
851854 hir:: ImplItemKind :: Type ( ty)
852855 }
853856 Some ( ty) => {
@@ -973,7 +976,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
973976 fn lower_block_expr_opt ( & mut self , span : Span , block : Option < & Block > ) -> hir:: Expr < ' hir > {
974977 match block {
975978 Some ( block) => self . lower_block_expr ( block) ,
976- None => self . expr_err ( span) ,
979+ None => self . expr_err ( span, self . tcx . sess . delay_span_bug ( span , "no block" ) ) ,
977980 }
978981 }
979982
@@ -983,7 +986,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
983986 & [ ] ,
984987 match expr {
985988 Some ( expr) => this. lower_expr_mut ( expr) ,
986- None => this. expr_err ( span) ,
989+ None => this. expr_err ( span, this . tcx . sess . delay_span_bug ( span , "no block" ) ) ,
987990 } ,
988991 )
989992 } )
0 commit comments