Skip to content

Commit 6d9d025

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.
1 parent 03a7c68 commit 6d9d025

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>,
@@ -765,6 +764,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
765764
/// | ^^^^^^^^^^^^^^ function was supposed to return data with lifetime `'a` but it
766765
/// | is returning data with lifetime `'b`
767766
/// ```
767+
#[allow(rustc::diagnostic_outside_of_impl)] // FIXME
768768
fn report_general_error(&self, errci: &ErrorConstraintInfo<'tcx>) -> DiagnosticBuilder<'tcx> {
769769
let ErrorConstraintInfo {
770770
fr,
@@ -826,6 +826,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
826826
/// LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> + 'a {
827827
/// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
828828
/// ```
829+
#[allow(rustc::diagnostic_outside_of_impl)]
829830
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
830831
fn add_static_impl_trait_suggestion(
831832
&self,
@@ -977,6 +978,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
977978
self.suggest_constrain_dyn_trait_in_impl(diag, &visitor.0, ident, self_ty);
978979
}
979980

981+
#[allow(rustc::diagnostic_outside_of_impl)]
980982
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
981983
#[instrument(skip(self, err), level = "debug")]
982984
fn suggest_constrain_dyn_trait_in_impl(
@@ -1045,6 +1047,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
10451047
suggest_adding_lifetime_params(self.infcx.tcx, sub, ty_sup, ty_sub, diag);
10461048
}
10471049

1050+
#[allow(rustc::diagnostic_outside_of_impl)]
10481051
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
10491052
fn suggest_move_on_borrowing_closure(&self, diag: &mut DiagnosticBuilder<'_>) {
10501053
let map = self.infcx.tcx.hir();

compiler/rustc_errors/src/diagnostic.rs

+31
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
586586
///
587587
/// In the meantime, though, callsites are required to deal with the "bug"
588588
/// locally in whichever way makes the most sense.
589+
#[rustc_lint_diagnostics]
589590
#[track_caller]
590591
pub fn downgrade_to_delayed_bug(&mut self) {
591592
assert!(
@@ -619,13 +620,15 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
619620
with_fn! { with_span_labels,
620621
/// Labels all the given spans with the provided label.
621622
/// See [`Self::span_label()`] for more information.
623+
#[rustc_lint_diagnostics]
622624
pub fn span_labels(&mut self, spans: impl IntoIterator<Item = Span>, label: &str) -> &mut Self {
623625
for span in spans {
624626
self.span_label(span, label.to_string());
625627
}
626628
self
627629
} }
628630

631+
#[rustc_lint_diagnostics]
629632
pub fn replace_span_with(&mut self, after: Span, keep_label: bool) -> &mut Self {
630633
let before = self.span.clone();
631634
self.span(after);
@@ -641,6 +644,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
641644
self
642645
}
643646

647+
#[rustc_lint_diagnostics]
644648
pub fn note_expected_found(
645649
&mut self,
646650
expected_label: &dyn fmt::Display,
@@ -651,6 +655,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
651655
self.note_expected_found_extra(expected_label, expected, found_label, found, &"", &"")
652656
}
653657

658+
#[rustc_lint_diagnostics]
654659
pub fn note_expected_found_extra(
655660
&mut self,
656661
expected_label: &dyn fmt::Display,
@@ -693,6 +698,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
693698
self
694699
}
695700

701+
#[rustc_lint_diagnostics]
696702
pub fn note_trait_signature(&mut self, name: Symbol, signature: String) -> &mut Self {
697703
self.highlighted_note(vec![
698704
StringPart::normal(format!("`{name}` from trait: `")),
@@ -710,12 +716,14 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
710716
self
711717
} }
712718

719+
#[rustc_lint_diagnostics]
713720
fn highlighted_note(&mut self, msg: Vec<StringPart>) -> &mut Self {
714721
self.sub_with_highlights(Level::Note, msg, MultiSpan::new());
715722
self
716723
}
717724

718725
/// This is like [`DiagnosticBuilder::note()`], but it's only printed once.
726+
#[rustc_lint_diagnostics]
719727
pub fn note_once(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self {
720728
self.sub(Level::OnceNote, msg, MultiSpan::new());
721729
self
@@ -736,6 +744,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
736744

737745
/// Prints the span with a note above it.
738746
/// This is like [`DiagnosticBuilder::note_once()`], but it gets its own span.
747+
#[rustc_lint_diagnostics]
739748
pub fn span_note_once<S: Into<MultiSpan>>(
740749
&mut self,
741750
sp: S,
@@ -774,12 +783,14 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
774783
} }
775784

776785
/// This is like [`DiagnosticBuilder::help()`], but it's only printed once.
786+
#[rustc_lint_diagnostics]
777787
pub fn help_once(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self {
778788
self.sub(Level::OnceHelp, msg, MultiSpan::new());
779789
self
780790
}
781791

782792
/// Add a help message attached to this diagnostic with a customizable highlighted message.
793+
#[rustc_lint_diagnostics]
783794
pub fn highlighted_help(&mut self, msg: Vec<StringPart>) -> &mut Self {
784795
self.sub_with_highlights(Level::Help, msg, MultiSpan::new());
785796
self
@@ -800,12 +811,14 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
800811
/// Disallow attaching suggestions this diagnostic.
801812
/// Any suggestions attached e.g. with the `span_suggestion_*` methods
802813
/// (before and after the call to `disable_suggestions`) will be ignored.
814+
#[rustc_lint_diagnostics]
803815
pub fn disable_suggestions(&mut self) -> &mut Self {
804816
self.suggestions = Err(SuggestionsDisabled);
805817
self
806818
}
807819

808820
/// Helper for pushing to `self.suggestions`, if available (not disable).
821+
#[rustc_lint_diagnostics]
809822
fn push_suggestion(&mut self, suggestion: CodeSuggestion) {
810823
for subst in &suggestion.substitutions {
811824
for part in &subst.parts {
@@ -826,6 +839,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
826839
with_fn! { with_multipart_suggestion,
827840
/// Show a suggestion that has multiple parts to it.
828841
/// In other words, multiple changes need to be applied as part of this suggestion.
842+
#[rustc_lint_diagnostics]
829843
pub fn multipart_suggestion(
830844
&mut self,
831845
msg: impl Into<SubdiagnosticMessage>,
@@ -842,6 +856,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
842856

843857
/// Show a suggestion that has multiple parts to it, always as it's own subdiagnostic.
844858
/// In other words, multiple changes need to be applied as part of this suggestion.
859+
#[rustc_lint_diagnostics]
845860
pub fn multipart_suggestion_verbose(
846861
&mut self,
847862
msg: impl Into<SubdiagnosticMessage>,
@@ -857,6 +872,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
857872
}
858873

859874
/// [`DiagnosticBuilder::multipart_suggestion()`] but you can set the [`SuggestionStyle`].
875+
#[rustc_lint_diagnostics]
860876
pub fn multipart_suggestion_with_style(
861877
&mut self,
862878
msg: impl Into<SubdiagnosticMessage>,
@@ -899,6 +915,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
899915
/// be from the message, showing the span label inline would be visually unpleasant
900916
/// (marginally overlapping spans or multiline spans) and showing the snippet window wouldn't
901917
/// improve understandability.
918+
#[rustc_lint_diagnostics]
902919
pub fn tool_only_multipart_suggestion(
903920
&mut self,
904921
msg: impl Into<SubdiagnosticMessage>,
@@ -931,6 +948,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
931948
/// * may contain a name of a function, variable, or type, but not whole expressions
932949
///
933950
/// See `CodeSuggestion` for more information.
951+
#[rustc_lint_diagnostics]
934952
pub fn span_suggestion(
935953
&mut self,
936954
sp: Span,
@@ -949,6 +967,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
949967
} }
950968

951969
/// [`DiagnosticBuilder::span_suggestion()`] but you can set the [`SuggestionStyle`].
970+
#[rustc_lint_diagnostics]
952971
pub fn span_suggestion_with_style(
953972
&mut self,
954973
sp: Span,
@@ -974,6 +993,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
974993

975994
with_fn! { with_span_suggestion_verbose,
976995
/// Always show the suggested change.
996+
#[rustc_lint_diagnostics]
977997
pub fn span_suggestion_verbose(
978998
&mut self,
979999
sp: Span,
@@ -994,6 +1014,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
9941014
with_fn! { with_span_suggestions,
9951015
/// Prints out a message with multiple suggested edits of the code.
9961016
/// See also [`DiagnosticBuilder::span_suggestion()`].
1017+
#[rustc_lint_diagnostics]
9971018
pub fn span_suggestions(
9981019
&mut self,
9991020
sp: Span,
@@ -1010,6 +1031,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
10101031
)
10111032
} }
10121033

1034+
#[rustc_lint_diagnostics]
10131035
pub fn span_suggestions_with_style(
10141036
&mut self,
10151037
sp: Span,
@@ -1040,6 +1062,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
10401062
/// Prints out a message with multiple suggested edits of the code, where each edit consists of
10411063
/// multiple parts.
10421064
/// See also [`DiagnosticBuilder::multipart_suggestion()`].
1065+
#[rustc_lint_diagnostics]
10431066
pub fn multipart_suggestions(
10441067
&mut self,
10451068
msg: impl Into<SubdiagnosticMessage>,
@@ -1086,6 +1109,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
10861109
/// inline, it will only show the message and not the suggestion.
10871110
///
10881111
/// See `CodeSuggestion` for more information.
1112+
#[rustc_lint_diagnostics]
10891113
pub fn span_suggestion_short(
10901114
&mut self,
10911115
sp: Span,
@@ -1109,6 +1133,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
11091133
/// be from the message, showing the span label inline would be visually unpleasant
11101134
/// (marginally overlapping spans or multiline spans) and showing the snippet window wouldn't
11111135
/// improve understandability.
1136+
#[rustc_lint_diagnostics]
11121137
pub fn span_suggestion_hidden(
11131138
&mut self,
11141139
sp: Span,
@@ -1153,6 +1178,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
11531178
/// [rustc_macros::Subdiagnostic]). Performs eager translation of any translatable messages
11541179
/// used in the subdiagnostic, so suitable for use with repeated messages (i.e. re-use of
11551180
/// interpolated variables).
1181+
#[rustc_lint_diagnostics]
11561182
pub fn subdiagnostic(
11571183
&mut self,
11581184
dcx: &crate::DiagCtxt,
@@ -1168,6 +1194,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
11681194

11691195
with_fn! { with_span,
11701196
/// Add a span.
1197+
#[rustc_lint_diagnostics]
11711198
pub fn span(&mut self, sp: impl Into<MultiSpan>) -> &mut Self {
11721199
self.span = sp.into();
11731200
if let Some(span) = self.span.primary_span() {
@@ -1176,27 +1203,31 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
11761203
self
11771204
} }
11781205

1206+
#[rustc_lint_diagnostics]
11791207
pub fn is_lint(&mut self, name: String, has_future_breakage: bool) -> &mut Self {
11801208
self.is_lint = Some(IsLint { name, has_future_breakage });
11811209
self
11821210
}
11831211

11841212
with_fn! { with_code,
11851213
/// Add an error code.
1214+
#[rustc_lint_diagnostics]
11861215
pub fn code(&mut self, code: ErrCode) -> &mut Self {
11871216
self.code = Some(code);
11881217
self
11891218
} }
11901219

11911220
with_fn! { with_primary_message,
11921221
/// Add a primary message.
1222+
#[rustc_lint_diagnostics]
11931223
pub fn primary_message(&mut self, msg: impl Into<DiagnosticMessage>) -> &mut Self {
11941224
self.messages[0] = (msg.into(), Style::NoStyle);
11951225
self
11961226
} }
11971227

11981228
with_fn! { with_arg,
11991229
/// Add an argument.
1230+
#[rustc_lint_diagnostics]
12001231
pub fn arg(
12011232
&mut self,
12021233
name: impl Into<DiagnosticArgName>,

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
@@ -170,6 +170,7 @@ pub fn add_feature_diagnostics<G: EmissionGuarantee>(
170170
/// This variant allows you to control whether it is a library or language feature.
171171
/// Almost always, you want to use this for a language feature. If so, prefer
172172
/// `add_feature_diagnostics`.
173+
#[allow(rustc::diagnostic_outside_of_impl)] // FIXME
173174
pub fn add_feature_diagnostics_for_issue<G: EmissionGuarantee>(
174175
err: &mut DiagnosticBuilder<'_, G>,
175176
sess: &Session,

compiler/rustc_session/src/session.rs

+1
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ impl Session {
311311
) -> DiagnosticBuilder<'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)