1
1
//! Concrete error types for all operations which may be invalid in a certain const context.
2
2
3
3
use hir:: def_id:: LocalDefId ;
4
- use rustc_errors:: { struct_span_err, Applicability , DiagnosticBuilder , ErrorGuaranteed } ;
4
+ use rustc_errors:: {
5
+ error_code, struct_span_err, Applicability , DiagnosticBuilder , ErrorGuaranteed ,
6
+ } ;
5
7
use rustc_hir as hir;
6
8
use rustc_hir:: def_id:: DefId ;
7
9
use rustc_infer:: infer:: TyCtxtInferExt ;
@@ -20,7 +22,7 @@ use rustc_span::{BytePos, Pos, Span, Symbol};
20
22
use rustc_trait_selection:: traits:: SelectionContext ;
21
23
22
24
use super :: ConstCx ;
23
- use crate :: errors:: NonConstOpErr ;
25
+ use crate :: errors:: { NonConstOpErr , StaticAccessErr } ;
24
26
use crate :: util:: { call_kind, CallDesugaringKind , CallKind } ;
25
27
26
28
#[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
@@ -731,24 +733,11 @@ impl<'tcx> NonConstOp<'tcx> for StaticAccess {
731
733
ccx : & ConstCx < ' _ , ' tcx > ,
732
734
span : Span ,
733
735
) -> DiagnosticBuilder < ' tcx , ErrorGuaranteed > {
734
- let mut err = struct_span_err ! (
735
- ccx. tcx. sess,
736
+ ccx. tcx . sess . create_err ( StaticAccessErr {
736
737
span,
737
- E0013 ,
738
- "{}s cannot refer to statics" ,
739
- ccx. const_kind( )
740
- ) ;
741
- err. help (
742
- "consider extracting the value of the `static` to a `const`, and referring to that" ,
743
- ) ;
744
- if ccx. tcx . sess . teach ( & err. get_code ( ) . unwrap ( ) ) {
745
- err. note (
746
- "`static` and `const` variables can refer to other `const` variables. \
747
- A `const` variable, however, cannot refer to a `static` variable.",
748
- ) ;
749
- err. help ( "To fix this, the value can be extracted to a `const` and then used." ) ;
750
- }
751
- err
738
+ kind : ccx. const_kind ( ) ,
739
+ teach : ccx. tcx . sess . teach ( & error_code ! ( E0013 ) ) . then_some ( ( ) ) ,
740
+ } )
752
741
}
753
742
}
754
743
0 commit comments