@@ -2,7 +2,6 @@ use std::error::Error;
22use std:: fmt;
33
44use rustc_errors:: Diagnostic ;
5- use rustc_hir as hir;
65use rustc_middle:: mir:: AssertKind ;
76use rustc_middle:: ty:: { layout:: LayoutError , query:: TyCtxtAt , ConstInt } ;
87use rustc_span:: { Span , Symbol } ;
@@ -23,11 +22,7 @@ pub enum ConstEvalErrKind {
2322 Abort ( String ) ,
2423}
2524
26- impl MachineStopType for ConstEvalErrKind {
27- fn is_hard_err ( & self ) -> bool {
28- matches ! ( self , Self :: Panic { .. } )
29- }
30- }
25+ impl MachineStopType for ConstEvalErrKind { }
3126
3227// The errors become `MachineStop` with plain strings when being raised.
3328// `ConstEvalErr` (in `librustc_middle/mir/interpret/error.rs`) knows to
@@ -87,48 +82,10 @@ impl<'tcx> ConstEvalErr<'tcx> {
8782 ConstEvalErr { error : error. into_kind ( ) , stacktrace, span }
8883 }
8984
90- pub fn struct_error (
91- & self ,
92- tcx : TyCtxtAt < ' tcx > ,
93- message : & str ,
94- decorate : impl FnOnce ( & mut Diagnostic ) ,
95- ) -> ErrorHandled {
96- self . struct_generic ( tcx, message, decorate, None )
97- }
98-
9985 pub fn report_as_error ( & self , tcx : TyCtxtAt < ' tcx > , message : & str ) -> ErrorHandled {
10086 self . struct_error ( tcx, message, |_| { } )
10187 }
10288
103- pub fn report_as_lint (
104- & self ,
105- tcx : TyCtxtAt < ' tcx > ,
106- message : & str ,
107- lint_root : hir:: HirId ,
108- span : Option < Span > ,
109- ) -> ErrorHandled {
110- self . struct_generic (
111- tcx,
112- message,
113- |lint : & mut Diagnostic | {
114- // Apply the span.
115- if let Some ( span) = span {
116- let primary_spans = lint. span . primary_spans ( ) . to_vec ( ) ;
117- // point at the actual error as the primary span
118- lint. replace_span_with ( span) ;
119- // point to the `const` statement as a secondary span
120- // they don't have any label
121- for sp in primary_spans {
122- if sp != span {
123- lint. span_label ( sp, "" ) ;
124- }
125- }
126- }
127- } ,
128- Some ( lint_root) ,
129- )
130- }
131-
13289 /// Create a diagnostic for this const eval error.
13390 ///
13491 /// Sets the message passed in via `message` and adds span labels with detailed error
@@ -137,13 +94,12 @@ impl<'tcx> ConstEvalErr<'tcx> {
13794 ///
13895 /// If `lint_root.is_some()` report it as a lint, else report it as a hard error.
13996 /// (Except that for some errors, we ignore all that -- see `must_error` below.)
140- #[ instrument( skip( self , tcx, decorate, lint_root ) , level = "debug" ) ]
141- fn struct_generic (
97+ #[ instrument( skip( self , tcx, decorate) , level = "debug" ) ]
98+ pub fn struct_error (
14299 & self ,
143100 tcx : TyCtxtAt < ' tcx > ,
144101 message : & str ,
145102 decorate : impl FnOnce ( & mut Diagnostic ) ,
146- lint_root : Option < hir:: HirId > ,
147103 ) -> ErrorHandled {
148104 let finish = |err : & mut Diagnostic , span_msg : Option < String > | {
149105 trace ! ( "reporting const eval failure at {:?}" , self . span) ;
@@ -224,27 +180,9 @@ impl<'tcx> ConstEvalErr<'tcx> {
224180
225181 let err_msg = self . error . to_string ( ) ;
226182
227- // Regular case - emit a lint.
228- if let Some ( lint_root) = lint_root {
229- // Report as lint.
230- let hir_id =
231- self . stacktrace . iter ( ) . rev ( ) . find_map ( |frame| frame. lint_root ) . unwrap_or ( lint_root) ;
232- tcx. struct_span_lint_hir (
233- rustc_session:: lint:: builtin:: CONST_ERR ,
234- hir_id,
235- tcx. span ,
236- message,
237- |lint| {
238- finish ( lint, Some ( err_msg) ) ;
239- lint
240- } ,
241- ) ;
242- ErrorHandled :: Linted
243- } else {
244- // Report as hard error.
245- let mut err = struct_error ( tcx, message) ;
246- finish ( & mut err, Some ( err_msg) ) ;
247- ErrorHandled :: Reported ( err. emit ( ) )
248- }
183+ // Report as hard error.
184+ let mut err = struct_error ( tcx, message) ;
185+ finish ( & mut err, Some ( err_msg) ) ;
186+ ErrorHandled :: Reported ( err. emit ( ) )
249187 }
250188}
0 commit comments