Skip to content

Commit

Permalink
Fix nightly build / simplify no_std (#30)
Browse files Browse the repository at this point in the history
We were using `alloc` as `std` when the `std` feature was not present.
However, there is a new nightly warning about redundant imports that
this was raising, as `use std::vec::Vec`, for example, is not needed
when using `std`.

Instead, we just use `alloc` always.
  • Loading branch information
paholg authored Mar 12, 2024
1 parent bd8c572 commit 4c8f2f2
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use alloc::{format, vec::Vec};
use proc_macro2::TokenStream as TokenStream2;
use quote::{format_ident, quote};
use std::{format, vec::Vec};
use syn::{punctuated::Punctuated, DeriveInput, Generics, Ident, Token, TypeParamBound, Variant};

use crate::{
Expand Down
7 changes: 4 additions & 3 deletions src/enum.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::{BTreeMap, BTreeSet};
use std::vec::Vec;

use alloc::{
collections::{BTreeMap, BTreeSet},
vec::Vec,
};
use proc_macro2::TokenStream;
use syn::{punctuated::Punctuated, Generics, Ident, Token, TypeParamBound, Variant};

Expand Down
4 changes: 1 addition & 3 deletions src/extractor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::borrow::ToOwned;
use std::boxed::Box;
use std::vec::Vec;
use alloc::{borrow::ToOwned, boxed::Box, vec::Vec};
use syn::{Ident, Lifetime, Type, TypeParamBound};

use crate::{iter::BoxedIter, param::Param};
Expand Down
2 changes: 1 addition & 1 deletion src/iter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::boxed::Box;
use alloc::boxed::Box;

pub trait BoxedIter {
type Item;
Expand Down
19 changes: 4 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#![doc = include_str!("../README.md")]
#![cfg_attr(not(feature = "std"), no_std)]
#![no_std]

#[cfg(feature = "std")]
extern crate std;

#[cfg(not(feature = "std"))]
extern crate alloc as std;
extern crate alloc;

mod build;
mod derive;
Expand All @@ -14,9 +10,7 @@ mod extractor;
mod iter;
mod param;

use std::collections::BTreeMap;
#[cfg(not(feature = "std"))]
use std::{borrow::ToOwned, string::ToString, vec::Vec};
use alloc::{borrow::ToOwned, collections::BTreeMap, string::ToString, vec::Vec};

use derive::Derive;
use heck::ToSnakeCase;
Expand Down Expand Up @@ -170,12 +164,7 @@ pub fn subenum(args: TokenStream, tokens: TokenStream) -> TokenStream {
};

// We want all attributes except the "subenum" one.
var.attrs = var
.attrs
.iter()
.cloned()
.filter(|attr| attribute != attr)
.collect();
var.attrs.retain(|attr| attribute != attr);

let e = enums
.get_mut(ident)
Expand Down
4 changes: 1 addition & 3 deletions src/param.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::collections::BTreeMap;
use std::vec::Vec;

use alloc::{collections::BTreeMap, vec::Vec};
use syn::{GenericParam, Generics, Ident, Lifetime, TypeParamBound, WherePredicate};

use crate::extractor::Extractor;
Expand Down

0 comments on commit 4c8f2f2

Please sign in to comment.