Skip to content

Commit 3591e77

Browse files
committed
Add missing #[rustc_lint_diagnostics] attributes.
Prior to the previous commit, `#[rust_lint_diagnostics]` attributes could only be used on methods with an `impl Into<{D,Subd}iagMessage>` parameter. But there are many other nearby diagnostic methods (e.g. `Diag::span`) that don't take such a parameter and 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.
1 parent b7d58ee commit 3591e77

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

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

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

670+
#[rustc_lint_diagnostics]
666671
pub fn note_expected_found_extra(
667672
&mut self,
668673
expected_label: &dyn fmt::Display,
@@ -705,6 +710,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
705710
self
706711
}
707712

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

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

730737
/// This is like [`Diag::note()`], but it's only printed once.
738+
#[rustc_lint_diagnostics]
731739
pub fn note_once(&mut self, msg: impl Into<SubdiagMessage>) -> &mut Self {
732740
self.sub(Level::OnceNote, msg, MultiSpan::new());
733741
self
@@ -748,6 +756,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
748756

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

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

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

820832
/// Helper for pushing to `self.suggestions`, if available (not disable).
833+
#[rustc_lint_diagnostics]
821834
fn push_suggestion(&mut self, suggestion: CodeSuggestion) {
822835
for subst in &suggestion.substitutions {
823836
for part in &subst.parts {
@@ -838,6 +851,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
838851
with_fn! { with_multipart_suggestion,
839852
/// Show a suggestion that has multiple parts to it.
840853
/// In other words, multiple changes need to be applied as part of this suggestion.
854+
#[rustc_lint_diagnostics]
841855
pub fn multipart_suggestion(
842856
&mut self,
843857
msg: impl Into<SubdiagMessage>,
@@ -854,6 +868,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
854868

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

871886
/// [`Diag::multipart_suggestion()`] but you can set the [`SuggestionStyle`].
887+
#[rustc_lint_diagnostics]
872888
pub fn multipart_suggestion_with_style(
873889
&mut self,
874890
msg: impl Into<SubdiagMessage>,
@@ -911,6 +927,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
911927
/// be from the message, showing the span label inline would be visually unpleasant
912928
/// (marginally overlapping spans or multiline spans) and showing the snippet window wouldn't
913929
/// improve understandability.
930+
#[rustc_lint_diagnostics]
914931
pub fn tool_only_multipart_suggestion(
915932
&mut self,
916933
msg: impl Into<SubdiagMessage>,
@@ -943,6 +960,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
943960
/// * may contain a name of a function, variable, or type, but not whole expressions
944961
///
945962
/// See `CodeSuggestion` for more information.
963+
#[rustc_lint_diagnostics]
946964
pub fn span_suggestion(
947965
&mut self,
948966
sp: Span,
@@ -961,6 +979,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
961979
} }
962980

963981
/// [`Diag::span_suggestion()`] but you can set the [`SuggestionStyle`].
982+
#[rustc_lint_diagnostics]
964983
pub fn span_suggestion_with_style(
965984
&mut self,
966985
sp: Span,
@@ -986,6 +1005,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
9861005

9871006
with_fn! { with_span_suggestion_verbose,
9881007
/// Always show the suggested change.
1008+
#[rustc_lint_diagnostics]
9891009
pub fn span_suggestion_verbose(
9901010
&mut self,
9911011
sp: Span,
@@ -1006,6 +1026,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
10061026
with_fn! { with_span_suggestions,
10071027
/// Prints out a message with multiple suggested edits of the code.
10081028
/// See also [`Diag::span_suggestion()`].
1029+
#[rustc_lint_diagnostics]
10091030
pub fn span_suggestions(
10101031
&mut self,
10111032
sp: Span,
@@ -1022,6 +1043,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
10221043
)
10231044
} }
10241045

1046+
#[rustc_lint_diagnostics]
10251047
pub fn span_suggestions_with_style(
10261048
&mut self,
10271049
sp: Span,
@@ -1052,6 +1074,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
10521074
/// Prints out a message with multiple suggested edits of the code, where each edit consists of
10531075
/// multiple parts.
10541076
/// See also [`Diag::multipart_suggestion()`].
1077+
#[rustc_lint_diagnostics]
10551078
pub fn multipart_suggestions(
10561079
&mut self,
10571080
msg: impl Into<SubdiagMessage>,
@@ -1098,6 +1121,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
10981121
/// inline, it will only show the message and not the suggestion.
10991122
///
11001123
/// See `CodeSuggestion` for more information.
1124+
#[rustc_lint_diagnostics]
11011125
pub fn span_suggestion_short(
11021126
&mut self,
11031127
sp: Span,
@@ -1121,6 +1145,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
11211145
/// be from the message, showing the span label inline would be visually unpleasant
11221146
/// (marginally overlapping spans or multiline spans) and showing the snippet window wouldn't
11231147
/// improve understandability.
1148+
#[rustc_lint_diagnostics]
11241149
pub fn span_suggestion_hidden(
11251150
&mut self,
11261151
sp: Span,
@@ -1165,6 +1190,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
11651190
/// [rustc_macros::Subdiagnostic]). Performs eager translation of any translatable messages
11661191
/// used in the subdiagnostic, so suitable for use with repeated messages (i.e. re-use of
11671192
/// interpolated variables).
1193+
#[rustc_lint_diagnostics]
11681194
pub fn subdiagnostic(
11691195
&mut self,
11701196
dcx: &crate::DiagCtxt,
@@ -1180,6 +1206,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
11801206

11811207
with_fn! { with_span,
11821208
/// Add a span.
1209+
#[rustc_lint_diagnostics]
11831210
pub fn span(&mut self, sp: impl Into<MultiSpan>) -> &mut Self {
11841211
self.span = sp.into();
11851212
if let Some(span) = self.span.primary_span() {
@@ -1188,27 +1215,31 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
11881215
self
11891216
} }
11901217

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

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

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

12101240
with_fn! { with_arg,
12111241
/// Add an argument.
1242+
#[rustc_lint_diagnostics]
12121243
pub fn arg(
12131244
&mut self,
12141245
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
@@ -168,6 +168,7 @@ pub fn add_feature_diagnostics<G: EmissionGuarantee>(
168168
/// This variant allows you to control whether it is a library or language feature.
169169
/// Almost always, you want to use this for a language feature. If so, prefer
170170
/// `add_feature_diagnostics`.
171+
#[allow(rustc::diagnostic_outside_of_impl)] // FIXME
171172
pub fn add_feature_diagnostics_for_issue<G: EmissionGuarantee>(
172173
err: &mut Diag<'_, G>,
173174
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)