Skip to content

Commit 2011da4

Browse files
authored
Fix #[warn(dead_code)] in the SDK crate for a service with no operations defined (#3012)
## Motivation and Context When a service has no operations, the following places in a generated SDK issue `dead_code` warnings: ``` error: field `runtime_plugins` is never read --> src/client.rs:5:16 | 3 | pub(crate) struct Handle { | ------ field in this struct 4 | pub(crate) conf: crate::Config, 5 | pub(crate) runtime_plugins: ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins, | ^^^^^^^^^^^^^^^ | = note: `Handle` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis = note: `-D dead-code` implied by `-D warnings` error: associated function `new` is never used --> src/client/customize.rs:30:23 | 28 | impl<T, E, B> CustomizableOperation<T, E, B> { | -------------------------------------------- associated function in this implementation 29 | /// Creates a new `CustomizableOperation` from `customizable_send`. 30 | pub(crate) fn new(customizable_send: B) -> Self { | ^^^ error: associated function `new` is never used --> src/config.rs:853:19 | 852 | impl ConfigOverrideRuntimePlugin { | -------------------------------- associated function in this implementation 853 | pub(crate) fn new( | ^^^ ``` This PR adds `#[allow(dead_code)]` to the code generator at the corresponding places to suppress those warnings. ## Testing - Added a new unit test to ensure that the warnings are not issued for a service with no operations. ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._
1 parent 8a1f09e commit 2011da4

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ConfigOverrideRuntimePluginGenerator.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class ConfigOverrideRuntimePluginGenerator(
4848
}
4949
5050
impl ConfigOverrideRuntimePlugin {
51+
##[allow(dead_code)] // unused when a service does not provide any operations
5152
pub(crate) fn new(
5253
config_override: Builder,
5354
initial_config: #{FrozenLayer},

codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ class CustomizableOperationGenerator(
197197
198198
impl<T, E, B> CustomizableOperation<T, E, B> {
199199
/// Creates a new `CustomizableOperation` from `customizable_send`.
200+
##[allow(dead_code)] // unused when a service does not provide any operations
200201
pub(crate) fn new(customizable_send: B) -> Self {
201202
Self {
202203
customizable_send,

codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerator.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ class FluentClientGenerator(
184184
##[derive(Debug)]
185185
pub(crate) struct Handle {
186186
pub(crate) conf: crate::Config,
187+
##[allow(dead_code)] // unused when a service does not provide any operations
187188
pub(crate) runtime_plugins: #{RuntimePlugins},
188189
}
189190

codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGeneratorTest.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,19 @@ class FluentClientGeneratorTest {
162162
test = test,
163163
)
164164
}
165+
166+
@Test
167+
fun `dead-code warning should not be issued when a service has no operations`() {
168+
val model = """
169+
namespace com.example
170+
use aws.protocols#awsJson1_0
171+
172+
@awsJson1_0
173+
service HelloService {
174+
version: "1"
175+
}
176+
""".asSmithyModel()
177+
178+
clientIntegrationTest(model)
179+
}
165180
}

0 commit comments

Comments
 (0)