Skip to content

Commit a3bd2a6

Browse files
committed
transpile: add SrcLoc to pref_align_of warning
1 parent cdfc7af commit a3bd2a6

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

  • c2rust-transpile/src/translator

c2rust-transpile/src/translator/mod.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3379,6 +3379,7 @@ impl<'c> Translation<'c> {
33793379
&self,
33803380
mut type_id: CTypeId,
33813381
preferred: bool,
3382+
src_loc: &Option<SrcSpan>,
33823383
) -> TranslationResult<WithStmts<Box<Expr>>> {
33833384
type_id = self.variable_array_base_type(type_id);
33843385

@@ -3400,10 +3401,13 @@ impl<'c> Translation<'c> {
34003401
path.push(mk().path_segment_with_args("pref_align_of", mk().angle_bracketed_args(tys)));
34013402
} else {
34023403
if preferred {
3403-
warn!(
3404-
"using `core::mem::align_of` instead of `core::intrinsics::pref_align_of` \
3405-
for preferred alignment (`__alignof`/`__alignof__`) as the latter has been removed in Rust"
3406-
);
3404+
let msg = "using `core::mem::align_of` instead of `core::intrinsics::pref_align_of` \
3405+
for preferred alignment (`__alignof`/`__alignof__`) as the latter has been removed in Rust";
3406+
if let Some(loc) = self.ast_context.display_loc(src_loc) {
3407+
warn!("{loc}: {msg}");
3408+
} else {
3409+
warn!("{msg}");
3410+
}
34073411
}
34083412
path.push(mk().path_segment("mem"));
34093413
path.push(mk().path_segment_with_args("align_of", mk().angle_bracketed_args(tys)));
@@ -3536,8 +3540,12 @@ impl<'c> Translation<'c> {
35363540
}
35373541
}
35383542
},
3539-
UnTypeOp::AlignOf => self.compute_align_of_type(arg_ty.ctype, false)?,
3540-
UnTypeOp::PreferredAlignOf => self.compute_align_of_type(arg_ty.ctype, true)?,
3543+
UnTypeOp::AlignOf => {
3544+
self.compute_align_of_type(arg_ty.ctype, false, src_loc)?
3545+
}
3546+
UnTypeOp::PreferredAlignOf => {
3547+
self.compute_align_of_type(arg_ty.ctype, true, src_loc)?
3548+
}
35413549
};
35423550

35433551
Ok(result)

0 commit comments

Comments
 (0)