Skip to content

Commit 79fb0a9

Browse files
committed
Add missing #[rustc_lint_diagnostics] attributes.
Prior the previous commit, `#[rust_lint_diagnostics]` attributes could only be used on methods with an `impl Into<{D,Subd}iagnosticMessage>` parameter. But there are lots of other nearby diagnostic methods (e.g. `Diag::span`) that don't take such a parameter, which should have the attribute. This commit adds the missing attribute to these `Diag` methods. This requires adding some missing `#[allow(rustc::diagnostic_outside_of_impl)]` markers at call sites to these methods. Note: 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 c14998d commit 79fb0a9

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
@@ -599,6 +599,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
599599
///
600600
/// In the meantime, though, callsites are required to deal with the "bug"
601601
/// locally in whichever way makes the most sense.
602+
#[rustc_lint_diagnostics]
602603
#[track_caller]
603604
pub fn downgrade_to_delayed_bug(&mut self) {
604605
assert!(
@@ -632,13 +633,15 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
632633
with_fn! { with_span_labels,
633634
/// Labels all the given spans with the provided label.
634635
/// See [`Self::span_label()`] for more information.
636+
#[rustc_lint_diagnostics]
635637
pub fn span_labels(&mut self, spans: impl IntoIterator<Item = Span>, label: &str) -> &mut Self {
636638
for span in spans {
637639
self.span_label(span, label.to_string());
638640
}
639641
self
640642
} }
641643

644+
#[rustc_lint_diagnostics]
642645
pub fn replace_span_with(&mut self, after: Span, keep_label: bool) -> &mut Self {
643646
let before = self.span.clone();
644647
self.span(after);
@@ -654,6 +657,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
654657
self
655658
}
656659

660+
#[rustc_lint_diagnostics]
657661
pub fn note_expected_found(
658662
&mut self,
659663
expected_label: &dyn fmt::Display,
@@ -664,6 +668,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
664668
self.note_expected_found_extra(expected_label, expected, found_label, found, &"", &"")
665669
}
666670

671+
#[rustc_lint_diagnostics]
667672
pub fn note_expected_found_extra(
668673
&mut self,
669674
expected_label: &dyn fmt::Display,
@@ -706,6 +711,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
706711
self
707712
}
708713

714+
#[rustc_lint_diagnostics]
709715
pub fn note_trait_signature(&mut self, name: Symbol, signature: String) -> &mut Self {
710716
self.highlighted_note(vec![
711717
StringPart::normal(format!("`{name}` from trait: `")),
@@ -723,12 +729,14 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
723729
self
724730
} }
725731

732+
#[rustc_lint_diagnostics]
726733
fn highlighted_note(&mut self, msg: Vec<StringPart>) -> &mut Self {
727734
self.sub_with_highlights(Level::Note, msg, MultiSpan::new());
728735
self
729736
}
730737

731738
/// This is like [`Diag::note()`], but it's only printed once.
739+
#[rustc_lint_diagnostics]
732740
pub fn note_once(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self {
733741
self.sub(Level::OnceNote, msg, MultiSpan::new());
734742
self
@@ -749,6 +757,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
749757

750758
/// Prints the span with a note above it.
751759
/// This is like [`Diag::note_once()`], but it gets its own span.
760+
#[rustc_lint_diagnostics]
752761
pub fn span_note_once<S: Into<MultiSpan>>(
753762
&mut self,
754763
sp: S,
@@ -787,12 +796,14 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
787796
} }
788797

789798
/// This is like [`Diag::help()`], but it's only printed once.
799+
#[rustc_lint_diagnostics]
790800
pub fn help_once(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self {
791801
self.sub(Level::OnceHelp, msg, MultiSpan::new());
792802
self
793803
}
794804

795805
/// Add a help message attached to this diagnostic with a customizable highlighted message.
806+
#[rustc_lint_diagnostics]
796807
pub fn highlighted_help(&mut self, msg: Vec<StringPart>) -> &mut Self {
797808
self.sub_with_highlights(Level::Help, msg, MultiSpan::new());
798809
self
@@ -813,12 +824,14 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
813824
/// Disallow attaching suggestions this diagnostic.
814825
/// Any suggestions attached e.g. with the `span_suggestion_*` methods
815826
/// (before and after the call to `disable_suggestions`) will be ignored.
827+
#[rustc_lint_diagnostics]
816828
pub fn disable_suggestions(&mut self) -> &mut Self {
817829
self.suggestions = Err(SuggestionsDisabled);
818830
self
819831
}
820832

821833
/// Helper for pushing to `self.suggestions`, if available (not disable).
834+
#[rustc_lint_diagnostics]
822835
fn push_suggestion(&mut self, suggestion: CodeSuggestion) {
823836
for subst in &suggestion.substitutions {
824837
for part in &subst.parts {
@@ -839,6 +852,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
839852
with_fn! { with_multipart_suggestion,
840853
/// Show a suggestion that has multiple parts to it.
841854
/// In other words, multiple changes need to be applied as part of this suggestion.
855+
#[rustc_lint_diagnostics]
842856
pub fn multipart_suggestion(
843857
&mut self,
844858
msg: impl Into<SubdiagnosticMessage>,
@@ -855,6 +869,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
855869

856870
/// Show a suggestion that has multiple parts to it, always as it's own subdiagnostic.
857871
/// In other words, multiple changes need to be applied as part of this suggestion.
872+
#[rustc_lint_diagnostics]
858873
pub fn multipart_suggestion_verbose(
859874
&mut self,
860875
msg: impl Into<SubdiagnosticMessage>,
@@ -870,6 +885,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
870885
}
871886

872887
/// [`Diag::multipart_suggestion()`] but you can set the [`SuggestionStyle`].
888+
#[rustc_lint_diagnostics]
873889
pub fn multipart_suggestion_with_style(
874890
&mut self,
875891
msg: impl Into<SubdiagnosticMessage>,
@@ -912,6 +928,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
912928
/// be from the message, showing the span label inline would be visually unpleasant
913929
/// (marginally overlapping spans or multiline spans) and showing the snippet window wouldn't
914930
/// improve understandability.
931+
#[rustc_lint_diagnostics]
915932
pub fn tool_only_multipart_suggestion(
916933
&mut self,
917934
msg: impl Into<SubdiagnosticMessage>,
@@ -944,6 +961,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
944961
/// * may contain a name of a function, variable, or type, but not whole expressions
945962
///
946963
/// See `CodeSuggestion` for more information.
964+
#[rustc_lint_diagnostics]
947965
pub fn span_suggestion(
948966
&mut self,
949967
sp: Span,
@@ -962,6 +980,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
962980
} }
963981

964982
/// [`Diag::span_suggestion()`] but you can set the [`SuggestionStyle`].
983+
#[rustc_lint_diagnostics]
965984
pub fn span_suggestion_with_style(
966985
&mut self,
967986
sp: Span,
@@ -987,6 +1006,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
9871006

9881007
with_fn! { with_span_suggestion_verbose,
9891008
/// Always show the suggested change.
1009+
#[rustc_lint_diagnostics]
9901010
pub fn span_suggestion_verbose(
9911011
&mut self,
9921012
sp: Span,
@@ -1007,6 +1027,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
10071027
with_fn! { with_span_suggestions,
10081028
/// Prints out a message with multiple suggested edits of the code.
10091029
/// See also [`Diag::span_suggestion()`].
1030+
#[rustc_lint_diagnostics]
10101031
pub fn span_suggestions(
10111032
&mut self,
10121033
sp: Span,
@@ -1023,6 +1044,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
10231044
)
10241045
} }
10251046

1047+
#[rustc_lint_diagnostics]
10261048
pub fn span_suggestions_with_style(
10271049
&mut self,
10281050
sp: Span,
@@ -1053,6 +1075,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
10531075
/// Prints out a message with multiple suggested edits of the code, where each edit consists of
10541076
/// multiple parts.
10551077
/// See also [`Diag::multipart_suggestion()`].
1078+
#[rustc_lint_diagnostics]
10561079
pub fn multipart_suggestions(
10571080
&mut self,
10581081
msg: impl Into<SubdiagnosticMessage>,
@@ -1099,6 +1122,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
10991122
/// inline, it will only show the message and not the suggestion.
11001123
///
11011124
/// See `CodeSuggestion` for more information.
1125+
#[rustc_lint_diagnostics]
11021126
pub fn span_suggestion_short(
11031127
&mut self,
11041128
sp: Span,
@@ -1122,6 +1146,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
11221146
/// be from the message, showing the span label inline would be visually unpleasant
11231147
/// (marginally overlapping spans or multiline spans) and showing the snippet window wouldn't
11241148
/// improve understandability.
1149+
#[rustc_lint_diagnostics]
11251150
pub fn span_suggestion_hidden(
11261151
&mut self,
11271152
sp: Span,
@@ -1166,6 +1191,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
11661191
/// [rustc_macros::Subdiagnostic]). Performs eager translation of any translatable messages
11671192
/// used in the subdiagnostic, so suitable for use with repeated messages (i.e. re-use of
11681193
/// interpolated variables).
1194+
#[rustc_lint_diagnostics]
11691195
pub fn subdiagnostic(
11701196
&mut self,
11711197
dcx: &crate::DiagCtxt,
@@ -1181,6 +1207,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
11811207

11821208
with_fn! { with_span,
11831209
/// Add a span.
1210+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
11841211
pub fn span(&mut self, sp: impl Into<MultiSpan>) -> &mut Self {
11851212
self.span = sp.into();
11861213
if let Some(span) = self.span.primary_span() {
@@ -1189,27 +1216,31 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
11891216
self
11901217
} }
11911218

1219+
#[rustc_lint_diagnostics]
11921220
pub fn is_lint(&mut self, name: String, has_future_breakage: bool) -> &mut Self {
11931221
self.is_lint = Some(IsLint { name, has_future_breakage });
11941222
self
11951223
}
11961224

11971225
with_fn! { with_code,
11981226
/// Add an error code.
1227+
#[rustc_lint_diagnostics]
11991228
pub fn code(&mut self, code: ErrCode) -> &mut Self {
12001229
self.code = Some(code);
12011230
self
12021231
} }
12031232

12041233
with_fn! { with_primary_message,
12051234
/// Add a primary message.
1235+
#[rustc_lint_diagnostics]
12061236
pub fn primary_message(&mut self, msg: impl Into<DiagnosticMessage>) -> &mut Self {
12071237
self.messages[0] = (msg.into(), Style::NoStyle);
12081238
self
12091239
} }
12101240

12111241
with_fn! { with_arg,
12121242
/// Add an argument.
1243+
#[rustc_lint_diagnostics]
12131244
pub fn arg(
12141245
&mut self,
12151246
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
@@ -312,6 +312,7 @@ impl Session {
312312
) -> Diag<'a> {
313313
let mut err = self.dcx().create_err(err);
314314
if err.code.is_none() {
315+
#[allow(rustc::diagnostic_outside_of_impl)]
315316
err.code(E0658);
316317
}
317318
add_feature_diagnostics(&mut err, self, feature);

0 commit comments

Comments
 (0)