1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-12-22 06:47:49 +02:00

Introduce a cargo clippy run (#2025)

This might help catch stylistic problems in our Rust code.

Related to #2587.
This commit is contained in:
Martin Geisler
2025-09-20 13:38:54 +02:00
committed by GitHub
parent 80a2f2ff71
commit 1e3be175fa
13 changed files with 81 additions and 57 deletions

View File

@@ -41,7 +41,7 @@ async fn main() -> Result<(), tokio_websockets::Error> {
println!("From server: {}", text);
}
},
Some(Err(err)) => return Err(err.into()),
Some(Err(err)) => return Err(err),
None => return Ok(()),
}
}

View File

@@ -116,7 +116,7 @@ fn unpack_tag(tag: u64) -> (u64, WireType) {
// ANCHOR: parse_field
/// Parse a field, returning the remaining bytes
fn parse_field(data: &[u8]) -> (Field, &[u8]) {
fn parse_field(data: &[u8]) -> (Field<'_>, &[u8]) {
let (tag, remainder) = parse_varint(data);
let (field_num, wire_type) = unpack_tag(tag);
let (fieldvalue, remainder) = match wire_type {

View File

@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// Iterators are covered later.
#[allow(clippy::needless_range_loop)]
// ANCHOR: solution
// ANCHOR: transpose
fn transpose(matrix: [[i32; 3]; 3]) -> [[i32; 3]; 3] {

View File

@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// Omitting `return` is covered later.
#[allow(clippy::needless_return)]
// ANCHOR: solution
// ANCHOR: fib
fn fib(n: u32) -> u32 {

View File

@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// `DIR` matches name of C struct.
#[allow(clippy::upper_case_acronyms)]
// ANCHOR: solution
// ANCHOR: ffi
mod ffi {
@@ -40,7 +42,7 @@ mod ffi {
}
// Layout according to the macOS man page for dir(5).
#[cfg(all(target_os = "macos"))]
#[cfg(target_os = "macos")]
#[repr(C)]
pub struct dirent {
pub d_fileno: u64,