Skip to content

Commit d4fc5ae

Browse files
committed
rustc_errors: handle force_warn only through DiagnosticId::Lint.
1 parent 02ff9e0 commit d4fc5ae

File tree

3 files changed

+8
-42
lines changed

3 files changed

+8
-42
lines changed

compiler/rustc_errors/src/lib.rs

+6-28
Original file line numberDiff line numberDiff line change
@@ -632,27 +632,15 @@ impl Handler {
632632

633633
/// Construct a builder at the `Warning` level at the given `span` and with the `msg`.
634634
///
635-
/// The builder will be canceled if warnings cannot be emitted.
635+
/// Attempting to `.emit()` the builder will only emit if either:
636+
/// * `can_emit_warnings` is `true`
637+
/// * `is_force_warn` was set in `DiagnosticId::Lint`
636638
pub fn struct_span_warn(&self, span: impl Into<MultiSpan>, msg: &str) -> DiagnosticBuilder<'_> {
637639
let mut result = self.struct_warn(msg);
638640
result.set_span(span);
639641
result
640642
}
641643

642-
/// Construct a builder at the `Warning` level at the given `span` and with the `msg`.
643-
///
644-
/// This will "force" the warning meaning it will not be canceled even
645-
/// if warnings cannot be emitted.
646-
pub fn struct_span_force_warn(
647-
&self,
648-
span: impl Into<MultiSpan>,
649-
msg: &str,
650-
) -> DiagnosticBuilder<'_> {
651-
let mut result = self.struct_force_warn(msg);
652-
result.set_span(span);
653-
result
654-
}
655-
656644
/// Construct a builder at the `Allow` level at the given `span` and with the `msg`.
657645
pub fn struct_span_allow(
658646
&self,
@@ -679,20 +667,10 @@ impl Handler {
679667

680668
/// Construct a builder at the `Warning` level with the `msg`.
681669
///
682-
/// The builder will be canceled if warnings cannot be emitted.
670+
/// Attempting to `.emit()` the builder will only emit if either:
671+
/// * `can_emit_warnings` is `true`
672+
/// * `is_force_warn` was set in `DiagnosticId::Lint`
683673
pub fn struct_warn(&self, msg: &str) -> DiagnosticBuilder<'_> {
684-
let mut result = DiagnosticBuilder::new(self, Level::Warning, msg);
685-
if !self.flags.can_emit_warnings {
686-
result.cancel();
687-
}
688-
result
689-
}
690-
691-
/// Construct a builder at the `Warning` level with the `msg`.
692-
///
693-
/// This will "force" a warning meaning it will not be canceled even
694-
/// if warnings cannot be emitted.
695-
pub fn struct_force_warn(&self, msg: &str) -> DiagnosticBuilder<'_> {
696674
DiagnosticBuilder::new(self, Level::Warning, msg)
697675
}
698676

compiler/rustc_middle/src/lint.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,8 @@ pub fn struct_lint_level<'s, 'd>(
314314
return;
315315
}
316316
}
317-
(Level::Warn, Some(span)) => sess.struct_span_warn(span, ""),
318-
(Level::Warn, None) => sess.struct_warn(""),
319-
(Level::ForceWarn, Some(span)) => sess.struct_span_force_warn(span, ""),
320-
(Level::ForceWarn, None) => sess.struct_force_warn(""),
317+
(Level::Warn | Level::ForceWarn, Some(span)) => sess.struct_span_warn(span, ""),
318+
(Level::Warn | Level::ForceWarn, None) => sess.struct_warn(""),
321319
(Level::Deny | Level::Forbid, Some(span)) => {
322320
let mut builder = sess.diagnostic().struct_err_lint("");
323321
builder.set_span(span);

compiler/rustc_session/src/session.rs

-10
Original file line numberDiff line numberDiff line change
@@ -306,13 +306,6 @@ impl Session {
306306
pub fn struct_span_warn<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> DiagnosticBuilder<'_> {
307307
self.diagnostic().struct_span_warn(sp, msg)
308308
}
309-
pub fn struct_span_force_warn<S: Into<MultiSpan>>(
310-
&self,
311-
sp: S,
312-
msg: &str,
313-
) -> DiagnosticBuilder<'_> {
314-
self.diagnostic().struct_span_force_warn(sp, msg)
315-
}
316309
pub fn struct_span_warn_with_code<S: Into<MultiSpan>>(
317310
&self,
318311
sp: S,
@@ -324,9 +317,6 @@ impl Session {
324317
pub fn struct_warn(&self, msg: &str) -> DiagnosticBuilder<'_> {
325318
self.diagnostic().struct_warn(msg)
326319
}
327-
pub fn struct_force_warn(&self, msg: &str) -> DiagnosticBuilder<'_> {
328-
self.diagnostic().struct_force_warn(msg)
329-
}
330320
pub fn struct_span_allow<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> DiagnosticBuilder<'_> {
331321
self.diagnostic().struct_span_allow(sp, msg)
332322
}

0 commit comments

Comments
 (0)