Skip to content

Commit eefd356

Browse files
committed
Remove all eight DiagnosticBuilder::*_with_code methods.
These all have relatively low use, and can be perfectly emulated with a simpler construction method combined with `code` or `code_mv`.
1 parent d98c92e commit eefd356

File tree

14 files changed

+85
-180
lines changed

14 files changed

+85
-180
lines changed

compiler/rustc_errors/src/diagnostic_builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,11 +528,11 @@ impl<G: EmissionGuarantee> Drop for DiagnosticBuilder<'_, G> {
528528
#[macro_export]
529529
macro_rules! struct_span_err {
530530
($dcx:expr, $span:expr, $code:ident, $($message:tt)*) => ({
531-
$dcx.struct_span_err_with_code(
531+
$dcx.struct_span_err(
532532
$span,
533533
format!($($message)*),
534-
$crate::error_code!($code),
535534
)
535+
.code_mv($crate::error_code!($code))
536536
})
537537
}
538538

compiler/rustc_errors/src/lib.rs

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -734,19 +734,6 @@ impl DiagCtxt {
734734
self.struct_warn(msg).span_mv(span)
735735
}
736736

737-
/// Construct a builder at the `Warning` level at the given `span` and with the `msg`.
738-
/// Also include a code.
739-
#[rustc_lint_diagnostics]
740-
#[track_caller]
741-
pub fn struct_span_warn_with_code(
742-
&self,
743-
span: impl Into<MultiSpan>,
744-
msg: impl Into<DiagnosticMessage>,
745-
code: DiagnosticId,
746-
) -> DiagnosticBuilder<'_, ()> {
747-
self.struct_span_warn(span, msg).code_mv(code)
748-
}
749-
750737
/// Construct a builder at the `Warning` level with the `msg`.
751738
///
752739
/// Attempting to `.emit()` the builder will only emit if either:
@@ -787,18 +774,6 @@ impl DiagCtxt {
787774
self.struct_err(msg).span_mv(span)
788775
}
789776

790-
/// Construct a builder at the `Error` level at the given `span`, with the `msg`, and `code`.
791-
#[rustc_lint_diagnostics]
792-
#[track_caller]
793-
pub fn struct_span_err_with_code(
794-
&self,
795-
span: impl Into<MultiSpan>,
796-
msg: impl Into<DiagnosticMessage>,
797-
code: DiagnosticId,
798-
) -> DiagnosticBuilder<'_> {
799-
self.struct_span_err(span, msg).code_mv(code)
800-
}
801-
802777
/// Construct a builder at the `Error` level with the `msg`.
803778
// FIXME: This method should be removed (every error should have an associated error code).
804779
#[rustc_lint_diagnostics]
@@ -807,28 +782,6 @@ impl DiagCtxt {
807782
DiagnosticBuilder::new(self, Error, msg)
808783
}
809784

810-
/// Construct a builder at the `Error` level with the `msg` and the `code`.
811-
#[rustc_lint_diagnostics]
812-
#[track_caller]
813-
pub fn struct_err_with_code(
814-
&self,
815-
msg: impl Into<DiagnosticMessage>,
816-
code: DiagnosticId,
817-
) -> DiagnosticBuilder<'_> {
818-
self.struct_err(msg).code_mv(code)
819-
}
820-
821-
/// Construct a builder at the `Warn` level with the `msg` and the `code`.
822-
#[rustc_lint_diagnostics]
823-
#[track_caller]
824-
pub fn struct_warn_with_code(
825-
&self,
826-
msg: impl Into<DiagnosticMessage>,
827-
code: DiagnosticId,
828-
) -> DiagnosticBuilder<'_, ()> {
829-
self.struct_warn(msg).code_mv(code)
830-
}
831-
832785
/// Construct a builder at the `Fatal` level at the given `span` and with the `msg`.
833786
#[rustc_lint_diagnostics]
834787
#[track_caller]
@@ -840,18 +793,6 @@ impl DiagCtxt {
840793
self.struct_fatal(msg).span_mv(span)
841794
}
842795

843-
/// Construct a builder at the `Fatal` level at the given `span`, with the `msg`, and `code`.
844-
#[rustc_lint_diagnostics]
845-
#[track_caller]
846-
pub fn struct_span_fatal_with_code(
847-
&self,
848-
span: impl Into<MultiSpan>,
849-
msg: impl Into<DiagnosticMessage>,
850-
code: DiagnosticId,
851-
) -> DiagnosticBuilder<'_, FatalAbort> {
852-
self.struct_span_fatal(span, msg).code_mv(code)
853-
}
854-
855796
/// Construct a builder at the `Fatal` level with the `msg`.
856797
#[rustc_lint_diagnostics]
857798
#[track_caller]
@@ -899,17 +840,6 @@ impl DiagCtxt {
899840
self.struct_span_fatal(span, msg).emit()
900841
}
901842

902-
#[rustc_lint_diagnostics]
903-
#[track_caller]
904-
pub fn span_fatal_with_code(
905-
&self,
906-
span: impl Into<MultiSpan>,
907-
msg: impl Into<DiagnosticMessage>,
908-
code: DiagnosticId,
909-
) -> ! {
910-
self.struct_span_fatal_with_code(span, msg, code).emit()
911-
}
912-
913843
#[rustc_lint_diagnostics]
914844
#[track_caller]
915845
pub fn span_err(
@@ -920,34 +850,12 @@ impl DiagCtxt {
920850
self.struct_span_err(span, msg).emit()
921851
}
922852

923-
#[rustc_lint_diagnostics]
924-
#[track_caller]
925-
pub fn span_err_with_code(
926-
&self,
927-
span: impl Into<MultiSpan>,
928-
msg: impl Into<DiagnosticMessage>,
929-
code: DiagnosticId,
930-
) -> ErrorGuaranteed {
931-
self.struct_span_err_with_code(span, msg, code).emit()
932-
}
933-
934853
#[rustc_lint_diagnostics]
935854
#[track_caller]
936855
pub fn span_warn(&self, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>) {
937856
self.struct_span_warn(span, msg).emit()
938857
}
939858

940-
#[rustc_lint_diagnostics]
941-
#[track_caller]
942-
pub fn span_warn_with_code(
943-
&self,
944-
span: impl Into<MultiSpan>,
945-
msg: impl Into<DiagnosticMessage>,
946-
code: DiagnosticId,
947-
) {
948-
self.struct_span_warn_with_code(span, msg, code).emit()
949-
}
950-
951859
pub fn span_bug(&self, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>) -> ! {
952860
self.struct_span_bug(span, msg).emit()
953861
}

compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1647,7 +1647,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
16471647
let msg = format!("{kind} `{name}` is private");
16481648
let def_span = tcx.def_span(item);
16491649
tcx.dcx()
1650-
.struct_span_err_with_code(span, msg, rustc_errors::error_code!(E0624))
1650+
.struct_span_err(span, msg)
1651+
.code_mv(rustc_errors::error_code!(E0624))
16511652
.span_label_mv(span, format!("private {kind}"))
16521653
.span_label_mv(def_span, format!("{kind} defined here"))
16531654
.emit();

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,7 +1371,7 @@ fn compare_number_of_generics<'tcx>(
13711371
let spans = arg_spans(impl_.kind, impl_item.generics);
13721372
let span = spans.first().copied();
13731373

1374-
let mut err = tcx.dcx().struct_span_err_with_code(
1374+
let mut err = tcx.dcx().struct_span_err(
13751375
spans,
13761376
format!(
13771377
"{} `{}` has {} {kind} parameter{} but its trait \
@@ -1384,8 +1384,8 @@ fn compare_number_of_generics<'tcx>(
13841384
pluralize!(trait_count),
13851385
kind = kind,
13861386
),
1387-
DiagnosticId::Error("E0049".into()),
13881387
);
1388+
err.code(DiagnosticId::Error("E0049".into()));
13891389

13901390
let msg =
13911391
format!("expected {trait_count} {kind} parameter{}", pluralize!(trait_count),);

compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
523523
fn start_diagnostics(&self) -> DiagnosticBuilder<'tcx> {
524524
let span = self.path_segment.ident.span;
525525
let msg = self.create_error_message();
526-
527-
self.tcx.dcx().struct_span_err_with_code(span, msg, self.code())
526+
self.tcx.dcx().struct_span_err(span, msg).code_mv(self.code())
528527
}
529528

530529
/// Builds the `expected 1 type argument / supplied 2 type arguments` message.

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -939,12 +939,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
939939
return;
940940
}
941941

942-
// FIXME: Make this use Diagnostic once error codes can be dynamically set.
943-
let mut err = self.dcx().struct_span_err_with_code(
944-
op_span,
945-
"invalid left-hand side of assignment",
946-
DiagnosticId::Error(err_code.into()),
947-
);
942+
let mut err = self.dcx().struct_span_err(op_span, "invalid left-hand side of assignment");
943+
err.code(DiagnosticId::Error(err_code.into()));
948944
err.span_label(lhs.span, "cannot assign to this expression");
949945

950946
self.comes_from_while_condition(lhs.hir_id, |expr| {

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
664664
format!("arguments to this {call_name} are incorrect"),
665665
);
666666
} else {
667-
err = tcx.dcx().struct_span_err_with_code(
667+
err = tcx.dcx().struct_span_err(
668668
full_call_span,
669669
format!(
670670
"{call_name} takes {}{} but {} {} supplied",
@@ -676,8 +676,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
676676
potentially_plural_count(provided_args.len(), "argument"),
677677
pluralize!("was", provided_args.len())
678678
),
679-
DiagnosticId::Error(err_code.to_owned()),
680679
);
680+
err.code(DiagnosticId::Error(err_code.to_owned()));
681681
err.multipart_suggestion_verbose(
682682
"wrap these arguments in parentheses to construct a tuple",
683683
vec![
@@ -815,18 +815,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
815815
call_name,
816816
)
817817
} else {
818-
tcx.dcx().struct_span_err_with_code(
819-
full_call_span,
820-
format!(
821-
"this {} takes {}{} but {} {} supplied",
822-
call_name,
823-
if c_variadic { "at least " } else { "" },
824-
potentially_plural_count(formal_and_expected_inputs.len(), "argument"),
825-
potentially_plural_count(provided_args.len(), "argument"),
826-
pluralize!("was", provided_args.len())
827-
),
828-
DiagnosticId::Error(err_code.to_owned()),
829-
)
818+
tcx.dcx()
819+
.struct_span_err(
820+
full_call_span,
821+
format!(
822+
"this {} takes {}{} but {} {} supplied",
823+
call_name,
824+
if c_variadic { "at least " } else { "" },
825+
potentially_plural_count(formal_and_expected_inputs.len(), "argument"),
826+
potentially_plural_count(provided_args.len(), "argument"),
827+
pluralize!("was", provided_args.len())
828+
),
829+
)
830+
.code_mv(DiagnosticId::Error(err_code.to_owned()))
830831
};
831832

832833
// As we encounter issues, keep track of what we want to provide for the suggestion

compiler/rustc_hir_typeck/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,11 @@ fn report_unexpected_variant_res(
368368
_ => res.descr(),
369369
};
370370
let path_str = rustc_hir_pretty::qpath_to_string(qpath);
371-
let err = tcx.dcx().struct_span_err_with_code(
372-
span,
373-
format!("expected {expected}, found {res_descr} `{path_str}`"),
374-
DiagnosticId::Error(err_code.into()),
375-
);
371+
let err = tcx
372+
.dcx()
373+
.struct_span_err(span, format!("expected {expected}, found {res_descr} `{path_str}`"))
374+
.code_mv(DiagnosticId::Error(err_code.into()));
375+
// njn: redo this to not use _mv bits
376376
match res {
377377
Res::Def(DefKind::Fn | DefKind::AssocFn, _) if err_code == "E0164" => {
378378
let patterns_url = "https://doc.rust-lang.org/book/ch18-00-patterns.html";

compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2356,15 +2356,15 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
23562356
},
23572357
};
23582358

2359-
let mut err = self.tcx.dcx().struct_span_err_with_code(
2360-
span,
2361-
format!("{labeled_user_string} may not live long enough"),
2362-
match sub.kind() {
2363-
ty::ReEarlyParam(_) | ty::ReLateParam(_) if sub.has_name() => error_code!(E0309),
2364-
ty::ReStatic => error_code!(E0310),
2365-
_ => error_code!(E0311),
2366-
},
2367-
);
2359+
let mut err = self
2360+
.tcx
2361+
.dcx()
2362+
.struct_span_err(span, format!("{labeled_user_string} may not live long enough"));
2363+
err.code(match sub.kind() {
2364+
ty::ReEarlyParam(_) | ty::ReLateParam(_) if sub.has_name() => error_code!(E0309),
2365+
ty::ReStatic => error_code!(E0310),
2366+
_ => error_code!(E0311),
2367+
});
23682368

23692369
'_explain: {
23702370
let (description, span) = match sub.kind() {

0 commit comments

Comments
 (0)