11//! The `Visitor` responsible for actually checking a `mir::Body` for invalid operations.
22
3- use rustc_errors:: { struct_span_err, Applicability , Diagnostic } ;
3+ use rustc_errors:: { struct_span_err, Applicability , Diagnostic , ErrorReported } ;
44use rustc_hir:: def_id:: DefId ;
55use rustc_hir:: { self as hir, HirId , LangItem } ;
66use rustc_infer:: infer:: TyCtxtInferExt ;
@@ -123,7 +123,11 @@ impl Qualifs<'mir, 'tcx> {
123123 has_mut_interior. get ( ) . contains ( local) || self . indirectly_mutable ( ccx, local, location)
124124 }
125125
126- fn in_return_place ( & mut self , ccx : & ' mir ConstCx < ' mir , ' tcx > ) -> ConstQualifs {
126+ fn in_return_place (
127+ & mut self ,
128+ ccx : & ' mir ConstCx < ' mir , ' tcx > ,
129+ error_occured : Option < ErrorReported > ,
130+ ) -> ConstQualifs {
127131 // Find the `Return` terminator if one exists.
128132 //
129133 // If no `Return` terminator exists, this MIR is divergent. Just return the conservative
@@ -139,7 +143,7 @@ impl Qualifs<'mir, 'tcx> {
139143 . map ( |( bb, _) | bb) ;
140144
141145 let return_block = match return_block {
142- None => return qualifs:: in_any_value_of_ty ( ccx, ccx. body . return_ty ( ) ) ,
146+ None => return qualifs:: in_any_value_of_ty ( ccx, ccx. body . return_ty ( ) , error_occured ) ,
143147 Some ( bb) => bb,
144148 } ;
145149
@@ -170,6 +174,7 @@ impl Qualifs<'mir, 'tcx> {
170174 needs_drop : self . needs_drop ( ccx, RETURN_PLACE , return_loc) ,
171175 has_mut_interior : self . has_mut_interior ( ccx, RETURN_PLACE , return_loc) ,
172176 custom_eq,
177+ error_occured,
173178 }
174179 }
175180}
@@ -181,7 +186,7 @@ pub struct Validator<'mir, 'tcx> {
181186 /// The span of the current statement.
182187 span : Span ,
183188
184- error_emitted : bool ,
189+ error_emitted : Option < ErrorReported > ,
185190 secondary_errors : Vec < Diagnostic > ,
186191}
187192
@@ -199,7 +204,7 @@ impl Validator<'mir, 'tcx> {
199204 span : ccx. body . span ,
200205 ccx,
201206 qualifs : Default :: default ( ) ,
202- error_emitted : false ,
207+ error_emitted : None ,
203208 secondary_errors : Vec :: new ( ) ,
204209 }
205210 }
@@ -266,7 +271,7 @@ impl Validator<'mir, 'tcx> {
266271 // If we got through const-checking without emitting any "primary" errors, emit any
267272 // "secondary" errors if they occurred.
268273 let secondary_errors = mem:: take ( & mut self . secondary_errors ) ;
269- if ! self . error_emitted {
274+ if self . error_emitted . is_none ( ) {
270275 for error in secondary_errors {
271276 self . tcx . sess . diagnostic ( ) . emit_diagnostic ( & error) ;
272277 }
@@ -276,7 +281,7 @@ impl Validator<'mir, 'tcx> {
276281 }
277282
278283 pub fn qualifs_in_return_place ( & mut self ) -> ConstQualifs {
279- self . qualifs . in_return_place ( self . ccx )
284+ self . qualifs . in_return_place ( self . ccx , self . error_emitted )
280285 }
281286
282287 /// Emits an error if an expression cannot be evaluated in the current context.
@@ -318,7 +323,7 @@ impl Validator<'mir, 'tcx> {
318323
319324 match op. importance ( ) {
320325 ops:: DiagnosticImportance :: Primary => {
321- self . error_emitted = true ;
326+ self . error_emitted = Some ( ErrorReported ) ;
322327 err. emit ( ) ;
323328 }
324329
0 commit comments