Skip to content

Commit 9e0a86b

Browse files
committed
Add missing #[rustc_lint_diagnostics] attributes.
These are generally next to other methods that do have the attribute. Requires adding some missing `#[allow(rustc::diagnostic_outside_of_impl)]` markers. The attribute added to `Diag::span` is guarded by `bootstrap` so that tests/ui-fulldeps/internal-lints/diagnostics.rs passes. Otherwise when doing stage 1 testing the old linter is used, and it can't handle `rustc_lint_diagnostics` attributes on functions that lack a message argument.
1 parent e023837 commit 9e0a86b

File tree

6 files changed

+45
-3
lines changed

6 files changed

+45
-3
lines changed

compiler/rustc_borrowck/src/diagnostics/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
7676
/// LL | for (key, value) in dict {
7777
/// | ^^^^
7878
/// ```
79+
#[allow(rustc::diagnostic_outside_of_impl)] // FIXME
7980
pub(super) fn add_moved_or_invoked_closure_note(
8081
&self,
8182
location: Location,
@@ -585,6 +586,7 @@ impl UseSpans<'_> {
585586
}
586587

587588
/// Add a span label to the arguments of the closure, if it exists.
589+
#[allow(rustc::diagnostic_outside_of_impl)]
588590
pub(super) fn args_subdiag(
589591
self,
590592
dcx: &rustc_errors::DiagCtxt,
@@ -598,6 +600,7 @@ impl UseSpans<'_> {
598600

599601
/// Add a span label to the use of the captured variable, if it exists.
600602
/// only adds label to the `path_span`
603+
#[allow(rustc::diagnostic_outside_of_impl)]
601604
pub(super) fn var_path_only_subdiag(
602605
self,
603606
dcx: &rustc_errors::DiagCtxt,
@@ -635,6 +638,7 @@ impl UseSpans<'_> {
635638
}
636639

637640
/// Add a subdiagnostic to the use of the captured variable, if it exists.
641+
#[allow(rustc::diagnostic_outside_of_impl)]
638642
pub(super) fn var_subdiag(
639643
self,
640644
dcx: &rustc_errors::DiagCtxt,
@@ -1008,6 +1012,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10081012
self.borrow_spans(span, borrow.reserve_location)
10091013
}
10101014

1015+
#[allow(rustc::diagnostic_outside_of_impl)]
10111016
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
10121017
fn explain_captures(
10131018
&mut self,

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
201201
// For generic associated types (GATs) which implied 'static requirement
202202
// from higher-ranked trait bounds (HRTB). Try to locate span of the trait
203203
// and the span which bounded to the trait for adding 'static lifetime suggestion
204+
#[allow(rustc::diagnostic_outside_of_impl)]
204205
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
205206
fn suggest_static_lifetime_for_gat_from_hrtb(
206207
&self,
@@ -255,9 +256,6 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
255256

256257
hrtb_bounds.iter().for_each(|bound| {
257258
let Trait(PolyTraitRef { trait_ref, span: trait_span, .. }, _) = bound else { return; };
258-
// FIXME: make this translatable
259-
#[allow(rustc::diagnostic_outside_of_impl)]
260-
#[allow(rustc::untranslatable_diagnostic)]
261259
diag.span_note(
262260
*trait_span,
263261
"due to current limitations in the borrow checker, this implies a `'static` lifetime"
@@ -581,6 +579,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
581579
/// executing...
582580
/// = note: ...therefore, returned references to captured variables will escape the closure
583581
/// ```
582+
#[allow(rustc::diagnostic_outside_of_impl)] // FIXME
584583
fn report_fnmut_error(
585584
&self,
586585
errci: &ErrorConstraintInfo<'tcx>,
@@ -762,6 +761,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
762761
/// | ^^^^^^^^^^^^^^ function was supposed to return data with lifetime `'a` but it
763762
/// | is returning data with lifetime `'b`
764763
/// ```
764+
#[allow(rustc::diagnostic_outside_of_impl)] // FIXME
765765
fn report_general_error(&self, errci: &ErrorConstraintInfo<'tcx>) -> Diag<'tcx> {
766766
let ErrorConstraintInfo {
767767
fr,
@@ -823,6 +823,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
823823
/// LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> + 'a {
824824
/// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
825825
/// ```
826+
#[allow(rustc::diagnostic_outside_of_impl)]
826827
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
827828
fn add_static_impl_trait_suggestion(
828829
&self,
@@ -974,6 +975,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
974975
self.suggest_constrain_dyn_trait_in_impl(diag, &visitor.0, ident, self_ty);
975976
}
976977

978+
#[allow(rustc::diagnostic_outside_of_impl)]
977979
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
978980
#[instrument(skip(self, err), level = "debug")]
979981
fn suggest_constrain_dyn_trait_in_impl(
@@ -1037,6 +1039,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
10371039
suggest_adding_lifetime_params(self.infcx.tcx, sub, ty_sup, ty_sub, diag);
10381040
}
10391041

1042+
#[allow(rustc::diagnostic_outside_of_impl)]
10401043
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
10411044
fn suggest_move_on_borrowing_closure(&self, diag: &mut Diag<'_>) {
10421045
let map = self.infcx.tcx.hir();

compiler/rustc_errors/src/diagnostic.rs

+31
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
580580
///
581581
/// In the meantime, though, callsites are required to deal with the "bug"
582582
/// locally in whichever way makes the most sense.
583+
#[rustc_lint_diagnostics]
583584
#[track_caller]
584585
pub fn downgrade_to_delayed_bug(&mut self) {
585586
assert!(
@@ -613,13 +614,15 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
613614
with_fn! { with_span_labels,
614615
/// Labels all the given spans with the provided label.
615616
/// See [`Self::span_label()`] for more information.
617+
#[rustc_lint_diagnostics]
616618
pub fn span_labels(&mut self, spans: impl IntoIterator<Item = Span>, label: &str) -> &mut Self {
617619
for span in spans {
618620
self.span_label(span, label.to_string());
619621
}
620622
self
621623
} }
622624

625+
#[rustc_lint_diagnostics]
623626
pub fn replace_span_with(&mut self, after: Span, keep_label: bool) -> &mut Self {
624627
let before = self.span.clone();
625628
self.span(after);
@@ -635,6 +638,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
635638
self
636639
}
637640

641+
#[rustc_lint_diagnostics]
638642
pub fn note_expected_found(
639643
&mut self,
640644
expected_label: &dyn fmt::Display,
@@ -645,6 +649,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
645649
self.note_expected_found_extra(expected_label, expected, found_label, found, &"", &"")
646650
}
647651

652+
#[rustc_lint_diagnostics]
648653
pub fn note_expected_found_extra(
649654
&mut self,
650655
expected_label: &dyn fmt::Display,
@@ -687,6 +692,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
687692
self
688693
}
689694

695+
#[rustc_lint_diagnostics]
690696
pub fn note_trait_signature(&mut self, name: Symbol, signature: String) -> &mut Self {
691697
self.highlighted_note(vec![
692698
StringPart::normal(format!("`{name}` from trait: `")),
@@ -704,12 +710,14 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
704710
self
705711
} }
706712

713+
#[rustc_lint_diagnostics]
707714
fn highlighted_note(&mut self, msg: Vec<StringPart>) -> &mut Self {
708715
self.sub_with_highlights(Level::Note, msg, MultiSpan::new());
709716
self
710717
}
711718

712719
/// This is like [`Diag::note()`], but it's only printed once.
720+
#[rustc_lint_diagnostics]
713721
pub fn note_once(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self {
714722
self.sub(Level::OnceNote, msg, MultiSpan::new());
715723
self
@@ -730,6 +738,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
730738

731739
/// Prints the span with a note above it.
732740
/// This is like [`Diag::note_once()`], but it gets its own span.
741+
#[rustc_lint_diagnostics]
733742
pub fn span_note_once<S: Into<MultiSpan>>(
734743
&mut self,
735744
sp: S,
@@ -768,12 +777,14 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
768777
} }
769778

770779
/// This is like [`Diag::help()`], but it's only printed once.
780+
#[rustc_lint_diagnostics]
771781
pub fn help_once(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self {
772782
self.sub(Level::OnceHelp, msg, MultiSpan::new());
773783
self
774784
}
775785

776786
/// Add a help message attached to this diagnostic with a customizable highlighted message.
787+
#[rustc_lint_diagnostics]
777788
pub fn highlighted_help(&mut self, msg: Vec<StringPart>) -> &mut Self {
778789
self.sub_with_highlights(Level::Help, msg, MultiSpan::new());
779790
self
@@ -794,12 +805,14 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
794805
/// Disallow attaching suggestions this diagnostic.
795806
/// Any suggestions attached e.g. with the `span_suggestion_*` methods
796807
/// (before and after the call to `disable_suggestions`) will be ignored.
808+
#[rustc_lint_diagnostics]
797809
pub fn disable_suggestions(&mut self) -> &mut Self {
798810
self.suggestions = Err(SuggestionsDisabled);
799811
self
800812
}
801813

802814
/// Helper for pushing to `self.suggestions`, if available (not disable).
815+
#[rustc_lint_diagnostics]
803816
fn push_suggestion(&mut self, suggestion: CodeSuggestion) {
804817
for subst in &suggestion.substitutions {
805818
for part in &subst.parts {
@@ -820,6 +833,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
820833
with_fn! { with_multipart_suggestion,
821834
/// Show a suggestion that has multiple parts to it.
822835
/// In other words, multiple changes need to be applied as part of this suggestion.
836+
#[rustc_lint_diagnostics]
823837
pub fn multipart_suggestion(
824838
&mut self,
825839
msg: impl Into<SubdiagnosticMessage>,
@@ -836,6 +850,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
836850

837851
/// Show a suggestion that has multiple parts to it, always as it's own subdiagnostic.
838852
/// In other words, multiple changes need to be applied as part of this suggestion.
853+
#[rustc_lint_diagnostics]
839854
pub fn multipart_suggestion_verbose(
840855
&mut self,
841856
msg: impl Into<SubdiagnosticMessage>,
@@ -851,6 +866,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
851866
}
852867

853868
/// [`Diag::multipart_suggestion()`] but you can set the [`SuggestionStyle`].
869+
#[rustc_lint_diagnostics]
854870
pub fn multipart_suggestion_with_style(
855871
&mut self,
856872
msg: impl Into<SubdiagnosticMessage>,
@@ -893,6 +909,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
893909
/// be from the message, showing the span label inline would be visually unpleasant
894910
/// (marginally overlapping spans or multiline spans) and showing the snippet window wouldn't
895911
/// improve understandability.
912+
#[rustc_lint_diagnostics]
896913
pub fn tool_only_multipart_suggestion(
897914
&mut self,
898915
msg: impl Into<SubdiagnosticMessage>,
@@ -925,6 +942,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
925942
/// * may contain a name of a function, variable, or type, but not whole expressions
926943
///
927944
/// See `CodeSuggestion` for more information.
945+
#[rustc_lint_diagnostics]
928946
pub fn span_suggestion(
929947
&mut self,
930948
sp: Span,
@@ -943,6 +961,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
943961
} }
944962

945963
/// [`Diag::span_suggestion()`] but you can set the [`SuggestionStyle`].
964+
#[rustc_lint_diagnostics]
946965
pub fn span_suggestion_with_style(
947966
&mut self,
948967
sp: Span,
@@ -968,6 +987,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
968987

969988
with_fn! { with_span_suggestion_verbose,
970989
/// Always show the suggested change.
990+
#[rustc_lint_diagnostics]
971991
pub fn span_suggestion_verbose(
972992
&mut self,
973993
sp: Span,
@@ -988,6 +1008,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
9881008
with_fn! { with_span_suggestions,
9891009
/// Prints out a message with multiple suggested edits of the code.
9901010
/// See also [`Diag::span_suggestion()`].
1011+
#[rustc_lint_diagnostics]
9911012
pub fn span_suggestions(
9921013
&mut self,
9931014
sp: Span,
@@ -1004,6 +1025,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
10041025
)
10051026
} }
10061027

1028+
#[rustc_lint_diagnostics]
10071029
pub fn span_suggestions_with_style(
10081030
&mut self,
10091031
sp: Span,
@@ -1034,6 +1056,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
10341056
/// Prints out a message with multiple suggested edits of the code, where each edit consists of
10351057
/// multiple parts.
10361058
/// See also [`Diag::multipart_suggestion()`].
1059+
#[rustc_lint_diagnostics]
10371060
pub fn multipart_suggestions(
10381061
&mut self,
10391062
msg: impl Into<SubdiagnosticMessage>,
@@ -1080,6 +1103,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
10801103
/// inline, it will only show the message and not the suggestion.
10811104
///
10821105
/// See `CodeSuggestion` for more information.
1106+
#[rustc_lint_diagnostics]
10831107
pub fn span_suggestion_short(
10841108
&mut self,
10851109
sp: Span,
@@ -1103,6 +1127,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
11031127
/// be from the message, showing the span label inline would be visually unpleasant
11041128
/// (marginally overlapping spans or multiline spans) and showing the snippet window wouldn't
11051129
/// improve understandability.
1130+
#[rustc_lint_diagnostics]
11061131
pub fn span_suggestion_hidden(
11071132
&mut self,
11081133
sp: Span,
@@ -1147,6 +1172,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
11471172
/// [rustc_macros::Subdiagnostic]). Performs eager translation of any translatable messages
11481173
/// used in the subdiagnostic, so suitable for use with repeated messages (i.e. re-use of
11491174
/// interpolated variables).
1175+
#[rustc_lint_diagnostics]
11501176
pub fn subdiagnostic(
11511177
&mut self,
11521178
dcx: &crate::DiagCtxt,
@@ -1162,6 +1188,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
11621188

11631189
with_fn! { with_span,
11641190
/// Add a span.
1191+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
11651192
pub fn span(&mut self, sp: impl Into<MultiSpan>) -> &mut Self {
11661193
self.span = sp.into();
11671194
if let Some(span) = self.span.primary_span() {
@@ -1170,27 +1197,31 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
11701197
self
11711198
} }
11721199

1200+
#[rustc_lint_diagnostics]
11731201
pub fn is_lint(&mut self, name: String, has_future_breakage: bool) -> &mut Self {
11741202
self.is_lint = Some(IsLint { name, has_future_breakage });
11751203
self
11761204
}
11771205

11781206
with_fn! { with_code,
11791207
/// Add an error code.
1208+
#[rustc_lint_diagnostics]
11801209
pub fn code(&mut self, code: ErrCode) -> &mut Self {
11811210
self.code = Some(code);
11821211
self
11831212
} }
11841213

11851214
with_fn! { with_primary_message,
11861215
/// Add a primary message.
1216+
#[rustc_lint_diagnostics]
11871217
pub fn primary_message(&mut self, msg: impl Into<DiagnosticMessage>) -> &mut Self {
11881218
self.messages[0] = (msg.into(), Style::NoStyle);
11891219
self
11901220
} }
11911221

11921222
with_fn! { with_arg,
11931223
/// Add an argument.
1224+
#[rustc_lint_diagnostics]
11941225
pub fn arg(
11951226
&mut self,
11961227
name: impl Into<DiagArgName>,

compiler/rustc_passes/src/check_attr.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2330,6 +2330,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
23302330

23312331
let hir_sig = tcx.hir().fn_sig_by_hir_id(hir_id);
23322332
if let Some(hir_sig) = hir_sig {
2333+
#[allow(rustc::diagnostic_outside_of_impl)] // FIXME
23332334
match terr {
23342335
TypeError::ArgumentMutability(idx) | TypeError::ArgumentSorts(_, idx) => {
23352336
if let Some(ty) = hir_sig.decl.inputs.get(idx) {

compiler/rustc_session/src/parse.rs

+1
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ pub fn add_feature_diagnostics<G: EmissionGuarantee>(
169169
/// This variant allows you to control whether it is a library or language feature.
170170
/// Almost always, you want to use this for a language feature. If so, prefer
171171
/// `add_feature_diagnostics`.
172+
#[allow(rustc::diagnostic_outside_of_impl)] // FIXME
172173
pub fn add_feature_diagnostics_for_issue<G: EmissionGuarantee>(
173174
err: &mut Diag<'_, G>,
174175
sess: &Session,

compiler/rustc_session/src/session.rs

+1
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ impl Session {
311311
) -> Diag<'a> {
312312
let mut err = self.dcx().create_err(err);
313313
if err.code.is_none() {
314+
#[allow(rustc::diagnostic_outside_of_impl)]
314315
err.code(E0658);
315316
}
316317
add_feature_diagnostics(&mut err, self, feature);

0 commit comments

Comments
 (0)