Skip to content

Commit

Permalink
rustc_errors: handle force_warn only through DiagnosticId::Lint.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Feb 23, 2022
1 parent 02ff9e0 commit d4fc5ae
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 42 deletions.
34 changes: 6 additions & 28 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,27 +632,15 @@ impl Handler {

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

/// Construct a builder at the `Warning` level at the given `span` and with the `msg`.
///
/// This will "force" the warning meaning it will not be canceled even
/// if warnings cannot be emitted.
pub fn struct_span_force_warn(
&self,
span: impl Into<MultiSpan>,
msg: &str,
) -> DiagnosticBuilder<'_> {
let mut result = self.struct_force_warn(msg);
result.set_span(span);
result
}

/// Construct a builder at the `Allow` level at the given `span` and with the `msg`.
pub fn struct_span_allow(
&self,
Expand All @@ -679,20 +667,10 @@ impl Handler {

/// Construct a builder at the `Warning` level with the `msg`.
///
/// The builder will be canceled if warnings cannot be emitted.
/// Attempting to `.emit()` the builder will only emit if either:
/// * `can_emit_warnings` is `true`
/// * `is_force_warn` was set in `DiagnosticId::Lint`
pub fn struct_warn(&self, msg: &str) -> DiagnosticBuilder<'_> {
let mut result = DiagnosticBuilder::new(self, Level::Warning, msg);
if !self.flags.can_emit_warnings {
result.cancel();
}
result
}

/// Construct a builder at the `Warning` level with the `msg`.
///
/// This will "force" a warning meaning it will not be canceled even
/// if warnings cannot be emitted.
pub fn struct_force_warn(&self, msg: &str) -> DiagnosticBuilder<'_> {
DiagnosticBuilder::new(self, Level::Warning, msg)
}

Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_middle/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,8 @@ pub fn struct_lint_level<'s, 'd>(
return;
}
}
(Level::Warn, Some(span)) => sess.struct_span_warn(span, ""),
(Level::Warn, None) => sess.struct_warn(""),
(Level::ForceWarn, Some(span)) => sess.struct_span_force_warn(span, ""),
(Level::ForceWarn, None) => sess.struct_force_warn(""),
(Level::Warn | Level::ForceWarn, Some(span)) => sess.struct_span_warn(span, ""),
(Level::Warn | Level::ForceWarn, None) => sess.struct_warn(""),
(Level::Deny | Level::Forbid, Some(span)) => {
let mut builder = sess.diagnostic().struct_err_lint("");
builder.set_span(span);
Expand Down
10 changes: 0 additions & 10 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,6 @@ impl Session {
pub fn struct_span_warn<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> DiagnosticBuilder<'_> {
self.diagnostic().struct_span_warn(sp, msg)
}
pub fn struct_span_force_warn<S: Into<MultiSpan>>(
&self,
sp: S,
msg: &str,
) -> DiagnosticBuilder<'_> {
self.diagnostic().struct_span_force_warn(sp, msg)
}
pub fn struct_span_warn_with_code<S: Into<MultiSpan>>(
&self,
sp: S,
Expand All @@ -324,9 +317,6 @@ impl Session {
pub fn struct_warn(&self, msg: &str) -> DiagnosticBuilder<'_> {
self.diagnostic().struct_warn(msg)
}
pub fn struct_force_warn(&self, msg: &str) -> DiagnosticBuilder<'_> {
self.diagnostic().struct_force_warn(msg)
}
pub fn struct_span_allow<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> DiagnosticBuilder<'_> {
self.diagnostic().struct_span_allow(sp, msg)
}
Expand Down

0 comments on commit d4fc5ae

Please sign in to comment.