Commit Graph

36 Commits

Author SHA1 Message Date
Nick Mathewson cec6d0ce33 Run add_warnings on all files. 2023-08-04 07:45:04 -04:00
Ian Jackson 473447a82e Run maint/add_warning to actually apply new lint allows 2023-07-10 13:49:51 +01:00
Nick Mathewson 03f9f9987a Run add_warning to remove `missing_panics_doc` deny.
Closes #950.
2023-07-06 14:32:23 -04:00
Ian Jackson 161b9844da lints: Run maint/add_warning to actually apply new lints 2023-06-21 12:15:41 +01:00
Ian Jackson bb2ab7c2a3 tor-units: Fix IntegerMinutes accessor (omg) 2023-02-09 12:56:18 +00:00
Nick Mathewson bf04641c68 Disable clippy::unlinlined-format-args
This warning kind of snuck up on us! (See #748)  For now, let's
disable it.  (I've cleaned it up in a couple of examples, since
those are meant to be more idiomatic and user-facing.)

Closes #748.
2023-01-27 08:27:47 -05:00
Nick Mathewson 136f70545d tor-units: Add an IntegerMinutes. 2023-01-11 09:10:08 -05:00
Nick Mathewson 932fe48eaf Run add_warnings. 2022-11-03 11:06:02 -04:00
Nick Mathewson 8f267ba166 Fix some rustdoc errors.
In addition to the usual "You named that method wrong!" errors, we
have a new rustdoc error that complains about bogus "HTML tags" that
are actually unquoted usage of types like `Result<Foo>`.
2022-10-13 09:08:46 -04:00
Ian Jackson f84d8777db cargo fmt to remove blank lines
Apparently cargo fmt doesn't like these, which my perl rune didn't
delete.

This commit is precisely the result of `cargo fmt`.
2022-10-12 15:29:04 +01:00
Ian Jackson d9910dba08 Replace all README copies in src/lib.rs with includes
The feature we want is `#[doc = include_str!("README.md")]`, which is
stable since 1.54 and our MSRV is now 1.56.

This commit is precisely the result of the following Perl rune:
  perl -i~ -0777 -pe 's{(^//!(?!.*\@\@).*\n)+}{#![doc = include_str!("../README.md")]\n}m' crates/*/src/lib.rs
2022-10-12 15:29:03 +01:00
trinity-1686a 7f939fa480 enable doc_auto_cfg feature on every crate when documenting for docs.rs 2022-08-24 18:22:41 +02:00
Ian Jackson 589c6e52bb Run maint/add_warning crates/*/src/{lib,main}.rs
Update all lint blocks
2022-06-23 19:15:42 +01:00
Nick Mathewson 210f3f1587 Merge branch 'error_cleanup' into 'main'
Error cleanup, part 1

See merge request tpo/core/arti!601
2022-06-22 19:43:50 +00:00
Nick Mathewson 9ba7750dfe Style fixes to tor-units errors. 2022-06-22 08:42:13 -04:00
Ian Jackson b1b840c7c6 tor-units: IntegerTimeUnit: Provide try_map
This lets a caller map the inner value, eg to convert the type.
I don't provide `map` as well as `try_map` now, since I don't need it;
we could add it later if it is desirable (although try_map can always
be used instead).

I was hoping to provide a `TryFrom` instead, but that necesasrily
overlaps with the std conversion impl from IntegerMilliseconds<T> to
IntegerMilliseconds<U> where T == U.
2022-06-21 19:19:22 +01:00
Ian Jackson 0ea34e3280 tor-units: IntegerTimeUnit: Relax condition on T
It is semantically quite meaningful for these to contain something
that isn't `TryInto<u64>`.  (Of course the `Duration` conversion won't
work without that.)

Indeed, this condition was only applied to two out of the three types.

Prompted by being near this code, but not actually necessary for
anything I'm doing here.
2022-06-21 19:19:22 +01:00
Ian Jackson ec756c79e7 tor-units: IntegerTimeUnit: Provide as_time_unit deconstructor
We're going to need this to use this in the padding timer parameters.
2022-06-21 19:19:22 +01:00
Ian Jackson 4f42101554 lints: Add let_unit_value allow to all crates
From running add_warning, with manual picking of the right
hunks/lines.
2022-05-31 15:23:52 +01:00
Ian Jackson ba0843da4a lints: Add lint block delimiters to every crate
This was the result of:
  maint/add_warning crates/*/src/{lib,main}.rs
and then manually curating the results.
2022-05-31 13:00:31 +01:00
Nick Mathewson 2f6bc6bdc4 squash! Bump every crate's edition to 2021.
Remove all `use` statements for `TryFrom` and `TryInto`.  These are
now redundant in Rust 2021.
2022-04-25 13:06:26 -04:00
Ian Jackson afb50fe735 Disable clippy::clone_on_ref_ptr
This lint is IMO inherently ill-conceived.

I have looked for the reasons why this might be thought to be a good
idea and there were basically two (and they are sort of contradictory):

I. "Calling ‘.clone()` on an Rc, Arc, or Weak can obscure the fact
    that only the pointer is being cloned, not the underlying data."

This is the wording from
  https://rust-lang.github.io/rust-clippy/v0.0.212/#clone_on_ref_ptr

It is a bit terse; we are left to infer why it is a bad idea to
obscure this fact.  It seems to me that if it is bad to obscure some
fact, that must be because the fact is a hazard.  But why would it be
a hazard to not copy the underlying data ?

In other languages, faliing to copy the underlying data is a serious
correctness hazard.  There is a whose class of bugs where things were
not copied, and then mutated and/or reused in multiple places in ways
that were not what the programmer intended.  In my experience, this is
a very common bug when writing Python and Javascript.  I'm told it's
common in golang too.

But in Rust this bug is much much harder to write.  The data inside an
Arc is immutable.  To have this bug you'd have use interior mutability
- ie mess around with Mutex or RefCell.  That provides a good barrier
to these kind of accidents.

II. "The reason for writing Rc::clone and Arc::clone [is] to make it
     clear that only the pointer is being cloned, as opposed to the
     underlying data. The former is always fast, while the latter can
     be very expensive depending on what is being cloned."

This is the reasoning found here
  https://github.com/rust-lang/rust-clippy/issues/2048

This is saying that *not* using Arc::clone is hazardous.
Specifically, that a deep clone is a performance hazard.

But for this argument, the lint is precisely backwards.  It's linting
the "good" case and asking for it to be written in a more explicit
way; while the supposedly bad case can be written conveniently.

Also, many objects (in our codebase, and in all the libraries we use)
that are Clone are in fact simply handles.  They contain Arc(s) (or
similar) and are cheap to clone.  Indeed, that is the usual case.

It does not make sense to distinguish in the syntax we use to clone
such a handle, whether the handle is a transparent Arc, or an opaque
struct containing one or more other handles.

Forcing Arc::clone to be written as such makes for code churn when a
type is changed from Arc<Something> to Something: Clone, or vice
versa.
2022-02-24 18:15:44 +00:00
Nick Mathewson 1cecc7e45a Change deny(clippy::all) to warn(clippy::all).
Closes #338.
2022-02-14 09:24:06 -05:00
Daniel Eades 592642a9e6 extend lints to include 'clippy::all' 2021-12-28 20:15:40 +00:00
Daniel Eades 47554556ec address lint warnings 2021-12-09 13:47:59 +00:00
Nick Mathewson a25960b44c tor-netdir: Resolve an XXXX about type ugliness
We had no function to infallibly convert BoundedInt32<{0 or 1},H>
into a u32, even though we could have.  Because of that, we were
treating weight_scale as an i32 when logically it's a u32 or a
NonZeroU32.

Moreover, it turns out we were using an incorrect minimum for the
bwweightscale param, which would in theory have allowed the
authorities to make us divide by zero.

This patch introduces the necessary From<> implementation and uses
it.  It corrects the binimum bwweightscale, and prevents a
division-by-zero issue in case weight_scale is zero.
2021-12-08 12:32:44 -05:00
Nick Mathewson 99a046da46 Get tor-units grcov line coverage to 100%
This is mostly a finger exercise, and an experiment in "what does
grcov consider to be coverage".  Here's what I've found out...

* In grcov's eyes, most #[derive(Foo)] lines count as containing code;
  but calling any one derived function counts as calling those lines.

* Unlike with tarpaulin, it is actually possible to reach 100% grcov
  line coverage.  (Tarpaulin likes to pick "}" lines and tell you that
  you never reached them; or sometimes it picks expression
  statements that have the effect of a return, and tells you that
  they're unreached.  Even with these tests, tarpaulin claims that
  the line coverage of tor-units is only 97.3%.)

* In rust, it may be a bit hopeless trying to get high function
  coverage. Even though we've hit every line of the tor-units crate,
  the function coverage from its own tests is only 9.38% (55.41%
  from other crates).  I think this is probably due to derived
  functions, or maybe due to generics getting instantiated?
  I've got no idea; the denominator for the function coverage
  lines fluctuates oddly.
2021-12-02 17:08:22 -05:00
Nick Mathewson 47614ee737 Implement Eq,PartialEq for BoundedInt32. 2021-12-02 16:40:22 -05:00
Daniel Eades db16d13df4 add semicolons if nothing returned 2021-11-25 13:20:37 +00:00
Nick Mathewson 3e7e599a22 More typo fixes that I forgot to save :( 2021-11-24 18:23:12 -05:00
Nick Mathewson af7c9d5a0b enable checked_conversions lint. 2021-10-09 16:53:13 -04:00
Nick Mathewson 0779923d64 Initial backend implementation for guard node manager.
There are some missing parts here (like persistence and tests)
and some incorrect parts (I am 90% sure that the "exploratory
circuit" flag is bogus).  Also it is not integrated with the circuit
manager code.
2021-10-07 10:45:42 -04:00
Nick Mathewson 0635ec6721 Add an IntegerDays numeric type. 2021-09-09 12:32:13 -04:00
Nick Mathewson 41f96c4f2f Use macros and traits to simplify the declaration of parameters.
Previously, we'd have to declare the field for a parameter in one
place, its default in a second, and its consensus key in a third.
That's error-prone and not so fun!  This patch changes the
way we declare parameters so that we declare a structure once,
and macros expand it to all do the right thing.

This required a few new traits and implementations to ensure
uniformity across the types that can go in parameters: We need every
parameter type to implement TryFrom<i32> and to implement
SaturatingFromInt32.

Eventually we might want SaturatingFromInt32 to be a more generic
SaturatingFrom, but that's not for now.
2021-09-09 09:29:04 -04:00
Daniel Eades fb3b8b84b5 fix/silence clippy lints in test modules 2021-09-08 17:28:31 +02:00
Nick Mathewson 557a0ff40b Move all crates into a `crates` subdirectory.
This will cause some pain for now, but now is really the best time
to do this kind of thing.
2021-08-27 09:53:09 -04:00