Skip to content

Remove unused Option.or_{default,zero} and a minor cleanup #9279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 19, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions src/libstd/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,23 +467,14 @@ impl<T: Default> Option<T> {
None => Default::default()
}
}

/// Returns self or `Some`-wrapped default value
#[inline]
pub fn or_default(self) -> Option<T> {
match self {
None => Some(Default::default()),
x => x,
}
}
}

impl<T> Default for Option<T> {
#[inline]
fn default() -> Option<T> { None }
}

impl<T:Zero> Option<T> {
impl<T: Zero> Option<T> {
/// Returns the contained value or zero (for this type)
#[inline]
pub fn unwrap_or_zero(self) -> T {
Expand All @@ -492,15 +483,6 @@ impl<T:Zero> Option<T> {
None => Zero::zero()
}
}

/// Returns self or `Some`-wrapped zero value
#[inline]
pub fn or_zero(self) -> Option<T> {
match self {
None => Some(Zero::zero()),
x => x
}
}
}

/// An iterator that yields either one or zero elements
Expand Down
8 changes: 3 additions & 5 deletions src/libsyntax/ext/deriving/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ fn default_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Exp
cx.ident_of("Default"),
cx.ident_of("default")
];
let default_call = || {
cx.expr_call_global(span, default_ident.clone(), ~[])
};
let default_call = cx.expr_call_global(span, default_ident.clone(), ~[]);

return match *substr.fields {
StaticStruct(_, ref summary) => {
Expand All @@ -58,13 +56,13 @@ fn default_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Exp
if count == 0 {
cx.expr_ident(span, substr.type_ident)
} else {
let exprs = vec::from_fn(count, |_| default_call());
let exprs = vec::from_elem(count, default_call);
cx.expr_call_ident(span, substr.type_ident, exprs)
}
}
Right(ref fields) => {
let default_fields = do fields.map |ident| {
cx.field_imm(span, *ident, default_call())
cx.field_imm(span, *ident, default_call)
};
cx.expr_struct_ident(span, substr.type_ident, default_fields)
}
Expand Down
8 changes: 3 additions & 5 deletions src/libsyntax/ext/deriving/zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ fn zero_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
cx.ident_of("Zero"),
cx.ident_of("zero")
];
let zero_call = || {
cx.expr_call_global(span, zero_ident.clone(), ~[])
};
let zero_call = cx.expr_call_global(span, zero_ident.clone(), ~[]);

return match *substr.fields {
StaticStruct(_, ref summary) => {
Expand All @@ -73,13 +71,13 @@ fn zero_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
if count == 0 {
cx.expr_ident(span, substr.type_ident)
} else {
let exprs = vec::from_fn(count, |_| zero_call());
let exprs = vec::from_elem(count, zero_call);
cx.expr_call_ident(span, substr.type_ident, exprs)
}
}
Right(ref fields) => {
let zero_fields = do fields.map |ident| {
cx.field_imm(span, *ident, zero_call())
cx.field_imm(span, *ident, zero_call)
};
cx.expr_struct_ident(span, substr.type_ident, zero_fields)
}
Expand Down