Skip to content

Commit fa35840

Browse files
aborgna-qcqc-alec
andauthored
chore: Fix new lints in rust 1.83 (#1686)
New rust coming on 2024-11-28. This PR fixes new lints that would make our CI runs fail. A big noisy change is due to public test definitions now triggering the `missing_docs` lint. See [rust-lang/rust#130025](https://www.github.com/rust-lang/rust/pull/130025). This can be fixed avoided either by adding the docs or by making functions private. Passing check: https://github.com/CQCL/hugr/actions/runs/12013283775/job/33486450494#step:7:1 --------- Co-authored-by: Alec Edgington <[email protected]>
1 parent 8e797ae commit fa35840

File tree

16 files changed

+76
-31
lines changed

16 files changed

+76
-31
lines changed

Cargo.toml

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ lto = "thin"
33

44
[workspace]
55
resolver = "2"
6-
members = ["hugr", "hugr-core", "hugr-passes", "hugr-cli", "hugr-model", "hugr-llvm"]
6+
members = [
7+
"hugr",
8+
"hugr-core",
9+
"hugr-passes",
10+
"hugr-cli",
11+
"hugr-model",
12+
"hugr-llvm",
13+
]
714
default-members = ["hugr", "hugr-core", "hugr-passes", "hugr-cli", "hugr-model"]
815

916
[workspace.package]

hugr-core/src/extension.rs

+1
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,7 @@ impl FromIterator<ExtensionId> for ExtensionSet {
624624
}
625625
}
626626

627+
/// Extension tests.
627628
#[cfg(test)]
628629
pub mod test {
629630
// We re-export this here because mod op_def is private.

hugr-core/src/extension/op_def.rs

+2
Original file line numberDiff line numberDiff line change
@@ -514,10 +514,12 @@ pub(super) mod test {
514514
const EXT_ID: ExtensionId = "MyExt";
515515
}
516516

517+
/// A dummy wrapper over an operation definition.
517518
#[derive(serde::Serialize, serde::Deserialize, Debug)]
518519
pub struct SimpleOpDef(OpDef);
519520

520521
impl SimpleOpDef {
522+
/// Create a new dummy opdef.
521523
pub fn new(op_def: OpDef) -> Self {
522524
assert!(op_def.constant_folder.is_none());
523525
assert!(matches!(

hugr-core/src/hugr/internal.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ pub trait HugrInternals {
3232
}
3333

3434
impl<T: AsRef<Hugr>> HugrInternals for T {
35-
type Portgraph<'p> = &'p MultiPortGraph where Self: 'p;
35+
type Portgraph<'p>
36+
= &'p MultiPortGraph
37+
where
38+
Self: 'p;
3639

3740
#[inline]
3841
fn portgraph(&self) -> Self::Portgraph<'_> {

hugr-core/src/hugr/serialize/test.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Tests for the HUGR serialization format.
2+
13
use super::*;
24
use crate::builder::{
35
endo_sig, inout_sig, test::closed_dfg_root_hugr, Container, DFGBuilder, Dataflow, DataflowHugr,
@@ -182,13 +184,15 @@ pub fn check_hugr_roundtrip(hugr: &Hugr, check_schema: bool) -> Hugr {
182184
new_hugr
183185
}
184186

187+
/// Deserialize a HUGR json, ensuring that it is valid against the schema.
185188
pub fn check_hugr_deserialize(hugr: &Hugr, value: serde_json::Value, check_schema: bool) -> Hugr {
186189
let new_hugr = ser_deserialize_check_schema(value, get_schemas(check_schema));
187190

188191
check_hugr(hugr, &new_hugr);
189192
new_hugr
190193
}
191194

195+
/// Check that two HUGRs are equivalent, up to node renumbering.
192196
pub fn check_hugr(lhs: &Hugr, rhs: &Hugr) {
193197
// Original HUGR, with canonicalized node indices
194198
//

hugr-core/src/hugr/views/descendants.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl<'g, Root: NodeHandle> HugrView for DescendantsGraph<'g, Root> {
124124
self.graph.all_neighbours(node.pg_index()).map_into()
125125
}
126126
}
127-
impl<'g, Root: NodeHandle> RootTagged for DescendantsGraph<'g, Root> {
127+
impl<Root: NodeHandle> RootTagged for DescendantsGraph<'_, Root> {
128128
type RootHandle = Root;
129129
}
130130

@@ -144,13 +144,16 @@ where
144144
}
145145
}
146146

147-
impl<'g, Root: NodeHandle> ExtractHugr for DescendantsGraph<'g, Root> {}
147+
impl<Root: NodeHandle> ExtractHugr for DescendantsGraph<'_, Root> {}
148148

149149
impl<'g, Root> super::HugrInternals for DescendantsGraph<'g, Root>
150150
where
151151
Root: NodeHandle,
152152
{
153-
type Portgraph<'p> = &'p RegionGraph<'g> where Self: 'p;
153+
type Portgraph<'p>
154+
= &'p RegionGraph<'g>
155+
where
156+
Self: 'p;
154157

155158
#[inline]
156159
fn portgraph(&self) -> Self::Portgraph<'_> {

hugr-core/src/hugr/views/petgraph.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ pub struct PetgraphWrapper<'a, T> {
1616
pub(crate) hugr: &'a T,
1717
}
1818

19-
impl<'a, T> Clone for PetgraphWrapper<'a, T> {
19+
impl<T> Clone for PetgraphWrapper<'_, T> {
2020
fn clone(&self) -> Self {
2121
*self
2222
}
2323
}
2424

25-
impl<'a, T> Copy for PetgraphWrapper<'a, T> {}
25+
impl<T> Copy for PetgraphWrapper<'_, T> {}
2626

2727
impl<'a, T> From<&'a T> for PetgraphWrapper<'a, T>
2828
where
@@ -33,24 +33,24 @@ where
3333
}
3434
}
3535

36-
impl<'a, T> pv::GraphBase for PetgraphWrapper<'a, T>
36+
impl<T> pv::GraphBase for PetgraphWrapper<'_, T>
3737
where
3838
T: HugrView,
3939
{
4040
type NodeId = Node;
4141
type EdgeId = ((Node, Port), (Node, Port));
4242
}
4343

44-
impl<'a, T> pv::GraphProp for PetgraphWrapper<'a, T>
44+
impl<T> pv::GraphProp for PetgraphWrapper<'_, T>
4545
where
4646
T: HugrView,
4747
{
4848
type EdgeType = petgraph::Directed;
4949
}
5050

51-
impl<'a, T> pv::GraphRef for PetgraphWrapper<'a, T> where T: HugrView {}
51+
impl<T> pv::GraphRef for PetgraphWrapper<'_, T> where T: HugrView {}
5252

53-
impl<'a, T> pv::NodeCount for PetgraphWrapper<'a, T>
53+
impl<T> pv::NodeCount for PetgraphWrapper<'_, T>
5454
where
5555
T: HugrView,
5656
{
@@ -59,7 +59,7 @@ where
5959
}
6060
}
6161

62-
impl<'a, T> pv::NodeIndexable for PetgraphWrapper<'a, T>
62+
impl<T> pv::NodeIndexable for PetgraphWrapper<'_, T>
6363
where
6464
T: HugrView,
6565
{
@@ -76,7 +76,7 @@ where
7676
}
7777
}
7878

79-
impl<'a, T> pv::EdgeCount for PetgraphWrapper<'a, T>
79+
impl<T> pv::EdgeCount for PetgraphWrapper<'_, T>
8080
where
8181
T: HugrView,
8282
{
@@ -85,7 +85,7 @@ where
8585
}
8686
}
8787

88-
impl<'a, T> pv::Data for PetgraphWrapper<'a, T>
88+
impl<T> pv::Data for PetgraphWrapper<'_, T>
8989
where
9090
T: HugrView,
9191
{
@@ -146,7 +146,7 @@ where
146146
}
147147
}
148148

149-
impl<'a, T> pv::Visitable for PetgraphWrapper<'a, T>
149+
impl<T> pv::Visitable for PetgraphWrapper<'_, T>
150150
where
151151
T: HugrView,
152152
{
@@ -161,7 +161,7 @@ where
161161
}
162162
}
163163

164-
impl<'a, T> pv::GetAdjacencyMatrix for PetgraphWrapper<'a, T>
164+
impl<T> pv::GetAdjacencyMatrix for PetgraphWrapper<'_, T>
165165
where
166166
T: HugrView,
167167
{

hugr-core/src/hugr/views/sibling.rs

+15-8
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl<'g, Root: NodeHandle> HugrView for SiblingGraph<'g, Root> {
140140
self.graph.all_neighbours(node.pg_index()).map_into()
141141
}
142142
}
143-
impl<'g, Root: NodeHandle> RootTagged for SiblingGraph<'g, Root> {
143+
impl<Root: NodeHandle> RootTagged for SiblingGraph<'_, Root> {
144144
type RootHandle = Root;
145145
}
146146

@@ -171,13 +171,16 @@ where
171171
}
172172
}
173173

174-
impl<'g, Root: NodeHandle> ExtractHugr for SiblingGraph<'g, Root> {}
174+
impl<Root: NodeHandle> ExtractHugr for SiblingGraph<'_, Root> {}
175175

176176
impl<'g, Root> HugrInternals for SiblingGraph<'g, Root>
177177
where
178178
Root: NodeHandle,
179179
{
180-
type Portgraph<'p> = &'p FlatRegionGraph<'g> where Self: 'p;
180+
type Portgraph<'p>
181+
= &'p FlatRegionGraph<'g>
182+
where
183+
Self: 'p;
181184

182185
#[inline]
183186
fn portgraph(&self) -> Self::Portgraph<'_> {
@@ -236,10 +239,14 @@ impl<'g, Root: NodeHandle> SiblingMut<'g, Root> {
236239
}
237240
}
238241

239-
impl<'g, Root: NodeHandle> ExtractHugr for SiblingMut<'g, Root> {}
242+
impl<Root: NodeHandle> ExtractHugr for SiblingMut<'_, Root> {}
240243

241244
impl<'g, Root: NodeHandle> HugrInternals for SiblingMut<'g, Root> {
242-
type Portgraph<'p> = FlatRegionGraph<'p> where 'g: 'p, Root: 'p;
245+
type Portgraph<'p>
246+
= FlatRegionGraph<'p>
247+
where
248+
'g: 'p,
249+
Root: 'p;
243250

244251
fn portgraph(&self) -> Self::Portgraph<'_> {
245252
FlatRegionGraph::new_flat_region(
@@ -311,17 +318,17 @@ impl<'g, Root: NodeHandle> HugrView for SiblingMut<'g, Root> {
311318
}
312319
}
313320

314-
impl<'g, Root: NodeHandle> RootTagged for SiblingMut<'g, Root> {
321+
impl<Root: NodeHandle> RootTagged for SiblingMut<'_, Root> {
315322
type RootHandle = Root;
316323
}
317324

318-
impl<'g, Root: NodeHandle> HugrMutInternals for SiblingMut<'g, Root> {
325+
impl<Root: NodeHandle> HugrMutInternals for SiblingMut<'_, Root> {
319326
fn hugr_mut(&mut self) -> &mut Hugr {
320327
self.hugr
321328
}
322329
}
323330

324-
impl<'g, Root: NodeHandle> HugrMut for SiblingMut<'g, Root> {}
331+
impl<Root: NodeHandle> HugrMut for SiblingMut<'_, Root> {}
325332

326333
#[cfg(test)]
327334
mod test {

hugr-core/src/hugr/views/sibling_subgraph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ impl<'g, Base: HugrView> TopoConvexChecker<'g, Base> {
514514
}
515515
}
516516

517-
impl<'g, Base: HugrView> ConvexChecker for TopoConvexChecker<'g, Base> {
517+
impl<Base: HugrView> ConvexChecker for TopoConvexChecker<'_, Base> {
518518
fn is_convex(
519519
&self,
520520
nodes: impl IntoIterator<Item = portgraph::NodeIndex>,

hugr-core/src/proptest.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Generator functions for property testing the Hugr data structures.
2+
13
use ::proptest::collection::vec;
24
use ::proptest::prelude::*;
35
use lazy_static::lazy_static;
@@ -38,6 +40,7 @@ pub struct RecursionDepth(usize);
3840

3941
impl RecursionDepth {
4042
const DEFAULT_RECURSION_DEPTH: usize = 4;
43+
/// Decrement the recursion depth counter.
4144
pub fn descend(&self) -> Self {
4245
if self.leaf() {
4346
*self
@@ -46,10 +49,12 @@ impl RecursionDepth {
4649
}
4750
}
4851

52+
/// Returns `true` if the recursion depth counter is zero.
4953
pub fn leaf(&self) -> bool {
5054
self.0 == 0
5155
}
5256

57+
/// Create a new [RecursionDepth] with the default recursion depth.
5358
pub fn new() -> Self {
5459
Self(Self::DEFAULT_RECURSION_DEPTH)
5560
}
@@ -135,26 +140,32 @@ lazy_static! {
135140
};
136141
}
137142

143+
/// A strategy for generating an arbitrary nonempty [String].
138144
pub fn any_nonempty_string() -> SBoxedStrategy<String> {
139145
ANY_NONEMPTY_STRING.to_owned()
140146
}
141147

148+
/// A strategy for generating an arbitrary nonempty [SmolStr].
142149
pub fn any_nonempty_smolstr() -> SBoxedStrategy<SmolStr> {
143150
ANY_NONEMPTY_STRING.to_owned().prop_map_into().sboxed()
144151
}
145152

153+
/// A strategy for generating an arbitrary nonempty identifier [String].
146154
pub fn any_ident_string() -> SBoxedStrategy<String> {
147155
ANY_IDENT_STRING.to_owned()
148156
}
149157

158+
/// A strategy for generating an arbitrary [String].
150159
pub fn any_string() -> SBoxedStrategy<String> {
151160
ANY_STRING.to_owned()
152161
}
153162

163+
/// A strategy for generating an arbitrary [SmolStr].
154164
pub fn any_smolstr() -> SBoxedStrategy<SmolStr> {
155165
ANY_STRING.clone().prop_map_into().sboxed()
156166
}
157167

168+
/// A strategy for generating an arbitrary [serde_json::Value].
158169
pub fn any_serde_json_value() -> impl Strategy<Value = serde_json::Value> {
159170
ANY_SERDE_JSON_VALUE_LEAF
160171
.clone()
@@ -175,6 +186,7 @@ pub fn any_serde_json_value() -> impl Strategy<Value = serde_json::Value> {
175186
.boxed()
176187
}
177188

189+
/// A strategy for generating an arbitrary HUGR.
178190
pub fn any_hugr() -> SBoxedStrategy<Hugr> {
179191
ANY_HUGR.to_owned()
180192
}

hugr-core/src/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ impl From<Type> for TypeRV {
540540
/// (Variables out of the range of the list will result in a panic)
541541
pub(crate) struct Substitution<'a>(&'a [TypeArg], &'a ExtensionRegistry);
542542

543-
impl<'a> Substitution<'a> {
543+
impl Substitution<'_> {
544544
pub(crate) fn apply_var(&self, idx: usize, decl: &TypeParam) -> TypeArg {
545545
let arg = self
546546
.0

hugr-core/src/types/custom.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl From<CustomType> for Type {
139139
}
140140

141141
#[cfg(test)]
142-
pub mod test {
142+
mod test {
143143

144144
pub mod proptest {
145145
use crate::extension::ExtensionId;

hugr-core/tests/model.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(missing_docs)]
2+
13
use hugr::std_extensions::std_reg;
24
use hugr_core::{export::export_hugr, import::import_hugr};
35
use hugr_model::v0 as model;

hugr-model/src/v0/text/print.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl<'p, 'a: 'p> PrintContext<'p, 'a> {
109109
let root_data = self
110110
.module
111111
.get_region(root_id)
112-
.ok_or_else(|| PrintError::RegionNotFound(root_id))?;
112+
.ok_or(PrintError::RegionNotFound(root_id))?;
113113

114114
self.print_meta(root_data.meta)?;
115115
self.print_nodes(root_id)?;
@@ -132,7 +132,7 @@ impl<'p, 'a: 'p> PrintContext<'p, 'a> {
132132
let node_data = self
133133
.module
134134
.get_node(node_id)
135-
.ok_or_else(|| PrintError::NodeNotFound(node_id))?;
135+
.ok_or(PrintError::NodeNotFound(node_id))?;
136136

137137
self.print_parens(|this| match &node_data.operation {
138138
Operation::Invalid => Err(ModelError::InvalidOperation(node_id)),
@@ -473,7 +473,7 @@ impl<'p, 'a: 'p> PrintContext<'p, 'a> {
473473
let term_data = self
474474
.module
475475
.get_term(term_id)
476-
.ok_or_else(|| PrintError::TermNotFound(term_id))?;
476+
.ok_or(PrintError::TermNotFound(term_id))?;
477477

478478
match term_data {
479479
Term::Wildcard => {
@@ -617,7 +617,7 @@ impl<'p, 'a: 'p> PrintContext<'p, 'a> {
617617
let node_data = self
618618
.module
619619
.get_node(node_id)
620-
.ok_or_else(|| PrintError::NodeNotFound(node_id))?;
620+
.ok_or(PrintError::NodeNotFound(node_id))?;
621621

622622
let name = match &node_data.operation {
623623
Operation::DefineFunc { decl } => decl.name,

hugr-model/tests/binary.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(missing_docs)]
2+
13
use bumpalo::Bump;
24
use hugr_model::v0 as model;
35
use pretty_assertions::assert_eq;

0 commit comments

Comments
 (0)