From 0f6982432c79f8d9047930ec6914c6141dd21c55 Mon Sep 17 00:00:00 2001 From: Jaic1 <506933131@qq.com> Date: Sun, 27 Mar 2022 17:45:28 +0800 Subject: [PATCH 1/4] First submit --- CHANGELOG.md | 1 + clippy_lints/src/lib.register_lints.rs | 1 + clippy_lints/src/lib.register_pedantic.rs | 1 + clippy_lints/src/lib.rs | 3 + clippy_lints/src/static_items_large_align.rs | 93 ++++++++++++++++++ clippy_lints/src/utils/conf.rs | 5 + .../static_items_large_align/clippy.toml | 1 + .../static_items_large_align.rs | 37 ++++++++ tests/ui/static_items_large_align.rs | 37 ++++++++ tests/ui/static_items_large_align.stderr | 94 +++++++++++++++++++ 10 files changed, 273 insertions(+) create mode 100644 clippy_lints/src/static_items_large_align.rs create mode 100644 tests/ui-toml/static_items_large_align/clippy.toml create mode 100644 tests/ui-toml/static_items_large_align/static_items_large_align.rs create mode 100644 tests/ui/static_items_large_align.rs create mode 100644 tests/ui/static_items_large_align.stderr diff --git a/CHANGELOG.md b/CHANGELOG.md index 257add86b6e5..465469beb499 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4064,6 +4064,7 @@ Released 2018-09-13 [`skip_while_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#skip_while_next [`slow_vector_initialization`]: https://rust-lang.github.io/rust-clippy/master/index.html#slow_vector_initialization [`stable_sort_primitive`]: https://rust-lang.github.io/rust-clippy/master/index.html#stable_sort_primitive +[`static_items_large_align`]: https://rust-lang.github.io/rust-clippy/master/index.html#static_items_large_align [`std_instead_of_alloc`]: https://rust-lang.github.io/rust-clippy/master/index.html#std_instead_of_alloc [`std_instead_of_core`]: https://rust-lang.github.io/rust-clippy/master/index.html#std_instead_of_core [`str_to_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#str_to_string diff --git a/clippy_lints/src/lib.register_lints.rs b/clippy_lints/src/lib.register_lints.rs index 13b573beea1b..adb97fd16c76 100644 --- a/clippy_lints/src/lib.register_lints.rs +++ b/clippy_lints/src/lib.register_lints.rs @@ -515,6 +515,7 @@ store.register_lints(&[ single_component_path_imports::SINGLE_COMPONENT_PATH_IMPORTS, size_of_in_element_count::SIZE_OF_IN_ELEMENT_COUNT, slow_vector_initialization::SLOW_VECTOR_INITIALIZATION, + static_items_large_align::STATIC_ITEMS_LARGE_ALIGN, std_instead_of_core::ALLOC_INSTEAD_OF_CORE, std_instead_of_core::STD_INSTEAD_OF_ALLOC, std_instead_of_core::STD_INSTEAD_OF_CORE, diff --git a/clippy_lints/src/lib.register_pedantic.rs b/clippy_lints/src/lib.register_pedantic.rs index 03c3c202e0a8..0539285c1530 100644 --- a/clippy_lints/src/lib.register_pedantic.rs +++ b/clippy_lints/src/lib.register_pedantic.rs @@ -87,6 +87,7 @@ store.register_group(true, "clippy::pedantic", Some("clippy_pedantic"), vec![ LintId::of(ref_option_ref::REF_OPTION_REF), LintId::of(return_self_not_must_use::RETURN_SELF_NOT_MUST_USE), LintId::of(semicolon_if_nothing_returned::SEMICOLON_IF_NOTHING_RETURNED), + LintId::of(static_items_large_align::STATIC_ITEMS_LARGE_ALIGN), LintId::of(strings::STRING_ADD_ASSIGN), LintId::of(transmute::TRANSMUTE_PTR_TO_PTR), LintId::of(types::LINKEDLIST), diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index a26e129f094e..b1ffe00b8ce9 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -356,6 +356,7 @@ mod single_char_lifetime_names; mod single_component_path_imports; mod size_of_in_element_count; mod slow_vector_initialization; +mod static_items_large_align; mod std_instead_of_core; mod strings; mod strlen_on_c_strings; @@ -902,6 +903,8 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: store.register_late_pass(|| Box::new(unused_peekable::UnusedPeekable)); store.register_early_pass(|| Box::new(multi_assignments::MultiAssignments)); store.register_late_pass(|| Box::new(bool_to_int_with_if::BoolToIntWithIf)); + let page_size = conf.page_size; + store.register_late_pass(move || Box::new(static_items_large_align::StaticItemsLargeAlign { page_size })); // add lints here, do not remove this comment, it's used in `new_lint` } diff --git a/clippy_lints/src/static_items_large_align.rs b/clippy_lints/src/static_items_large_align.rs new file mode 100644 index 000000000000..2ec5bae67c25 --- /dev/null +++ b/clippy_lints/src/static_items_large_align.rs @@ -0,0 +1,93 @@ +use clippy_utils::diagnostics::span_lint_and_note; +use rustc_hir::{Item, ItemKind}; +use rustc_lint::{LateContext, LateLintPass}; +use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt}; +use rustc_session::{declare_tool_lint, impl_lint_pass}; +use rustc_target::abi::Align; +use rustc_typeck::hir_ty_to_ty; + +pub struct StaticItemsLargeAlign { + pub page_size: u64, +} + +declare_clippy_lint! { + /// ### What it does + /// Check for usage of static items which have type alignment larger than page size. + /// + /// ### Why is this bad? + /// Due to some known unsound issues, the type alignment may not be fulfilled. + /// For more information, see: + /// and + /// . + /// + /// ### Example + /// ```rust + /// #[repr(align(0x100000))] + /// struct Aligned(u8); + /// + /// static X: Aligned = Aligned(0); // Bad + /// + /// fn main() { + /// let x = Aligned(0); // Good + /// println!("{:#x}", &x as *const _ as usize); + /// println!("{:#x}", &X as *const _ as usize); + /// let b = Box::new(Aligned(0)); // Good + /// println!("{:#x}", Box::into_raw(b) as usize); + /// } + #[clippy::version = "1.61.0"] + pub STATIC_ITEMS_LARGE_ALIGN, + pedantic, + "static items with large type alignment, which may trigger unsound problems" +} +impl_lint_pass!(StaticItemsLargeAlign => [STATIC_ITEMS_LARGE_ALIGN]); + +impl LateLintPass<'_> for StaticItemsLargeAlign { + fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) { + if_chain! { + if let ItemKind::Static(hir_ty, _, _) = item.kind; + let ty = hir_ty_to_ty(cx.tcx, hir_ty); + if let Some(adt_ref) = self.check_ty_alignment(cx.tcx, ty); + let def_span = cx.tcx.def_span(adt_ref.did()); + then { + span_lint_and_note( + cx, + STATIC_ITEMS_LARGE_ALIGN, + item.span, + "this static item (itself or its subfield) has large type alignment, which may not be fulfilled,\n\ + for more information, see ", + Some(def_span), + format!("this type has an alignment larger than page size ({}KB)", self.page_size/1024).as_str() + ); + } + } + } +} + +impl StaticItemsLargeAlign { + /// It checks a type with the following steps: + /// 1. picks out this type if its kind is among adt, array, tuple or ref to them; + /// otherwise return None + /// 2. check if its (or its inner fields') alignment are larger than page size + /// 3. return one of them; + /// otherwise return None + fn check_ty_alignment<'tcx>(&self, tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option> { + match ty.kind() { + ty::Adt(adt_ref, subst_ref) => { + if let Some(align) = adt_ref.repr().align && + align > Align::from_bytes(self.page_size).unwrap() + { + Some(*adt_ref) + } else { + adt_ref.all_fields() + .map(|field_ref| field_ref.ty(tcx, subst_ref)) + .find_map(|ty| self.check_ty_alignment(tcx, ty)) + } + }, + ty::Array(ty, _) => self.check_ty_alignment(tcx, *ty), + ty::Tuple(ty_list) => ty_list.iter() + .find_map(|ty| self.check_ty_alignment(tcx, ty)), + ty::Ref(region, ty, _) if region.is_static() => self.check_ty_alignment(tcx, *ty), + _ => None, + } + } +} diff --git a/clippy_lints/src/utils/conf.rs b/clippy_lints/src/utils/conf.rs index 84e65d5fa0b7..ee4994f15467 100644 --- a/clippy_lints/src/utils/conf.rs +++ b/clippy_lints/src/utils/conf.rs @@ -383,6 +383,11 @@ define_Conf! { /// /// The maximum size of the `Err`-variant in a `Result` returned from a function (large_error_threshold: u64 = 128), + /// Lint: STATIC_ITEMS_LARGE_ALIGN. + /// + /// The page size of the target platform. It is useful when we know the exact page size and know that + /// it could be fulfilled (e.g., when we are targeting embedded platforms). + (page_size: u64 = 4096), } /// Search for the configuration file. diff --git a/tests/ui-toml/static_items_large_align/clippy.toml b/tests/ui-toml/static_items_large_align/clippy.toml new file mode 100644 index 000000000000..b10ec23a5055 --- /dev/null +++ b/tests/ui-toml/static_items_large_align/clippy.toml @@ -0,0 +1 @@ +page-size = 0x100000 diff --git a/tests/ui-toml/static_items_large_align/static_items_large_align.rs b/tests/ui-toml/static_items_large_align/static_items_large_align.rs new file mode 100644 index 000000000000..d6f9be3b25a0 --- /dev/null +++ b/tests/ui-toml/static_items_large_align/static_items_large_align.rs @@ -0,0 +1,37 @@ +// The example is adapted from https://github.com/rust-lang/rust/issues/70022 + +#![warn(clippy::static_items_large_align)] + +#[repr(align(0x100000))] +#[derive(Clone, Copy)] +struct Aligned(u8); + +struct AlignedWrapper { + f: u8, + g: Aligned, +} + +enum AlignedEnum { + A(Aligned), +} + +struct AlignedGeneric(T); + +static X: Aligned = Aligned(0); + +static X_REF: &Aligned = &Aligned(0); + +static ARRAY: [Aligned; 10] = [Aligned(0); 10]; + +static TUPLE: (u8, Aligned) = (0, Aligned(0)); + +static XW: AlignedWrapper = AlignedWrapper { f: 0, g: Aligned(0) }; + +static XE: AlignedEnum = AlignedEnum::A(Aligned(0)); + +static XG: AlignedGeneric = AlignedGeneric(Aligned(0)); + +fn main() { + let x = Aligned(0); + println!("{:#x}", Box::into_raw(Box::new(Aligned(0))) as usize); +} diff --git a/tests/ui/static_items_large_align.rs b/tests/ui/static_items_large_align.rs new file mode 100644 index 000000000000..d6f9be3b25a0 --- /dev/null +++ b/tests/ui/static_items_large_align.rs @@ -0,0 +1,37 @@ +// The example is adapted from https://github.com/rust-lang/rust/issues/70022 + +#![warn(clippy::static_items_large_align)] + +#[repr(align(0x100000))] +#[derive(Clone, Copy)] +struct Aligned(u8); + +struct AlignedWrapper { + f: u8, + g: Aligned, +} + +enum AlignedEnum { + A(Aligned), +} + +struct AlignedGeneric(T); + +static X: Aligned = Aligned(0); + +static X_REF: &Aligned = &Aligned(0); + +static ARRAY: [Aligned; 10] = [Aligned(0); 10]; + +static TUPLE: (u8, Aligned) = (0, Aligned(0)); + +static XW: AlignedWrapper = AlignedWrapper { f: 0, g: Aligned(0) }; + +static XE: AlignedEnum = AlignedEnum::A(Aligned(0)); + +static XG: AlignedGeneric = AlignedGeneric(Aligned(0)); + +fn main() { + let x = Aligned(0); + println!("{:#x}", Box::into_raw(Box::new(Aligned(0))) as usize); +} diff --git a/tests/ui/static_items_large_align.stderr b/tests/ui/static_items_large_align.stderr new file mode 100644 index 000000000000..67555ee23cb0 --- /dev/null +++ b/tests/ui/static_items_large_align.stderr @@ -0,0 +1,94 @@ +error: this static item (itself or its subfield) has large type alignment, which may not be fulfilled, + for more information, see + --> $DIR/static_items_large_align.rs:20:1 + | +LL | static X: Aligned = Aligned(0); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `-D clippy::static-items-large-align` implied by `-D warnings` +note: this type has an alignment larger than page size (4KB) + --> $DIR/static_items_large_align.rs:7:1 + | +LL | struct Aligned(u8); + | ^^^^^^^^^^^^^^^^^^^ + +error: this static item (itself or its subfield) has large type alignment, which may not be fulfilled, + for more information, see + --> $DIR/static_items_large_align.rs:22:1 + | +LL | static X_REF: &Aligned = &Aligned(0); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: this type has an alignment larger than page size (4KB) + --> $DIR/static_items_large_align.rs:7:1 + | +LL | struct Aligned(u8); + | ^^^^^^^^^^^^^^^^^^^ + +error: this static item (itself or its subfield) has large type alignment, which may not be fulfilled, + for more information, see + --> $DIR/static_items_large_align.rs:24:1 + | +LL | static ARRAY: [Aligned; 10] = [Aligned(0); 10]; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: this type has an alignment larger than page size (4KB) + --> $DIR/static_items_large_align.rs:7:1 + | +LL | struct Aligned(u8); + | ^^^^^^^^^^^^^^^^^^^ + +error: this static item (itself or its subfield) has large type alignment, which may not be fulfilled, + for more information, see + --> $DIR/static_items_large_align.rs:26:1 + | +LL | static TUPLE: (u8, Aligned) = (0, Aligned(0)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: this type has an alignment larger than page size (4KB) + --> $DIR/static_items_large_align.rs:7:1 + | +LL | struct Aligned(u8); + | ^^^^^^^^^^^^^^^^^^^ + +error: this static item (itself or its subfield) has large type alignment, which may not be fulfilled, + for more information, see + --> $DIR/static_items_large_align.rs:28:1 + | +LL | static XW: AlignedWrapper = AlignedWrapper { f: 0, g: Aligned(0) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: this type has an alignment larger than page size (4KB) + --> $DIR/static_items_large_align.rs:7:1 + | +LL | struct Aligned(u8); + | ^^^^^^^^^^^^^^^^^^^ + +error: this static item (itself or its subfield) has large type alignment, which may not be fulfilled, + for more information, see + --> $DIR/static_items_large_align.rs:30:1 + | +LL | static XE: AlignedEnum = AlignedEnum::A(Aligned(0)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: this type has an alignment larger than page size (4KB) + --> $DIR/static_items_large_align.rs:7:1 + | +LL | struct Aligned(u8); + | ^^^^^^^^^^^^^^^^^^^ + +error: this static item (itself or its subfield) has large type alignment, which may not be fulfilled, + for more information, see + --> $DIR/static_items_large_align.rs:32:1 + | +LL | static XG: AlignedGeneric = AlignedGeneric(Aligned(0)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: this type has an alignment larger than page size (4KB) + --> $DIR/static_items_large_align.rs:7:1 + | +LL | struct Aligned(u8); + | ^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 7 previous errors + From 216e89d6405cb9caaadcb4a6b55eba3a049bf162 Mon Sep 17 00:00:00 2001 From: Jaic1 <506933131@qq.com> Date: Sun, 27 Mar 2022 19:10:25 +0800 Subject: [PATCH 2/4] Fix dogfood failure --- clippy_lints/src/static_items_large_align.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clippy_lints/src/static_items_large_align.rs b/clippy_lints/src/static_items_large_align.rs index 2ec5bae67c25..ef8b6d4941b7 100644 --- a/clippy_lints/src/static_items_large_align.rs +++ b/clippy_lints/src/static_items_large_align.rs @@ -47,7 +47,6 @@ impl LateLintPass<'_> for StaticItemsLargeAlign { if let ItemKind::Static(hir_ty, _, _) = item.kind; let ty = hir_ty_to_ty(cx.tcx, hir_ty); if let Some(adt_ref) = self.check_ty_alignment(cx.tcx, ty); - let def_span = cx.tcx.def_span(adt_ref.did()); then { span_lint_and_note( cx, @@ -55,7 +54,7 @@ impl LateLintPass<'_> for StaticItemsLargeAlign { item.span, "this static item (itself or its subfield) has large type alignment, which may not be fulfilled,\n\ for more information, see ", - Some(def_span), + Some(cx.tcx.def_span(adt_ref.did())), format!("this type has an alignment larger than page size ({}KB)", self.page_size/1024).as_str() ); } From d07511e3fceee02bd13fd3ba2634039b77ae69c9 Mon Sep 17 00:00:00 2001 From: Jaic1 <506933131@qq.com> Date: Sat, 2 Apr 2022 15:51:18 +0800 Subject: [PATCH 3/4] Report the intermediate spans --- clippy_lints/src/static_items_large_align.rs | 145 ++++++++++--- clippy_lints/src/utils/conf.rs | 2 +- tests/ui/static_items_large_align.rs | 44 +++- tests/ui/static_items_large_align.stderr | 211 ++++++++++++++++--- 4 files changed, 337 insertions(+), 65 deletions(-) diff --git a/clippy_lints/src/static_items_large_align.rs b/clippy_lints/src/static_items_large_align.rs index ef8b6d4941b7..dabca8c77ef2 100644 --- a/clippy_lints/src/static_items_large_align.rs +++ b/clippy_lints/src/static_items_large_align.rs @@ -1,9 +1,10 @@ -use clippy_utils::diagnostics::span_lint_and_note; +use clippy_utils::diagnostics::span_lint_and_then; +use rustc_data_structures::fx::FxHashSet; use rustc_hir::{Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt}; +use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt, TypeAndMut}; use rustc_session::{declare_tool_lint, impl_lint_pass}; -use rustc_target::abi::Align; +use rustc_span::Span; use rustc_typeck::hir_ty_to_ty; pub struct StaticItemsLargeAlign { @@ -46,16 +47,37 @@ impl LateLintPass<'_> for StaticItemsLargeAlign { if_chain! { if let ItemKind::Static(hir_ty, _, _) = item.kind; let ty = hir_ty_to_ty(cx.tcx, hir_ty); - if let Some(adt_ref) = self.check_ty_alignment(cx.tcx, ty); + let mut visited_tys = FxHashSet::default(); + let mut intermediate_tys = Vec::new(); + if let Some(la_ty) = self.check_ty_alignment(cx.tcx, ty, &mut visited_tys, &mut intermediate_tys); then { - span_lint_and_note( + let mut span_notes: Vec<(Span, String)> = Vec::new(); + if !intermediate_tys.is_empty() { + let top_ty = intermediate_tys[0].ty; + if !top_ty.is_adt() { + span_notes.push(( + hir_ty.span, + format!("this {} contains an inner type with large alignment", top_ty.prefix_string(cx.tcx)), + )); + } + intermediate_tys.iter() + .filter_map(|im_ty| Self::report_im_ty(cx, im_ty)) + .for_each(|ss| span_notes.push(ss)); + } + span_notes.push(self.report_la_ty(cx, &la_ty)); + + span_lint_and_then( cx, STATIC_ITEMS_LARGE_ALIGN, item.span, - "this static item (itself or its subfield) has large type alignment, which may not be fulfilled,\n\ - for more information, see ", - Some(cx.tcx.def_span(adt_ref.did())), - format!("this type has an alignment larger than page size ({}KB)", self.page_size/1024).as_str() + "this static item (itself or its subfield) has a type alignment,\n\ + which is larger than page size and may not be fulfilled,\n\ + for more information, see .", + move |diag| { + for (span, s) in span_notes { + diag.span_note(span, s.as_str()); + } + } ); } } @@ -64,29 +86,100 @@ impl LateLintPass<'_> for StaticItemsLargeAlign { impl StaticItemsLargeAlign { /// It checks a type with the following steps: - /// 1. picks out this type if its kind is among adt, array, tuple or ref to them; - /// otherwise return None - /// 2. check if its (or its inner fields') alignment are larger than page size - /// 3. return one of them; - /// otherwise return None - fn check_ty_alignment<'tcx>(&self, tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option> { - match ty.kind() { - ty::Adt(adt_ref, subst_ref) => { - if let Some(align) = adt_ref.repr().align && - align > Align::from_bytes(self.page_size).unwrap() + /// 1. Check if the type is already visited (for a static item), + /// if not, continue; + /// otherwise, return `None` early. + /// 2. Push the type in the checked types. + /// 3. Pick out this type if its kind is among adt, tuple, array, ref or raw ptr to them; + /// otherwise return `None`. + /// 4. Check if its (or its inner fields') alignment are larger than page size. + /// 5. Return one of them; + /// otherwise pop the current checked type and return `None`. + fn check_ty_alignment<'tcx>( + &self, + tcx: TyCtxt<'tcx>, + ty: Ty<'tcx>, + visited_tys: &mut FxHashSet>, + intermediate_tys: &mut Vec>, + ) -> Option> { + if visited_tys.contains(&ty) { + return None; + } + visited_tys.insert(ty); + intermediate_tys.push(IntermediateTy { ty }); + + let ret = match ty.kind() { + ty::Adt(adt_def, subst_ref) => { + if let Some(align) = adt_def.repr().align && + align.bytes() > self.page_size { - Some(*adt_ref) + intermediate_tys.pop(); // the last element is already in the return value + Some(LargeAlignmentTy { + adt: *adt_def, + name: ty.sort_string(tcx).into_owned(), + align: align.bytes(), + }) } else { - adt_ref.all_fields() + adt_def.all_fields() .map(|field_ref| field_ref.ty(tcx, subst_ref)) - .find_map(|ty| self.check_ty_alignment(tcx, ty)) + .find_map(|ty| self.check_ty_alignment(tcx, ty, visited_tys, intermediate_tys)) } }, - ty::Array(ty, _) => self.check_ty_alignment(tcx, *ty), - ty::Tuple(ty_list) => ty_list.iter() - .find_map(|ty| self.check_ty_alignment(tcx, ty)), - ty::Ref(region, ty, _) if region.is_static() => self.check_ty_alignment(tcx, *ty), + ty::Tuple(ty_list) => ty_list + .iter() + .find_map(|ty| self.check_ty_alignment(tcx, ty, visited_tys, intermediate_tys)), + ty::Array(ty, _) | ty::Ref(_, ty, _) | ty::RawPtr(TypeAndMut { ty, .. }) => { + self.check_ty_alignment(tcx, *ty, visited_tys, intermediate_tys) + }, _ => None, + }; + + if ret.is_none() { + intermediate_tys.pop(); + } + ret + } + + fn report_im_ty(cx: &LateContext<'_>, im_ty: &IntermediateTy<'_>) -> Option<(Span, String)> { + let ty = im_ty.ty; + if let ty::Adt(adt_def, substs_ref) = ty.kind() { + Some(( + cx.tcx.def_span(adt_def.did()), + if substs_ref.is_empty() { + format!("{} contains an inner type with large alignment", ty.sort_string(cx.tcx)) + } else { + // TODO - can we use :#? + format!( + "{} with substitutions {:#?},\n\ + contains an inner type with large alignment", + ty.sort_string(cx.tcx), + substs_ref + ) + }, + )) + } else { + None } } + + fn report_la_ty(&self, cx: &LateContext<'_>, la_ty: &LargeAlignmentTy<'_>) -> (Span, String) { + ( + cx.tcx.def_span(la_ty.adt.did()), + format!( + "{} has alignment {:#x}, which is larger than {:#x},\n\ + if you know what you are doing, config the default page size clippy uses in clippy.toml", + la_ty.name, la_ty.align, self.page_size, + ), + ) + } +} + +struct IntermediateTy<'tcx> { + ty: Ty<'tcx>, +} + +struct LargeAlignmentTy<'tcx> { + adt: AdtDef<'tcx>, + name: String, + align: u64, } diff --git a/clippy_lints/src/utils/conf.rs b/clippy_lints/src/utils/conf.rs index ee4994f15467..a9393879ae47 100644 --- a/clippy_lints/src/utils/conf.rs +++ b/clippy_lints/src/utils/conf.rs @@ -387,7 +387,7 @@ define_Conf! { /// /// The page size of the target platform. It is useful when we know the exact page size and know that /// it could be fulfilled (e.g., when we are targeting embedded platforms). - (page_size: u64 = 4096), + (page_size: u64 = 0x1000), } /// Search for the configuration file. diff --git a/tests/ui/static_items_large_align.rs b/tests/ui/static_items_large_align.rs index d6f9be3b25a0..74c6dceca12c 100644 --- a/tests/ui/static_items_large_align.rs +++ b/tests/ui/static_items_large_align.rs @@ -15,23 +15,61 @@ enum AlignedEnum { A(Aligned), } +struct AlignedPtr(*const Aligned); + +unsafe impl Sync for AlignedPtr {} + struct AlignedGeneric(T); static X: Aligned = Aligned(0); static X_REF: &Aligned = &Aligned(0); -static ARRAY: [Aligned; 10] = [Aligned(0); 10]; - -static TUPLE: (u8, Aligned) = (0, Aligned(0)); +static X_PTR: AlignedPtr = AlignedPtr(&Aligned(0) as *const _); static XW: AlignedWrapper = AlignedWrapper { f: 0, g: Aligned(0) }; +static ARRAY: [Aligned; 10] = [Aligned(0); 10]; + +static TUPLE: (u8, (Aligned, u8)) = (0, (Aligned(0), 0)); + static XE: AlignedEnum = AlignedEnum::A(Aligned(0)); static XG: AlignedGeneric = AlignedGeneric(Aligned(0)); +static XGW: AlignedGeneric = AlignedGeneric(AlignedWrapper { f: 0, g: Aligned(0) }); + fn main() { let x = Aligned(0); println!("{:#x}", Box::into_raw(Box::new(Aligned(0))) as usize); } + +//////////////////////////////////////////////////////////////// +/////////////// below is a more involved example /////////////// +//////////////////////////////////////////////////////////////// + +#[repr(align(0x100000))] +struct AlignedA(u8); + +#[repr(align(0x100000))] +struct AlignedB(u8); + +struct FnPtr(fn() -> Box); + +struct AG(T); + +type AGAlias = AG; + +struct AGWithArgs { + not_aligned: FnPtr, + aligned: AGAlias, +} + +static XG_ARGS: AGWithArgs = AGWithArgs { + not_aligned: FnPtr(box_aligned), + aligned: AG(AlignedB(0)), +}; + +fn box_aligned() -> Box { + Box::new(AlignedA(0)) +} diff --git a/tests/ui/static_items_large_align.stderr b/tests/ui/static_items_large_align.stderr index 67555ee23cb0..098fed63a9c2 100644 --- a/tests/ui/static_items_large_align.stderr +++ b/tests/ui/static_items_large_align.stderr @@ -1,94 +1,235 @@ -error: this static item (itself or its subfield) has large type alignment, which may not be fulfilled, - for more information, see - --> $DIR/static_items_large_align.rs:20:1 +error: this static item (itself or its subfield) has a type alignment, + which is larger than page size and may not be fulfilled, + for more information, see . + --> $DIR/static_items_large_align.rs:24:1 | LL | static X: Aligned = Aligned(0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::static-items-large-align` implied by `-D warnings` -note: this type has an alignment larger than page size (4KB) +note: struct `Aligned` has alignment 0x100000, which is larger than 0x1000, + if you know what you are doing, config the default page size clippy uses in clippy.toml --> $DIR/static_items_large_align.rs:7:1 | LL | struct Aligned(u8); | ^^^^^^^^^^^^^^^^^^^ -error: this static item (itself or its subfield) has large type alignment, which may not be fulfilled, - for more information, see - --> $DIR/static_items_large_align.rs:22:1 +error: this static item (itself or its subfield) has a type alignment, + which is larger than page size and may not be fulfilled, + for more information, see . + --> $DIR/static_items_large_align.rs:26:1 | LL | static X_REF: &Aligned = &Aligned(0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -note: this type has an alignment larger than page size (4KB) +note: this reference contains an inner type with large alignment + --> $DIR/static_items_large_align.rs:26:15 + | +LL | static X_REF: &Aligned = &Aligned(0); + | ^^^^^^^^ +note: struct `Aligned` has alignment 0x100000, which is larger than 0x1000, + if you know what you are doing, config the default page size clippy uses in clippy.toml --> $DIR/static_items_large_align.rs:7:1 | LL | struct Aligned(u8); | ^^^^^^^^^^^^^^^^^^^ -error: this static item (itself or its subfield) has large type alignment, which may not be fulfilled, - for more information, see - --> $DIR/static_items_large_align.rs:24:1 +error: this static item (itself or its subfield) has a type alignment, + which is larger than page size and may not be fulfilled, + for more information, see . + --> $DIR/static_items_large_align.rs:28:1 | -LL | static ARRAY: [Aligned; 10] = [Aligned(0); 10]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | static X_PTR: AlignedPtr = AlignedPtr(&Aligned(0) as *const _); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -note: this type has an alignment larger than page size (4KB) +note: struct `AlignedPtr` contains an inner type with large alignment + --> $DIR/static_items_large_align.rs:18:1 + | +LL | struct AlignedPtr(*const Aligned); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +note: struct `Aligned` has alignment 0x100000, which is larger than 0x1000, + if you know what you are doing, config the default page size clippy uses in clippy.toml --> $DIR/static_items_large_align.rs:7:1 | LL | struct Aligned(u8); | ^^^^^^^^^^^^^^^^^^^ -error: this static item (itself or its subfield) has large type alignment, which may not be fulfilled, - for more information, see - --> $DIR/static_items_large_align.rs:26:1 +error: this static item (itself or its subfield) has a type alignment, + which is larger than page size and may not be fulfilled, + for more information, see . + --> $DIR/static_items_large_align.rs:30:1 + | +LL | static XW: AlignedWrapper = AlignedWrapper { f: 0, g: Aligned(0) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -LL | static TUPLE: (u8, Aligned) = (0, Aligned(0)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +note: struct `AlignedWrapper` contains an inner type with large alignment + --> $DIR/static_items_large_align.rs:9:1 | -note: this type has an alignment larger than page size (4KB) +LL | / struct AlignedWrapper { +LL | | f: u8, +LL | | g: Aligned, +LL | | } + | |_^ +note: struct `Aligned` has alignment 0x100000, which is larger than 0x1000, + if you know what you are doing, config the default page size clippy uses in clippy.toml --> $DIR/static_items_large_align.rs:7:1 | LL | struct Aligned(u8); | ^^^^^^^^^^^^^^^^^^^ -error: this static item (itself or its subfield) has large type alignment, which may not be fulfilled, - for more information, see - --> $DIR/static_items_large_align.rs:28:1 +error: this static item (itself or its subfield) has a type alignment, + which is larger than page size and may not be fulfilled, + for more information, see . + --> $DIR/static_items_large_align.rs:32:1 | -LL | static XW: AlignedWrapper = AlignedWrapper { f: 0, g: Aligned(0) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | static ARRAY: [Aligned; 10] = [Aligned(0); 10]; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: this array contains an inner type with large alignment + --> $DIR/static_items_large_align.rs:32:15 | -note: this type has an alignment larger than page size (4KB) +LL | static ARRAY: [Aligned; 10] = [Aligned(0); 10]; + | ^^^^^^^^^^^^^ +note: struct `Aligned` has alignment 0x100000, which is larger than 0x1000, + if you know what you are doing, config the default page size clippy uses in clippy.toml --> $DIR/static_items_large_align.rs:7:1 | LL | struct Aligned(u8); | ^^^^^^^^^^^^^^^^^^^ -error: this static item (itself or its subfield) has large type alignment, which may not be fulfilled, - for more information, see - --> $DIR/static_items_large_align.rs:30:1 +error: this static item (itself or its subfield) has a type alignment, + which is larger than page size and may not be fulfilled, + for more information, see . + --> $DIR/static_items_large_align.rs:34:1 + | +LL | static TUPLE: (u8, (Aligned, u8)) = (0, (Aligned(0), 0)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: this tuple contains an inner type with large alignment + --> $DIR/static_items_large_align.rs:34:15 + | +LL | static TUPLE: (u8, (Aligned, u8)) = (0, (Aligned(0), 0)); + | ^^^^^^^^^^^^^^^^^^^ +note: struct `Aligned` has alignment 0x100000, which is larger than 0x1000, + if you know what you are doing, config the default page size clippy uses in clippy.toml + --> $DIR/static_items_large_align.rs:7:1 + | +LL | struct Aligned(u8); + | ^^^^^^^^^^^^^^^^^^^ + +error: this static item (itself or its subfield) has a type alignment, + which is larger than page size and may not be fulfilled, + for more information, see . + --> $DIR/static_items_large_align.rs:36:1 | LL | static XE: AlignedEnum = AlignedEnum::A(Aligned(0)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -note: this type has an alignment larger than page size (4KB) +note: enum `AlignedEnum` contains an inner type with large alignment + --> $DIR/static_items_large_align.rs:14:1 + | +LL | / enum AlignedEnum { +LL | | A(Aligned), +LL | | } + | |_^ +note: struct `Aligned` has alignment 0x100000, which is larger than 0x1000, + if you know what you are doing, config the default page size clippy uses in clippy.toml --> $DIR/static_items_large_align.rs:7:1 | LL | struct Aligned(u8); | ^^^^^^^^^^^^^^^^^^^ -error: this static item (itself or its subfield) has large type alignment, which may not be fulfilled, - for more information, see - --> $DIR/static_items_large_align.rs:32:1 +error: this static item (itself or its subfield) has a type alignment, + which is larger than page size and may not be fulfilled, + for more information, see . + --> $DIR/static_items_large_align.rs:38:1 | LL | static XG: AlignedGeneric = AlignedGeneric(Aligned(0)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -note: this type has an alignment larger than page size (4KB) +note: struct `AlignedGeneric` with substitutions [ + Aligned, + ], + contains an inner type with large alignment + --> $DIR/static_items_large_align.rs:22:1 + | +LL | struct AlignedGeneric(T); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +note: struct `Aligned` has alignment 0x100000, which is larger than 0x1000, + if you know what you are doing, config the default page size clippy uses in clippy.toml --> $DIR/static_items_large_align.rs:7:1 | LL | struct Aligned(u8); | ^^^^^^^^^^^^^^^^^^^ -error: aborting due to 7 previous errors +error: this static item (itself or its subfield) has a type alignment, + which is larger than page size and may not be fulfilled, + for more information, see . + --> $DIR/static_items_large_align.rs:40:1 + | +LL | static XGW: AlignedGeneric = AlignedGeneric(AlignedWrapper { f: 0, g: Aligned(0) }); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: struct `AlignedGeneric` with substitutions [ + AlignedWrapper, + ], + contains an inner type with large alignment + --> $DIR/static_items_large_align.rs:22:1 + | +LL | struct AlignedGeneric(T); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +note: struct `AlignedWrapper` contains an inner type with large alignment + --> $DIR/static_items_large_align.rs:9:1 + | +LL | / struct AlignedWrapper { +LL | | f: u8, +LL | | g: Aligned, +LL | | } + | |_^ +note: struct `Aligned` has alignment 0x100000, which is larger than 0x1000, + if you know what you are doing, config the default page size clippy uses in clippy.toml + --> $DIR/static_items_large_align.rs:7:1 + | +LL | struct Aligned(u8); + | ^^^^^^^^^^^^^^^^^^^ + +error: this static item (itself or its subfield) has a type alignment, + which is larger than page size and may not be fulfilled, + for more information, see . + --> $DIR/static_items_large_align.rs:68:1 + | +LL | / static XG_ARGS: AGWithArgs = AGWithArgs { +LL | | not_aligned: FnPtr(box_aligned), +LL | | aligned: AG(AlignedB(0)), +LL | | }; + | |__^ + | +note: struct `AGWithArgs` with substitutions [ + AlignedA, + AlignedB, + ], + contains an inner type with large alignment + --> $DIR/static_items_large_align.rs:63:1 + | +LL | / struct AGWithArgs { +LL | | not_aligned: FnPtr, +LL | | aligned: AGAlias, +LL | | } + | |_^ +note: struct `AG` with substitutions [ + AlignedB, + ], + contains an inner type with large alignment + --> $DIR/static_items_large_align.rs:59:1 + | +LL | struct AG(T); + | ^^^^^^^^^^^^^^^^ +note: struct `AlignedB` has alignment 0x100000, which is larger than 0x1000, + if you know what you are doing, config the default page size clippy uses in clippy.toml + --> $DIR/static_items_large_align.rs:55:1 + | +LL | struct AlignedB(u8); + | ^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 10 previous errors From 53d917bcbfbdbebd789abbb201bf6d27ebe8aee6 Mon Sep 17 00:00:00 2001 From: Jaic1 <506933131@qq.com> Date: Thu, 8 Sep 2022 11:11:02 +0800 Subject: [PATCH 4/4] Fix test failure --- clippy_lints/src/static_items_large_align.rs | 1 + src/docs.rs | 1 + src/docs/static_items_large_align.txt | 24 ++++++++ .../toml_unknown_key/conf_unknown_key.stderr | 1 + tests/ui/static_items_large_align.stderr | 55 ++++++++----------- 5 files changed, 49 insertions(+), 33 deletions(-) create mode 100644 src/docs/static_items_large_align.txt diff --git a/clippy_lints/src/static_items_large_align.rs b/clippy_lints/src/static_items_large_align.rs index dabca8c77ef2..c19eba358317 100644 --- a/clippy_lints/src/static_items_large_align.rs +++ b/clippy_lints/src/static_items_large_align.rs @@ -35,6 +35,7 @@ declare_clippy_lint! { /// let b = Box::new(Aligned(0)); // Good /// println!("{:#x}", Box::into_raw(b) as usize); /// } + /// ``` #[clippy::version = "1.61.0"] pub STATIC_ITEMS_LARGE_ALIGN, pedantic, diff --git a/src/docs.rs b/src/docs.rs index 69243bf4d9c9..7af3c4c199e9 100644 --- a/src/docs.rs +++ b/src/docs.rs @@ -465,6 +465,7 @@ docs! { "skip_while_next", "slow_vector_initialization", "stable_sort_primitive", + "static_items_large_align", "std_instead_of_alloc", "std_instead_of_core", "str_to_string", diff --git a/src/docs/static_items_large_align.txt b/src/docs/static_items_large_align.txt new file mode 100644 index 000000000000..2d0e91e4c68c --- /dev/null +++ b/src/docs/static_items_large_align.txt @@ -0,0 +1,24 @@ +### What it does +Check for usage of static items which have type alignment larger than page size. + +### Why is this bad? +Due to some known unsound issues, the type alignment may not be fulfilled. +For more information, see: + and +. + +### Example +``` +#[repr(align(0x100000))] +struct Aligned(u8); + +static X: Aligned = Aligned(0); // Bad + +fn main() { + let x = Aligned(0); // Good + println!("{:#x}", &x as *const _ as usize); + println!("{:#x}", &X as *const _ as usize); + let b = Box::new(Aligned(0)); // Good + println!("{:#x}", Box::into_raw(b) as usize); +} +``` \ No newline at end of file diff --git a/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr b/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr index a52a0b5289fe..29db06df2f8a 100644 --- a/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr +++ b/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr @@ -27,6 +27,7 @@ error: error reading Clippy's configuration file `$DIR/clippy.toml`: unknown fie max-suggested-slice-pattern-length max-trait-bounds msrv + page-size pass-by-value-size-limit single-char-binding-names-threshold standard-macro-braces diff --git a/tests/ui/static_items_large_align.stderr b/tests/ui/static_items_large_align.stderr index 098fed63a9c2..a565e67d5ea1 100644 --- a/tests/ui/static_items_large_align.stderr +++ b/tests/ui/static_items_large_align.stderr @@ -12,7 +12,7 @@ note: struct `Aligned` has alignment 0x100000, which is larger than 0x1000, --> $DIR/static_items_large_align.rs:7:1 | LL | struct Aligned(u8); - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^ error: this static item (itself or its subfield) has a type alignment, which is larger than page size and may not be fulfilled, @@ -32,7 +32,7 @@ note: struct `Aligned` has alignment 0x100000, which is larger than 0x1000, --> $DIR/static_items_large_align.rs:7:1 | LL | struct Aligned(u8); - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^ error: this static item (itself or its subfield) has a type alignment, which is larger than page size and may not be fulfilled, @@ -46,13 +46,13 @@ note: struct `AlignedPtr` contains an inner type with large alignment --> $DIR/static_items_large_align.rs:18:1 | LL | struct AlignedPtr(*const Aligned); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ note: struct `Aligned` has alignment 0x100000, which is larger than 0x1000, if you know what you are doing, config the default page size clippy uses in clippy.toml --> $DIR/static_items_large_align.rs:7:1 | LL | struct Aligned(u8); - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^ error: this static item (itself or its subfield) has a type alignment, which is larger than page size and may not be fulfilled, @@ -65,17 +65,14 @@ LL | static XW: AlignedWrapper = AlignedWrapper { f: 0, g: Aligned(0) }; note: struct `AlignedWrapper` contains an inner type with large alignment --> $DIR/static_items_large_align.rs:9:1 | -LL | / struct AlignedWrapper { -LL | | f: u8, -LL | | g: Aligned, -LL | | } - | |_^ +LL | struct AlignedWrapper { + | ^^^^^^^^^^^^^^^^^^^^^ note: struct `Aligned` has alignment 0x100000, which is larger than 0x1000, if you know what you are doing, config the default page size clippy uses in clippy.toml --> $DIR/static_items_large_align.rs:7:1 | LL | struct Aligned(u8); - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^ error: this static item (itself or its subfield) has a type alignment, which is larger than page size and may not be fulfilled, @@ -95,7 +92,7 @@ note: struct `Aligned` has alignment 0x100000, which is larger than 0x1000, --> $DIR/static_items_large_align.rs:7:1 | LL | struct Aligned(u8); - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^ error: this static item (itself or its subfield) has a type alignment, which is larger than page size and may not be fulfilled, @@ -115,7 +112,7 @@ note: struct `Aligned` has alignment 0x100000, which is larger than 0x1000, --> $DIR/static_items_large_align.rs:7:1 | LL | struct Aligned(u8); - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^ error: this static item (itself or its subfield) has a type alignment, which is larger than page size and may not be fulfilled, @@ -128,16 +125,14 @@ LL | static XE: AlignedEnum = AlignedEnum::A(Aligned(0)); note: enum `AlignedEnum` contains an inner type with large alignment --> $DIR/static_items_large_align.rs:14:1 | -LL | / enum AlignedEnum { -LL | | A(Aligned), -LL | | } - | |_^ +LL | enum AlignedEnum { + | ^^^^^^^^^^^^^^^^ note: struct `Aligned` has alignment 0x100000, which is larger than 0x1000, if you know what you are doing, config the default page size clippy uses in clippy.toml --> $DIR/static_items_large_align.rs:7:1 | LL | struct Aligned(u8); - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^ error: this static item (itself or its subfield) has a type alignment, which is larger than page size and may not be fulfilled, @@ -154,13 +149,13 @@ note: struct `AlignedGeneric` with substitutions [ --> $DIR/static_items_large_align.rs:22:1 | LL | struct AlignedGeneric(T); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^ note: struct `Aligned` has alignment 0x100000, which is larger than 0x1000, if you know what you are doing, config the default page size clippy uses in clippy.toml --> $DIR/static_items_large_align.rs:7:1 | LL | struct Aligned(u8); - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^ error: this static item (itself or its subfield) has a type alignment, which is larger than page size and may not be fulfilled, @@ -177,21 +172,18 @@ note: struct `AlignedGeneric` with substitutions [ --> $DIR/static_items_large_align.rs:22:1 | LL | struct AlignedGeneric(T); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^ note: struct `AlignedWrapper` contains an inner type with large alignment --> $DIR/static_items_large_align.rs:9:1 | -LL | / struct AlignedWrapper { -LL | | f: u8, -LL | | g: Aligned, -LL | | } - | |_^ +LL | struct AlignedWrapper { + | ^^^^^^^^^^^^^^^^^^^^^ note: struct `Aligned` has alignment 0x100000, which is larger than 0x1000, if you know what you are doing, config the default page size clippy uses in clippy.toml --> $DIR/static_items_large_align.rs:7:1 | LL | struct Aligned(u8); - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^ error: this static item (itself or its subfield) has a type alignment, which is larger than page size and may not be fulfilled, @@ -211,11 +203,8 @@ note: struct `AGWithArgs` with substitutions [ contains an inner type with large alignment --> $DIR/static_items_large_align.rs:63:1 | -LL | / struct AGWithArgs { -LL | | not_aligned: FnPtr, -LL | | aligned: AGAlias, -LL | | } - | |_^ +LL | struct AGWithArgs { + | ^^^^^^^^^^^^^^^^^^^^^^^ note: struct `AG` with substitutions [ AlignedB, ], @@ -223,13 +212,13 @@ note: struct `AG` with substitutions [ --> $DIR/static_items_large_align.rs:59:1 | LL | struct AG(T); - | ^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^ note: struct `AlignedB` has alignment 0x100000, which is larger than 0x1000, if you know what you are doing, config the default page size clippy uses in clippy.toml --> $DIR/static_items_large_align.rs:55:1 | LL | struct AlignedB(u8); - | ^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^ error: aborting due to 10 previous errors