Skip to content

Commit e11fc88

Browse files
kepler-5bluejekyll
authored andcommitted
Fully qualify both Option and Result in generated code, along with their variants.
1 parent 2464bb4 commit e11fc88

File tree

7 files changed

+89
-17
lines changed

7 files changed

+89
-17
lines changed

src/lib.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -176,23 +176,23 @@ fn unnamed_fields_return(
176176

177177
#[doc = #doc_mut_ref ]
178178
#[inline]
179-
pub fn #function_name_mut_ref(&mut self) -> Option<#returns_mut_ref> {
179+
pub fn #function_name_mut_ref(&mut self) -> ::core::option::Option<#returns_mut_ref> {
180180
match self {
181181
Self::#variant_name(#matches) => {
182-
Some((#matches))
182+
::core::option::Option::Some((#matches))
183183
}
184-
_ => None
184+
_ => ::core::option::Option::None
185185
}
186186
}
187187

188188
#[doc = #doc_ref ]
189189
#[inline]
190-
pub fn #function_name_ref(&self) -> Option<#returns_ref> {
190+
pub fn #function_name_ref(&self) -> ::core::option::Option<#returns_ref> {
191191
match self {
192192
Self::#variant_name(#matches) => {
193-
Some((#matches))
193+
::core::option::Option::Some((#matches))
194194
}
195-
_ => None
195+
_ => ::core::option::Option::None
196196
}
197197
}
198198

@@ -201,9 +201,9 @@ fn unnamed_fields_return(
201201
pub fn #function_name_val(self) -> ::core::result::Result<#returns_val, Self> {
202202
match self {
203203
Self::#variant_name(#matches) => {
204-
Ok((#matches))
204+
::core::result::Result::Ok((#matches))
205205
},
206-
_ => Err(self)
206+
_ => ::core::result::Result::Err(self)
207207
}
208208
}
209209
)
@@ -267,23 +267,23 @@ fn named_fields_return(
267267

268268
#[doc = #doc_mut_ref ]
269269
#[inline]
270-
pub fn #function_name_mut_ref(&mut self) -> Option<#returns_mut_ref> {
270+
pub fn #function_name_mut_ref(&mut self) -> ::core::option::Option<#returns_mut_ref> {
271271
match self {
272272
Self::#variant_name{ #matches } => {
273-
Some((#matches))
273+
::core::option::Option::Some((#matches))
274274
}
275-
_ => None
275+
_ => ::core::option::Option::None
276276
}
277277
}
278278

279279
#[doc = #doc_ref ]
280280
#[inline]
281-
pub fn #function_name_ref(&self) -> Option<#returns_ref> {
281+
pub fn #function_name_ref(&self) -> ::core::option::Option<#returns_ref> {
282282
match self {
283283
Self::#variant_name{ #matches } => {
284-
Some((#matches))
284+
::core::option::Option::Some((#matches))
285285
}
286-
_ => None
286+
_ => ::core::option::Option::None
287287
}
288288
}
289289

@@ -292,9 +292,9 @@ fn named_fields_return(
292292
pub fn #function_name_val(self) -> ::core::result::Result<#returns_val, Self> {
293293
match self {
294294
Self::#variant_name{ #matches } => {
295-
Ok((#matches))
295+
::core::result::Result::Ok((#matches))
296296
}
297-
_ => Err(self)
297+
_ => ::core::result::Result::Err(self)
298298
}
299299
}
300300
)

tests/basic.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,24 @@
1414

1515
use enum_as_inner::EnumAsInner;
1616

17+
mod name_collisions {
18+
#![allow(dead_code, missing_copy_implementations, missing_docs)]
19+
struct Option;
20+
struct Some;
21+
struct None;
22+
struct Result;
23+
struct Ok;
24+
struct Err;
25+
}
26+
#[allow(unused_imports)]
27+
use name_collisions::*;
28+
1729
#[derive(Debug, EnumAsInner)]
1830
enum EmptyTest {}
1931

2032
#[test]
2133
fn test_empty() {
22-
let empty = None::<EmptyTest>;
34+
let empty = std::option::Option::None::<EmptyTest>;
2335

2436
assert!(empty.is_none());
2537
}

tests/generics.rs

+12
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@
1414

1515
use enum_as_inner::EnumAsInner;
1616

17+
mod name_collisions {
18+
#![allow(dead_code, missing_copy_implementations, missing_docs)]
19+
struct Option;
20+
struct Some;
21+
struct None;
22+
struct Result;
23+
struct Ok;
24+
struct Err;
25+
}
26+
#[allow(unused_imports)]
27+
use name_collisions::*;
28+
1729
#[allow(dead_code)]
1830
#[derive(Debug, Clone, Copy, EnumAsInner)]
1931
enum WithGenerics<T: Clone + Copy> {

tests/named.rs

+12
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@
1414

1515
use enum_as_inner::EnumAsInner;
1616

17+
mod name_collisions {
18+
#![allow(dead_code, missing_copy_implementations, missing_docs)]
19+
struct Option;
20+
struct Some;
21+
struct None;
22+
struct Result;
23+
struct Ok;
24+
struct Err;
25+
}
26+
#[allow(unused_imports)]
27+
use name_collisions::*;
28+
1729
#[derive(Debug, EnumAsInner)]
1830
enum ManyVariants {
1931
One { one: u32 },

tests/snake_case.rs

+12
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@
1414

1515
use enum_as_inner::EnumAsInner;
1616

17+
mod name_collisions {
18+
#![allow(dead_code, missing_copy_implementations, missing_docs)]
19+
struct Option;
20+
struct Some;
21+
struct None;
22+
struct Result;
23+
struct Ok;
24+
struct Err;
25+
}
26+
#[allow(unused_imports)]
27+
use name_collisions::*;
28+
1729
#[derive(Debug, EnumAsInner)]
1830
#[allow(non_camel_case_types)]
1931
#[allow(clippy::upper_case_acronyms)]

tests/unit.rs

+12
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@
1414

1515
use enum_as_inner::EnumAsInner;
1616

17+
mod name_collisions {
18+
#![allow(dead_code, missing_copy_implementations, missing_docs)]
19+
struct Option;
20+
struct Some;
21+
struct None;
22+
struct Result;
23+
struct Ok;
24+
struct Err;
25+
}
26+
#[allow(unused_imports)]
27+
use name_collisions::*;
28+
1729
#[derive(EnumAsInner)]
1830
enum UnitVariants {
1931
Zero,

tests/unnamed.rs

+12
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@
1414

1515
use enum_as_inner::EnumAsInner;
1616

17+
mod name_collisions {
18+
#![allow(dead_code, missing_copy_implementations, missing_docs)]
19+
struct Option;
20+
struct Some;
21+
struct None;
22+
struct Result;
23+
struct Ok;
24+
struct Err;
25+
}
26+
#[allow(unused_imports)]
27+
use name_collisions::*;
28+
1729
#[derive(Debug, EnumAsInner)]
1830
enum ManyVariants {
1931
One(u32),

0 commit comments

Comments
 (0)