@@ -7,6 +7,7 @@ use rustc_ast::ptr::P;
7
7
use rustc_ast:: visit:: AssocCtxt ;
8
8
use rustc_ast:: * ;
9
9
use rustc_data_structures:: sorted_map:: SortedMap ;
10
+ use rustc_errors:: ErrorGuaranteed ;
10
11
use rustc_hir as hir;
11
12
use rustc_hir:: def:: { DefKind , Res } ;
12
13
use rustc_hir:: def_id:: { LocalDefId , CRATE_DEF_ID } ;
@@ -284,7 +285,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
284
285
. alloc_from_iter ( fm. items . iter ( ) . map ( |x| self . lower_foreign_item_ref ( x) ) ) ,
285
286
} ,
286
287
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, .. } ) => {
288
289
// We lower
289
290
//
290
291
// type Foo = impl Trait
@@ -299,18 +300,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
299
300
& generics,
300
301
id,
301
302
& 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
+ } ,
314
313
) ;
315
314
hir:: ItemKind :: TyAlias ( ty, generics)
316
315
}
@@ -798,8 +797,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
798
797
}
799
798
800
799
/// 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 ) )
803
802
}
804
803
805
804
fn lower_impl_item ( & mut self , i : & AssocItem ) -> & ' hir hir:: ImplItem < ' hir > {
@@ -847,7 +846,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
847
846
& ImplTraitContext :: Disallowed ( ImplTraitPosition :: Generic ) ,
848
847
|this| match ty {
849
848
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) ) ) ;
851
854
hir:: ImplItemKind :: Type ( ty)
852
855
}
853
856
Some ( ty) => {
@@ -973,7 +976,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
973
976
fn lower_block_expr_opt ( & mut self , span : Span , block : Option < & Block > ) -> hir:: Expr < ' hir > {
974
977
match block {
975
978
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" ) ) ,
977
980
}
978
981
}
979
982
@@ -983,7 +986,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
983
986
& [ ] ,
984
987
match expr {
985
988
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" ) ) ,
987
990
} ,
988
991
)
989
992
} )
0 commit comments