Skip to content

Commit b544231

Browse files
committed
Use is_diagnostic_item to detect format_args/format_args_nl
1 parent 74b9f8e commit b544231

File tree

3 files changed

+10
-7
lines changed
  • compiler
    • rustc_span/src
    • rustc_trait_selection/src/error_reporting/traits
  • library/core/src/macros

3 files changed

+10
-7
lines changed

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,7 @@ symbols! {
10271027
format_args_capture,
10281028
format_args_macro,
10291029
format_args_nl,
1030+
format_args_nl_macro,
10301031
format_argument,
10311032
format_arguments,
10321033
format_count,

compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,14 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
178178

179179
match e.obligation.predicate.kind().skip_binder() {
180180
ty::PredicateKind::Subtype(_)
181-
if matches! (
182-
outer_expn_data.kind,
183-
ExpnKind::Macro(_, name) if matches!(
184-
name.as_str().rsplit("::").next(),
185-
Some("format_args" | "format_args_nl")
186-
)
187-
) =>
181+
if let Some(def_id) = outer_expn_data.macro_def_id
182+
&& (self
183+
.tcx
184+
.is_diagnostic_item(rustc_span::sym::format_args_nl_macro, def_id)
185+
|| self.tcx.is_diagnostic_item(
186+
rustc_span::sym::format_args_macro,
187+
def_id,
188+
)) =>
188189
{
189190
let sm = self.tcx.sess.source_map();
190191
let lc = sm.span_to_location_info(span);

library/core/src/macros/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,7 @@ pub(crate) mod builtin {
10121012
///
10131013
/// This macro will be removed once `format_args` is allowed in const contexts.
10141014
#[unstable(feature = "const_format_args", issue = "none")]
1015+
#[rustc_diagnostic_item = "format_args_nl_macro"]
10151016
#[allow_internal_unstable(fmt_internals, const_fmt_arguments_new)]
10161017
#[rustc_builtin_macro]
10171018
#[macro_export]

0 commit comments

Comments
 (0)