From a2f17cff314946a8c26908e08535b755588249d5 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Thu, 18 Aug 2022 05:40:54 +0900 Subject: [PATCH] Support raw pointer in cargo-check-external-types (#1643) --- .../cargo-check-external-types/src/visitor.rs | 4 +- .../test-workspace/test-crate/src/lib.rs | 1 + .../allow-some-types-expected-output.txt | 12 ++-- .../tests/default-config-expected-output.txt | 64 +++++++++++-------- ...t-format-markdown-table-expected-output.md | 21 +++--- 5 files changed, 57 insertions(+), 45 deletions(-) diff --git a/tools/cargo-check-external-types/src/visitor.rs b/tools/cargo-check-external-types/src/visitor.rs index 2ed9d1b8a..9eff6ea9f 100644 --- a/tools/cargo-check-external-types/src/visitor.rs +++ b/tools/cargo-check-external-types/src/visitor.rs @@ -322,7 +322,9 @@ impl Visitor { } } Type::Infer => unimplemented!("visit_type Type::Infer"), - Type::RawPointer { type_: _, .. } => unimplemented!("visit_type Type::RawPointer"), + Type::RawPointer { type_, .. } => { + self.visit_type(path, what, type_).context(here!())? + } Type::BorrowedRef { type_, .. } => { self.visit_type(path, what, type_).context(here!())? } diff --git a/tools/cargo-check-external-types/test-workspace/test-crate/src/lib.rs b/tools/cargo-check-external-types/test-workspace/test-crate/src/lib.rs index b17bb16f0..8fd3bcb73 100644 --- a/tools/cargo-check-external-types/test-workspace/test-crate/src/lib.rs +++ b/tools/cargo-check-external-types/test-workspace/test-crate/src/lib.rs @@ -120,6 +120,7 @@ pub type NotExternalReferencing = u32; pub type ExternalReferencingTypedef = SomeStruct; pub type OptionalExternalReferencingTypedef = Option; pub type DynExternalReferencingTypedef = Box; +pub type ExternalReferencingRawPtr = *const SomeStruct; pub fn fn_with_external_trait_bounds(_thing: T) where diff --git a/tools/cargo-check-external-types/tests/allow-some-types-expected-output.txt b/tools/cargo-check-external-types/tests/allow-some-types-expected-output.txt index 78fe40ac7..c0f42ec87 100644 --- a/tools/cargo-check-external-types/tests/allow-some-types-expected-output.txt +++ b/tools/cargo-check-external-types/tests/allow-some-types-expected-output.txt @@ -1,19 +1,19 @@ error: Unapproved external type `external_lib::AssociatedGenericTrait` referenced in public API - --> test-crate/src/lib.rs:124:1 + --> test-crate/src/lib.rs:125:1 | -124 | pub fn fn_with_external_trait_bounds(_thing: T) +125 | pub fn fn_with_external_trait_bounds(_thing: T) | ... -131 | }␊ +132 | }␊ | ^ | = in trait bound of `test_crate::fn_with_external_trait_bounds` error: Unapproved external type `external_lib::AssociatedGenericTrait` referenced in public API - --> test-crate/src/lib.rs:135:5 + --> test-crate/src/lib.rs:136:5 | -135 | type OtherThing: AssociatedGenericTrait< +136 | type OtherThing: AssociatedGenericTrait< | ... -139 | >;␊ +140 | >;␊ | ^^ | = in trait bound of `test_crate::SomeTraitWithExternalDefaultTypes::OtherThing` diff --git a/tools/cargo-check-external-types/tests/default-config-expected-output.txt b/tools/cargo-check-external-types/tests/default-config-expected-output.txt index f4fef16f4..6c897ab44 100644 --- a/tools/cargo-check-external-types/tests/default-config-expected-output.txt +++ b/tools/cargo-check-external-types/tests/default-config-expected-output.txt @@ -236,98 +236,106 @@ error: Unapproved external type `external_lib::SimpleTrait` referenced in public | = in generic arg of `test_crate::DynExternalReferencingTypedef` +error: Unapproved external type `external_lib::SomeStruct` referenced in public API + --> test-crate/src/lib.rs:123:1 + | +123 | pub type ExternalReferencingRawPtr = *const SomeStruct; + | ^-----------------------------------------------------^ + | + = in typedef type of `test_crate::ExternalReferencingRawPtr` + error: Unapproved external type `external_lib::AssociatedGenericTrait` referenced in public API - --> test-crate/src/lib.rs:124:1 + --> test-crate/src/lib.rs:125:1 | -124 | pub fn fn_with_external_trait_bounds(_thing: T) +125 | pub fn fn_with_external_trait_bounds(_thing: T) | ... -131 | }␊ +132 | }␊ | ^ | = in trait bound of `test_crate::fn_with_external_trait_bounds` error: Unapproved external type `external_lib::SomeOtherStruct` referenced in public API - --> test-crate/src/lib.rs:124:1 + --> test-crate/src/lib.rs:125:1 | -124 | pub fn fn_with_external_trait_bounds(_thing: T) +125 | pub fn fn_with_external_trait_bounds(_thing: T) | ... -131 | }␊ +132 | }␊ | ^ | = in generic arg of `test_crate::fn_with_external_trait_bounds` error: Unapproved external type `external_lib::SomeStruct` referenced in public API - --> test-crate/src/lib.rs:124:1 + --> test-crate/src/lib.rs:125:1 | -124 | pub fn fn_with_external_trait_bounds(_thing: T) +125 | pub fn fn_with_external_trait_bounds(_thing: T) | ... -131 | }␊ +132 | }␊ | ^ | = in generic arg of `test_crate::fn_with_external_trait_bounds` error: Unapproved external type `external_lib::SimpleTrait` referenced in public API - --> test-crate/src/lib.rs:134:5 + --> test-crate/src/lib.rs:135:5 | -134 | type Thing: SimpleTrait; +135 | type Thing: SimpleTrait; | ^----------------------^ | = in trait bound of `test_crate::SomeTraitWithExternalDefaultTypes::Thing` error: Unapproved external type `external_lib::AssociatedGenericTrait` referenced in public API - --> test-crate/src/lib.rs:135:5 + --> test-crate/src/lib.rs:136:5 | -135 | type OtherThing: AssociatedGenericTrait< +136 | type OtherThing: AssociatedGenericTrait< | ... -139 | >;␊ +140 | >;␊ | ^^ | = in trait bound of `test_crate::SomeTraitWithExternalDefaultTypes::OtherThing` error: Unapproved external type `external_lib::SomeOtherStruct` referenced in public API - --> test-crate/src/lib.rs:135:5 + --> test-crate/src/lib.rs:136:5 | -135 | type OtherThing: AssociatedGenericTrait< +136 | type OtherThing: AssociatedGenericTrait< | ... -139 | >;␊ +140 | >;␊ | ^^ | = in generic default binding of `test_crate::SomeTraitWithExternalDefaultTypes::OtherThing` error: Unapproved external type `external_lib::SomeStruct` referenced in public API - --> test-crate/src/lib.rs:135:5 + --> test-crate/src/lib.rs:136:5 | -135 | type OtherThing: AssociatedGenericTrait< +136 | type OtherThing: AssociatedGenericTrait< | ... -139 | >;␊ +140 | >;␊ | ^^ | = in generic default binding of `test_crate::SomeTraitWithExternalDefaultTypes::OtherThing` error: Unapproved external type `external_lib::SimpleTrait` referenced in public API - --> test-crate/src/lib.rs:145:5 + --> test-crate/src/lib.rs:146:5 | -145 | type MyGAT +146 | type MyGAT | ... -147 | T: SimpleTrait;␊ +148 | T: SimpleTrait;␊ | ^-----------------^ | = in trait bound of `test_crate::SomeTraitWithGenericAssociatedType::MyGAT` error: Unapproved external type `external_lib::SimpleTrait` referenced in public API - --> test-crate/src/lib.rs:149:5 + --> test-crate/src/lib.rs:150:5 | -149 | fn some_fn(&self, thing: Self::MyGAT); +150 | fn some_fn(&self, thing: Self::MyGAT); | ^-------------------------------------------------------^ | = in trait bound of `test_crate::SomeTraitWithGenericAssociatedType::some_fn` error: Unapproved external type `external_lib::SimpleNewType` referenced in public API - --> test-crate/src/lib.rs:157:5 + --> test-crate/src/lib.rs:158:5 | -157 | pub const OTHER_CONST: SimpleNewType = SimpleNewType(5); +158 | pub const OTHER_CONST: SimpleNewType = SimpleNewType(5); | ^------------------------------------------------------^ | = in struct field of `test_crate::AssocConstStruct::OTHER_CONST` -38 errors emitted +39 errors emitted diff --git a/tools/cargo-check-external-types/tests/output-format-markdown-table-expected-output.md b/tools/cargo-check-external-types/tests/output-format-markdown-table-expected-output.md index 0d8a1cce5..9674fff9d 100644 --- a/tools/cargo-check-external-types/tests/output-format-markdown-table-expected-output.md +++ b/tools/cargo-check-external-types/tests/output-format-markdown-table-expected-output.md @@ -1,20 +1,20 @@ | Crate | Type | Used In | | --- | --- | --- | -| external_lib | external_lib::AssociatedGenericTrait | test-crate/src/lib.rs:124:0 | -| external_lib | external_lib::AssociatedGenericTrait | test-crate/src/lib.rs:135:4 | -| external_lib | external_lib::SimpleNewType | test-crate/src/lib.rs:157:4 | +| external_lib | external_lib::AssociatedGenericTrait | test-crate/src/lib.rs:125:0 | +| external_lib | external_lib::AssociatedGenericTrait | test-crate/src/lib.rs:136:4 | +| external_lib | external_lib::SimpleNewType | test-crate/src/lib.rs:158:4 | | external_lib | external_lib::SimpleTrait | test-crate/src/lib.rs:104:4 | | external_lib | external_lib::SimpleTrait | test-crate/src/lib.rs:122:0 | -| external_lib | external_lib::SimpleTrait | test-crate/src/lib.rs:134:4 | -| external_lib | external_lib::SimpleTrait | test-crate/src/lib.rs:145:4 | -| external_lib | external_lib::SimpleTrait | test-crate/src/lib.rs:149:4 | +| external_lib | external_lib::SimpleTrait | test-crate/src/lib.rs:135:4 | +| external_lib | external_lib::SimpleTrait | test-crate/src/lib.rs:146:4 | +| external_lib | external_lib::SimpleTrait | test-crate/src/lib.rs:150:4 | | external_lib | external_lib::SimpleTrait | test-crate/src/lib.rs:38:0 | | external_lib | external_lib::SimpleTrait | test-crate/src/lib.rs:38:0 | | external_lib | external_lib::SimpleTrait | test-crate/src/lib.rs:47:0 | | external_lib | external_lib::SimpleTrait | test-crate/src/lib.rs:89:4 | | external_lib | external_lib::SimpleTrait | test-crate/src/lib.rs:92:8 | -| external_lib | external_lib::SomeOtherStruct | test-crate/src/lib.rs:124:0 | -| external_lib | external_lib::SomeOtherStruct | test-crate/src/lib.rs:135:4 | +| external_lib | external_lib::SomeOtherStruct | test-crate/src/lib.rs:125:0 | +| external_lib | external_lib::SomeOtherStruct | test-crate/src/lib.rs:136:4 | | external_lib | external_lib::SomeOtherStruct | test-crate/src/lib.rs:72:4 | | external_lib | external_lib::SomeStruct | test-crate/src/lib.rs:109:0 | | external_lib | external_lib::SomeStruct | test-crate/src/lib.rs:110:0 | @@ -22,8 +22,9 @@ | external_lib | external_lib::SomeStruct | test-crate/src/lib.rs:116:4 | | external_lib | external_lib::SomeStruct | test-crate/src/lib.rs:120:0 | | external_lib | external_lib::SomeStruct | test-crate/src/lib.rs:121:0 | -| external_lib | external_lib::SomeStruct | test-crate/src/lib.rs:124:0 | -| external_lib | external_lib::SomeStruct | test-crate/src/lib.rs:135:4 | +| external_lib | external_lib::SomeStruct | test-crate/src/lib.rs:123:0 | +| external_lib | external_lib::SomeStruct | test-crate/src/lib.rs:125:0 | +| external_lib | external_lib::SomeStruct | test-crate/src/lib.rs:136:4 | | external_lib | external_lib::SomeStruct | test-crate/src/lib.rs:38:0 | | external_lib | external_lib::SomeStruct | test-crate/src/lib.rs:43:0 | | external_lib | external_lib::SomeStruct | test-crate/src/lib.rs:54:0 | -- GitLab