Skip to content

Commit 443a5c1

Browse files
authored
Use workspace lint settings (#1224)
This change shifts from having common lints described at the top of each crate's lib.rs to having them in a single top-level lints section of the workspace Cargo.toml. This feature was new as of Rust 1.74, but we hadn't switched to it ahead of the initial release. Of note, a few crates were missing the top-level lints, so had lots of fixup to do to get them up to the bar of the rest of code.
1 parent c91ac5d commit 443a5c1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+314
-272
lines changed

Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ quantum-sparse-sim = { git = "https://github.com/qir-alliance/qir-runner", rev =
6565
async-trait = "0.1"
6666
tokio = { version = "1.35", features = ["macros", "rt"] }
6767

68+
[workspace.lints.clippy]
69+
mod_module_files = "warn"
70+
pedantic = "warn"
71+
unwrap_used = "warn"
72+
missing_errors_doc = "allow"
73+
missing_panics_doc = "allow"
74+
module_name_repetitions = "allow"
75+
6876
[profile.release]
6977
debug = 1
7078
strip = true

compiler/qsc/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ criterion = { workspace = true, features = ["cargo_bench_support"] }
3434
expect-test = { workspace = true }
3535
indoc = { workspace = true }
3636

37+
[lints]
38+
workspace = true
39+
3740
[lib]
3841
bench = false
3942
doctest = false

compiler/qsc/benches/eval.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn teleport(c: &mut Criterion) {
2828
let mut out = Vec::new();
2929
let mut rec = GenericReceiver::new(&mut out);
3030
assert!(evaluator.eval_entry(&mut rec).is_ok());
31-
})
31+
});
3232
});
3333
}
3434

@@ -47,7 +47,7 @@ pub fn deutsch_jozsa(c: &mut Criterion) {
4747
let mut out = Vec::new();
4848
let mut rec = GenericReceiver::new(&mut out);
4949
assert!(evaluator.eval_entry(&mut rec).is_ok());
50-
})
50+
});
5151
});
5252
}
5353

@@ -66,7 +66,7 @@ pub fn large_file(c: &mut Criterion) {
6666
let mut out = Vec::new();
6767
let mut rec = GenericReceiver::new(&mut out);
6868
assert!(evaluator.eval_entry(&mut rec).is_ok());
69-
})
69+
});
7070
});
7171
}
7272

@@ -97,7 +97,7 @@ pub fn array_append(c: &mut Criterion) {
9797
let mut out = Vec::new();
9898
let mut rec = GenericReceiver::new(&mut out);
9999
assert!(evaluator.eval_entry(&mut rec).is_ok());
100-
})
100+
});
101101
});
102102
}
103103

@@ -128,7 +128,7 @@ pub fn array_update(c: &mut Criterion) {
128128
let mut out = Vec::new();
129129
let mut rec = GenericReceiver::new(&mut out);
130130
assert!(evaluator.eval_entry(&mut rec).is_ok());
131-
})
131+
});
132132
});
133133
}
134134

@@ -147,7 +147,7 @@ pub fn array_literal(c: &mut Criterion) {
147147
let mut out = Vec::new();
148148
let mut rec = GenericReceiver::new(&mut out);
149149
assert!(evaluator.eval_entry(&mut rec).is_ok());
150-
})
150+
});
151151
});
152152
}
153153

@@ -183,7 +183,7 @@ pub fn large_nested_iteration(c: &mut Criterion) {
183183
let mut out = Vec::new();
184184
let mut rec = GenericReceiver::new(&mut out);
185185
assert!(evaluator.eval_entry(&mut rec).is_ok());
186-
})
186+
});
187187
});
188188
}
189189

compiler/qsc/benches/large.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub fn large_file(c: &mut Criterion) {
2424
LanguageFeatures::default(),
2525
);
2626
assert!(reports.is_empty());
27-
})
27+
});
2828
});
2929
}
3030

compiler/qsc/benches/library.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use qsc_frontend::compile::{PackageStore, RuntimeCapabilityFlags};
88
pub fn library(c: &mut Criterion) {
99
let store = PackageStore::new(compile::core());
1010
c.bench_function("Standard library", |b| {
11-
b.iter(|| compile::std(&store, RuntimeCapabilityFlags::all()))
11+
b.iter(|| compile::std(&store, RuntimeCapabilityFlags::all()));
1212
});
1313
}
1414

compiler/qsc/build.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
#![warn(clippy::mod_module_files, clippy::pedantic, clippy::unwrap_used)]
5-
#![allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
6-
74
use std::process::Command;
85

96
fn main() {

compiler/qsc/src/bin/memtest.rs

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ impl<A: GlobalAlloc> AllocationCounter<A> {
4545
#[global_allocator]
4646
static ALLOCATOR: AllocationCounter<System> = AllocationCounter::new(System);
4747

48+
#[must_use]
4849
pub fn compile_stdlib() -> CompileUnit {
4950
let store = PackageStore::new(compile::core());
5051
compile::std(&store, RuntimeCapabilityFlags::all())

compiler/qsc/src/bin/qsc.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
#![warn(clippy::mod_module_files, clippy::pedantic, clippy::unwrap_used)]
5-
#![allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
6-
74
use clap::{crate_version, ArgGroup, Parser, ValueEnum};
85
use log::info;
96
use miette::{Context, IntoDiagnostic, Report};

compiler/qsc/src/bin/qsi.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
#![warn(clippy::mod_module_files, clippy::pedantic, clippy::unwrap_used)]
5-
#![allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
6-
74
use clap::{crate_version, Parser};
85
use miette::{Context, IntoDiagnostic, Report, Result};
96
use num_bigint::BigUint;

compiler/qsc/src/interpret.rs

-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ pub struct Interpreter {
113113
env: Env,
114114
}
115115

116-
#[allow(clippy::module_name_repetitions)]
117116
pub type InterpretResult = std::result::Result<Value, Vec<Error>>;
118117

119118
impl Interpreter {

compiler/qsc/src/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
#![warn(clippy::mod_module_files, clippy::pedantic, clippy::unwrap_used)]
5-
#![allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
6-
74
pub mod compile;
85
pub mod error;
96
pub mod incremental;

compiler/qsc_ast/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@ miette = { workspace = true }
1414
num-bigint = { workspace = true }
1515
qsc_data_structures = { path = "../qsc_data_structures" }
1616

17+
[lints]
18+
workspace = true
19+
1720
[lib]
1821
doctest = false

compiler/qsc_ast/src/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
#![warn(clippy::mod_module_files, clippy::pedantic, clippy::unwrap_used)]
5-
#![allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
6-
74
pub mod assigner;
85
pub mod ast;
96
pub mod mut_visit;

compiler/qsc_codegen/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@ expect-test = { workspace = true }
2323
indoc = { workspace = true }
2424
qsc_passes = { path = "../qsc_passes" }
2525

26+
[lints]
27+
workspace = true
28+
2629
[lib]
2730
doctest = false

compiler/qsc_codegen/src/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
#![warn(clippy::mod_module_files, clippy::pedantic, clippy::unwrap_used)]
5-
#![allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
6-
74
pub mod qir_base;

compiler/qsc_data_structures/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,8 @@ bitflags = { workspace = true }
1616
[dev-dependencies]
1717
expect-test = { workspace = true }
1818

19+
[lints]
20+
workspace = true
21+
1922
[lib]
2023
doctest = false

compiler/qsc_data_structures/src/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
#![warn(clippy::mod_module_files, clippy::pedantic, clippy::unwrap_used)]
5-
#![allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
6-
74
pub mod display;
85
pub mod functors;
96
pub mod index_map;

compiler/qsc_data_structures/src/span.rs

-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ impl From<Span> for SourceSpan {
7575
}
7676
}
7777

78-
#[allow(clippy::module_name_repetitions)]
7978
pub trait WithSpan {
8079
#[must_use]
8180
fn with_span(self, span: Span) -> Self;

compiler/qsc_doc_gen/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@ qsc_ast = { path = "../qsc_ast" }
1818
qsc_hir = { path = "../qsc_hir" }
1919
rustc-hash = { workspace = true }
2020

21+
[lints]
22+
workspace = true
23+
2124
[lib]
2225
doctest = false

compiler/qsc_doc_gen/src/display.rs

+11
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,20 @@ pub struct CodeDisplay<'a> {
5656

5757
#[allow(clippy::unused_self)]
5858
impl<'a> CodeDisplay<'a> {
59+
#[must_use]
5960
pub fn hir_callable_decl(&self, decl: &'a hir::CallableDecl) -> impl Display + '_ {
6061
HirCallableDecl { decl }
6162
}
6263

64+
#[must_use]
6365
pub fn ast_callable_decl(&self, decl: &'a ast::CallableDecl) -> impl Display + '_ {
6466
AstCallableDecl {
6567
lookup: self.compilation,
6668
decl,
6769
}
6870
}
6971

72+
#[must_use]
7073
pub fn name_ty_id(&self, name: &'a str, ty_id: ast::NodeId) -> impl Display + '_ {
7174
NameTyId {
7275
lookup: self.compilation,
@@ -75,22 +78,27 @@ impl<'a> CodeDisplay<'a> {
7578
}
7679
}
7780

81+
#[must_use]
7882
pub fn ident_ty(&self, ident: &'a ast::Ident, ty: &'a ast::Ty) -> impl Display + '_ {
7983
IdentTy { ident, ty }
8084
}
8185

86+
#[must_use]
8287
pub fn ident_ty_def(&self, ident: &'a ast::Ident, def: &'a ast::TyDef) -> impl Display + 'a {
8388
IdentTyDef { ident, def }
8489
}
8590

91+
#[must_use]
8692
pub fn hir_udt(&self, udt: &'a ty::Udt) -> impl Display + '_ {
8793
HirUdt { udt }
8894
}
8995

96+
#[must_use]
9097
pub fn hir_pat(&self, pat: &'a hir::Pat) -> impl Display + '_ {
9198
HirPat { pat }
9299
}
93100

101+
#[must_use]
94102
pub fn get_param_offset(&self, decl: &hir::CallableDecl) -> u32 {
95103
HirCallableDecl { decl }.get_param_offset()
96104
}
@@ -601,13 +609,15 @@ fn eval_functor_expr(expr: &ast::FunctorExpr) -> ty::FunctorSetValue {
601609

602610
/// Takes a doc string from Q# and increases all of the markdown header levels by one level.
603611
/// i.e. `# Summary` becomes `## Summary`
612+
#[must_use]
604613
pub fn increase_header_level(doc: &str) -> String {
605614
let re = Regex::new(r"(?mi)^(#+)( [\s\S]+?)$").expect("Invalid regex");
606615
re.replace_all(doc, "$1#$2").to_string()
607616
}
608617

609618
/// Takes a doc string from Q# and returns the contents of the `# Summary` section. If no
610619
/// such section can be found, returns the original doc string.
620+
#[must_use]
611621
pub fn parse_doc_for_summary(doc: &str) -> String {
612622
let re = Regex::new(r"(?mi)(?:^# Summary$)([\s\S]*?)(?:(^# .*)|\z)").expect("Invalid regex");
613623
match re.captures(doc) {
@@ -626,6 +636,7 @@ pub fn parse_doc_for_summary(doc: &str) -> String {
626636
/// Takes a doc string from a Q# callable and the name of a parameter of
627637
/// that callable. Returns the description of that parameter found in the
628638
/// doc string. If no description is found, returns the empty string.
639+
#[must_use]
629640
pub fn parse_doc_for_param(doc: &str, param: &str) -> String {
630641
let re = Regex::new(r"(?mi)(?:^# Input$)([\s\S]*?)(?:(^# .*)|\z)").expect("Invalid regex");
631642
let input = match re.captures(doc) {

compiler/qsc_doc_gen/src/generate_docs.rs

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ impl Lookup for Compilation {
102102
}
103103
}
104104

105+
#[must_use]
105106
pub fn generate_docs() -> Files {
106107
let compilation = Compilation::new();
107108
let mut files: Files = vec![];

compiler/qsc_eval/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,8 @@ indoc = { workspace = true }
2727
qsc_frontend = { path = "../qsc_frontend" }
2828
qsc_passes = { path = "../qsc_passes" }
2929

30+
[lints]
31+
workspace = true
32+
3033
[lib]
3134
doctest = false

compiler/qsc_eval/src/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
#![warn(clippy::mod_module_files, clippy::pedantic, clippy::unwrap_used)]
5-
#![allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
6-
74
#[cfg(test)]
85
mod tests;
96

compiler/qsc_eval/src/lower.rs

-1
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,6 @@ fn lower_functor_set_value(value: qsc_hir::ty::FunctorSetValue) -> qsc_fir::ty::
683683
}
684684

685685
#[must_use]
686-
#[allow(clippy::module_name_repetitions)]
687686
fn lower_local_item_id(id: qsc_hir::hir::LocalItemId) -> LocalItemId {
688687
LocalItemId::from(usize::from(id))
689688
}

compiler/qsc_fir/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@ num-bigint = { workspace = true }
1414
qsc_data_structures = { path = "../qsc_data_structures" }
1515
rustc-hash = { workspace = true }
1616

17+
[lints]
18+
workspace = true
19+
1720
[lib]
1821
doctest = false

compiler/qsc_fir/src/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
#![warn(clippy::mod_module_files, clippy::pedantic, clippy::unwrap_used)]
5-
#![allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
6-
74
pub mod assigner;
85
pub mod fir;
96
pub mod global;

compiler/qsc_frontend/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@ thiserror = { workspace = true }
2323
expect-test = { workspace = true }
2424
indoc = { workspace = true }
2525

26+
[lints]
27+
workspace = true
28+
2629
[lib]
2730
doctest = false

compiler/qsc_frontend/src/compile.rs

-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ impl From<ConfigAttr> for RuntimeCapabilityFlags {
9090
}
9191
}
9292

93-
#[allow(clippy::module_name_repetitions)]
9493
#[derive(Debug, Default)]
9594
pub struct CompileUnit {
9695
pub package: hir::Package,

compiler/qsc_frontend/src/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
#![warn(clippy::mod_module_files, clippy::pedantic, clippy::unwrap_used)]
5-
#![allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
6-
74
mod closure;
85
pub mod compile;
96
pub mod error;

compiler/qsc_hir/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@ num-bigint = { workspace = true }
1414
qsc_data_structures = { path = "../qsc_data_structures" }
1515
rustc-hash = { workspace = true }
1616

17+
[lints]
18+
workspace = true
19+
1720
[lib]
1821
doctest = false

0 commit comments

Comments
 (0)