Skip to content

Commit 2a4a38b

Browse files
committed
Make absence of perfect-derive feature on miette-derive actually disable adding trait bounds
Signed-off-by: Justus Flügel <[email protected]>
1 parent d4a468c commit 2a4a38b

File tree

6 files changed

+41
-3
lines changed

6 files changed

+41
-3
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ strip-ansi-escapes = "0.2.0"
5151
[features]
5252
default = ["derive"]
5353
derive = ["dep:miette-derive"]
54-
perfect-derive = ["dep:miette-derive","miette-derive?/perfect-derive"]
54+
perfect-derive = ["derive","miette-derive?/perfect-derive"]
5555
no-format-args-capture = []
5656
fancy-base = [
5757
"dep:owo-colors",

miette-derive/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ perfect-derive = ["syn/extra-traits"]
1616
[dependencies]
1717
proc-macro2 = "1.0.83"
1818
quote = "1.0.35"
19-
syn = { version = "2.0.87", features = ["extra-traits"] }
19+
syn = "2.0.87"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#![allow(dead_code)]
2+
use syn::{punctuated::Punctuated, Generics, PredicateType, Token, WhereClause, WherePredicate};
3+
4+
// Mock for when perfect-derive is not enabled,
5+
// this should be completely optimized away and enables
6+
// easily switching on/off the perfect-derive feature without
7+
// needing to modify any other code.
8+
pub struct TypeParamBoundStore;
9+
10+
impl TypeParamBoundStore {
11+
pub fn new(_: &Generics) -> Self {
12+
Self
13+
}
14+
15+
pub fn add_predicate(&mut self, _: PredicateType) {}
16+
17+
pub fn add_where_predicate(&mut self, _: WherePredicate) {}
18+
19+
pub fn extend_where_predicates(&mut self, _: Punctuated<WherePredicate, Token![,]>) {}
20+
21+
pub fn add_to_where_clause(&self, where_clause: Option<&WhereClause>) -> Option<WhereClause> {
22+
where_clause.cloned()
23+
}
24+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#[cfg(not(feature = "perfect-derive"))]
2+
mod mock_store;
3+
#[cfg(not(feature = "perfect-derive"))]
4+
pub use mock_store::TypeParamBoundStore;
5+
6+
#[cfg(feature = "perfect-derive")]
7+
mod store;
8+
#[cfg(feature = "perfect-derive")]
9+
pub use store::TypeParamBoundStore;
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ use syn::{
1212
};
1313

1414
// Potential improvement, although idk if this actually ends up
15-
// mattering is to switch this to something like FxHashMap like the rustc compiler uses internally
15+
// mattering (if it is a messurable improvement) is to switch this to something like FxHashMap
16+
// like the rustc compiler uses internally, although we should benchmark this and can always do it later
17+
// since it is easy enough to change.
18+
#[cfg(feature = "perfect-derive")]
1619
pub struct TypeParamBoundStore(HashMap<(Option<BoundLifetimes>, Type), HashSet<TypeParamBound>>);
1720

21+
#[cfg(feature = "perfect-derive")]
1822
impl TypeParamBoundStore {
1923
/// Creates a new TraitBoundStore, filling it with some generics which are used to heuristically remove trivial bounds.
2024
///

tests/test_derive_attr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ fn attr_not_required() {
146146
assert_eq!(err_span, expectation);
147147
}
148148

149+
// Tests for the feature = "perfect-derive".
149150
fn assert_impl_diagnostic<T: Diagnostic>() {}
150151

151152
#[test]

0 commit comments

Comments
 (0)