Skip to content

Commit 9d79e45

Browse files
authored
RUST-968 Remove u2i feature flag (#296)
1 parent dbfa947 commit 9d79e45

File tree

9 files changed

+16
-182
lines changed

9 files changed

+16
-182
lines changed

.evergreen/config.yml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,6 @@ functions:
8282
${PREPARE_SHELL}
8383
.evergreen/run-tests.sh
8484
85-
"run tests no default features":
86-
- command: shell.exec
87-
type: test
88-
params:
89-
shell: bash
90-
working_dir: "src"
91-
script: |
92-
${PREPARE_SHELL}
93-
.evergreen/run-tests-no-default-features.sh
94-
9585
"compile only":
9686
- command: shell.exec
9787
type: test
@@ -146,10 +136,6 @@ tasks:
146136
commands:
147137
- func: "run tests"
148138

149-
- name: "test-no-default-features"
150-
commands:
151-
- func: "run tests no default features"
152-
153139
- name: "compile-only"
154140
commands:
155141
- func: "compile only"
@@ -182,7 +168,6 @@ buildvariants:
182168
- ubuntu1804-test
183169
tasks:
184170
- name: "test"
185-
- name: "test-no-default-features"
186171

187172
- matrix_name: "compile only"
188173
matrix_spec:

.evergreen/run-tests-no-default-features.sh

Lines changed: 0 additions & 9 deletions
This file was deleted.

Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,11 @@ exclude = [
3131
]
3232

3333
[features]
34-
default = ["u2i"]
34+
default = []
3535
# if enabled, include API for interfacing with chrono 0.4
3636
chrono-0_4 = []
3737
# if enabled, include API for interfacing with uuid 0.8
3838
uuid-0_8 = []
39-
# attempt to encode unsigned types in signed types in serde serializers
40-
u2i = []
4139

4240
[lib]
4341
name = "bson"

serde-tests/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ authors = ["Kevin Yeh <[email protected]>"]
55
edition = "2018"
66

77
[features]
8-
default = ["u2i"]
9-
u2i = ["bson/u2i"]
8+
default = []
109

1110
[dependencies]
1211
bson = { path = "..", default-features = false }

serde-tests/test.rs

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,6 @@ fn borrowed() {
868868
assert_eq!(deserialized, v);
869869
}
870870

871-
#[cfg(feature = "u2i")]
872871
#[test]
873872
fn u2i() {
874873
#[derive(Serialize, Deserialize, Debug, PartialEq)]
@@ -911,39 +910,3 @@ fn u2i() {
911910
bson::to_document(&v).unwrap_err();
912911
bson::to_vec(&v).unwrap_err();
913912
}
914-
915-
#[cfg(not(feature = "u2i"))]
916-
#[test]
917-
fn unsigned() {
918-
#[derive(Serialize, Debug)]
919-
struct U8 {
920-
v: u8,
921-
}
922-
let v = U8 { v: 1 };
923-
bson::to_document(&v).unwrap_err();
924-
bson::to_vec(&v).unwrap_err();
925-
926-
#[derive(Serialize, Debug)]
927-
struct U16 {
928-
v: u16,
929-
}
930-
let v = U16 { v: 1 };
931-
bson::to_document(&v).unwrap_err();
932-
bson::to_vec(&v).unwrap_err();
933-
934-
#[derive(Serialize, Debug)]
935-
struct U32 {
936-
v: u32,
937-
}
938-
let v = U32 { v: 1 };
939-
bson::to_document(&v).unwrap_err();
940-
bson::to_vec(&v).unwrap_err();
941-
942-
#[derive(Serialize, Debug)]
943-
struct U64 {
944-
v: u64,
945-
}
946-
let v = U64 { v: 1 };
947-
bson::to_document(&v).unwrap_err();
948-
bson::to_vec(&v).unwrap_err();
949-
}

src/ser/error.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,6 @@ pub enum Error {
2222
message: String,
2323
},
2424

25-
#[cfg(not(feature = "u2i"))]
26-
/// Returned when serialization of an unsigned integer was attempted. BSON only supports
27-
/// 32-bit and 64-bit signed integers.
28-
///
29-
/// To serialize unsigned integers to BSON, use an appropriate helper from
30-
/// [`crate::serde_helpers`] or enable the "u2i" feature flag.
31-
UnsupportedUnsignedInteger(u64),
32-
33-
#[cfg(feature = "u2i")]
3425
/// An unsigned integer type could not fit into a signed integer type.
3526
UnsignedIntegerExceededRange(u64),
3627
}
@@ -47,15 +38,6 @@ impl fmt::Display for Error {
4738
Error::Io(ref inner) => inner.fmt(fmt),
4839
Error::InvalidDocumentKey(ref key) => write!(fmt, "Invalid map key type: {}", key),
4940
Error::SerializationError { ref message } => message.fmt(fmt),
50-
#[cfg(not(feature = "u2i"))]
51-
Error::UnsupportedUnsignedInteger(value) => write!(
52-
fmt,
53-
"BSON does not support unsigned integers, cannot serialize value: {}. To \
54-
serialize unsigned integers to BSON, use an appropriate serde helper or enable \
55-
the u2i feature.",
56-
value
57-
),
58-
#[cfg(feature = "u2i")]
5941
Error::UnsignedIntegerExceededRange(value) => write!(
6042
fmt,
6143
"BSON does not support unsigned integers.

src/ser/raw/mod.rs

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -117,51 +117,27 @@ impl<'a> serde::Serializer for &'a mut Serializer {
117117

118118
#[inline]
119119
fn serialize_u8(self, v: u8) -> Result<Self::Ok> {
120-
#[cfg(feature = "u2i")]
121-
{
122-
self.serialize_i32(v.into())
123-
}
124-
125-
#[cfg(not(feature = "u2i"))]
126-
Err(Error::UnsupportedUnsignedInteger(v.into()))
120+
self.serialize_i32(v.into())
127121
}
128122

129123
#[inline]
130124
fn serialize_u16(self, v: u16) -> Result<Self::Ok> {
131-
#[cfg(feature = "u2i")]
132-
{
133-
self.serialize_i32(v.into())
134-
}
135-
136-
#[cfg(not(feature = "u2i"))]
137-
Err(Error::UnsupportedUnsignedInteger(v.into()))
125+
self.serialize_i32(v.into())
138126
}
139127

140128
#[inline]
141129
fn serialize_u32(self, v: u32) -> Result<Self::Ok> {
142-
#[cfg(feature = "u2i")]
143-
{
144-
self.serialize_i64(v.into())
145-
}
146-
147-
#[cfg(not(feature = "u2i"))]
148-
Err(Error::UnsupportedUnsignedInteger(v.into()))
130+
self.serialize_i64(v.into())
149131
}
150132

151133
#[inline]
152134
fn serialize_u64(self, v: u64) -> Result<Self::Ok> {
153-
#[cfg(feature = "u2i")]
154-
{
155-
use std::convert::TryFrom;
135+
use std::convert::TryFrom;
156136

157-
match i64::try_from(v) {
158-
Ok(ivalue) => self.serialize_i64(ivalue),
159-
Err(_) => Err(Error::UnsignedIntegerExceededRange(v)),
160-
}
137+
match i64::try_from(v) {
138+
Ok(ivalue) => self.serialize_i64(ivalue),
139+
Err(_) => Err(Error::UnsignedIntegerExceededRange(v)),
161140
}
162-
163-
#[cfg(not(feature = "u2i"))]
164-
Err(Error::UnsupportedUnsignedInteger(v))
165141
}
166142

167143
#[inline]

src/ser/serde.rs

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,7 @@ impl ser::Serializer for Serializer {
140140

141141
#[inline]
142142
fn serialize_u8(self, value: u8) -> crate::ser::Result<Bson> {
143-
#[cfg(feature = "u2i")]
144-
{
145-
Ok(Bson::Int32(value as i32))
146-
}
147-
148-
#[cfg(not(feature = "u2i"))]
149-
Err(Error::UnsupportedUnsignedInteger(value as u64))
143+
Ok(Bson::Int32(value as i32))
150144
}
151145

152146
#[inline]
@@ -156,13 +150,7 @@ impl ser::Serializer for Serializer {
156150

157151
#[inline]
158152
fn serialize_u16(self, value: u16) -> crate::ser::Result<Bson> {
159-
#[cfg(feature = "u2i")]
160-
{
161-
Ok(Bson::Int32(value as i32))
162-
}
163-
164-
#[cfg(not(feature = "u2i"))]
165-
Err(Error::UnsupportedUnsignedInteger(value as u64))
153+
Ok(Bson::Int32(value as i32))
166154
}
167155

168156
#[inline]
@@ -172,13 +160,7 @@ impl ser::Serializer for Serializer {
172160

173161
#[inline]
174162
fn serialize_u32(self, value: u32) -> crate::ser::Result<Bson> {
175-
#[cfg(feature = "u2i")]
176-
{
177-
Ok(Bson::Int64(value as i64))
178-
}
179-
180-
#[cfg(not(feature = "u2i"))]
181-
Err(Error::UnsupportedUnsignedInteger(value as u64))
163+
Ok(Bson::Int64(value as i64))
182164
}
183165

184166
#[inline]
@@ -188,18 +170,12 @@ impl ser::Serializer for Serializer {
188170

189171
#[inline]
190172
fn serialize_u64(self, value: u64) -> crate::ser::Result<Bson> {
191-
#[cfg(feature = "u2i")]
192-
{
193-
use std::convert::TryFrom;
173+
use std::convert::TryFrom;
194174

195-
match i64::try_from(value) {
196-
Ok(ivalue) => Ok(Bson::Int64(ivalue)),
197-
Err(_) => Err(Error::UnsignedIntegerExceededRange(value)),
198-
}
175+
match i64::try_from(value) {
176+
Ok(ivalue) => Ok(Bson::Int64(ivalue)),
177+
Err(_) => Err(Error::UnsignedIntegerExceededRange(value)),
199178
}
200-
201-
#[cfg(not(feature = "u2i"))]
202-
Err(Error::UnsupportedUnsignedInteger(value))
203179
}
204180

205181
#[inline]

src/tests/modules/ser.rs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,6 @@ fn int32() {
6767
}
6868

6969
#[test]
70-
#[cfg(not(feature = "u2i"))]
71-
fn uint8() {
72-
let _guard = LOCK.run_concurrently();
73-
let obj_min: ser::Result<Bson> = to_bson(&u8::MIN);
74-
assert_matches!(obj_min, Err(ser::Error::UnsupportedUnsignedInteger(_)));
75-
}
76-
77-
#[test]
78-
#[cfg(feature = "u2i")]
7970
fn uint8_u2i() {
8071
let _guard = LOCK.run_concurrently();
8172
let obj: Bson = to_bson(&u8::MIN).unwrap();
@@ -88,15 +79,6 @@ fn uint8_u2i() {
8879
}
8980

9081
#[test]
91-
#[cfg(not(feature = "u2i"))]
92-
fn uint16() {
93-
let _guard = LOCK.run_concurrently();
94-
let obj_min: ser::Result<Bson> = to_bson(&u16::MIN);
95-
assert_matches!(obj_min, Err(ser::Error::UnsupportedUnsignedInteger(_)));
96-
}
97-
98-
#[test]
99-
#[cfg(feature = "u2i")]
10082
fn uint16_u2i() {
10183
let _guard = LOCK.run_concurrently();
10284
let obj: Bson = to_bson(&u16::MIN).unwrap();
@@ -109,15 +91,6 @@ fn uint16_u2i() {
10991
}
11092

11193
#[test]
112-
#[cfg(not(feature = "u2i"))]
113-
fn uint32() {
114-
let _guard = LOCK.run_concurrently();
115-
let obj_min: ser::Result<Bson> = to_bson(&u32::MIN);
116-
assert_matches!(obj_min, Err(ser::Error::UnsupportedUnsignedInteger(_)));
117-
}
118-
119-
#[test]
120-
#[cfg(feature = "u2i")]
12194
fn uint32_u2i() {
12295
let _guard = LOCK.run_concurrently();
12396
let obj_min: Bson = to_bson(&u32::MIN).unwrap();
@@ -130,15 +103,6 @@ fn uint32_u2i() {
130103
}
131104

132105
#[test]
133-
#[cfg(not(feature = "u2i"))]
134-
fn uint64() {
135-
let _guard = LOCK.run_concurrently();
136-
let obj_min: ser::Result<Bson> = to_bson(&u64::MIN);
137-
assert_matches!(obj_min, Err(ser::Error::UnsupportedUnsignedInteger(_)));
138-
}
139-
140-
#[test]
141-
#[cfg(feature = "u2i")]
142106
fn uint64_u2i() {
143107
let _guard = LOCK.run_concurrently();
144108
let obj_min: Bson = to_bson(&u64::MIN).unwrap();

0 commit comments

Comments
 (0)