Skip to content

Commit ff9fd36

Browse files
Implement IntoDiagnosticArg for hir::ConstContext
1 parent 1c4afbd commit ff9fd36

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3813,6 +3813,7 @@ dependencies = [
38133813
"atty",
38143814
"rustc_data_structures",
38153815
"rustc_error_messages",
3816+
"rustc_hir",
38163817
"rustc_lint_defs",
38173818
"rustc_macros",
38183819
"rustc_serialize",

compiler/rustc_errors/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ rustc_serialize = { path = "../rustc_serialize" }
1313
rustc_span = { path = "../rustc_span" }
1414
rustc_macros = { path = "../rustc_macros" }
1515
rustc_data_structures = { path = "../rustc_data_structures" }
16+
rustc_hir = { path = "../rustc_hir" }
1617
rustc_lint_defs = { path = "../rustc_lint_defs" }
1718
unicode-width = "0.1.4"
1819
atty = "0.2"

compiler/rustc_errors/src/diagnostic.rs

+11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::{
55
};
66
use rustc_data_structures::stable_map::FxHashMap;
77
use rustc_error_messages::FluentValue;
8+
use rustc_hir as hir;
89
use rustc_lint_defs::{Applicability, LintExpectationId};
910
use rustc_span::edition::LATEST_STABLE_EDITION;
1011
use rustc_span::symbol::{Ident, Symbol};
@@ -160,6 +161,16 @@ impl<'source> Into<FluentValue<'source>> for DiagnosticArgValue<'source> {
160161
}
161162
}
162163

164+
impl IntoDiagnosticArg for hir::ConstContext {
165+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
166+
DiagnosticArgValue::Str(Cow::Borrowed(match self {
167+
hir::ConstContext::ConstFn => "constant function",
168+
hir::ConstContext::Static(_) => "static",
169+
hir::ConstContext::Const => "constant",
170+
}))
171+
}
172+
}
173+
163174
/// Trait implemented by error types. This should not be implemented manually. Instead, use
164175
/// `#[derive(SessionSubdiagnostic)]` -- see [rustc_macros::SessionSubdiagnostic].
165176
#[rustc_diagnostic_item = "AddSubdiagnostic"]

compiler/rustc_hir/src/hir.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1595,6 +1595,9 @@ impl fmt::Display for ConstContext {
15951595
}
15961596
}
15971597

1598+
// NOTE: `IntoDiagnosticArg` impl for `ConstContext` lives in `rustc_errors`
1599+
// due to a cyclical dependency between hir that crate.
1600+
15981601
/// A literal.
15991602
pub type Lit = Spanned<LitKind>;
16001603

0 commit comments

Comments
 (0)