Skip to content

Commit f3cc844

Browse files
authored
fix: new clippy issues from recent Rust update (#97)
1 parent 9435ce8 commit f3cc844

12 files changed

Lines changed: 185 additions & 16 deletions

File tree

.github/copilot-instructions.md

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# Copilot Instructions
2+
3+
## Overview
4+
5+
This repository contains a Rust implementation of an NFS3 protocol with server and client components. The development environment is equipped with a comprehensive Rust MCP (Model Context Protocol) server that provides specialized tools for Rust development.
6+
7+
## Rust MCP Server Tools
8+
9+
The following Rust-specific tools are available through the MCP server and should be used for all Rust development tasks:
10+
11+
### Core Build & Test Tools
12+
13+
- **Generic arguments**:
14+
- Use `package: "crate-name"` to build a specific crate
15+
- Use `all_features: true` to build with all features enabled
16+
- Use `all_targets: true` to build all targets (e.g., tests, examples)
17+
- Use `warnings_as_errors: true` for strict checking
18+
19+
- **`Rust-cargo-build`**: Build the project using Cargo
20+
21+
- **`Rust-cargo-check`**: Fast compilation check without code generation
22+
- Preferred for quick validation during development
23+
- Use before making code changes to understand existing issues
24+
25+
- **`Rust-cargo-test`**: Run tests
26+
27+
- **`Rust-cargo-clippy`**: Advanced linting with Clippy
28+
- Use `fix: true` to automatically apply fixes for Clippy warnings
29+
- Use `allow_dirty: true` to allow dirty workspaces (useful for CI/CD)
30+
31+
- **`Rust-cargo-fmt`**: Code formatting with rustfmt
32+
- Use `all: true` to format all packages
33+
- Use `check: true` to verify formatting without applying changes
34+
35+
### Dependency Management
36+
37+
- **`Rust-cargo-add`**: Add dependencies to Cargo.toml
38+
- **`Rust-cargo-remove`**: Remove dependencies from Cargo.toml
39+
- **`Rust-cargo-update`**: Update dependencies in Cargo.lock
40+
- **`Rust-cargo-machete`**: Find unused dependencies
41+
- **`Rust-cargo-deny-check`**: Security and compliance checking
42+
43+
### Development Workflow
44+
45+
- **`Rust-cargo-metadata`**: Get project metadata in JSON format
46+
- **`Rust-cargo-search`**: Search for crates on crates.io
47+
- **`Rust-cargo-info`**: Get information about specific crates
48+
49+
## Project Structure
50+
51+
```
52+
nfs3/
53+
├── crates/
54+
│ ├── cargo_nfs3_server/ # Lightweight NFSv3 server tool
55+
│ ├── nfs3_client/ # Async NFS3 client implementation
56+
│ ├── nfs3_server/ # Async NFS3 server implementation
57+
│ ├── nfs3_types/ # Types and utilities for NFS operations
58+
│ ├── nfs3_macros/ # Procedural macros
59+
│ └── nfs3_tests/ # Integration tests
60+
├── .github/workflows/ # CI/CD workflows
61+
└── scripts/ # Build and utility scripts
62+
```
63+
64+
## AI Agent Guidelines
65+
66+
### 1. Always Use Rust MCP Tools
67+
68+
- **DO**: Use `Rust-cargo-build` instead of `bash` commands like `cargo build`
69+
- **DO**: Use `Rust-cargo-check` for quick validation
70+
- **DO**: Use `Rust-cargo-clippy` for linting instead of manual clippy commands
71+
- **WHY**: MCP tools provide better defaults, better structured output and better error handling
72+
73+
### 2. Development Workflow
74+
75+
When working on code changes:
76+
77+
1. **Check current state**: Use `Rust-cargo-check` with `all_targets: true, all_features: true`
78+
2. **Make changes**: Edit code using appropriate tools
79+
3. **Validate**: Use `Rust-cargo-clippy` with `workspace: true, all_targets: true`
80+
4. **Format**: Use `Rust-cargo-fmt` with `all: true`
81+
5. **Test**: Use `Rust-cargo-test` with `all_features: true`
82+
6. **Build**: Use `Rust-cargo-build` with `all_targets: true, all_features: true` for final verification
83+
7. **Check unused dependencies**: Use `Rust-cargo-machete` to find unused dependencies
84+
8. **Check security compliance**: Use `Rust-cargo-deny-check` to verify security and compliance
85+
86+
### 3. Dependency Management
87+
88+
- When adding dependencies, prefer workspace-level dependencies in the root `Cargo.toml`
89+
90+
### 4. Code Quality Standards
91+
92+
This project follows strict code quality standards:
93+
94+
- **Clippy**: All clippy warnings must be addressed
95+
- **Formatting**: Code must be formatted with rustfmt using nightly toolchain
96+
- **Tests**: All changes must maintain test coverage
97+
- **Documentation**: Public APIs must be documented
98+
99+
### 5. Common Patterns
100+
101+
#### Checking Project Health
102+
```
103+
1. Rust-cargo-check (all_features: true, all_targets: true)
104+
2. Rust-cargo-clippy (warnings_as_errors: true)
105+
3. Rust-cargo-test (all_features: true)
106+
4. Rust-cargo-fmt (check: true)
107+
```
108+
109+
#### Fixing Clippy Issues
110+
```
111+
1. Rust-cargo-clippy (all_targets: true, fix: true, allow_dirty: true)
112+
2. Rust-cargo-fmt (all: true)
113+
3. Rust-cargo-test (all_features: true)
114+
```
115+
116+
#### Adding New Dependencies
117+
```
118+
1. Rust-cargo-add (package: "dependency-name", workspace: true if workspace dep)
119+
2. Rust-cargo-deny-check (verify security compliance)
120+
```
121+
122+
## Repository-Specific Context
123+
124+
### NFS3 Protocol Implementation
125+
126+
This project implements the NFS3 protocol in Rust with the following key components:
127+
128+
- **Types**: Core NFS3 types and RPC definitions
129+
- **Server**: Async server implementation with pluggable VFS backends
130+
- **Client**: Async client for NFS3 operations
131+
- **Testing**: Comprehensive integration tests including WASM targets
132+
133+
### Key Files to Understand
134+
135+
- `crates/nfs3_types/src/lib.rs`: Core NFS3 type definitions
136+
- `crates/nfs3_server/src/vfs/mod.rs`: Virtual file system traits
137+
- `crates/nfs3_client/src/lib.rs`: Client API
138+
- `crates/nfs3_tests/src/`: Integration test suites
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
on:
2+
workflow_dispatch:
3+
permissions:
4+
id-token: write
5+
contents: write
6+
jobs:
7+
copilot-setup-steps:
8+
runs-on: ubuntu-latest
9+
permissions:
10+
id-token: write
11+
contents: write
12+
environment: copilot
13+
steps:
14+
- name: Install nightly rustfmt
15+
run: rustup component add --toolchain nightly rustfmt
16+
- name: Cache Cargo dependencies
17+
uses: actions/cache@v4
18+
with:
19+
path: |
20+
~/.cargo/registry
21+
~/.cargo/git
22+
key: copilot-cargo
23+
- name: Install Rust MCP Server
24+
run: cargo install --git https://github.com/Vaiz/rust-mcp-server.git --tag stable
25+
- name: Install machete
26+
run: cargo install cargo-machete
27+
- name: Install cargo-deny
28+
run: cargo install cargo-deny

crates/cargo_nfs3_server/src/mirror.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ impl NfsReadFileSystem for MirrorFs {
451451
Ok(iter)
452452
}
453453

454-
async fn readlink(&self, id: &Self::Handle) -> Result<nfspath3, nfsstat3> {
454+
async fn readlink(&self, id: &Self::Handle) -> Result<nfspath3<'_>, nfsstat3> {
455455
let id = id.as_u64();
456456
let fsmap = self.fsmap.read().await;
457457
let ent = fsmap.find_entry(id)?;

crates/nfs3_client/src/tokio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl Connector for TokioConnector {
5959
local_port: u16,
6060
) -> std::io::Result<Self::Connection> {
6161
let socket = TcpSocket::new_v4()?;
62-
let local_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), local_port);
62+
let local_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), local_port);
6363
socket.bind(local_addr)?;
6464

6565
let remote_addr = SocketAddr::new(host.parse().expect("invalid host address"), port);

crates/nfs3_server/examples/mirrorfs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ impl NfsReadFileSystem for MirrorFs {
484484
Ok(iter)
485485
}
486486

487-
async fn readlink(&self, id: &Self::Handle) -> Result<nfspath3, nfsstat3> {
487+
async fn readlink(&self, id: &Self::Handle) -> Result<nfspath3<'_>, nfsstat3> {
488488
let id = id.as_u64();
489489
let fsmap = self.fsmap.read().await;
490490
let ent = fsmap.find_entry(id)?;

crates/nfs3_server/src/memfs/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ impl NfsReadFileSystem for MemFs {
735735
Ok(iter)
736736
}
737737

738-
async fn readlink(&self, _id: &FileHandleU64) -> Result<nfspath3, nfsstat3> {
738+
async fn readlink(&self, _id: &FileHandleU64) -> Result<nfspath3<'_>, nfsstat3> {
739739
tracing::warn!("readlink not implemented");
740740
Err(nfsstat3::NFS3ERR_NOTSUPP)
741741
}

crates/nfs3_server/src/vfs/adapter.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ where
7878
.map(ReadOnlyIterator)
7979
}
8080

81-
async fn readlink(&self, id: &Self::Handle) -> Result<nfs3_types::nfs3::nfspath3, nfsstat3> {
81+
async fn readlink(
82+
&self,
83+
id: &Self::Handle,
84+
) -> Result<nfs3_types::nfs3::nfspath3<'_>, nfsstat3> {
8285
self.0.readlink(id).await
8386
}
8487
}

crates/nfs3_server/src/vfs/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ pub trait NfsReadFileSystem: Send + Sync {
127127
fn readlink(
128128
&self,
129129
id: &Self::Handle,
130-
) -> impl Future<Output = Result<nfspath3, nfsstat3>> + Send;
130+
) -> impl Future<Output = Result<nfspath3<'_>, nfsstat3>> + Send;
131131

132132
/// Get static file system Information
133133
fn fsinfo(

crates/nfs3_tests/examples/perf_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ async fn main() {
2020
let requests_count = test_dir(&mut client, "dir_10000").await.unwrap();
2121
let elapsed_time = start_time.elapsed();
2222

23-
println!("Elapsed time: {:?}", elapsed_time);
23+
println!("Elapsed time: {elapsed_time:?}");
2424
println!("Requests count: {requests_count}");
2525
println!(
2626
"Requests per second: {}",

crates/nfs3_tests/src/rpc_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl RpcTestContext {
8484
Ok(())
8585
}
8686

87-
pub async fn recv_reply<T>(&mut self) -> anyhow::Result<(rpc_msg, Option<T>)>
87+
pub async fn recv_reply<T>(&mut self) -> anyhow::Result<(rpc_msg<'_, '_>, Option<T>)>
8888
where
8989
T: Unpack<Cursor<Vec<u8>>>,
9090
{

0 commit comments

Comments
 (0)