Skip to content

Commit c2abed5

Browse files
authored
x509-cert: enable and fix clippy core/alloc/std lints (#1643)
Enables the following clippy lints: - `clippy::alloc_instead_of_core` - `clippy::std_instead_of_alloc` - `clippy::std_instead_of_core` These check that imports are coming from the correct package in the standard library, enabling more features to be used in `no_std` environments.
1 parent 2834b1d commit c2abed5

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

x509-cert/src/builder.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ pub enum Error {
6666
MissingAttributes,
6767
}
6868

69-
#[cfg(feature = "std")]
70-
impl std::error::Error for Error {}
69+
impl core::error::Error for Error {}
7170

7271
impl fmt::Display for Error {
7372
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

x509-cert/src/ext/pkix/name/general.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,18 @@ pub enum GeneralName {
6262
RegisteredId(ObjectIdentifier),
6363
}
6464

65-
#[cfg(feature = "std")]
66-
impl From<std::net::IpAddr> for GeneralName {
67-
fn from(ip: std::net::IpAddr) -> Self {
65+
impl From<core::net::IpAddr> for GeneralName {
66+
fn from(ip: core::net::IpAddr) -> Self {
6867
// Safety: this is unfailable here, OctetString will issue an error if you go
6968
// over 256MiB, here the buffer is at most 16 bytes (ipv6). The two `expect`s
7069
// below are safe.
7170
let buf = match ip {
72-
std::net::IpAddr::V4(v) => {
71+
core::net::IpAddr::V4(v) => {
7372
let value = v.octets();
7473
OctetString::new(&value[..])
7574
.expect("OctetString is not expected to fail with a 4 bytes long buffer")
7675
}
77-
std::net::IpAddr::V6(v) => {
76+
core::net::IpAddr::V6(v) => {
7877
let value = v.octets();
7978
OctetString::new(&value[..])
8079
.expect("OctetString is not expected to fail with a 16 bytes long buffer")
@@ -85,15 +84,15 @@ impl From<std::net::IpAddr> for GeneralName {
8584
}
8685
}
8786

88-
#[cfg(all(feature = "std", test))]
87+
#[cfg(test)]
8988
#[allow(clippy::unwrap_used)]
9089
mod tests {
9190
use super::*;
9291
use der::Encode;
9392

9493
#[test]
9594
fn test_convert() {
96-
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
95+
use core::net::{IpAddr, Ipv4Addr, Ipv6Addr};
9796

9897
let localhost_v4 = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1));
9998
let localhost_v6 = IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1));

x509-cert/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
)]
88
#![forbid(unsafe_code)]
99
#![warn(
10+
clippy::alloc_instead_of_core,
1011
clippy::mod_module_files,
12+
clippy::std_instead_of_alloc,
13+
clippy::std_instead_of_core,
1114
clippy::unwrap_used,
1215
missing_docs,
1316
rust_2018_idioms,

0 commit comments

Comments
 (0)