Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e89626f

Browse files
committedMay 2, 2021
Disable trivial_cast_lint inside format_args expansion.
1 parent 3259ba1 commit e89626f

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed
 

‎compiler/rustc_builtin_macros/src/format.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -610,11 +610,11 @@ impl<'a, 'b> Context<'a, 'b> {
610610
let string_length = self.ecx.expr_usize(sp, self.literal.len());
611611
let string = self.ecx.expr_str(sp, Symbol::intern(&self.literal));
612612
let string_as_ptr = self.ecx.expr_cast(
613-
sp,
613+
self.macsp,
614614
string,
615615
self.ecx.ty_ptr(
616-
sp,
617-
self.ecx.ty_path(self.ecx.path_ident(sp, Ident::new(sym::str, sp))),
616+
self.macsp,
617+
self.ecx.ty_path(self.ecx.path_ident(self.macsp, Ident::new(sym::str, self.macsp))),
618618
Mutability::Not,
619619
),
620620
);

‎compiler/rustc_typeck/src/check/cast.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,11 @@ impl<'a, 'tcx> CastCheck<'tcx> {
541541
}
542542

543543
fn trivial_cast_lint(&self, fcx: &FnCtxt<'a, 'tcx>) {
544+
if let Some(id) = self.span.ctxt().outer_expn_data().macro_def_id {
545+
if fcx.tcx.is_diagnostic_item(sym::format_args, id) {
546+
return;
547+
}
548+
}
544549
let t_cast = self.cast_ty;
545550
let t_expr = self.expr_ty;
546551
let type_asc_or =

‎library/core/src/macros/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,7 @@ pub(crate) mod builtin {
826826
#[allow_internal_unstable(fmt_internals)]
827827
#[rustc_builtin_macro]
828828
#[macro_export]
829+
#[rustc_diagnostic_item = "format_args"]
829830
macro_rules! format_args {
830831
($fmt:expr) => {{ /* compiler built-in */ }};
831832
($fmt:expr, $($args:tt)*) => {{ /* compiler built-in */ }};

0 commit comments

Comments
 (0)
Please sign in to comment.