Skip to content

Commit c8189ea

Browse files
committed
Enable and fix extra rustc lints
1 parent af340a3 commit c8189ea

File tree

9 files changed

+66
-34
lines changed

9 files changed

+66
-34
lines changed

crates/aide/src/axum/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ where
283283
/// This method accepts a transform function to edit each [`PathItem`] provided by this router.
284284
pub fn with_path_items(
285285
mut self,
286-
mut transform: impl FnMut(TransformPathItem) -> TransformPathItem,
286+
mut transform: impl FnMut(TransformPathItem<'_>) -> TransformPathItem<'_>,
287287
) -> Self {
288288
for (_, item) in &mut self.paths {
289289
let _ = transform(TransformPathItem::new(item));
@@ -348,7 +348,7 @@ where
348348
mut self,
349349
path: &str,
350350
mut method_router: ApiMethodRouter<S>,
351-
transform: impl FnOnce(TransformPathItem) -> TransformPathItem,
351+
transform: impl FnOnce(TransformPathItem<'_>) -> TransformPathItem<'_>,
352352
) -> Self {
353353
in_context(|ctx| {
354354
let mut p = method_router.take_path_item();
@@ -380,7 +380,7 @@ where
380380
mut self,
381381
path: &str,
382382
mut method_router: ApiMethodRouter<S>,
383-
transform: impl FnOnce(TransformPathItem) -> TransformPathItem,
383+
transform: impl FnOnce(TransformPathItem<'_>) -> TransformPathItem<'_>,
384384
) -> Self {
385385
in_context(|ctx| {
386386
let mut p = method_router.take_path_item();
@@ -415,7 +415,7 @@ where
415415
#[tracing::instrument(skip_all)]
416416
pub fn finish_api_with<F>(mut self, api: &mut OpenApi, transform: F) -> Router<S>
417417
where
418-
F: FnOnce(TransformOpenApi) -> TransformOpenApi,
418+
F: FnOnce(TransformOpenApi<'_>) -> TransformOpenApi<'_>,
419419
{
420420
self.merge_api_with(api, transform);
421421
self.router
@@ -427,7 +427,7 @@ where
427427

428428
fn merge_api_with<F>(&mut self, api: &mut OpenApi, transform: F)
429429
where
430-
F: FnOnce(TransformOpenApi) -> TransformOpenApi,
430+
F: FnOnce(TransformOpenApi<'_>) -> TransformOpenApi<'_>,
431431
{
432432
if api.paths.is_none() {
433433
api.paths = Some(Default::default());
@@ -498,7 +498,7 @@ where
498498
mut self,
499499
path: &str,
500500
docs: routing::ApiMethodDocs,
501-
transform: impl FnOnce(TransformPathItem) -> TransformPathItem,
501+
transform: impl FnOnce(TransformPathItem<'_>) -> TransformPathItem<'_>,
502502
) -> Self {
503503
in_context(|ctx| {
504504
let mut path_item = if let Some(existing) = self.paths.get_mut(path) {

crates/aide/src/axum/routing/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ macro_rules! method_router_chain_method {
136136
I: OperationInput,
137137
O: OperationOutput,
138138
T: 'static,
139-
F: FnOnce(TransformOperation) -> TransformOperation,
139+
F: FnOnce(TransformOperation<'_>) -> TransformOperation<'_>,
140140
{
141141
let mut operation = Operation::default();
142142
in_context(|ctx| {
@@ -199,7 +199,7 @@ macro_rules! method_router_top_level {
199199
O: OperationOutput,
200200
S: Clone + Send + Sync + 'static,
201201
T: 'static,
202-
F: FnOnce(TransformOperation) -> TransformOperation,
202+
F: FnOnce(TransformOperation<'_>) -> TransformOperation<'_>,
203203
{
204204
let mut router = ApiMethodRouter::from(routing::$name(handler));
205205
let mut operation = Operation::default();

crates/aide/src/helpers/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
pub mod no_api;
2-
pub mod use_api;
3-
pub mod with_api;
1+
pub(crate) mod no_api;
2+
pub(crate) mod use_api;
3+
pub(crate) mod with_api;

crates/aide/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
//! it might support older versions but without guarantees.
115115
//!
116116
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
117-
#![warn(clippy::pedantic, missing_docs)]
117+
#![warn(clippy::pedantic, missing_docs, unreachable_pub, rust_2018_idioms)]
118118
#![allow(
119119
clippy::default_trait_access,
120120
clippy::doc_markdown,

crates/aide/src/openapi/openapi.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,16 @@ mod serde_version {
102102

103103
use serde::{Deserialize, Deserializer, Serialize, Serializer};
104104

105-
pub fn serialize<S: Serializer>(_: &Cow<'static, str>, ser: S) -> Result<S::Ok, S::Error> {
105+
pub(super) fn serialize<S: Serializer>(
106+
_: &Cow<'static, str>,
107+
ser: S,
108+
) -> Result<S::Ok, S::Error> {
106109
Cow::Borrowed("3.1.0").serialize(ser)
107110
}
108111

109-
pub fn deserialize<'de, D: Deserializer<'de>>(de: D) -> Result<Cow<'static, str>, D::Error> {
112+
pub(super) fn deserialize<'de, D: Deserializer<'de>>(
113+
de: D,
114+
) -> Result<Cow<'static, str>, D::Error> {
110115
<&'de str>::deserialize(de).and_then(|s| match s == "3.1.0" {
111116
true => Ok(Cow::Owned("3.1.0".to_owned())),
112117
false => Err(serde::de::Error::custom("expected 3.1.0")),

crates/aide/src/openapi/paths.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ pub struct Paths {
164164

165165
impl Paths {
166166
/// Iterate over path items.
167-
pub fn iter(&self) -> indexmap::map::Iter<String, ReferenceOr<PathItem>> {
167+
pub fn iter(&self) -> indexmap::map::Iter<'_, String, ReferenceOr<PathItem>> {
168168
self.paths.iter()
169169
}
170170
}

crates/aide/src/openapi/status_code.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl<'de> Deserialize<'de> for StatusCode {
2828
impl<'de> Visitor<'de> for StatusCodeVisitor {
2929
type Value = StatusCode;
3030

31-
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
31+
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
3232
formatter.write_str("number between 100 and 999 (as string or integer) or a string that matches `\\dXX`")
3333
}
3434

crates/aide/src/transform.rs

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ impl<'t> TransformOpenApi<'t> {
175175
pub fn default_response_with<R, F>(self, transform: F) -> Self
176176
where
177177
R: OperationOutput,
178-
F: Fn(TransformResponse<R::Inner>) -> TransformResponse<R::Inner> + Clone,
178+
F: Fn(TransformResponse<'_, R::Inner>) -> TransformResponse<'_, R::Inner> + Clone,
179179
{
180180
if let Some(p) = &mut self.api.paths {
181181
for (_, p) in &mut p.paths {
@@ -393,7 +393,7 @@ impl<'t> TransformPathItem<'t> {
393393
pub fn default_response_with<R, F>(self, transform: F) -> Self
394394
where
395395
R: OperationOutput,
396-
F: Fn(TransformResponse<R::Inner>) -> TransformResponse<R::Inner> + Clone,
396+
F: Fn(TransformResponse<'_, R::Inner>) -> TransformResponse<'_, R::Inner> + Clone,
397397
{
398398
in_context(|ctx| ctx.show_error = filter_no_duplicate_response);
399399

@@ -558,7 +558,7 @@ impl<'t> TransformOperation<'t> {
558558
pub fn parameter<T, F>(self, name: &str, transform: F) -> Self
559559
where
560560
T: Serialize,
561-
F: FnOnce(TransformParameter<T>) -> TransformParameter<T>,
561+
F: FnOnce(TransformParameter<'_, T>) -> TransformParameter<'_, T>,
562562
{
563563
let (idx, param) = match self
564564
.operation
@@ -601,7 +601,7 @@ impl<'t> TransformOperation<'t> {
601601
#[tracing::instrument(skip_all, fields(operation_id = self.operation.operation_id))]
602602
pub fn parameter_untyped<F>(self, name: &str, transform: F) -> Self
603603
where
604-
F: FnOnce(TransformParameter<()>) -> TransformParameter<()>,
604+
F: FnOnce(TransformParameter<'_, ()>) -> TransformParameter<'_, ()>,
605605
{
606606
self.parameter(name, transform)
607607
}
@@ -644,7 +644,7 @@ impl<'t> TransformOperation<'t> {
644644
pub fn default_response_with<R, F>(self, transform: F) -> Self
645645
where
646646
R: OperationOutput,
647-
F: FnOnce(TransformResponse<R::Inner>) -> TransformResponse<R::Inner>,
647+
F: FnOnce(TransformResponse<'_, R::Inner>) -> TransformResponse<'_, R::Inner>,
648648
{
649649
in_context(|ctx| {
650650
if let Some(mut res) = R::operation_response(ctx, self.operation) {
@@ -707,7 +707,7 @@ impl<'t> TransformOperation<'t> {
707707
pub fn response_with<const N: u16, R, F>(self, transform: F) -> Self
708708
where
709709
R: OperationOutput,
710-
F: FnOnce(TransformResponse<R::Inner>) -> TransformResponse<R::Inner>,
710+
F: FnOnce(TransformResponse<'_, R::Inner>) -> TransformResponse<'_, R::Inner>,
711711
{
712712
if self.operation.responses.is_none() {
713713
self.operation.responses = Some(Default::default());
@@ -777,7 +777,7 @@ impl<'t> TransformOperation<'t> {
777777
pub fn response_range_with<const N: u16, R, F>(self, transform: F) -> Self
778778
where
779779
R: OperationOutput,
780-
F: FnOnce(TransformResponse<R::Inner>) -> TransformResponse<R::Inner>,
780+
F: FnOnce(TransformResponse<'_, R::Inner>) -> TransformResponse<'_, R::Inner>,
781781
{
782782
if self.operation.responses.is_none() {
783783
self.operation.responses = Some(Default::default());
@@ -812,7 +812,7 @@ impl<'t> TransformOperation<'t> {
812812
self,
813813
callback_name: &str,
814814
callback_url: &str,
815-
callback_transform: impl FnOnce(TransformCallback) -> TransformCallback,
815+
callback_transform: impl FnOnce(TransformCallback<'_>) -> TransformCallback<'_>,
816816
) -> Self {
817817
let callbacks = self
818818
.operation
@@ -1115,7 +1115,10 @@ impl<'t> TransformCallback<'t> {
11151115

11161116
/// Add a "delete" callback operation.
11171117
#[allow(clippy::missing_panics_doc)]
1118-
pub fn delete(self, operation: impl FnOnce(TransformOperation) -> TransformOperation) -> Self {
1118+
pub fn delete(
1119+
self,
1120+
operation: impl FnOnce(TransformOperation<'_>) -> TransformOperation<'_>,
1121+
) -> Self {
11191122
let op = match &mut self.path.delete {
11201123
Some(op) => op,
11211124
None => {
@@ -1135,7 +1138,10 @@ impl<'t> TransformCallback<'t> {
11351138

11361139
/// Add a "get" callback operation.
11371140
#[allow(clippy::missing_panics_doc)]
1138-
pub fn get(self, operation: impl FnOnce(TransformOperation) -> TransformOperation) -> Self {
1141+
pub fn get(
1142+
self,
1143+
operation: impl FnOnce(TransformOperation<'_>) -> TransformOperation<'_>,
1144+
) -> Self {
11391145
let op = match &mut self.path.get {
11401146
Some(op) => op,
11411147
None => {
@@ -1155,7 +1161,10 @@ impl<'t> TransformCallback<'t> {
11551161

11561162
/// Add a "head" callback operation.
11571163
#[allow(clippy::missing_panics_doc)]
1158-
pub fn head(self, operation: impl FnOnce(TransformOperation) -> TransformOperation) -> Self {
1164+
pub fn head(
1165+
self,
1166+
operation: impl FnOnce(TransformOperation<'_>) -> TransformOperation<'_>,
1167+
) -> Self {
11591168
let op = match &mut self.path.head {
11601169
Some(op) => op,
11611170
None => {
@@ -1175,7 +1184,10 @@ impl<'t> TransformCallback<'t> {
11751184

11761185
/// Add a "options" callback operation.
11771186
#[allow(clippy::missing_panics_doc)]
1178-
pub fn options(self, operation: impl FnOnce(TransformOperation) -> TransformOperation) -> Self {
1187+
pub fn options(
1188+
self,
1189+
operation: impl FnOnce(TransformOperation<'_>) -> TransformOperation<'_>,
1190+
) -> Self {
11791191
let op = match &mut self.path.options {
11801192
Some(op) => op,
11811193
None => {
@@ -1195,7 +1207,10 @@ impl<'t> TransformCallback<'t> {
11951207

11961208
/// Add a "patch" callback operation.
11971209
#[allow(clippy::missing_panics_doc)]
1198-
pub fn patch(self, operation: impl FnOnce(TransformOperation) -> TransformOperation) -> Self {
1210+
pub fn patch(
1211+
self,
1212+
operation: impl FnOnce(TransformOperation<'_>) -> TransformOperation<'_>,
1213+
) -> Self {
11991214
let op = match &mut self.path.patch {
12001215
Some(op) => op,
12011216
None => {
@@ -1215,7 +1230,10 @@ impl<'t> TransformCallback<'t> {
12151230

12161231
/// Add a "post" callback operation.
12171232
#[allow(clippy::missing_panics_doc)]
1218-
pub fn post(self, operation: impl FnOnce(TransformOperation) -> TransformOperation) -> Self {
1233+
pub fn post(
1234+
self,
1235+
operation: impl FnOnce(TransformOperation<'_>) -> TransformOperation<'_>,
1236+
) -> Self {
12191237
let op = match &mut self.path.post {
12201238
Some(op) => op,
12211239
None => {
@@ -1235,7 +1253,10 @@ impl<'t> TransformCallback<'t> {
12351253

12361254
/// Add a "put" callback operation.
12371255
#[allow(clippy::missing_panics_doc)]
1238-
pub fn put(self, operation: impl FnOnce(TransformOperation) -> TransformOperation) -> Self {
1256+
pub fn put(
1257+
self,
1258+
operation: impl FnOnce(TransformOperation<'_>) -> TransformOperation<'_>,
1259+
) -> Self {
12391260
let op = match &mut self.path.put {
12401261
Some(op) => op,
12411262
None => {
@@ -1255,7 +1276,10 @@ impl<'t> TransformCallback<'t> {
12551276

12561277
/// Add a "trace" callback operation.
12571278
#[allow(clippy::missing_panics_doc)]
1258-
pub fn trace(self, operation: impl FnOnce(TransformOperation) -> TransformOperation) -> Self {
1279+
pub fn trace(
1280+
self,
1281+
operation: impl FnOnce(TransformOperation<'_>) -> TransformOperation<'_>,
1282+
) -> Self {
12591283
let op = match &mut self.path.trace {
12601284
Some(op) => op,
12611285
None => {
@@ -1274,7 +1298,10 @@ impl<'t> TransformCallback<'t> {
12741298
}
12751299

12761300
/// Apply an another transform function.
1277-
pub fn path(mut self, transform: impl FnOnce(TransformPathItem) -> TransformPathItem) -> Self {
1301+
pub fn path(
1302+
mut self,
1303+
transform: impl FnOnce(TransformPathItem<'_>) -> TransformPathItem<'_>,
1304+
) -> Self {
12781305
let t = transform(TransformPathItem::new(self.path));
12791306

12801307
if t.hidden {

crates/aide/src/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ mod spec {
184184
{
185185
type Value = IndexMap<K, V>;
186186

187-
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
187+
fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
188188
formatter.write_str("a map whose fields obey a predicate")
189189
}
190190

0 commit comments

Comments
 (0)