Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ no-serde-warnings = []
proc-macro = true

[dependencies]
indexmap = "2"
proc-macro2 = "1"
quote = "1"
syn = { version = "2.0.28", features = ["full", "extra-traits"] }
Expand Down
12 changes: 7 additions & 5 deletions macros/src/deps.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use std::{collections::HashSet, rc::Rc};
use std::rc::Rc;

use indexmap::IndexSet;

use proc_macro2::TokenStream;
use quote::{quote, ToTokens};
use syn::{Path, Type};

pub struct Dependencies {
crate_rename: Rc<Path>,
dependencies: HashSet<Dependency>,
types: HashSet<Rc<Type>>,
dependencies: IndexSet<Dependency>,
types: IndexSet<Rc<Type>>,
}

#[derive(Hash, Eq, PartialEq)]
Expand All @@ -30,9 +32,9 @@ enum Dependency {
impl Dependencies {
pub fn new(crate_rename: Path) -> Self {
Self {
dependencies: HashSet::new(),
dependencies: IndexSet::new(),
crate_rename: Rc::new(crate_rename),
types: HashSet::new(),
types: IndexSet::new(),
}
}

Expand Down
8 changes: 5 additions & 3 deletions macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#![macro_use]
#![deny(unused)]

use std::collections::{HashMap, HashSet};
use std::collections::HashMap;

use indexmap::IndexSet;

use proc_macro2::{Ident, TokenStream};
use quote::{format_ident, quote};
Expand Down Expand Up @@ -442,7 +444,7 @@ fn generate_where_clause(
let used_types = {
let is_type_param = |id: &Ident| generics.type_params().any(|p| &p.ident == id);

let mut used_types = HashSet::new();
let mut used_types = IndexSet::new();
for ty in dependencies.used_types() {
used_type_params(&mut used_types, ty, is_type_param);
}
Expand All @@ -459,7 +461,7 @@ fn generate_where_clause(
// Associated types of a type parameter are extracted as well.
// Note: This will not extract `I` from `I::Item`, but just `I::Item`!
fn used_type_params<'ty, 'out>(
out: &'out mut HashSet<&'ty Type>,
out: &'out mut IndexSet<&'ty Type>,
ty: &'ty Type,
is_type_param: impl Fn(&'ty Ident) -> bool + Copy + 'out,
) {
Expand Down
Loading