@@ -146,13 +146,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
146146 debug ! ( "write_ty({:?}, {:?}) in fcx {}" , id, self . resolve_vars_if_possible( ty) , self . tag( ) ) ;
147147 let mut typeck = self . typeck_results . borrow_mut ( ) ;
148148 let mut node_ty = typeck. node_types_mut ( ) ;
149- if let Some ( ty) = node_ty. get ( id)
150- && ty. references_error ( )
151- {
152- return ;
153- }
154149
155- node_ty. insert ( id, ty) ;
150+ if let Some ( prev) = node_ty. insert ( id, ty) {
151+ if prev. references_error ( ) {
152+ node_ty. insert ( id, prev) ;
153+ } else if !ty. references_error ( ) {
154+ // Could change this to a bug, but there's lots of diagnostic code re-lowering
155+ // or re-typechecking nodes that were already typecked.
156+ // Lots of that diagnostics code relies on subtle effects of re-lowering, so we'll
157+ // let it keep doing that and just ensure that compilation won't succeed.
158+ self . dcx ( ) . span_delayed_bug (
159+ self . tcx . hir ( ) . span ( id) ,
160+ format ! ( "`{prev}` overridden by `{ty}` for {id:?} in {:?}" , self . body_id) ,
161+ ) ;
162+ }
163+ }
156164
157165 if let Err ( e) = ty. error_reported ( ) {
158166 self . set_tainted_by_errors ( e) ;
0 commit comments