Skip to content

Commit 3f171b1

Browse files
authored
Merge pull request #4414 from nyurik/ctest-lints
chore: lint `ctest` crate
2 parents f2dc14f + 511bdcf commit 3f171b1

File tree

2 files changed

+33
-50
lines changed

2 files changed

+33
-50
lines changed

ctest/Cargo.toml

+1-13
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,6 @@ indoc = "2.0.6"
1818
# once MSRV is above 1.64 and replaced with `[lints] workspace=true`
1919

2020
[lints.rust]
21-
# FIXME(cleanup): make ident usage consistent in each file
22-
unused_qualifications = "allow"
21+
unused_qualifications = "warn"
2322

2423
[lints.clippy]
25-
# FIXME(clippy): fix these
26-
doc_lazy_continuation = "allow"
27-
if_same_then_else = "allow"
28-
needless_borrow = "allow"
29-
needless_borrowed_reference = "allow"
30-
needless_borrows_for_generic_args = "allow"
31-
needless_lifetimes = "allow"
32-
only_used_in_recursion = "allow"
33-
option_as_ref_deref = "allow"
34-
type_complexity = "allow"
35-
useless_format = "allow"

ctest/src/lib.rs

+32-37
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ pub enum VolatileItemKind {
7474
/// This builder has a number of configuration options which modify how the
7575
/// generated tests are emitted, and it is also the main entry point for parsing
7676
/// an FFI header crate for definitions.
77+
#[allow(clippy::type_complexity)]
7778
pub struct TestGenerator {
7879
headers: Vec<String>,
7980
includes: Vec<PathBuf>,
@@ -163,7 +164,7 @@ impl TestGenerator {
163164
f.to_string()
164165
}
165166
}),
166-
const_cname: Box::new(std::string::ToString::to_string),
167+
const_cname: Box::new(ToString::to_string),
167168
rust_version: rustc_version::version().unwrap(),
168169
}
169170
}
@@ -324,7 +325,7 @@ impl TestGenerator {
324325
/// ```
325326
pub fn define(&mut self, k: &str, v: Option<&str>) -> &mut Self {
326327
self.defines
327-
.push((k.to_string(), v.map(std::string::ToString::to_string)));
328+
.push((k.to_string(), v.map(ToString::to_string)));
328329
self
329330
}
330331

@@ -337,10 +338,10 @@ impl TestGenerator {
337338
/// optional value of `v`:
338339
///
339340
/// * `k == "foo"` and `v == None` makes `#[cfg(foo)]` expand. That is,
340-
/// `cfg!(foo)` expands to `true`.
341+
/// `cfg!(foo)` expands to `true`.
341342
///
342343
/// * `k == "bar"` and `v == Some("baz")` makes `#[cfg(bar = "baz")]`
343-
/// expand. That is, `cfg!(bar = "baz")` expands to `true`.
344+
/// expand. That is, `cfg!(bar = "baz")` expands to `true`.
344345
///
345346
/// # Examples
346347
///
@@ -352,8 +353,7 @@ impl TestGenerator {
352353
/// .cfg("bar", Some("baz")); // cfg!(bar = "baz")
353354
/// ```
354355
pub fn cfg(&mut self, k: &str, v: Option<&str>) -> &mut Self {
355-
self.cfg
356-
.push((k.to_string(), v.map(std::string::ToString::to_string)));
356+
self.cfg.push((k.to_string(), v.map(ToString::to_string)));
357357
self
358358
}
359359

@@ -811,7 +811,7 @@ impl TestGenerator {
811811
Lang::C => "c",
812812
Lang::CXX => "cpp",
813813
};
814-
cfg.file(&out.with_extension(ext));
814+
cfg.file(out.with_extension(ext));
815815
if target.contains("msvc") {
816816
cfg.flag("/W3").flag("/Wall").flag("/WX")
817817
// ignored warnings
@@ -844,7 +844,7 @@ impl TestGenerator {
844844
cfg.flag(flag);
845845
}
846846

847-
for &(ref a, ref b) in &self.defines {
847+
for (a, b) in &self.defines {
848848
cfg.define(a, b.as_ref().map(|s| &s[..]));
849849
}
850850
for p in &self.includes {
@@ -884,7 +884,7 @@ impl TestGenerator {
884884
.clone()
885885
.unwrap_or_else(|| env::var("TARGET").unwrap());
886886
for (k, v) in default_cfg(&target).into_iter().chain(self.cfg.clone()) {
887-
let s = |s: &str| ast::Name::intern(s);
887+
let s = |s: &str| Name::intern(s);
888888
sess.config.insert((s(&k), v.as_ref().map(|n| s(n))));
889889
}
890890

@@ -995,9 +995,7 @@ fn default_cfg(target: &str) -> Vec<(String, Option<String>)> {
995995
("powerpc", "32", "big")
996996
} else if target.starts_with("s390x") {
997997
("s390x", "64", "big")
998-
} else if target.starts_with("sparc64") {
999-
("sparc64", "64", "big")
1000-
} else if target.starts_with("sparcv9") {
998+
} else if target.starts_with("sparc64") || target.starts_with("sparcv9") {
1001999
("sparc64", "64", "big")
10021000
} else if target.starts_with("asmjs") {
10031001
("asmjs", "32", "little")
@@ -1092,7 +1090,7 @@ fn linkage(lang: &Lang) -> &'static str {
10921090
}
10931091
}
10941092

1095-
impl<'a> Generator<'a> {
1093+
impl Generator<'_> {
10961094
fn rust2c_test(&self, ty: &str) -> bool {
10971095
let rustc_types = [
10981096
"usize", "u8", "u16", "u32", "u64", "isize", "i8", "i16", "i32", "i64",
@@ -1116,7 +1114,7 @@ impl<'a> Generator<'a> {
11161114

11171115
fn rust2c(&self, ty: &str) -> String {
11181116
match ty {
1119-
"c_longdouble" | "c_long_double" => format!("long double"),
1117+
"c_longdouble" | "c_long_double" => "long double".to_string(),
11201118
t if t.starts_with("c_") => match &ty[2..].replace("long", " long")[..] {
11211119
s if s.starts_with('u') => format!("unsigned {}", &s[1..]),
11221120
"short" => "short".to_string(),
@@ -1983,8 +1981,8 @@ impl<'a> Generator<'a> {
19831981
ast::TyKind::Path(_, ref path) => {
19841982
let last = path.segments.last().unwrap();
19851983
if last.identifier.to_string() == "Option" {
1986-
match last.parameters.as_ref().map(|p| &**p) {
1987-
Some(&ast::PathParameters::AngleBracketed(ref p)) => {
1984+
match last.parameters.as_deref() {
1985+
Some(ast::PathParameters::AngleBracketed(p)) => {
19881986
self.ty2name(&p.types[0], rust)
19891987
}
19901988
_ => panic!(),
@@ -2016,7 +2014,7 @@ impl<'a> Generator<'a> {
20162014
format!("{} {modifier}*", self.ty2name(&t.ty, rust))
20172015
}
20182016
ast::TyKind::Array(ref t, ref e) => {
2019-
let len = self.expr2str(e);
2017+
let len = Self::expr2str(e);
20202018
let ty = self.ty2name(t, rust);
20212019
format!("{modifier} {ty} [{len}]")
20222020
}
@@ -2055,9 +2053,9 @@ impl<'a> Generator<'a> {
20552053
}
20562054
ast::TyKind::Array(ref t, ref e) => {
20572055
if rust {
2058-
format!("[{}; {}]", self.ty2name(t, rust), self.expr2str(e))
2056+
format!("[{}; {}]", self.ty2name(t, rust), Self::expr2str(e))
20592057
} else {
2060-
let len = self.expr2str(e);
2058+
let len = Self::expr2str(e);
20612059
let ty = self.ty2name(t, rust);
20622060
format!("{ty} [{len}]")
20632061
}
@@ -2124,8 +2122,8 @@ impl<'a> Generator<'a> {
21242122
if path.segments.last().unwrap().identifier.to_string() == "Option" =>
21252123
{
21262124
let last = path.segments.last().unwrap();
2127-
match last.parameters.as_ref().map(|s| &**s) {
2128-
Some(&ast::PathParameters::AngleBracketed(ref p)) => {
2125+
match last.parameters.as_deref() {
2126+
Some(ast::PathParameters::AngleBracketed(p)) => {
21292127
self.csig_returning_ptr(&p.types[0], sig)
21302128
}
21312129
_ => panic!(),
@@ -2146,16 +2144,16 @@ impl<'a> Generator<'a> {
21462144
ast::TyKind::Array(ref t2, ref e2) => format!(
21472145
"{}(*{sig})[{}][{}]",
21482146
self.ty2name(t2, false),
2149-
self.expr2str(e),
2150-
self.expr2str(e2)
2147+
Self::expr2str(e),
2148+
Self::expr2str(e2)
21512149
),
2152-
_ => format!("{}(*{sig})[{}]", self.ty2name(t, false), self.expr2str(e)),
2150+
_ => format!("{}(*{sig})[{}]", self.ty2name(t, false), Self::expr2str(e)),
21532151
},
21542152
_ => format!("{}* {sig}", self.ty2name(ty, false)),
21552153
}
21562154
}
21572155

2158-
fn expr2str(&self, e: &ast::Expr) -> String {
2156+
fn expr2str(e: &ast::Expr) -> String {
21592157
match e.node {
21602158
ast::ExprKind::Lit(ref l) => match l.node {
21612159
ast::LitKind::Int(a, _) => a.to_string(),
@@ -2164,10 +2162,10 @@ impl<'a> Generator<'a> {
21642162
ast::ExprKind::Path(_, ref path) => {
21652163
path.segments.last().unwrap().identifier.to_string()
21662164
}
2167-
ast::ExprKind::Cast(ref e, _) => self.expr2str(e),
2165+
ast::ExprKind::Cast(ref e, _) => Self::expr2str(e),
21682166
ast::ExprKind::Binary(ref op, ref e1, ref e2) => {
2169-
let e1 = self.expr2str(e1);
2170-
let e2 = self.expr2str(e2);
2167+
let e1 = Self::expr2str(e1);
2168+
let e2 = Self::expr2str(e2);
21712169
match op.node {
21722170
ast::BinOpKind::Add => format!("{e1} + {e2}"),
21732171
ast::BinOpKind::Sub => format!("{e1} - {e2}"),
@@ -2246,7 +2244,7 @@ impl<'a> Generator<'a> {
22462244
}
22472245
}
22482246

2249-
impl<'a, 'v> Visitor<'v> for Generator<'a> {
2247+
impl<'v> Visitor<'v> for Generator<'_> {
22502248
fn visit_item(&mut self, i: &'v ast::Item) {
22512249
let prev_abi = self.abi;
22522250
let public = i.vis == ast::Visibility::Public;
@@ -2299,10 +2297,7 @@ impl<'a, 'v> Visitor<'v> for Generator<'a> {
22992297
self.assert_no_generics(i.ident, generics);
23002298
for arg in &decl.inputs {
23012299
if let ast::TyKind::Array(_, _) = arg.ty.node {
2302-
panic!(
2303-
"Foreign Function decl `{}` uses array in C FFI",
2304-
i.ident
2305-
);
2300+
panic!("Foreign Function decl `{}` uses array in C FFI", i.ident);
23062301
}
23072302
}
23082303

@@ -2314,8 +2309,8 @@ impl<'a, 'v> Visitor<'v> for Generator<'a> {
23142309
.unwrap();
23152310
}
23162311
ast::ForeignItemKind::Static(ref ty, mutbl) => {
2317-
let rust_ty = self.ty2name(&ty, true);
2318-
let c_ty = self.ty2name(&ty, false);
2312+
let rust_ty = self.ty2name(ty, true);
2313+
let c_ty = self.ty2name(ty, false);
23192314
let c_name = attr::first_attr_value_str_by_name(&i.attrs, "link_name")
23202315
.map(|i| i.to_string());
23212316
self.test_extern_static(&i.ident.to_string(), c_name, &rust_ty, &c_ty, mutbl)
@@ -2354,7 +2349,7 @@ struct MyResolver<'a> {
23542349
map: HashMap<Name, Rc<SyntaxExtension>>,
23552350
}
23562351

2357-
impl<'a> Resolver for MyResolver<'a> {
2352+
impl Resolver for MyResolver<'_> {
23582353
fn next_node_id(&mut self) -> ast::NodeId {
23592354
self.id += 1;
23602355
ast::NodeId::new(self.id)
@@ -2461,7 +2456,7 @@ struct MyVisitor<'b> {
24612456
map: &'b mut HashMap<Name, Rc<SyntaxExtension>>,
24622457
}
24632458

2464-
impl<'a, 'b> Visitor<'a> for MyVisitor<'b> {
2459+
impl<'a> Visitor<'a> for MyVisitor<'_> {
24652460
fn visit_item(&mut self, item: &'a ast::Item) {
24662461
if let ast::ItemKind::MacroDef(..) = item.node {
24672462
self.map.insert(

0 commit comments

Comments
 (0)