@@ -33,7 +33,7 @@ use rustc_middle::middle::stability;
33
33
use rustc_middle:: ty:: layout:: { LayoutError , LayoutOfHelpers , TyAndLayout } ;
34
34
use rustc_middle:: ty:: print:: with_no_trimmed_paths;
35
35
use rustc_middle:: ty:: { self , print:: Printer , subst:: GenericArg , RegisteredTools , Ty , TyCtxt } ;
36
- use rustc_session:: lint:: BuiltinLintDiagnostics ;
36
+ use rustc_session:: lint:: { BuiltinLintDiagnostics , LintExpectationId } ;
37
37
use rustc_session:: lint:: { FutureIncompatibleInfo , Level , Lint , LintBuffer , LintId } ;
38
38
use rustc_session:: Session ;
39
39
use rustc_span:: lev_distance:: find_best_match_for_name;
@@ -887,6 +887,29 @@ pub trait LintContext: Sized {
887
887
) {
888
888
self . lookup ( lint, None as Option < Span > , decorate) ;
889
889
}
890
+
891
+ /// This returns the lint level for the given lint at the current location.
892
+ fn get_lint_level ( & self , lint : & ' static Lint ) -> Level ;
893
+
894
+ /// This function can be used to manually fulfill an expectation. This can
895
+ /// be used for lints which contain several spans, and should be suppressed,
896
+ /// if either location was marked with an expectation.
897
+ ///
898
+ /// Note that this function should only be called for [`LintExpectationId`]s
899
+ /// retrieved from the current lint pass. Buffered or manually created ids can
900
+ /// cause ICEs.
901
+ fn fulfill_expectation ( & self , expectation : LintExpectationId ) {
902
+ // We need to make sure that submitted expectation ids are correctly fulfilled suppressed
903
+ // and stored between compilation sessions. To not manually do these steps, we simply create
904
+ // a dummy diagnostic and emit is as usual, which will be suppressed and stored like a normal
905
+ // expected lint diagnostic.
906
+ self . sess ( )
907
+ . struct_expect (
908
+ "this is a dummy diagnostic, to submit and store an expectation" ,
909
+ expectation,
910
+ )
911
+ . emit ( ) ;
912
+ }
890
913
}
891
914
892
915
impl < ' a > EarlyContext < ' a > {
@@ -934,6 +957,10 @@ impl LintContext for LateContext<'_> {
934
957
None => self . tcx . struct_lint_node ( lint, hir_id, decorate) ,
935
958
}
936
959
}
960
+
961
+ fn get_lint_level ( & self , lint : & ' static Lint ) -> Level {
962
+ self . tcx . lint_level_at_node ( lint, self . last_node_with_lint_attrs ) . 0
963
+ }
937
964
}
938
965
939
966
impl LintContext for EarlyContext < ' _ > {
@@ -956,6 +983,10 @@ impl LintContext for EarlyContext<'_> {
956
983
) {
957
984
self . builder . struct_lint ( lint, span. map ( |s| s. into ( ) ) , decorate)
958
985
}
986
+
987
+ fn get_lint_level ( & self , lint : & ' static Lint ) -> Level {
988
+ self . builder . lint_level ( lint) . 0
989
+ }
959
990
}
960
991
961
992
impl < ' tcx > LateContext < ' tcx > {
0 commit comments