Skip to content

Commit 4767ae2

Browse files
chore: fixes new clippy lints (dfinity#673)
Looks like a recent bump of the Rust version on CI introduced new Clippy lints that make CI fail on dfinity#668 This PR fixes those lint errors on the `next` branch.
1 parent 434e6f3 commit 4767ae2

File tree

9 files changed

+69
-66
lines changed

9 files changed

+69
-66
lines changed

rust/candid/src/pretty/candid.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,15 @@ fn ident_string(id: &str) -> String {
7171
}
7272
}
7373

74-
pub fn pp_text(id: &str) -> RcDoc {
74+
pub fn pp_text(id: &str) -> RcDoc<'_> {
7575
RcDoc::text(ident_string(id))
7676
}
7777

78-
pub fn pp_ty(ty: &Type) -> RcDoc {
78+
pub fn pp_ty(ty: &Type) -> RcDoc<'_> {
7979
pp_ty_inner(ty.as_ref())
8080
}
8181

82-
pub fn pp_ty_inner(ty: &TypeInner) -> RcDoc {
82+
pub fn pp_ty_inner(ty: &TypeInner) -> RcDoc<'_> {
8383
use TypeInner::*;
8484
match ty {
8585
Null => str("null"),
@@ -130,18 +130,18 @@ pub fn pp_docs<'a>(docs: &'a [String]) -> RcDoc<'a> {
130130
/// This function is kept for backward compatibility.
131131
///
132132
/// It is recommended to use [`pp_label_raw`] instead, which accepts a [`Label`].
133-
pub fn pp_label(id: &SharedLabel) -> RcDoc {
133+
pub fn pp_label(id: &SharedLabel) -> RcDoc<'_> {
134134
pp_label_raw(id.as_ref())
135135
}
136136

137-
pub fn pp_label_raw(id: &Label) -> RcDoc {
137+
pub fn pp_label_raw(id: &Label) -> RcDoc<'_> {
138138
match id {
139139
Label::Named(id) => pp_text(id),
140140
Label::Id(_) | Label::Unnamed(_) => RcDoc::as_string(id),
141141
}
142142
}
143143

144-
pub(crate) fn pp_field(field: &Field, is_variant: bool) -> RcDoc {
144+
pub(crate) fn pp_field(field: &Field, is_variant: bool) -> RcDoc<'_> {
145145
let ty_doc = if is_variant && *field.ty == TypeInner::Null {
146146
RcDoc::nil()
147147
} else {
@@ -150,12 +150,12 @@ pub(crate) fn pp_field(field: &Field, is_variant: bool) -> RcDoc {
150150
pp_label_raw(&field.id).append(ty_doc)
151151
}
152152

153-
fn pp_fields(fs: &[Field], is_variant: bool) -> RcDoc {
153+
fn pp_fields(fs: &[Field], is_variant: bool) -> RcDoc<'_> {
154154
let fields = fs.iter().map(|f| pp_field(f, is_variant));
155155
enclose_space("{", concat(fields, ";"), "}")
156156
}
157157

158-
pub fn pp_function(func: &Function) -> RcDoc {
158+
pub fn pp_function(func: &Function) -> RcDoc<'_> {
159159
let args = pp_named_args(&func.args);
160160
let rets = pp_rets(&func.rets);
161161
let modes = pp_modes(&func.modes);
@@ -168,7 +168,7 @@ pub fn pp_function(func: &Function) -> RcDoc {
168168
/// Pretty-prints named arguments in the form of `(name1 : type1, name2 : type2)`.
169169
///
170170
/// To print unnamed arguments, use [`pp_args`] instead.
171-
pub fn pp_named_args(args: &[ArgType]) -> RcDoc {
171+
pub fn pp_named_args(args: &[ArgType]) -> RcDoc<'_> {
172172
let args = args.iter().map(|arg| {
173173
if let Some(name) = &arg.name {
174174
pp_text(name).append(kwd(" :")).append(pp_ty(&arg.typ))
@@ -183,24 +183,24 @@ pub fn pp_named_args(args: &[ArgType]) -> RcDoc {
183183
/// Pretty-prints arguments in the form of `(type1, type2)`.
184184
///
185185
/// To print named arguments, use [`pp_named_args`] instead.
186-
pub fn pp_args(args: &[Type]) -> RcDoc {
186+
pub fn pp_args(args: &[Type]) -> RcDoc<'_> {
187187
let doc = concat(args.iter().map(pp_ty), ",");
188188
enclose("(", doc, ")")
189189
}
190190

191191
/// Pretty-prints return types in the form of `(type1, type2)`.
192-
pub fn pp_rets(args: &[Type]) -> RcDoc {
192+
pub fn pp_rets(args: &[Type]) -> RcDoc<'_> {
193193
pp_args(args)
194194
}
195195

196-
pub fn pp_mode(mode: &FuncMode) -> RcDoc {
196+
pub fn pp_mode(mode: &FuncMode) -> RcDoc<'_> {
197197
match mode {
198198
FuncMode::Oneway => RcDoc::text("oneway"),
199199
FuncMode::Query => RcDoc::text("query"),
200200
FuncMode::CompositeQuery => RcDoc::text("composite_query"),
201201
}
202202
}
203-
pub fn pp_modes(modes: &[FuncMode]) -> RcDoc {
203+
pub fn pp_modes(modes: &[FuncMode]) -> RcDoc<'_> {
204204
RcDoc::concat(modes.iter().map(|m| RcDoc::space().append(pp_mode(m))))
205205
}
206206

@@ -223,7 +223,7 @@ fn pp_service<'a>(serv: &'a [(String, Type)], docs: Option<&'a DocComments>) ->
223223
enclose_space("{", doc, "}")
224224
}
225225

226-
fn pp_defs(env: &TypeEnv) -> RcDoc {
226+
fn pp_defs(env: &TypeEnv) -> RcDoc<'_> {
227227
lines(env.to_sorted_iter().map(|(id, ty)| {
228228
kwd("type")
229229
.append(ident(id.as_str()))
@@ -523,7 +523,7 @@ pub mod value {
523523
}
524524
}
525525

526-
fn pp_field(depth: usize, field: &IDLField, is_variant: bool) -> RcDoc {
526+
fn pp_field(depth: usize, field: &IDLField, is_variant: bool) -> RcDoc<'_> {
527527
let val_doc = if is_variant && field.val == IDLValue::Null {
528528
RcDoc::nil()
529529
} else {
@@ -532,7 +532,7 @@ pub mod value {
532532
pp_label_raw(&field.id).append(val_doc)
533533
}
534534

535-
fn pp_fields(depth: usize, fields: &[IDLField]) -> RcDoc {
535+
fn pp_fields(depth: usize, fields: &[IDLField]) -> RcDoc<'_> {
536536
let fs = concat(fields.iter().map(|f| pp_field(depth, f, false)), ";");
537537
enclose_space("{", fs, "}")
538538
}
@@ -545,7 +545,7 @@ pub mod value {
545545
format!("\\{v:02x}")
546546
}
547547
}
548-
pub fn pp_value(depth: usize, v: &IDLValue) -> RcDoc {
548+
pub fn pp_value(depth: usize, v: &IDLValue) -> RcDoc<'_> {
549549
use IDLValue::*;
550550
if depth == 0 {
551551
return RcDoc::as_string(format!("{v:?}"));
@@ -579,7 +579,7 @@ pub mod value {
579579
}
580580
}
581581

582-
pub fn pp_args(args: &IDLArgs) -> RcDoc {
582+
pub fn pp_args(args: &IDLArgs) -> RcDoc<'_> {
583583
let args = args
584584
.args
585585
.iter()

rust/candid/src/pretty/utils.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,19 @@ where
7171
RcDoc::concat(docs.map(|doc| doc.append(RcDoc::hardline())))
7272
}
7373

74-
pub fn kwd<U: std::fmt::Display + ?Sized>(str: &U) -> RcDoc {
74+
pub fn kwd<U: std::fmt::Display + ?Sized>(str: &U) -> RcDoc<'_> {
7575
RcDoc::as_string(str).append(RcDoc::space())
7676
}
7777

78-
pub fn str(str: &str) -> RcDoc {
78+
pub fn str(str: &str) -> RcDoc<'_> {
7979
RcDoc::text(str)
8080
}
8181

82-
pub fn ident(id: &str) -> RcDoc {
82+
pub fn ident(id: &str) -> RcDoc<'_> {
8383
kwd(id)
8484
}
8585

86-
pub fn quote_ident(id: &str) -> RcDoc {
86+
pub fn quote_ident(id: &str) -> RcDoc<'_> {
8787
str("'")
8888
.append(format!("{}", id.escape_debug()))
8989
.append("'")

rust/candid_parser/src/bindings/javascript.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,15 @@ static KEYWORDS: [&str; 64] = [
9191
"with",
9292
"yield",
9393
];
94-
pub(crate) fn ident(id: &str) -> RcDoc {
94+
pub(crate) fn ident(id: &str) -> RcDoc<'_> {
9595
if KEYWORDS.contains(&id) {
9696
str(id).append("_")
9797
} else {
9898
str(id)
9999
}
100100
}
101101

102-
fn pp_ty(ty: &Type) -> RcDoc {
102+
fn pp_ty(ty: &Type) -> RcDoc<'_> {
103103
use TypeInner::*;
104104
match ty.as_ref() {
105105
Null => str("IDL.Null"),
@@ -139,7 +139,7 @@ fn pp_ty(ty: &Type) -> RcDoc {
139139
}
140140
}
141141

142-
fn pp_label(id: &SharedLabel) -> RcDoc {
142+
fn pp_label(id: &SharedLabel) -> RcDoc<'_> {
143143
match &**id {
144144
Label::Named(str) => quote_ident(str),
145145
Label::Id(n) | Label::Unnamed(n) => str("_")
@@ -149,36 +149,36 @@ fn pp_label(id: &SharedLabel) -> RcDoc {
149149
}
150150
}
151151

152-
fn pp_field(field: &Field) -> RcDoc {
152+
fn pp_field(field: &Field) -> RcDoc<'_> {
153153
pp_label(&field.id)
154154
.append(kwd(":"))
155155
.append(pp_ty(&field.ty))
156156
}
157157

158-
fn pp_fields(fs: &[Field]) -> RcDoc {
158+
fn pp_fields(fs: &[Field]) -> RcDoc<'_> {
159159
let fields = concat(fs.iter().map(pp_field), ",");
160160
enclose_space("({", fields, "})")
161161
}
162162

163-
fn pp_function(func: &Function) -> RcDoc {
163+
fn pp_function(func: &Function) -> RcDoc<'_> {
164164
let args = pp_args(&func.args);
165165
let rets = pp_rets(&func.rets);
166166
let modes = pp_modes(&func.modes);
167167
let doc = concat([args, rets, modes].into_iter(), ",");
168168
enclose("(", doc, ")").nest(INDENT_SPACE)
169169
}
170170

171-
fn pp_args(args: &[ArgType]) -> RcDoc {
171+
fn pp_args(args: &[ArgType]) -> RcDoc<'_> {
172172
let doc = concat(args.iter().map(|arg| pp_ty(&arg.typ)), ",");
173173
enclose("[", doc, "]")
174174
}
175175

176-
fn pp_rets(args: &[Type]) -> RcDoc {
176+
fn pp_rets(args: &[Type]) -> RcDoc<'_> {
177177
let doc = concat(args.iter().map(pp_ty), ",");
178178
enclose("[", doc, "]")
179179
}
180180

181-
fn pp_modes(modes: &[candid::types::FuncMode]) -> RcDoc {
181+
fn pp_modes(modes: &[candid::types::FuncMode]) -> RcDoc<'_> {
182182
let doc = concat(
183183
modes
184184
.iter()
@@ -188,7 +188,7 @@ fn pp_modes(modes: &[candid::types::FuncMode]) -> RcDoc {
188188
enclose("[", doc, "]")
189189
}
190190

191-
fn pp_service(serv: &[(String, Type)]) -> RcDoc {
191+
fn pp_service(serv: &[(String, Type)]) -> RcDoc<'_> {
192192
let doc = concat(
193193
serv.iter()
194194
.map(|(id, func)| quote_ident(id).append(kwd(":")).append(pp_ty(func))),
@@ -298,7 +298,7 @@ pub mod value {
298298
_ => false,
299299
}
300300
}
301-
fn pp_label(id: &Label) -> RcDoc {
301+
fn pp_label(id: &Label) -> RcDoc<'_> {
302302
match id {
303303
Label::Named(str) => quote_ident(str),
304304
Label::Id(n) | Label::Unnamed(n) => str("_")
@@ -307,17 +307,17 @@ pub mod value {
307307
.append(RcDoc::space()),
308308
}
309309
}
310-
fn pp_field(field: &IDLField) -> RcDoc {
310+
fn pp_field(field: &IDLField) -> RcDoc<'_> {
311311
pp_label(&field.id)
312312
.append(": ")
313313
.append(pp_value(&field.val))
314314
}
315315

316-
fn pp_fields(fields: &[IDLField]) -> RcDoc {
316+
fn pp_fields(fields: &[IDLField]) -> RcDoc<'_> {
317317
concat(fields.iter().map(pp_field), ",")
318318
}
319319

320-
pub fn pp_value(v: &IDLValue) -> RcDoc {
320+
pub fn pp_value(v: &IDLValue) -> RcDoc<'_> {
321321
use IDLValue::*;
322322
match v {
323323
Number(_) | Int(_) | Nat(_) | Int64(_) | Nat64(_) => {
@@ -362,7 +362,7 @@ pub mod value {
362362
}
363363
}
364364

365-
pub fn pp_args(args: &IDLArgs) -> RcDoc {
365+
pub fn pp_args(args: &IDLArgs) -> RcDoc<'_> {
366366
let body = concat(args.args.iter().map(pp_value), ",");
367367
enclose("[", body, "]")
368368
}

rust/candid_parser/src/bindings/motoko.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static KEYWORDS: [&str; 48] = [
7878
"while",
7979
"with",
8080
];
81-
fn escape(id: &str, is_method: bool) -> RcDoc {
81+
fn escape(id: &str, is_method: bool) -> RcDoc<'_> {
8282
if KEYWORDS.contains(&id) {
8383
str(id).append("_")
8484
} else if is_valid_as_id(id) {
@@ -118,7 +118,7 @@ fn pp_ty_rich<'a>(ty: &'a Type, syntax: Option<&'a IDLType>) -> RcDoc<'a> {
118118
}
119119
}
120120

121-
fn pp_ty(ty: &Type) -> RcDoc {
121+
fn pp_ty(ty: &Type) -> RcDoc<'_> {
122122
use TypeInner::*;
123123
match ty.as_ref() {
124124
Null => str("Null"),
@@ -151,7 +151,7 @@ fn pp_ty(ty: &Type) -> RcDoc {
151151
}
152152
}
153153

154-
fn pp_label(id: &SharedLabel) -> RcDoc {
154+
fn pp_label(id: &SharedLabel) -> RcDoc<'_> {
155155
match &**id {
156156
Label::Named(str) => escape(str, false),
157157
Label::Id(n) | Label::Unnamed(n) => str("_")
@@ -161,7 +161,7 @@ fn pp_label(id: &SharedLabel) -> RcDoc {
161161
}
162162
}
163163

164-
fn pp_function(func: &Function) -> RcDoc {
164+
fn pp_function(func: &Function) -> RcDoc<'_> {
165165
let args = pp_args(&func.args);
166166
let rets = pp_rets(&func.rets);
167167
match func.modes.as_slice() {
@@ -185,7 +185,7 @@ fn pp_function(func: &Function) -> RcDoc {
185185
}
186186
.nest(INDENT_SPACE)
187187
}
188-
fn pp_args(args: &[ArgType]) -> RcDoc {
188+
fn pp_args(args: &[ArgType]) -> RcDoc<'_> {
189189
match args {
190190
[ty] => {
191191
let typ = if is_tuple(&ty.typ) {
@@ -212,7 +212,7 @@ fn pp_args(args: &[ArgType]) -> RcDoc {
212212
}
213213
}
214214

215-
fn pp_rets(args: &[Type]) -> RcDoc {
215+
fn pp_rets(args: &[Type]) -> RcDoc<'_> {
216216
match args {
217217
[ty] => {
218218
if is_tuple(ty) {

rust/candid_parser/src/bindings/rust.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ static KEYWORDS: [&str; 51] = [
131131
"while", "async", "await", "dyn", "abstract", "become", "box", "do", "final", "macro",
132132
"override", "priv", "typeof", "unsized", "virtual", "yield", "try",
133133
];
134-
fn ident_(id: &str, case: Option<Case>) -> (RcDoc, bool) {
134+
fn ident_(id: &str, case: Option<Case>) -> (RcDoc<'_>, bool) {
135135
if id.is_empty()
136136
|| id.starts_with(|c: char| !c.is_ascii_alphabetic() && c != '_')
137137
|| id.chars().any(|c| !c.is_ascii_alphanumeric() && c != '_')
@@ -152,7 +152,7 @@ fn ident_(id: &str, case: Option<Case>) -> (RcDoc, bool) {
152152
(RcDoc::text(id), is_rename)
153153
}
154154
}
155-
fn ident(id: &str, case: Option<Case>) -> RcDoc {
155+
fn ident(id: &str, case: Option<Case>) -> RcDoc<'_> {
156156
ident_(id, case).0
157157
}
158158
fn pp_vis<'a>(vis: &Option<String>) -> RcDoc<'a> {
@@ -1032,7 +1032,7 @@ impl<'b> NominalState<'_, 'b> {
10321032
if let Some(syntax) = syntax {
10331033
self.generated_types.insert(new_var.clone(), syntax);
10341034
}
1035-
TypeInner::Var(new_var.into())
1035+
TypeInner::Var(new_var)
10361036
}
10371037
}
10381038
TypeInner::Variant(fs) => {
@@ -1078,7 +1078,7 @@ impl<'b> NominalState<'_, 'b> {
10781078
if let Some(syntax) = syntax {
10791079
self.generated_types.insert(new_var.clone(), syntax);
10801080
}
1081-
TypeInner::Var(new_var.into())
1081+
TypeInner::Var(new_var)
10821082
}
10831083
}
10841084
TypeInner::Func(func) => match path.last() {

rust/candid_parser/src/bindings/typescript.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ fn pp_inline_service<'a>() -> RcDoc<'a> {
9999
str("Principal")
100100
}
101101

102-
fn pp_label(id: &SharedLabel) -> RcDoc {
102+
fn pp_label(id: &SharedLabel) -> RcDoc<'_> {
103103
match &**id {
104104
Label::Named(str) => quote_ident(str),
105105
Label::Id(n) | Label::Unnamed(n) => str("_")

0 commit comments

Comments
 (0)