Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace per-type repr(C) lints with a single lint for all of struct/enum/union #678

Merged
merged 2 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/lints/enum_repr_c_removed.ron → src/lints/repr_c_removed.ron
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
SemverQuery(
id: "enum_repr_c_removed",
human_readable_name: "enum repr(C) removed",
description: "An enum that used to be repr(C) is no longer repr(C).",
reference: Some("An enum that used to be repr(C) is no longer repr(C). This can cause its memory layout to change, breaking FFI use cases."),
id: "repr_c_removed",
human_readable_name: "repr(C) removed",
description: "A type that used to be repr(C) is no longer repr(C).",
reference: Some("A type that used to be repr(C) is no longer repr(C). This can cause its memory layout to change, breaking FFI use cases."),
required_update: Major,

reference_link: Some("https://doc.rust-lang.org/cargo/reference/semver.html#repr-c-remove"),
Expand All @@ -11,7 +11,8 @@ SemverQuery(
CrateDiff {
baseline {
item {
... on Enum {
... on ImplOwner {
owner_type: __typename @tag @output
visibility_limit @filter(op: "=", value: ["$public"]) @output

attribute {
Expand All @@ -33,7 +34,8 @@ SemverQuery(
}
current {
item {
... on Enum {
... on ImplOwner {
__typename @filter(op: "=", value: ["%owner_type"])
visibility_limit @filter(op: "=", value: ["$public"])
name @output

Expand Down Expand Up @@ -67,6 +69,6 @@ SemverQuery(
"true": true,
"zero": 0,
},
error_message: "repr(C) was removed from an enum. This can cause its memory layout to change, breaking FFI use cases.",
per_result_error_template: Some("enum {{name}} in {{span_filename}}:{{span_begin_line}}"),
error_message: "repr(C) was removed from a type. This can cause its memory layout to change, breaking FFI use cases.",
per_result_error_template: Some("{{lowercase owner_type}} {{name}} in {{span_filename}}:{{span_begin_line}}"),
)
72 changes: 0 additions & 72 deletions src/lints/struct_repr_c_removed.ron

This file was deleted.

3 changes: 1 addition & 2 deletions src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,6 @@ add_lints!(
enum_missing,
enum_must_use_added,
enum_now_doc_hidden,
enum_repr_c_removed,
enum_repr_int_changed,
enum_repr_int_removed,
enum_repr_transparent_removed,
Expand All @@ -503,7 +502,6 @@ add_lints!(
struct_must_use_added,
struct_now_doc_hidden,
struct_pub_field_missing,
struct_repr_c_removed,
struct_repr_transparent_removed,
struct_with_pub_fields_changed_type,
trait_method_missing,
Expand All @@ -528,6 +526,7 @@ add_lints!(
trait_method_unsafe_added,
trait_method_unsafe_removed,
struct_pub_field_now_doc_hidden,
repr_c_removed,
repr_packed_added,
repr_packed_removed,
exported_function_changed_abi,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
publish = false
name = "enum_repr_c_removed"
name = "repr_c_removed"
version = "0.1.0"
edition = "2021"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,41 @@ pub enum SeparateCU8ToSeparateU8CEnum {
Bar,
Baz,
}

pub struct CStructToStruct {
pub bar: usize,
}

#[repr(align(16))]
pub struct Align16CStructToAlign16Struct {
pub bar: usize,
}

#[repr(align(16))]
pub struct SeparateAlign16CStructToAlign16Struct {
pub bar: usize,
}

#[repr(align(16))]
pub struct CAlign16StructToAlign16Struct {
pub bar: usize,
}

pub union CUnionToUnion {
pub bar: usize,
}

#[repr(align(16))]
pub union Align16CUnionToAlign16Union {
pub bar: usize,
}

#[repr(align(16))]
pub union SeparateAlign16CUnionToAlign16Union {
pub bar: usize,
}

#[repr(align(16))]
pub union CAlign16UnionToAlign16Union {
pub bar: usize,
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
publish = false
name = "enum_repr_c_removed"
name = "repr_c_removed"
version = "0.1.0"
edition = "2021"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ pub enum SeparateCU8EnumToU8Enum {
Baz,
}


// The following enums have *rearrangements* of repr(C), potentially
// splitting singular repr(*) into multiple, smaller repr(*) or merging
// repr(*) into larger repr(*).
Expand Down Expand Up @@ -93,3 +92,45 @@ pub enum SeparateCU8ToSeparateU8CEnum {
Bar,
Baz,
}

#[repr(C)]
pub struct CStructToStruct {
pub bar: usize,
}

#[repr(align(16), C)]
pub struct Align16CStructToAlign16Struct {
pub bar: usize,
}

#[repr(align(16))]
#[repr(C)]
pub struct SeparateAlign16CStructToAlign16Struct {
pub bar: usize,
}

#[repr(C, align(16))]
pub struct CAlign16StructToAlign16Struct {
pub bar: usize,
}

#[repr(C)]
pub union CUnionToUnion {
pub bar: usize,
}

#[repr(align(16), C)]
pub union Align16CUnionToAlign16Union {
pub bar: usize,
}

#[repr(align(16))]
#[repr(C)]
pub union SeparateAlign16CUnionToAlign16Union {
pub bar: usize,
}

#[repr(C, align(16))]
pub union CAlign16UnionToAlign16Union {
pub bar: usize,
}
7 changes: 0 additions & 7 deletions test_crates/struct_repr_c_removed/new/Cargo.toml

This file was deleted.

13 changes: 0 additions & 13 deletions test_crates/struct_repr_c_removed/new/src/lib.rs

This file was deleted.

7 changes: 0 additions & 7 deletions test_crates/struct_repr_c_removed/old/Cargo.toml

This file was deleted.

15 changes: 0 additions & 15 deletions test_crates/struct_repr_c_removed/old/src/lib.rs

This file was deleted.

59 changes: 0 additions & 59 deletions test_outputs/enum_repr_c_removed.output.ron

This file was deleted.

Loading
Loading