mirror of https://github.com/zkat/miette.git
Make absence of perfect-derive feature on miette-derive actually disable adding trait bounds
Signed-off-by: Justus Flügel <justusfluegel@gmail.com>
This commit is contained in:
parent
bc7b842ca3
commit
8c25ebde1e
|
|
@ -50,7 +50,7 @@ strip-ansi-escapes = "0.2.0"
|
|||
[features]
|
||||
default = ["derive"]
|
||||
derive = ["dep:miette-derive"]
|
||||
perfect-derive = ["dep:miette-derive","miette-derive?/perfect-derive"]
|
||||
perfect-derive = ["derive","miette-derive?/perfect-derive"]
|
||||
no-format-args-capture = []
|
||||
fancy-base = [
|
||||
"dep:owo-colors",
|
||||
|
|
|
|||
|
|
@ -16,4 +16,4 @@ perfect-derive = ["syn/extra-traits"]
|
|||
[dependencies]
|
||||
proc-macro2 = "1.0.83"
|
||||
quote = "1.0.35"
|
||||
syn = { version = "2.0.87", features = ["extra-traits"] }
|
||||
syn = "2.0.87"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
#![allow(dead_code)]
|
||||
use syn::{punctuated::Punctuated, Generics, PredicateType, Token, WhereClause, WherePredicate};
|
||||
|
||||
// Mock for when perfect-derive is not enabled,
|
||||
// this should be completely optimized away and enables
|
||||
// easily switching on/off the perfect-derive feature without
|
||||
// needing to modify any other code.
|
||||
pub struct TypeParamBoundStore;
|
||||
|
||||
impl TypeParamBoundStore {
|
||||
pub fn new(_: &Generics) -> Self {
|
||||
Self
|
||||
}
|
||||
|
||||
pub fn add_predicate(&mut self, _: PredicateType) {}
|
||||
|
||||
pub fn add_where_predicate(&mut self, _: WherePredicate) {}
|
||||
|
||||
pub fn extend_where_predicates(&mut self, _: Punctuated<WherePredicate, Token![,]>) {}
|
||||
|
||||
pub fn add_to_where_clause(&self, where_clause: Option<&WhereClause>) -> Option<WhereClause> {
|
||||
where_clause.cloned()
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
#[cfg(not(feature = "perfect-derive"))]
|
||||
mod mock_store;
|
||||
#[cfg(not(feature = "perfect-derive"))]
|
||||
pub use mock_store::TypeParamBoundStore;
|
||||
|
||||
#[cfg(feature = "perfect-derive")]
|
||||
mod store;
|
||||
#[cfg(feature = "perfect-derive")]
|
||||
pub use store::TypeParamBoundStore;
|
||||
|
|
@ -12,9 +12,13 @@ use syn::{
|
|||
};
|
||||
|
||||
// Potential improvement, although idk if this actually ends up
|
||||
// mattering is to switch this to something like FxHashMap like the rustc compiler uses internally
|
||||
// mattering (if it is a messurable improvement) is to switch this to something like FxHashMap
|
||||
// like the rustc compiler uses internally, although we should benchmark this and can always do it later
|
||||
// since it is easy enough to change.
|
||||
#[cfg(feature = "perfect-derive")]
|
||||
pub struct TypeParamBoundStore(HashMap<(Option<BoundLifetimes>, Type), HashSet<TypeParamBound>>);
|
||||
|
||||
#[cfg(feature = "perfect-derive")]
|
||||
impl TypeParamBoundStore {
|
||||
/// Creates a new TraitBoundStore, filling it with some generics which are used to heuristically remove trivial bounds.
|
||||
///
|
||||
|
|
@ -146,6 +146,7 @@ fn attr_not_required() {
|
|||
assert_eq!(err_span, expectation);
|
||||
}
|
||||
|
||||
// Tests for the feature = "perfect-derive".
|
||||
fn assert_impl_diagnostic<T: Diagnostic>() {}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Reference in New Issue