Skip to content

Commit 9c091b9

Browse files
committed
take some clippy pedantic suggestions
mostly docs
1 parent 5a58613 commit 9c091b9

File tree

7 files changed

+39
-22
lines changed

7 files changed

+39
-22
lines changed

src/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl AsRef<HugrMut> for HugrMut {
8181
}
8282
}
8383

84-
/// Trait allowing treating type as (im)mutable reference to HugrMut
84+
/// Trait allowing treating type as (im)mutable reference to [`HugrMut`]
8585
pub trait HugrMutRef: AsMut<HugrMut> + AsRef<HugrMut> {}
8686
impl HugrMutRef for HugrMut {}
8787
impl HugrMutRef for &mut HugrMut {}

src/builder/build_traits.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub trait Dataflow: Container {
104104
fn input_wires(&self) -> Outputs {
105105
self.input().outputs()
106106
}
107-
/// Add a dataflow op to the sibling graph, wiring up the input_wires to the
107+
/// Add a dataflow op to the sibling graph, wiring up the `input_wires` to the
108108
/// incoming ports of the resulting node.
109109
///
110110
/// # Errors
@@ -120,7 +120,7 @@ pub trait Dataflow: Container {
120120
Ok(outs.into())
121121
}
122122

123-
/// Wire up the output_wires to the input ports of the Output node.
123+
/// Wire up the `output_wires` to the input ports of the Output node.
124124
///
125125
/// # Errors
126126
///
@@ -142,7 +142,7 @@ pub trait Dataflow: Container {
142142
self.input_wires()
143143
.collect_vec()
144144
.try_into()
145-
.expect(&format!("Incorrect number of wires: {}", N)[..])
145+
.expect(&format!("Incorrect number of wires: {N}")[..])
146146
}
147147

148148
/// Return a builder for a [`crate::ops::dataflow::DataflowOp::DFG`] node, i.e. a nested dataflow subgraph.
@@ -255,7 +255,7 @@ pub trait Dataflow: Container {
255255
/// # Errors
256256
///
257257
/// This function will return an error if there is an error when building
258-
/// the TailLoop node.
258+
/// the [`ControlFlowOp::TailLoop`] node.
259259
fn tail_loop_builder(
260260
&mut self,
261261
just_inputs: impl IntoIterator<Item = (SimpleType, Wire)>,
@@ -279,7 +279,7 @@ pub trait Dataflow: Container {
279279
input_wires,
280280
)?;
281281

282-
TailLoopBuilder::create_with_io(self.base(), loop_node, tail_loop_signature)
282+
TailLoopBuilder::create_with_io(self.base(), loop_node, &tail_loop_signature)
283283
}
284284

285285
/// Return a builder for a [`crate::ops::controlflow::ControlFlowOp::Conditional`] node.
@@ -386,7 +386,7 @@ pub trait Dataflow: Container {
386386
/// # Errors
387387
///
388388
/// This function will return an error if there is an error adding the
389-
/// MakeTuple node.
389+
/// [`LeafOp::MakeTuple`] node.
390390
fn make_tuple(&mut self, values: impl IntoIterator<Item = Wire>) -> Result<Wire, BuildError> {
391391
let values = values.into_iter().collect_vec();
392392
let types: Result<Vec<SimpleType>, _> = values
@@ -427,7 +427,7 @@ pub trait Dataflow: Container {
427427
}
428428

429429
/// Use the wires in `values` to return a wire corresponding to the
430-
/// "Continue" variant of a TailLoop with `loop_signature`.
430+
/// "Continue" variant of a [`ControlFlowOp::TailLoop`] with `loop_signature`.
431431
///
432432
/// Packs the values in to a tuple and tags appropriately to generate a
433433
/// value of Sum type.
@@ -448,7 +448,7 @@ pub trait Dataflow: Container {
448448
}
449449

450450
/// Use the wires in `values` to return a wire corresponding to the
451-
/// "Break" variant of a TailLoop with `loop_signature`.
451+
/// "Break" variant of a [`ControlFlowOp::TailLoop`] with `loop_signature`.
452452
///
453453
/// Packs the values in to a tuple and tags appropriately to generate a
454454
/// value of Sum type.

src/builder/cfg.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,9 @@ impl<B: HugrMutRef> BlockBuilder<B> {
223223
) -> Result<Self, BuildError> {
224224
// The node outputs a predicate before the data outputs of the block node
225225
let predicate_type = SimpleType::new_predicate(predicate_variants);
226-
let node_outputs: TypeRow = [&[predicate_type], other_outputs.as_ref()].concat().into();
227-
let db = DFGBuilder::create_with_io(base, block_n, inputs, node_outputs)?;
226+
let mut node_outputs = vec![predicate_type];
227+
node_outputs.extend_from_slice(&other_outputs);
228+
let db = DFGBuilder::create_with_io(base, block_n, inputs, node_outputs.into())?;
228229
Ok(BlockBuilder::from_dfg_builder(db))
229230
}
230231
}
@@ -244,7 +245,7 @@ impl BlockBuilder<&mut HugrMut> {
244245
}
245246

246247
impl BlockBuilder<HugrMut> {
247-
/// Initialize a BasicBlock rooted HUGR builder
248+
/// Initialize a [`BasicBlockOp::Block`] rooted HUGR builder
248249
pub fn new(
249250
inputs: impl Into<TypeRow>,
250251
predicate_variants: impl IntoIterator<Item = TypeRow>,

src/builder/circuit_builder.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,22 @@ impl From<Wire> for AppendWire {
3737
}
3838

3939
#[derive(Debug, Clone, PartialEq, Eq, Error)]
40-
/// Error in CircuitBuilder
40+
/// Error in [`CircuitBuilder`]
4141
pub enum CircuitBuildError {
4242
/// Invalid index for stored wires.
4343
#[error("Invalid wire index.")]
4444
InvalidWireIndex,
4545
}
4646

4747
impl<'a, T: Dataflow + ?Sized> CircuitBuilder<'a, T> {
48-
/// Construct a new CircuitBuilder from a vector of incoming wires and the
48+
/// Construct a new [`CircuitBuilder`] from a vector of incoming wires and the
4949
/// builder for the graph
5050
pub fn new(wires: Vec<Wire>, builder: &'a mut T) -> Self {
5151
Self { wires, builder }
5252
}
5353

5454
/// Number of wires tracked, upper bound of valid wire indices
55+
#[must_use]
5556
pub fn n_wires(&self) -> usize {
5657
self.wires.len()
5758
}
@@ -184,7 +185,7 @@ mod test {
184185

185186
#[test]
186187
fn with_nonlinear_and_outputs() {
187-
use AppendWire::*;
188+
use AppendWire::{I, W};
188189
let build_res = build_main(
189190
Signature::new_df(type_row![QB, QB, F64], type_row![QB, QB, BIT]),
190191
|mut f_build| {

src/builder/dataflow.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ impl<T: HugrMutRef> DFGBuilder<T> {
5050
}
5151
impl DFGBuilder<HugrMut> {
5252
/// Begin building a new DFG rooted HUGR.
53+
///
54+
/// # Errors
55+
///
56+
/// Error in adding DFG child nodes.
5357
pub fn new(
5458
input: impl Into<TypeRow>,
5559
output: impl Into<TypeRow>,
@@ -123,6 +127,9 @@ pub type FunctionBuilder<B> = DFGWrapper<B, BuildHandle<FuncID<true>>>;
123127

124128
impl FunctionBuilder<HugrMut> {
125129
/// Initialize a builder for a Def rooted HUGR
130+
/// # Errors
131+
///
132+
/// Error in adding DFG child nodes.
126133
pub fn new(_name: impl Into<String>, signature: Signature) -> Result<Self, BuildError> {
127134
let inputs = signature.input.clone();
128135
let outputs = signature.output.clone();

src/builder/module_builder.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ impl<T: HugrMutRef> Container for ModuleBuilder<T> {
4040

4141
impl ModuleBuilder<HugrMut> {
4242
/// Begin building a new module.
43+
#[must_use]
4344
pub fn new() -> Self {
4445
Self(HugrMut::new_module())
4546
}
@@ -101,10 +102,10 @@ impl<T: HugrMutRef> ModuleBuilder<T> {
101102
/// [`ModuleOp::Def`] node.
102103
pub fn declare_and_def(
103104
&mut self,
104-
_name: impl Into<String>,
105+
name: impl Into<String>,
105106
signature: Signature,
106107
) -> Result<FunctionBuilder<&mut HugrMut>, BuildError> {
107-
let fid = self.declare(_name, signature)?;
108+
let fid = self.declare(name, signature)?;
108109
self.define_function(&fid)
109110
}
110111

@@ -126,6 +127,10 @@ impl<T: HugrMutRef> ModuleBuilder<T> {
126127
}
127128

128129
/// Add a [`ModuleOp::AliasDef`] node and return a handle to the Alias.
130+
///
131+
/// # Errors
132+
///
133+
/// Error in adding [`ModuleOp::AliasDef`] child node.
129134
pub fn add_alias_def(
130135
&mut self,
131136
name: impl Into<SmolStr>,
@@ -142,6 +147,9 @@ impl<T: HugrMutRef> ModuleBuilder<T> {
142147
}
143148

144149
/// Add a [`ModuleOp::AliasDeclare`] node and return a handle to the Alias.
150+
/// # Errors
151+
///
152+
/// Error in adding [`ModuleOp::AliasDeclare`] child node.
145153
pub fn add_alias_declare(
146154
&mut self,
147155
name: impl Into<SmolStr>,

src/builder/tail_loop.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl<B: HugrMutRef> TailLoopBuilder<B> {
2121
pub(super) fn create_with_io(
2222
base: B,
2323
loop_node: Node,
24-
tail_loop_sig: TailLoopSignature,
24+
tail_loop_sig: &TailLoopSignature,
2525
) -> Result<Self, BuildError> {
2626
let dfg_build = DFGBuilder::create_with_io(
2727
base,
@@ -32,7 +32,7 @@ impl<B: HugrMutRef> TailLoopBuilder<B> {
3232

3333
Ok(TailLoopBuilder::from_dfg_builder(dfg_build))
3434
}
35-
/// Set the outputs of the TailLoop, with `out_variant` as the value of the
35+
/// Set the outputs of the [`ControlFlowOp::TailLoop`], with `out_variant` as the value of the
3636
/// termination predicate, and `rest` being the remaining outputs
3737
pub fn set_outputs(
3838
&mut self,
@@ -43,7 +43,7 @@ impl<B: HugrMutRef> TailLoopBuilder<B> {
4343
}
4444

4545
/// Get a reference to the [`crate::ops::controlflow::TailLoopSignature`]
46-
/// that defines the signature of the TailLoop
46+
/// that defines the signature of the [`ControlFlowOp::TailLoop`]
4747
pub fn loop_signature(&self) -> Result<&TailLoopSignature, BuildError> {
4848
if let OpType::Dataflow(DataflowOp::ControlFlow {
4949
op: ControlFlowOp::TailLoop(tail_sig),
@@ -81,7 +81,7 @@ impl TailLoopBuilder<&mut HugrMut> {
8181
}
8282

8383
impl TailLoopBuilder<HugrMut> {
84-
/// Initialize new builder for a TailLoop rooted HUGR
84+
/// Initialize new builder for a [`ControlFlowOp::TailLoop`] rooted HUGR
8585
pub fn new(
8686
just_inputs: impl Into<TypeRow>,
8787
inputs_outputs: impl Into<TypeRow>,
@@ -95,7 +95,7 @@ impl TailLoopBuilder<HugrMut> {
9595
let op = ControlFlowOp::TailLoop(tail_loop_sig.clone());
9696
let base = HugrMut::new(op);
9797
let root = base.hugr().root();
98-
Self::create_with_io(base, root, tail_loop_sig)
98+
Self::create_with_io(base, root, &tail_loop_sig)
9999
}
100100
}
101101

0 commit comments

Comments
 (0)