Skip to content

Commit f8448ab

Browse files
committed
Use is_diagnostic_item to detect format_args/format_args_nl
1 parent 80049c8 commit f8448ab

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
@@ -1056,6 +1056,7 @@ symbols! {
10561056
format_args_capture,
10571057
format_args_macro,
10581058
format_args_nl,
1059+
format_args_nl_macro,
10591060
format_argument,
10601061
format_arguments,
10611062
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
@@ -188,13 +188,14 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
188188

189189
match e.obligation.predicate.kind().skip_binder() {
190190
ty::PredicateKind::Subtype(_)
191-
if matches! (
192-
outer_expn_data.kind,
193-
ExpnKind::Macro(_, name) if matches!(
194-
name.as_str().rsplit("::").next(),
195-
Some("format_args" | "format_args_nl")
196-
)
197-
) =>
191+
if let Some(def_id) = outer_expn_data.macro_def_id
192+
&& (self
193+
.tcx
194+
.is_diagnostic_item(rustc_span::sym::format_args_nl_macro, def_id)
195+
|| self.tcx.is_diagnostic_item(
196+
rustc_span::sym::format_args_macro,
197+
def_id,
198+
)) =>
198199
{
199200
let sm = self.tcx.sess.source_map();
200201
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)