@@ -33,7 +33,7 @@ use rustc_middle::middle::stability;
3333use rustc_middle:: ty:: layout:: { LayoutError , LayoutOfHelpers , TyAndLayout } ;
3434use rustc_middle:: ty:: print:: with_no_trimmed_paths;
3535use rustc_middle:: ty:: { self , print:: Printer , subst:: GenericArg , RegisteredTools , Ty , TyCtxt } ;
36- use rustc_session:: lint:: BuiltinLintDiagnostics ;
36+ use rustc_session:: lint:: { BuiltinLintDiagnostics , LintExpectationId } ;
3737use rustc_session:: lint:: { FutureIncompatibleInfo , Level , Lint , LintBuffer , LintId } ;
3838use rustc_session:: Session ;
3939use rustc_span:: lev_distance:: find_best_match_for_name;
@@ -887,6 +887,29 @@ pub trait LintContext: Sized {
887887 ) {
888888 self . lookup ( lint, None as Option < Span > , decorate) ;
889889 }
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+ }
890913}
891914
892915impl < ' a > EarlyContext < ' a > {
@@ -934,6 +957,10 @@ impl LintContext for LateContext<'_> {
934957 None => self . tcx . struct_lint_node ( lint, hir_id, decorate) ,
935958 }
936959 }
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+ }
937964}
938965
939966impl LintContext for EarlyContext < ' _ > {
@@ -956,6 +983,10 @@ impl LintContext for EarlyContext<'_> {
956983 ) {
957984 self . builder . struct_lint ( lint, span. map ( |s| s. into ( ) ) , decorate)
958985 }
986+
987+ fn get_lint_level ( & self , lint : & ' static Lint ) -> Level {
988+ self . builder . lint_level ( lint) . 0
989+ }
959990}
960991
961992impl < ' tcx > LateContext < ' tcx > {
0 commit comments