Skip to content

Commit

Permalink
error in core changes
Browse files Browse the repository at this point in the history
  • Loading branch information
knickish committed Jun 9, 2024
1 parent 7cd011f commit d28e068
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 52 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: test
args: --no-default-features --features ${{ matrix.feature }}
args: --no-default-features --features "std, ${{ matrix.feature }}"

no_std_features:
name: Test Individual Features NoStd
Expand All @@ -106,7 +106,7 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: test
args: --no-default-features --features "no_std, ${{ matrix.feature }}"
args: --no-default-features --features "${{ matrix.feature }}"

test:
name: Test
Expand Down Expand Up @@ -153,4 +153,4 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: test
args: --features "no_std"
args: --no-default-features --features "binary, json, ron, toml"
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ edition = "2018"
repository = "https://github.com/not-fl3/nanoserde"

[features]
default = ["json", "binary", "ron", "toml"]
default = ["json", "binary", "ron", "toml", "std"]
json = ["dep:nanoserde-derive", "nanoserde-derive/json"]
binary = ["dep:nanoserde-derive", "nanoserde-derive/binary"]
ron = ["dep:nanoserde-derive", "nanoserde-derive/ron"]
toml = []
no_std = []
std = []

[dependencies]
nanoserde-derive = { path = "derive", version = "=0.2.0", optional = true }
1 change: 0 additions & 1 deletion derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ default = []
json = []
binary = []
ron = []
no_std = []
2 changes: 1 addition & 1 deletion derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(feature = "no_std", no_std)]
#![no_std]

extern crate alloc;
extern crate proc_macro;
Expand Down
18 changes: 11 additions & 7 deletions derive/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
//! https://docs.rs/syn/0.15.44/syn/enum.Type.html
//! https://ziglang.org/documentation/0.5.0/#toc-typeInfo
use alloc::collections::BTreeSet;
use core::iter::Peekable;
use std::collections::HashSet;
use std::num::IntErrorKind;
use core::num::IntErrorKind;

use alloc::borrow::ToOwned;
use alloc::boxed::Box;
use alloc::string::{String, ToString};
use alloc::vec::Vec;
use alloc::{format, vec};
Expand All @@ -16,6 +18,7 @@ use proc_macro::{Delimiter, Group, TokenStream, TokenTree};

#[derive(Debug, Clone)]
pub struct Attribute {
#[allow(unused)]
pub name: String,
pub tokens: Vec<String>,
}
Expand All @@ -37,6 +40,7 @@ pub struct Lifetime {
#[derive(Debug, Clone)]
pub struct Field {
pub attributes: Vec<Attribute>,
#[allow(unused)]
pub vis: Visibility,
pub field_name: Option<String>,
pub ty: Type,
Expand Down Expand Up @@ -1079,14 +1083,14 @@ fn next_attribute<T: Iterator<Item = TokenTree>>(
(true, _) => {
attrs.push(Attribute {
name: name.clone(),
tokens: std::mem::take(&mut attr_tokens),
tokens: core::mem::take(&mut attr_tokens),
});
break;
}
(false, Some(",")) => {
attrs.push(Attribute {
name: name.clone(),
tokens: std::mem::take(&mut attr_tokens),
tokens: core::mem::take(&mut attr_tokens),
});
continue;
}
Expand All @@ -1105,14 +1109,14 @@ fn next_attribute<T: Iterator<Item = TokenTree>>(
(true, _) => {
attrs.push(Attribute {
name: name.clone(),
tokens: std::mem::take(&mut attr_tokens),
tokens: core::mem::take(&mut attr_tokens),
});
break;
}
(false, true) => {
attrs.push(Attribute {
name: name.clone(),
tokens: std::mem::take(&mut attr_tokens),
tokens: core::mem::take(&mut attr_tokens),
});
}
_ => {}
Expand Down Expand Up @@ -1402,7 +1406,7 @@ fn next_generic<T: Iterator<Item = TokenTree> + Clone>(

fn get_all_bounds<T: Iterator<Item = TokenTree> + Clone>(source: &mut Peekable<T>) -> Vec<Generic> {
let mut ret = Vec::new();
let mut already = HashSet::new();
let mut already = BTreeSet::new();
if source.peek().map_or(false, |x| x.to_string() == "<") {
source.next();
} else {
Expand Down
6 changes: 5 additions & 1 deletion derive/src/shared.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use alloc::string::String;
use alloc::{
format,

Check warning on line 2 in derive/src/shared.rs

View workflow job for this annotation

GitHub Actions / Test Individual Features (ron)

unused imports: `ToString`, `format`, `vec::Vec`

Check warning on line 2 in derive/src/shared.rs

View workflow job for this annotation

GitHub Actions / Test Individual Features NoStd (ron)

unused imports: `ToString`, `format`, and `vec::Vec`
string::{String, ToString},
vec::Vec,
};

#[cfg(any(feature = "binary", feature = "json"))]
use crate::parse::{Enum, Struct};
Expand Down
6 changes: 1 addition & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
//! `nanoserde` supports some serialization customisation with `#[nserde()]` attributes.
//! For `#[nserde(..)]` supported attributes for each format check [Features support matrix](https://github.com/not-fl3/nanoserde#features-support-matrix)
#![cfg_attr(feature = "no_std", no_std)]
// Possibly stable in 1.65.
// See: https://github.com/rust-lang/rust/pull/99917
// and https://github.com/rust-lang/rust/issues/103765
#![cfg_attr(feature = "no_std", feature(error_in_core))]
#![cfg_attr(not(feature = "std"), no_std)]

extern crate alloc;

Expand Down
12 changes: 4 additions & 8 deletions src/serde_bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,8 @@ impl core::fmt::Display for DeBinErr {
}
}

#[cfg(feature = "no_std")]
impl core::error::Error for DeBinErr {}

Check failure on line 80 in src/serde_bin.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, x86_64-unknown-linux-gnu)

use of unstable library feature 'error_in_core'

Check failure on line 80 in src/serde_bin.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, wasm32-unknown-unknown)

use of unstable library feature 'error_in_core'

Check failure on line 80 in src/serde_bin.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, x86_64-apple-darwin)

use of unstable library feature 'error_in_core'

Check failure on line 80 in src/serde_bin.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, x86_64-unknown-linux-gnu)

use of unstable library feature 'error_in_core'

Check failure on line 80 in src/serde_bin.rs

View workflow job for this annotation

GitHub Actions / Test Individual Features (binary)

use of unstable library feature 'error_in_core'

Check failure on line 80 in src/serde_bin.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, x86_64-pc-windows-gnu)

use of unstable library feature 'error_in_core'

Check failure on line 80 in src/serde_bin.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, x86_64-pc-windows-msvc)

use of unstable library feature 'error_in_core'

#[cfg(not(feature = "no_std"))]
impl std::error::Error for DeBinErr {}

macro_rules! impl_ser_de_bin_for {
($ty:ident) => {
impl SerBin for $ty {
Expand Down Expand Up @@ -287,7 +283,7 @@ where
}
}

#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
impl<T> SerBin for std::collections::HashSet<T>
where
T: SerBin,
Expand All @@ -301,7 +297,7 @@ where
}
}

#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
impl<T> DeBin for std::collections::HashSet<T>
where
T: DeBin + core::hash::Hash + Eq,
Expand Down Expand Up @@ -529,7 +525,7 @@ where
}
}

#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
impl<K, V> SerBin for std::collections::HashMap<K, V>
where
K: SerBin,
Expand All @@ -545,7 +541,7 @@ where
}
}

#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
impl<K, V> DeBin for std::collections::HashMap<K, V>
where
K: DeBin + core::cmp::Eq + core::hash::Hash,
Expand Down
12 changes: 4 additions & 8 deletions src/serde_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,8 @@ impl core::fmt::Display for DeJsonErr {
}
}

#[cfg(feature = "no_std")]
impl core::error::Error for DeJsonErr {}

Check failure on line 163 in src/serde_json.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, x86_64-unknown-linux-gnu)

use of unstable library feature 'error_in_core'

Check failure on line 163 in src/serde_json.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, wasm32-unknown-unknown)

use of unstable library feature 'error_in_core'

Check failure on line 163 in src/serde_json.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, x86_64-apple-darwin)

use of unstable library feature 'error_in_core'

Check failure on line 163 in src/serde_json.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, x86_64-unknown-linux-gnu)

use of unstable library feature 'error_in_core'

Check failure on line 163 in src/serde_json.rs

View workflow job for this annotation

GitHub Actions / Test Individual Features (json)

use of unstable library feature 'error_in_core'

Check failure on line 163 in src/serde_json.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, x86_64-pc-windows-gnu)

use of unstable library feature 'error_in_core'

Check failure on line 163 in src/serde_json.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, x86_64-pc-windows-msvc)

use of unstable library feature 'error_in_core'

#[cfg(not(feature = "no_std"))]
impl std::error::Error for DeJsonErr {}

impl DeJsonState {
pub fn next(&mut self, i: &mut Chars) {
if let Some(c) = i.next() {
Expand Down Expand Up @@ -878,7 +874,7 @@ where
}
}

#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
impl<T> SerJson for std::collections::HashSet<T>
where
T: SerJson,
Expand All @@ -899,7 +895,7 @@ where
}
}

#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
impl<T> DeJson for std::collections::HashSet<T>
where
T: DeJson + core::hash::Hash + Eq,
Expand Down Expand Up @@ -1172,7 +1168,7 @@ where
}
}

#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
impl<K, V> SerJson for std::collections::HashMap<K, V>
where
K: SerJson,
Expand All @@ -1197,7 +1193,7 @@ where
}
}

#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
impl<K, V> DeJson for std::collections::HashMap<K, V>
where
K: DeJson + Eq + core::hash::Hash,
Expand Down
12 changes: 4 additions & 8 deletions src/serde_ron.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,8 @@ impl core::fmt::Display for DeRonErr {
}
}

#[cfg(feature = "no_std")]
impl core::error::Error for DeRonErr {}

Check failure on line 160 in src/serde_ron.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, x86_64-unknown-linux-gnu)

use of unstable library feature 'error_in_core'

Check failure on line 160 in src/serde_ron.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, wasm32-unknown-unknown)

use of unstable library feature 'error_in_core'

Check failure on line 160 in src/serde_ron.rs

View workflow job for this annotation

GitHub Actions / Test Individual Features (ron)

use of unstable library feature 'error_in_core'

Check failure on line 160 in src/serde_ron.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, x86_64-apple-darwin)

use of unstable library feature 'error_in_core'

Check failure on line 160 in src/serde_ron.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, x86_64-unknown-linux-gnu)

use of unstable library feature 'error_in_core'

Check failure on line 160 in src/serde_ron.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, x86_64-pc-windows-gnu)

use of unstable library feature 'error_in_core'

Check failure on line 160 in src/serde_ron.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, x86_64-pc-windows-msvc)

use of unstable library feature 'error_in_core'

#[cfg(not(feature = "no_std"))]
impl std::error::Error for DeRonErr {}

impl DeRonState {
pub fn next(&mut self, i: &mut Chars) {
if let Some(c) = i.next() {
Expand Down Expand Up @@ -876,7 +872,7 @@ where
}
}

#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
impl<T> SerRon for std::collections::HashSet<T>
where
T: SerRon,
Expand All @@ -897,7 +893,7 @@ where
}
}

#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
impl<T> DeRon for std::collections::HashSet<T>
where
T: DeRon + core::hash::Hash + Eq,
Expand Down Expand Up @@ -1184,7 +1180,7 @@ where
}
}

#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
impl<K, V> SerRon for std::collections::HashMap<K, V>
where
K: SerRon,
Expand All @@ -1204,7 +1200,7 @@ where
}
}

#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
impl<K, V> DeRon for std::collections::HashMap<K, V>
where
K: DeRon + Eq + core::hash::Hash,
Expand Down
4 changes: 0 additions & 4 deletions src/toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,8 @@ impl Out {
}
}

#[cfg(feature = "no_std")]
impl core::error::Error for TomlErr {}

Check failure on line 252 in src/toml.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, x86_64-unknown-linux-gnu)

use of unstable library feature 'error_in_core'

Check failure on line 252 in src/toml.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, wasm32-unknown-unknown)

use of unstable library feature 'error_in_core'

Check failure on line 252 in src/toml.rs

View workflow job for this annotation

GitHub Actions / Test Individual Features (toml)

use of unstable library feature 'error_in_core'

Check failure on line 252 in src/toml.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, x86_64-apple-darwin)

use of unstable library feature 'error_in_core'

Check failure on line 252 in src/toml.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, x86_64-unknown-linux-gnu)

use of unstable library feature 'error_in_core'

Check failure on line 252 in src/toml.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, x86_64-pc-windows-gnu)

use of unstable library feature 'error_in_core'

Check failure on line 252 in src/toml.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, x86_64-pc-windows-msvc)

use of unstable library feature 'error_in_core'

#[cfg(not(feature = "no_std"))]
impl std::error::Error for TomlErr {}

impl TomlParser {
/// Parse a TOML string.
pub fn parse(data: &str) -> Result<BTreeMap<String, Toml>, TomlErr> {
Expand Down
6 changes: 4 additions & 2 deletions tests/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
sync::atomic::AtomicBool,
};

#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
use std::collections::HashMap;

#[test]
Expand Down Expand Up @@ -69,6 +69,7 @@ fn de_multiline_comment() {
fn de_illegal_inline_comment() {
#[derive(DeJson)]
pub struct Test {
#[allow(unused)]
pub a: f32,
}

Expand All @@ -92,6 +93,7 @@ fn de_illegal_inline_comment() {
fn de_illegal_multiline_comment() {
#[derive(DeJson)]
pub struct Test {
#[allow(unused)]
pub a: f32,
}

Expand Down Expand Up @@ -467,7 +469,7 @@ fn path_type() {
assert_eq!(bar.d, Some(vec![vec![1, 2], vec![3, 4]]));
}

#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
#[test]
fn hashmaps() {
#[derive(DeJson)]
Expand Down
4 changes: 2 additions & 2 deletions tests/ron.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
sync::atomic::AtomicBool,
};

#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
use std::collections::HashMap;

#[test]
Expand Down Expand Up @@ -263,7 +263,7 @@ fn path_type() {
assert_eq!(bar.d, Some(vec![vec![1, 2], vec![3, 4]]));
}

#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
#[test]
fn hashmaps() {
#[derive(DeRon)]
Expand Down

0 comments on commit d28e068

Please sign in to comment.