Skip to content

Commit

Permalink
refactor: Fix unreachable_pub lints in types
Browse files Browse the repository at this point in the history
Sadly, due to a known issue ([#64762]) with the lint, `pub` items that
are exposed through multi-item intermediate `pub use` re-exports trigger
false positives with the lint. There are two ways of working around
this:

1. Avoiding multi-item `pub use` statements. This leads to swathes of
   mostly redundant `pub use` lines, especially on modules like `types`.
2. Leaking the structure of nested modules up to a reachable `pub use`.
   This leaves the export-point vulnerable to module reorganisation.

For this module, option 2 was chosen due to the sheer number of
re-exported items, and the relatively shallow module hierarchies.

[#64726]: rust-lang/rust#64762
  • Loading branch information
Chris Connelly authored and bochaco committed Jul 6, 2021
1 parent a75218d commit 93ed430
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/types/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use thiserror::Error;
pub type Result<T> = result::Result<T, Error>;

/// Error debug struct
pub struct ErrorDebug<'a, T>(pub &'a Result<T>);
struct ErrorDebug<'a, T>(&'a Result<T>);

impl<'a, T> Debug for ErrorDebug<'a, T> {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
Expand Down
16 changes: 5 additions & 11 deletions src/types/keys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,8 @@
//! `new` functions. A `PublicKey` can't be generated by itself; it must always be derived from a
//! secret key.

mod keypair;
mod node_keypairs;
mod public_key;
mod secret_key;
mod signature;

pub use self::signature::*;
pub use keypair::*;
pub use node_keypairs::*;
pub use public_key::*;
pub use secret_key::*;
pub(super) mod keypair;
pub(super) mod node_keypairs;
pub(super) mod public_key;
pub(super) mod secret_key;
pub(super) mod signature;
2 changes: 1 addition & 1 deletion src/types/keys/node_keypairs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
// specific language governing permissions and limitations relating to use of the SAFE Network
// Software.

use super::super::keys::{BlsKeypairShare, SignatureShare};
use super::super::{PublicKey, Signature};
use crate::types::{BlsKeypairShare, SignatureShare};
use bls::{serde_impl::SerdeSecret, PublicKeySet, SecretKeyShare as BlsSecretKeyShare};
use ed25519_dalek::Keypair as Ed25519Keypair;
use rand::{CryptoRng, Rng};
Expand Down
2 changes: 1 addition & 1 deletion src/types/keys/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ pub(crate) mod tests {
]
}

pub fn gen_keys() -> Vec<PublicKey> {
pub(crate) fn gen_keys() -> Vec<PublicKey> {
gen_keypairs().iter().map(PublicKey::from).collect()
}

Expand Down
22 changes: 14 additions & 8 deletions src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ pub use chunk::{
};
pub use errors::{Error, Result};
pub use keys::{
BlsKeypairShare, Keypair, NodeKeypairs, OwnerType, PublicKey, SecretKey, Signature,
SignatureShare, Signing,
keypair::{BlsKeypairShare, Keypair, OwnerType, Signing},
node_keypairs::NodeKeypairs,
public_key::PublicKey,
secret_key::SecretKey,
signature::{Signature, SignatureShare},
};
pub use map::{
Action as MapAction, Address as MapAddress, Entries as MapEntries,
Expand All @@ -39,12 +42,15 @@ pub use map::{
pub use register::Address as RegisterAddress;
pub use section::SectionElders;
pub use sequence::{
Action as SequenceAction, Address as SequenceAddress, Data as Sequence, DataOp as SequenceOp,
Entries as SequenceEntries, Entry as SequenceEntry, Index as SequenceIndex,
Kind as SequenceKind, Permissions as SequencePermissions, Policy as SequencePolicy,
PrivatePermissions as SequencePrivatePermissions, PrivatePolicy as SequencePrivatePolicy,
PrivateSeqData, PublicPermissions as SequencePublicPermissions,
PublicPolicy as SequencePublicPolicy, PublicSeqData, User as SequenceUser,
metadata::{
Action as SequenceAction, Address as SequenceAddress, Entries as SequenceEntries,
Entry as SequenceEntry, Index as SequenceIndex, Kind as SequenceKind,
Permissions as SequencePermissions, Policy as SequencePolicy,
PrivatePermissions as SequencePrivatePermissions, PrivatePolicy as SequencePrivatePolicy,
PublicPermissions as SequencePublicPermissions, PublicPolicy as SequencePublicPolicy,
User as SequenceUser,
},
Data as Sequence, DataOp as SequenceOp, PrivateSeqData, PublicSeqData,
};
pub use token::Token;

Expand Down
16 changes: 8 additions & 8 deletions src/types/register/reg_crdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub struct CrdtOperation<T> {

/// Register data type as a CRDT with Access Control
#[derive(Clone, Serialize, Deserialize, PartialEq, Eq, Hash, PartialOrd)]
pub struct RegisterCrdt {
pub(super) struct RegisterCrdt {
/// Address on the network of this piece of data
address: Address,
/// CRDT to store the actual data, i.e. the items of the Register.
Expand All @@ -60,26 +60,26 @@ impl Display for RegisterCrdt {

impl RegisterCrdt {
/// Constructs a new 'RegisterCrdt'.
pub fn new(address: Address) -> Self {
pub(super) fn new(address: Address) -> Self {
Self {
address,
data: MerkleReg::new(),
}
}

/// Returns the address.
pub fn address(&self) -> &Address {
pub(super) fn address(&self) -> &Address {
&self.address
}

/// Returns total number of items in the register.
pub fn size(&self) -> u64 {
pub(super) fn size(&self) -> u64 {
(self.data.num_nodes() + self.data.num_orphans()) as u64
}

/// Write a new entry to the RegisterCrdt, returning the hash
/// of the entry and the CRDT operation without a signature
pub fn write(
pub(super) fn write(
&mut self,
entry: Entry,
parents: BTreeSet<EntryHash>,
Expand All @@ -103,7 +103,7 @@ impl RegisterCrdt {
}

/// Apply a remote data CRDT operation to this replica of the RegisterCrdt.
pub fn apply_op(&mut self, op: CrdtOperation<Entry>) -> Result<()> {
pub(super) fn apply_op(&mut self, op: CrdtOperation<Entry>) -> Result<()> {
// Let's first check the op is validly signed.
// Note: Perms for the op are checked at the upper Register layer.
let sig = op.signature.ok_or(Error::CrdtMissingOpSignature)?;
Expand All @@ -127,12 +127,12 @@ impl RegisterCrdt {
}

/// Get the entry corresponding to the provided `hash` if it exists.
pub fn get(&self, hash: EntryHash) -> Option<&Entry> {
pub(super) fn get(&self, hash: EntryHash) -> Option<&Entry> {
self.data.node(hash).map(|node| &node.value)
}

/// Read the last entry, or entries if there are branches.
pub fn read(&self) -> BTreeSet<(EntryHash, Entry)> {
pub(super) fn read(&self) -> BTreeSet<(EntryHash, Entry)> {
self.data
.read()
.hashes_and_nodes()
Expand Down
8 changes: 4 additions & 4 deletions src/types/sequence/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
// specific language governing permissions and limitations relating to use of the SAFE Network
// Software.

mod metadata;
pub(super) mod metadata;
mod seq_crdt;

use super::{Error, PublicKey, Result};
pub use metadata::{
Action, Address, Entries, Entry, Index, Kind, Perm, Permissions, Policy, PrivatePermissions,
PrivatePolicy, PublicPermissions, PublicPolicy, User,
use metadata::{
Action, Address, Entries, Entry, Index, Kind, Perm, Permissions, PrivatePolicy, PublicPolicy,
User,
};
use seq_crdt::{CrdtOperation, SequenceCrdt};
use serde::{Deserialize, Serialize};
Expand Down
6 changes: 4 additions & 2 deletions src/types/sequence/seq_crdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
use super::super::{utils, Error, PublicKey, Result, Signature};
use super::metadata::Entries;
use super::metadata::{Address, Entry, Index, Perm};
pub use crdts::list::Op;
use crdts::{list::List, CmRDT};
use crdts::{
list::{List, Op},
CmRDT,
};
use serde::{Deserialize, Serialize};
use std::{
fmt::{self, Debug, Display},
Expand Down

0 comments on commit 93ed430

Please sign in to comment.