Skip to content

Commit

Permalink
Deny clippy::large_futures and fix +nightly lint (#1895)
Browse files Browse the repository at this point in the history
* Deny clippy::large_futures and fix +nightly lint

* Fix test errors

* Add clippy to cspell dictionary
  • Loading branch information
heaths authored Nov 5, 2024
1 parent 2b536c6 commit 0cede91
Show file tree
Hide file tree
Showing 16 changed files with 36 additions and 47 deletions.
5 changes: 3 additions & 2 deletions .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"asyncoperation",
"azsdk",
"azurecli",
"Contoso",
"clippy",
"contoso",
"cplusplus",
"datalake",
"datetime",
Expand All @@ -40,7 +41,7 @@
"iothub",
"keyvault",
"msrc",
"Newtonsoft",
"newtonsoft",
"oidc",
"pageable",
"pkce",
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,5 @@ tz-rs = { version = "0.6" }
url = "2.2"
uuid = { version = "1.0", features = ["v4"] }

[workspace.lints]
[workspace.lints.clippy]
large_futures = "deny"
2 changes: 1 addition & 1 deletion eng/test/mock_transport/src/mock_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl<'de> Visitor<'de> for RequestVisitor {
}
}

impl<'a> Serialize for RequestSerializer<'a> {
impl Serialize for RequestSerializer<'_> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
Expand Down
1 change: 1 addition & 0 deletions sdk/core/azure_core/src/hmac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::{
};

/// Tries to create an HMAC SHA256 signature from the given `data` and `key`.
///
/// The `key` is expected to be a base64 encoded string and will be decoded
/// before using it for signing. The returned signature is also base64 encoded.
///
Expand Down
6 changes: 3 additions & 3 deletions sdk/core/azure_core_amqp/src/fe2o3/cbs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ impl<'a> Fe2o3ClaimsBasedSecurity<'a> {
}
}

impl<'a> Fe2o3ClaimsBasedSecurity<'a> {}
impl Fe2o3ClaimsBasedSecurity<'_> {}

impl<'a> Drop for Fe2o3ClaimsBasedSecurity<'a> {
impl Drop for Fe2o3ClaimsBasedSecurity<'_> {
fn drop(&mut self) {
debug!("Dropping Fe2o3ClaimsBasedSecurity.");
}
}

impl<'a> AmqpClaimsBasedSecurityApis for Fe2o3ClaimsBasedSecurity<'a> {
impl AmqpClaimsBasedSecurityApis for Fe2o3ClaimsBasedSecurity<'_> {
async fn attach(&self) -> Result<()> {
let session = self.session.implementation.get()?;
let mut session = session.lock().await;
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/azure_core_amqp/src/fe2o3/management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl<'a> WithApplicationPropertiesRequest<'a> {
}
}

impl<'a> fe2o3_amqp_management::Request for WithApplicationPropertiesRequest<'a> {
impl fe2o3_amqp_management::Request for WithApplicationPropertiesRequest<'_> {
const OPERATION: &'static str = "READ";
type Response = ReadResponse;
type Body = ();
Expand Down
3 changes: 2 additions & 1 deletion sdk/core/azure_core_amqp/src/messaging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,8 @@ impl AmqpApplicationProperties {
}
}

/// An AMQP message
/// An AMQP message.
///
/// This is a simplified version of the AMQP message
/// that is used in the Azure SDK for Event Hubs
/// and is not a complete implementation of the AMQP message
Expand Down
4 changes: 2 additions & 2 deletions sdk/cosmos/azure_data_cosmos/examples/cosmos/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.init();

let mut args = ProgramArgs::parse();
let args = ProgramArgs::parse();

let Some(cmd) = args.subcommand else {
ProgramArgs::command().print_long_help()?;
return Ok(());
};

let client = create_client(&mut args.shared_args)?;
let client = create_client(&args.shared_args)?;

match cmd {
Subcommands::Create(cmd) => cmd.run(client).await,
Expand Down
26 changes: 1 addition & 25 deletions sdk/eventhubs/azure_messaging_eventhubs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,6 @@
// cspell: words amqp eventdata
#![doc = include_str!("../README.md")]

/// This module contains the implementation of the Azure Messaging Event Hubs SDK for Rust.
///
/// The SDK provides types and functions to interact with Azure Event Hubs, which is a highly scalable data streaming platform and event ingestion service.
/// It allows you to consume events from an Event Hub and create/send events to an Event Hub.
///
/// # Examples
///
/// Consuming events from an Event Hub:
///
/// ```no_run
/// # use azure_identity::{DefaultAzureCredential, TokenCredentialOptions};
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error + 'static>> {
/// # let my_credentials = DefaultAzureCredential::new()?;

/// use azure_messaging_eventhubs::consumer::ConsumerClient;
/// use azure_messaging_eventhubs::models::EventData;
///
/// let consumer_client = ConsumerClient::new("fully_qualified_domain", "eventhub_name", None, my_credentials, None);
/// let partition_properties = consumer_client.get_partition_properties("0").await?;
/// # Ok(())
/// }
/// ```
///
pub(crate) mod common;

/// Types related to consuming events from an Event Hub.
Expand Down Expand Up @@ -408,8 +384,8 @@ pub mod models {
}

/// Represents the data associated with an event received from an Event Hub.
/// This struct provides the event data, enqueued time, offset, sequence number, partition key, and system properties of the event.
///
/// This struct provides the event data, enqueued time, offset, sequence number, partition key, and system properties of the event.
pub struct ReceivedEventData {
message: AmqpMessage,
event_data: EventData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use typespec_client_core::{fs::FileStreamBuilder, http::RequestContent};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Log traces to stdout.
let _log = tracing_subscriber::fmt()
tracing_subscriber::fmt()
.with_span_events(FmtSpan::ENTER | FmtSpan::EXIT)
.with_max_level(LevelFilter::DEBUG)
.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use tracing_subscriber::fmt::format::FmtSpan;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Log traces to stdout.
let _log = tracing_subscriber::fmt()
tracing_subscriber::fmt()
.with_span_events(FmtSpan::ENTER | FmtSpan::EXIT)
.with_max_level(LevelFilter::DEBUG)
.init();
Expand Down
2 changes: 1 addition & 1 deletion sdk/typespec/typespec_client_core/src/http/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl<'a> Context<'a> {
}
}

impl<'a> Default for Context<'a> {
impl Default for Context<'_> {
fn default() -> Self {
Self::new()
}
Expand Down
1 change: 0 additions & 1 deletion sdk/typespec/typespec_client_core/src/http/request/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ pub enum Body {
/// A streaming body.
///
/// This is not currently supported on WASM targets.

// We cannot currently implement `Body::SeekableStream` for WASM
// because `reqwest::Body::wrap_stream()` is not implemented for WASM.
#[cfg(not(target_arch = "wasm32"))]
Expand Down
1 change: 1 addition & 0 deletions sdk/typespec/typespec_client_core/src/sleep/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use std::{
};

/// Creates a future that resolves after a specified duration of time.
///
/// Uses a simple thread based implementation for sleep. A more efficient
/// implementation is available by using the `tokio_sleep` crate feature.
pub fn sleep(duration: Duration) -> Sleep {
Expand Down
21 changes: 15 additions & 6 deletions sdk/typespec/typespec_derive/tests/compilation-tests.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

use std::{collections::HashMap, io::BufReader, path::PathBuf, process::Stdio};

use cargo_metadata::{diagnostic::DiagnosticLevel, Message};
use serde::Serialize;
use std::{
collections::HashMap,
io::{BufReader, Read},
path::PathBuf,
process::Stdio,
};

#[derive(Serialize)]
struct MessageExpectation {
Expand All @@ -27,6 +31,7 @@ struct FileResult {
}

#[test]
#[ignore = "https://github.com/Azure/azure-sdk-for-rust/issues/1896"]
pub fn compilation_tests() {
let test_root = {
let mut p = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
Expand All @@ -43,18 +48,22 @@ pub fn compilation_tests() {
p
};

// Probably save to assume cargo is on the path, but if that's not the case, tests will start failing and we'll figure it out.
let mut compilation = std::process::Command::new("cargo")
let compilation = std::process::Command::new(env!("CARGO"))
.arg("build")
.arg("--message-format")
.arg("json")
.current_dir(test_root.clone())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
.output()
// An error here does not mean a non-zero exit code, it means a failure to run the process.
.expect("failed to execute compilation");
let reader = BufReader::new(compilation.stdout.take().unwrap());
assert!(
!compilation.status.success(),
"expected compilation to fail"
);

let reader = BufReader::new(compilation.stdout.take(u64::MAX));
let messages = Message::parse_stream(reader);
let file_messages = messages
.filter_map(|m| match m.expect("failed to parse message") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ edition = "2021"
publish = false

[dependencies]
typespec_client_core = { path = "../../typespec_client_core", features = ["derive"] }
typespec_client_core = { path = "../../../../typespec_client_core", features = ["derive"] }
serde = { version = "1.0", features = ["derive"] }

0 comments on commit 0cede91

Please sign in to comment.