Skip to content

Commit b7b6ebc

Browse files
committed
Fix inconsistencies in the diagnostic API methods.
- Remove low-value comments about functionality that is obvious. - Add missing `track_caller` attributes -- every method should have one. - Adjust `rustc_lint_diagnostic` attributes. Every method involving a `impl Into<DiagnosticMessage>` or `impl Into<SubdiangnosticMessage>` argument should have one, except for those producing bugs, which aren't user-facing.
1 parent c35983a commit b7b6ebc

File tree

1 file changed

+21
-32
lines changed
  • compiler/rustc_errors/src

1 file changed

+21
-32
lines changed

compiler/rustc_errors/src/lib.rs

+21-32
Original file line numberDiff line numberDiff line change
@@ -945,20 +945,19 @@ impl DiagCtxt {
945945
// Functions beginning with `struct_`/`create_` create a diagnostic. Other
946946
// functions create and emit a diagnostic all in one go.
947947
impl DiagCtxt {
948-
/// Construct a builder at the `Bug` level with the `msg`.
949-
#[rustc_lint_diagnostics]
948+
// No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing.
950949
#[track_caller]
951950
pub fn struct_bug(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, BugAbort> {
952951
DiagnosticBuilder::new(self, Bug, msg)
953952
}
954953

955-
#[rustc_lint_diagnostics]
954+
// No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing.
955+
#[track_caller]
956956
pub fn bug(&self, msg: impl Into<DiagnosticMessage>) -> ! {
957957
self.struct_bug(msg).emit()
958958
}
959959

960-
/// Construct a builder at the `Bug` level at the given `span` with the `msg`.
961-
#[rustc_lint_diagnostics]
960+
// No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing.
962961
#[track_caller]
963962
pub fn struct_span_bug(
964963
&self,
@@ -968,6 +967,8 @@ impl DiagCtxt {
968967
self.struct_bug(msg).with_span(span)
969968
}
970969

970+
// No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing.
971+
#[track_caller]
971972
pub fn span_bug(&self, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>) -> ! {
972973
self.struct_span_bug(span, msg).emit()
973974
}
@@ -981,11 +982,10 @@ impl DiagCtxt {
981982
}
982983

983984
#[track_caller]
984-
pub fn emit_bug<'a>(&'a self, bug: impl IntoDiagnostic<'a, diagnostic_builder::BugAbort>) -> ! {
985+
pub fn emit_bug<'a>(&'a self, bug: impl IntoDiagnostic<'a, BugAbort>) -> ! {
985986
self.create_bug(bug).emit()
986987
}
987988

988-
/// Construct a builder at the `Fatal` level with the `msg`.
989989
#[rustc_lint_diagnostics]
990990
#[track_caller]
991991
pub fn struct_fatal(
@@ -996,11 +996,11 @@ impl DiagCtxt {
996996
}
997997

998998
#[rustc_lint_diagnostics]
999+
#[track_caller]
9991000
pub fn fatal(&self, msg: impl Into<DiagnosticMessage>) -> ! {
10001001
self.struct_fatal(msg).emit()
10011002
}
10021003

1003-
/// Construct a builder at the `Fatal` level at the given `span` and with the `msg`.
10041004
#[rustc_lint_diagnostics]
10051005
#[track_caller]
10061006
pub fn struct_span_fatal(
@@ -1046,7 +1046,6 @@ impl DiagCtxt {
10461046
self.create_almost_fatal(fatal).emit()
10471047
}
10481048

1049-
/// Construct a builder at the `Error` level with the `msg`.
10501049
// FIXME: This method should be removed (every error should have an associated error code).
10511050
#[rustc_lint_diagnostics]
10521051
#[track_caller]
@@ -1055,11 +1054,11 @@ impl DiagCtxt {
10551054
}
10561055

10571056
#[rustc_lint_diagnostics]
1057+
#[track_caller]
10581058
pub fn err(&self, msg: impl Into<DiagnosticMessage>) -> ErrorGuaranteed {
10591059
self.struct_err(msg).emit()
10601060
}
10611061

1062-
/// Construct a builder at the `Error` level at the given `span` and with the `msg`.
10631062
#[rustc_lint_diagnostics]
10641063
#[track_caller]
10651064
pub fn struct_span_err(
@@ -1090,24 +1089,18 @@ impl DiagCtxt {
10901089
self.create_err(err).emit()
10911090
}
10921091

1093-
/// Ensures that compilation cannot succeed.
1094-
///
1095-
/// If this function has been called but no errors have been emitted and
1096-
/// compilation succeeds, it will cause an internal compiler error (ICE).
1097-
///
1098-
/// This can be used in code paths that should never run on successful compilations.
1099-
/// For example, it can be used to create an [`ErrorGuaranteed`]
1100-
/// (but you should prefer threading through the [`ErrorGuaranteed`] from an error emission
1101-
/// directly).
1092+
/// Ensures that an error is printed. See `Level::DelayedBug`.
1093+
// No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing.
11021094
#[track_caller]
11031095
pub fn delayed_bug(&self, msg: impl Into<DiagnosticMessage>) -> ErrorGuaranteed {
11041096
DiagnosticBuilder::<ErrorGuaranteed>::new(self, DelayedBug, msg).emit()
11051097
}
11061098

1107-
/// Like `delayed_bug`, but takes an additional span.
1099+
/// Ensures that an error is printed. See `Level::DelayedBug`.
11081100
///
11091101
/// Note: this function used to be called `delay_span_bug`. It was renamed
11101102
/// to match similar functions like `span_err`, `span_warn`, etc.
1103+
// No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing.
11111104
#[track_caller]
11121105
pub fn span_delayed_bug(
11131106
&self,
@@ -1118,27 +1111,24 @@ impl DiagCtxt {
11181111
}
11191112

11201113
/// Ensures that a diagnostic is printed. See `Level::GoodPathDelayedBug`.
1114+
// No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing.
1115+
#[track_caller]
11211116
pub fn good_path_delayed_bug(&self, msg: impl Into<DiagnosticMessage>) {
11221117
DiagnosticBuilder::<()>::new(self, GoodPathDelayedBug, msg).emit()
11231118
}
11241119

1125-
/// Construct a builder at the `Warning` level with the `msg`.
1126-
///
1127-
/// An `emit` call on the builder will only emit if `can_emit_warnings` is `true`.
11281120
#[rustc_lint_diagnostics]
11291121
#[track_caller]
11301122
pub fn struct_warn(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {
11311123
DiagnosticBuilder::new(self, Warning, msg)
11321124
}
11331125

11341126
#[rustc_lint_diagnostics]
1127+
#[track_caller]
11351128
pub fn warn(&self, msg: impl Into<DiagnosticMessage>) {
11361129
self.struct_warn(msg).emit()
11371130
}
11381131

1139-
/// Construct a builder at the `Warning` level at the given `span` and with the `msg`.
1140-
///
1141-
/// An `emit` call on the builder will only emit if `can_emit_warnings` is `true`.
11421132
#[rustc_lint_diagnostics]
11431133
#[track_caller]
11441134
pub fn struct_span_warn(
@@ -1168,20 +1158,20 @@ impl DiagCtxt {
11681158
self.create_warn(warning).emit()
11691159
}
11701160

1171-
/// Construct a builder at the `Note` level with the `msg`.
11721161
#[rustc_lint_diagnostics]
11731162
#[track_caller]
11741163
pub fn struct_note(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {
11751164
DiagnosticBuilder::new(self, Note, msg)
11761165
}
11771166

11781167
#[rustc_lint_diagnostics]
1168+
#[track_caller]
11791169
pub fn note(&self, msg: impl Into<DiagnosticMessage>) {
11801170
self.struct_note(msg).emit()
11811171
}
11821172

1183-
#[track_caller]
11841173
#[rustc_lint_diagnostics]
1174+
#[track_caller]
11851175
pub fn struct_span_note(
11861176
&self,
11871177
span: impl Into<MultiSpan>,
@@ -1190,8 +1180,8 @@ impl DiagCtxt {
11901180
DiagnosticBuilder::new(self, Note, msg).with_span(span)
11911181
}
11921182

1193-
#[track_caller]
11941183
#[rustc_lint_diagnostics]
1184+
#[track_caller]
11951185
pub fn span_note(&self, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>) {
11961186
self.struct_span_note(span, msg).emit()
11971187
}
@@ -1209,20 +1199,18 @@ impl DiagCtxt {
12091199
self.create_note(note).emit()
12101200
}
12111201

1212-
/// Construct a builder at the `Help` level with the `msg`.
12131202
#[rustc_lint_diagnostics]
1203+
#[track_caller]
12141204
pub fn struct_help(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {
12151205
DiagnosticBuilder::new(self, Help, msg)
12161206
}
12171207

1218-
/// Construct a builder at the `Allow` level with the `msg`.
12191208
#[rustc_lint_diagnostics]
12201209
#[track_caller]
12211210
pub fn struct_allow(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {
12221211
DiagnosticBuilder::new(self, Allow, msg)
12231212
}
12241213

1225-
/// Construct a builder at the `Expect` level with the `msg`.
12261214
#[rustc_lint_diagnostics]
12271215
#[track_caller]
12281216
pub fn struct_expect(
@@ -1589,6 +1577,7 @@ pub enum Level {
15891577
ForceWarning(Option<LintExpectationId>),
15901578

15911579
/// A warning about the code being compiled. Does not prevent compilation from finishing.
1580+
/// Will be skipped if `can_emit_warnings` is false.
15921581
Warning,
15931582

15941583
/// A message giving additional context.

0 commit comments

Comments
 (0)