Skip to content

Commit 2fe4b7f

Browse files
committed
Rename is_disaligned to is_potentially_disaligned for better semantic clarity; Unified to ty::Array(element_ty, _) | ty::Slice(element_ty) => …;
Modify Chinese comments to English comments
1 parent 4620527 commit 2fe4b7f

File tree

5 files changed

+9
-19
lines changed

5 files changed

+9
-19
lines changed

compiler/rustc_const_eval/src/util/alignment.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use tracing::debug;
66
/// Returns `true` if this place is allowed to be less aligned
77
/// than its containing struct (because it is within a packed
88
/// struct).
9-
pub fn is_disaligned<'tcx, L>(
9+
pub fn is_potentially_disaligned<'tcx, L>(
1010
tcx: TyCtxt<'tcx>,
1111
local_decls: &L,
1212
typing_env: ty::TypingEnv<'tcx>,
@@ -73,21 +73,10 @@ where
7373
/// Try to determine the alignment of an array element type
7474
fn get_element_alignment<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<Align> {
7575
match ty.kind() {
76-
ty::Array(element_ty, _) => {
77-
// For arrays, the alignment is the same as the element type
76+
ty::Array(element_ty, _) | ty::Slice(element_ty) => {
77+
// For arrays and slices, the alignment is the same as the element type
7878
let param_env = ty::ParamEnv::empty();
79-
let typing_env =
80-
ty::TypingEnv { typing_mode: ty::TypingMode::non_body_analysis(), param_env };
81-
match tcx.layout_of(typing_env.as_query_input(*element_ty)) {
82-
Ok(layout) => Some(layout.align.abi),
83-
Err(_) => None,
84-
}
85-
}
86-
ty::Slice(element_ty) => {
87-
// For slices, the alignment is the same as the element type
88-
let param_env = ty::ParamEnv::empty();
89-
let typing_env =
90-
ty::TypingEnv { typing_mode: ty::TypingMode::non_body_analysis(), param_env };
79+
let typing_env = ty::TypingEnv { typing_mode: ty::TypingMode::non_body_analysis(), param_env };
9180
match tcx.layout_of(typing_env.as_query_input(*element_ty)) {
9281
Ok(layout) => Some(layout.align.abi),
9382
Err(_) => None,
@@ -96,6 +85,7 @@ fn get_element_alignment<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<Align>
9685
_ => None,
9786
}
9887
}
88+
9989
pub fn is_within_packed<'tcx, L>(
10090
tcx: TyCtxt<'tcx>,
10191
local_decls: &L,

compiler/rustc_const_eval/src/util/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mod check_validity_requirement;
66
mod compare_types;
77
mod type_name;
88

9-
pub use self::alignment::{is_disaligned, is_within_packed};
9+
pub use self::alignment::{is_potentially_disaligned, is_within_packed};
1010
pub use self::check_validity_requirement::check_validity_requirement;
1111
pub(crate) use self::check_validity_requirement::validate_scalar_in_layout;
1212
pub use self::compare_types::{relate_types, sub_types};

compiler/rustc_mir_transform/src/add_moves_for_packed_drops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl<'tcx> crate::MirPass<'tcx> for AddMovesForPackedDrops {
5151

5252
match terminator.kind {
5353
TerminatorKind::Drop { place, .. }
54-
if util::is_disaligned(tcx, body, typing_env, place) =>
54+
if util::is_potentially_disaligned(tcx, body, typing_env, place) =>
5555
{
5656
add_move_for_packed_drop(
5757
tcx,

compiler/rustc_mir_transform/src/check_packed_ref.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl<'tcx> Visitor<'tcx> for PackedRefChecker<'_, 'tcx> {
3737
}
3838

3939
fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, _location: Location) {
40-
if context.is_borrow() && util::is_disaligned(self.tcx, self.body, self.typing_env, *place)
40+
if context.is_borrow() && util::is_potentially_disaligned(self.tcx, self.body, self.typing_env, *place)
4141
{
4242
let def_id = self.body.source.instance.def_id();
4343
if let Some(impl_def_id) = self.tcx.impl_of_assoc(def_id)

tests/ui/packed/packed-array-const-generic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ struct PascalString<const CAP: usize> {
88
}
99

1010
fn bar<const CAP: usize>(s: &PascalString<CAP>) -> &str {
11-
// 目标:这行不应触发 E0793
11+
// Goal: this line should not trigger E0793
1212
std::str::from_utf8(&s.buf[0..s.len as usize]).unwrap()
1313
}
1414

0 commit comments

Comments
 (0)