Use `to_option` in various places

This commit is contained in:
varkor 2019-10-08 01:14:42 +01:00
parent 51901eea8c
commit e3a8ea4e18
51 changed files with 81 additions and 236 deletions

View File

@ -11,6 +11,7 @@
#![feature(nll)] #![feature(nll)]
#![feature(rustc_private)] #![feature(rustc_private)]
#![feature(unicode_internals)] #![feature(unicode_internals)]
#![feature(bool_to_option)]
pub use Piece::*; pub use Piece::*;
pub use Position::*; pub use Position::*;
@ -644,11 +645,7 @@ impl<'a> Parser<'a> {
break; break;
} }
} }
if found { found.to_option(cur)
Some(cur)
} else {
None
}
} }
} }

View File

@ -147,13 +147,7 @@ impl<'a> FnLikeNode<'a> {
map::Node::Expr(e) => e.is_fn_like(), map::Node::Expr(e) => e.is_fn_like(),
_ => false _ => false
}; };
if fn_like { fn_like.to_option(FnLikeNode { node })
Some(FnLikeNode {
node,
})
} else {
None
}
} }
pub fn body(self) -> ast::BodyId { pub fn body(self) -> ast::BodyId {

View File

@ -211,11 +211,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
(r, p) (r, p)
); );
let p_ty = p.to_ty(tcx); let p_ty = p.to_ty(tcx);
if compare_ty(p_ty) { compare_ty(p_ty).to_option(ty::OutlivesPredicate(p_ty, r))
Some(ty::OutlivesPredicate(p_ty, r))
} else {
None
}
}); });
param_bounds param_bounds

View File

@ -29,6 +29,7 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
#![feature(arbitrary_self_types)] #![feature(arbitrary_self_types)]
#![feature(bool_to_option)]
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(box_syntax)] #![feature(box_syntax)]
#![feature(const_fn)] #![feature(const_fn)]

View File

@ -242,11 +242,7 @@ impl<'tcx> Body<'tcx> {
pub fn vars_iter<'a>(&'a self) -> impl Iterator<Item = Local> + 'a { pub fn vars_iter<'a>(&'a self) -> impl Iterator<Item = Local> + 'a {
(self.arg_count + 1..self.local_decls.len()).filter_map(move |index| { (self.arg_count + 1..self.local_decls.len()).filter_map(move |index| {
let local = Local::new(index); let local = Local::new(index);
if self.local_decls[local].is_user_variable() { self.local_decls[local].is_user_variable().to_option(local)
Some(local)
} else {
None
}
}) })
} }

View File

@ -363,11 +363,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
return None return None
}; };
if tcx.has_attr(impl_def_id, sym::rustc_on_unimplemented) { tcx.has_attr(impl_def_id, sym::rustc_on_unimplemented).to_option(impl_def_id)
Some(impl_def_id)
} else {
None
}
} }
fn describe_generator(&self, body_id: hir::BodyId) -> Option<&'static str> { fn describe_generator(&self, body_id: hir::BodyId) -> Option<&'static str> {

View File

@ -2784,11 +2784,7 @@ impl<'tcx> TyCtxt<'tcx> {
} }
}; };
if is_associated_item { is_associated_item.to_option_with(|| self.associated_item(def_id))
Some(self.associated_item(def_id))
} else {
None
}
} }
fn associated_item_from_trait_item_ref(self, fn associated_item_from_trait_item_ref(self,
@ -3253,7 +3249,7 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ParamEnv<'_> {
let unnormalized_env = ty::ParamEnv::new( let unnormalized_env = ty::ParamEnv::new(
tcx.intern_predicates(&predicates), tcx.intern_predicates(&predicates),
traits::Reveal::UserFacing, traits::Reveal::UserFacing,
if tcx.sess.opts.debugging_opts.chalk { Some(def_id) } else { None } tcx.sess.opts.debugging_opts.chalk.to_option(def_id),
); );
let body_id = tcx.hir().as_local_hir_id(def_id).map_or(hir::DUMMY_HIR_ID, |id| { let body_id = tcx.hir().as_local_hir_id(def_id).map_or(hir::DUMMY_HIR_ID, |id| {

View File

@ -303,13 +303,8 @@ fn connected_to_root<'tcx>(
return true; return true;
} }
visit_waiters(query, |_, successor| { visit_waiters(query, |_, successor| connected_to_root(successor, visited).to_option(None))
if connected_to_root(successor, visited) { .is_some()
Some(None)
} else {
None
}
}).is_some()
} }
// Deterministically pick an query from a list // Deterministically pick an query from a list

View File

@ -375,11 +375,7 @@ pub fn provide_extern(providers: &mut Providers<'_>) {
let native_libs = tcx.native_libraries(cnum); let native_libs = tcx.native_libraries(cnum);
let def_id_to_native_lib = native_libs.iter().filter_map(|lib| let def_id_to_native_lib = native_libs.iter().filter_map(|lib|
if let Some(id) = lib.foreign_module { lib.foreign_module.map(|id| (id, lib))
Some((id, lib))
} else {
None
}
).collect::<FxHashMap<_, _>>(); ).collect::<FxHashMap<_, _>>();
let mut ret = FxHashMap::default(); let mut ret = FxHashMap::default();

View File

@ -245,11 +245,7 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
let (mut lo, mut hi) = (0u64, 0u64); let (mut lo, mut hi) = (0u64, 0u64);
let success = llvm::LLVMRustConstInt128Get(v, sign_ext, let success = llvm::LLVMRustConstInt128Get(v, sign_ext,
&mut hi, &mut lo); &mut hi, &mut lo);
if success { success.to_option(hi_lo_to_u128(lo, hi))
Some(hi_lo_to_u128(lo, hi))
} else {
None
}
}) })
} }

View File

@ -6,6 +6,7 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
#![feature(bool_to_option)]
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(box_syntax)] #![feature(box_syntax)]
#![feature(const_cstr_unchecked)] #![feature(const_cstr_unchecked)]

View File

@ -119,11 +119,7 @@ fn path_relative_from(path: &Path, base: &Path) -> Option<PathBuf> {
use std::path::Component; use std::path::Component;
if path.is_absolute() != base.is_absolute() { if path.is_absolute() != base.is_absolute() {
if path.is_absolute() { path.is_absolute().to_option(PathBuf::from(path))
Some(PathBuf::from(path))
} else {
None
}
} else { } else {
let mut ita = path.components(); let mut ita = path.components();
let mut itb = base.components(); let mut itb = base.components();

View File

@ -85,11 +85,7 @@ fn reachable_non_generics_provider(
match tcx.hir().get(hir_id) { match tcx.hir().get(hir_id) {
Node::ForeignItem(..) => { Node::ForeignItem(..) => {
let def_id = tcx.hir().local_def_id(hir_id); let def_id = tcx.hir().local_def_id(hir_id);
if tcx.is_statically_included_foreign_item(def_id) { tcx.is_statically_included_foreign_item(def_id).to_option(def_id)
Some(def_id)
} else {
None
}
} }
// Only consider nodes that actually have exported symbols. // Only consider nodes that actually have exported symbols.

View File

@ -1,5 +1,6 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
#![feature(bool_to_option)]
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(box_syntax)] #![feature(box_syntax)]
#![feature(core_intrinsics)] #![feature(core_intrinsics)]
@ -68,22 +69,11 @@ impl<M> ModuleCodegen<M> {
emit_bc: bool, emit_bc: bool,
emit_bc_compressed: bool, emit_bc_compressed: bool,
outputs: &OutputFilenames) -> CompiledModule { outputs: &OutputFilenames) -> CompiledModule {
let object = if emit_obj { let object = emit_obj.to_option(outputs.temp_path(OutputType::Object, Some(&self.name)));
Some(outputs.temp_path(OutputType::Object, Some(&self.name))) let bytecode = emit_bc.to_option(outputs.temp_path(OutputType::Bitcode, Some(&self.name)));
} else { let bytecode_compressed = emit_bc_compressed.to_option(
None outputs.temp_path(OutputType::Bitcode, Some(&self.name))
}; .with_extension(RLIB_BYTECODE_EXTENSION));
let bytecode = if emit_bc {
Some(outputs.temp_path(OutputType::Bitcode, Some(&self.name)))
} else {
None
};
let bytecode_compressed = if emit_bc_compressed {
Some(outputs.temp_path(OutputType::Bitcode, Some(&self.name))
.with_extension(RLIB_BYTECODE_EXTENSION))
} else {
None
};
CompiledModule { CompiledModule {
name: self.name.clone(), name: self.name.clone(),

View File

@ -1,3 +1,4 @@
#![feature(bool_to_option)]
#![feature(box_syntax)] #![feature(box_syntax)]
#![feature(set_stdio)] #![feature(set_stdio)]
#![feature(nll)] #![feature(nll)]

View File

@ -547,13 +547,7 @@ fn output_contains_path(output_paths: &[PathBuf], input_path: &PathBuf) -> bool
} }
fn output_conflicts_with_dir(output_paths: &[PathBuf]) -> Option<PathBuf> { fn output_conflicts_with_dir(output_paths: &[PathBuf]) -> Option<PathBuf> {
let check = |output_path: &PathBuf| { let check = |output_path: &PathBuf| output_path.is_dir().to_option(output_path.clone());
if output_path.is_dir() {
Some(output_path.clone())
} else {
None
}
};
check_output(output_paths, check) check_output(output_paths, check)
} }

View File

@ -117,11 +117,9 @@ impl<'tcx> Queries<'tcx> {
pub fn dep_graph_future(&self) -> Result<&Query<Option<DepGraphFuture>>> { pub fn dep_graph_future(&self) -> Result<&Query<Option<DepGraphFuture>>> {
self.dep_graph_future.compute(|| { self.dep_graph_future.compute(|| {
Ok(if self.session().opts.build_dep_graph() { Ok(self.session().opts.build_dep_graph().to_option_with(|| {
Some(rustc_incremental::load_dep_graph(self.session())) rustc_incremental::load_dep_graph(self.session())
} else { }))
None
})
}) })
} }

View File

@ -107,11 +107,7 @@ const STACK_SIZE: usize = 16 * 1024 * 1024;
fn get_stack_size() -> Option<usize> { fn get_stack_size() -> Option<usize> {
// FIXME: Hacks on hacks. If the env is trying to override the stack size // FIXME: Hacks on hacks. If the env is trying to override the stack size
// then *don't* set it explicitly. // then *don't* set it explicitly.
if env::var_os("RUST_MIN_STACK").is_none() { env::var_os("RUST_MIN_STACK").is_none().to_option(STACK_SIZE)
Some(STACK_SIZE)
} else {
None
}
} }
struct Sink(Arc<Mutex<Vec<u8>>>); struct Sink(Arc<Mutex<Vec<u8>>>);
@ -285,11 +281,7 @@ fn get_rustc_path_inner(bin_path: &str) -> Option<PathBuf> {
} else { } else {
"rustc" "rustc"
}); });
if candidate.exists() { candidate.exists().to_option(candidate)
Some(candidate)
} else {
None
}
}) })
.next() .next()
} }

View File

@ -1491,11 +1491,7 @@ impl ExplicitOutlivesRequirements {
match pred { match pred {
ty::Predicate::TypeOutlives(outlives) => { ty::Predicate::TypeOutlives(outlives) => {
let outlives = outlives.skip_binder(); let outlives = outlives.skip_binder();
if outlives.0.is_param(index) { outlives.0.is_param(index).to_option(outlives.1)
Some(outlives.1)
} else {
None
}
} }
_ => None _ => None
} }
@ -1554,11 +1550,7 @@ impl ExplicitOutlivesRequirements {
}), }),
_ => false, _ => false,
}; };
if is_inferred { is_inferred.to_option((i, bound.span()))
Some((i, bound.span()))
} else {
None
}
} else { } else {
None None
} }

View File

@ -12,6 +12,7 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
#![cfg_attr(test, feature(test))] #![cfg_attr(test, feature(test))]
#![feature(bool_to_option)]
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(box_syntax)] #![feature(box_syntax)]
#![feature(nll)] #![feature(nll)]

View File

@ -802,11 +802,8 @@ impl<'a> CrateLoader<'a> {
// First up we check for global allocators. Look at the crate graph here // First up we check for global allocators. Look at the crate graph here
// and see what's a global allocator, including if we ourselves are a // and see what's a global allocator, including if we ourselves are a
// global allocator. // global allocator.
let mut global_allocator = if self.cstore.has_global_allocator { let mut global_allocator = self.cstore.has_global_allocator
Some(Symbol::intern("this crate")) .to_option_with(|| Symbol::intern("this crate"));
} else {
None
};
self.cstore.iter_crate_data(|_, data| { self.cstore.iter_crate_data(|_, data| {
if !data.has_global_allocator() { if !data.has_global_allocator() {
return return

View File

@ -1,5 +1,6 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
#![feature(bool_to_option)]
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(core_intrinsics)] #![feature(core_intrinsics)]
#![feature(crate_visibility_modifier)] #![feature(crate_visibility_modifier)]

View File

@ -173,11 +173,7 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
Option<Rc<Output<RegionVid, BorrowIndex, LocationIndex, Local, MovePathIndex>>>, Option<Rc<Output<RegionVid, BorrowIndex, LocationIndex, Local, MovePathIndex>>>,
Option<ClosureRegionRequirements<'tcx>>, Option<ClosureRegionRequirements<'tcx>>,
) { ) {
let mut all_facts = if AllFacts::enabled(infcx.tcx) { let mut all_facts = AllFacts::enabled(infcx.tcx).to_option(AllFacts::default());
Some(AllFacts::default())
} else {
None
};
let universal_regions = Rc::new(universal_regions); let universal_regions = Rc::new(universal_regions);

View File

@ -493,7 +493,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
// functions below, which will trigger them to report errors // functions below, which will trigger them to report errors
// eagerly. // eagerly.
let mut outlives_requirements = let mut outlives_requirements =
if infcx.tcx.is_closure(mir_def_id) { Some(vec![]) } else { None }; infcx.tcx.is_closure(mir_def_id).to_option_with(|| vec![]);
self.check_type_tests( self.check_type_tests(
infcx, infcx,
@ -709,14 +709,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
let min = |r1: ty::RegionVid, r2: ty::RegionVid| -> Option<ty::RegionVid> { let min = |r1: ty::RegionVid, r2: ty::RegionVid| -> Option<ty::RegionVid> {
let r1_outlives_r2 = self.universal_region_relations.outlives(r1, r2); let r1_outlives_r2 = self.universal_region_relations.outlives(r1, r2);
let r2_outlives_r1 = self.universal_region_relations.outlives(r2, r1); let r2_outlives_r1 = self.universal_region_relations.outlives(r2, r1);
if r1_outlives_r2 && r2_outlives_r1 { match (r1_outlives_r2, r2_outlives_r1) {
Some(r1.min(r2)) (true, true) => Some(r1.min(r2)),
} else if r1_outlives_r2 { (true, false) => Some(r2),
Some(r2) (false, true) => Some(r1),
} else if r2_outlives_r1 { (false, false) => None,
Some(r1)
} else {
None
} }
}; };
let mut min_choice = choice_regions[0]; let mut min_choice = choice_regions[0];

View File

@ -680,7 +680,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
} }
})(); })();
if no_overlap == Some(true) { if let Some(true) = no_overlap {
// Testing range does not overlap with pattern range, // Testing range does not overlap with pattern range,
// so the pattern can be matched only if this test fails. // so the pattern can be matched only if this test fails.
Some(1) Some(1)
@ -690,7 +690,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
} }
(&TestKind::Range(range), &PatKind::Constant { value }) => { (&TestKind::Range(range), &PatKind::Constant { value }) => {
if self.const_range_contains(range, value) == Some(false) { if let Some(false) = self.const_range_contains(range, value) {
// `value` is not contained in the testing range, // `value` is not contained in the testing range,
// so `value` can be matched only if this test fails. // so `value` can be matched only if this test fails.
Some(1) Some(1)

View File

@ -1154,13 +1154,7 @@ pub fn compare_const_vals<'tcx>(
) -> Option<Ordering> { ) -> Option<Ordering> {
trace!("compare_const_vals: {:?}, {:?}", a, b); trace!("compare_const_vals: {:?}, {:?}", a, b);
let from_bool = |v: bool| { let from_bool = |v: bool| v.to_option(Ordering::Equal);
if v {
Some(Ordering::Equal)
} else {
None
}
};
let fallback = || from_bool(a == b); let fallback = || from_bool(a == b);

View File

@ -324,7 +324,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
size: Size, size: Size,
align: Align, align: Align,
) -> InterpResult<'tcx, Option<Pointer<M::PointerTag>>> { ) -> InterpResult<'tcx, Option<Pointer<M::PointerTag>>> {
let align = if M::CHECK_ALIGN { Some(align) } else { None }; let align = M::CHECK_ALIGN.to_option(align);
self.check_ptr_access_align(sptr, size, align, CheckInAllocMsg::MemoryAccessTest) self.check_ptr_access_align(sptr, size, align, CheckInAllocMsg::MemoryAccessTest)
} }

View File

@ -157,9 +157,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
} }
BinaryOp(bin_op, ref left, ref right) => { BinaryOp(bin_op, ref left, ref right) => {
let layout = if binop_left_homogeneous(bin_op) { Some(dest.layout) } else { None }; let layout = binop_left_homogeneous(bin_op).to_option(dest.layout);
let left = self.read_immediate(self.eval_operand(left, layout)?)?; let left = self.read_immediate(self.eval_operand(left, layout)?)?;
let layout = if binop_right_homogeneous(bin_op) { Some(left.layout) } else { None }; let layout = binop_right_homogeneous(bin_op).to_option(left.layout);
let right = self.read_immediate(self.eval_operand(right, layout)?)?; let right = self.read_immediate(self.eval_operand(right, layout)?)?;
self.binop_ignore_overflow( self.binop_ignore_overflow(
bin_op, bin_op,
@ -172,7 +172,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
CheckedBinaryOp(bin_op, ref left, ref right) => { CheckedBinaryOp(bin_op, ref left, ref right) => {
// Due to the extra boolean in the result, we can never reuse the `dest.layout`. // Due to the extra boolean in the result, we can never reuse the `dest.layout`.
let left = self.read_immediate(self.eval_operand(left, None)?)?; let left = self.read_immediate(self.eval_operand(left, None)?)?;
let layout = if binop_right_homogeneous(bin_op) { Some(left.layout) } else { None }; let layout = binop_right_homogeneous(bin_op).to_option(left.layout);
let right = self.read_immediate(self.eval_operand(right, layout)?)?; let right = self.read_immediate(self.eval_operand(right, layout)?)?;
self.binop_with_overflow( self.binop_with_overflow(
bin_op, bin_op,

View File

@ -8,6 +8,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
#![feature(in_band_lifetimes)] #![feature(in_band_lifetimes)]
#![feature(inner_deref)] #![feature(inner_deref)]
#![feature(slice_patterns)] #![feature(slice_patterns)]
#![feature(bool_to_option)]
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(box_syntax)] #![feature(box_syntax)]
#![feature(crate_visibility_modifier)] #![feature(crate_visibility_modifier)]

View File

@ -761,11 +761,7 @@ fn compute_codegen_unit_name(
.iter() .iter()
.map(|part| part.data.as_symbol()); .map(|part| part.data.as_symbol());
let volatile_suffix = if volatile { let volatile_suffix = volatile.to_option("volatile");
Some("volatile")
} else {
None
};
name_builder.build_cgu_name(def_path.krate, components, volatile_suffix) name_builder.build_cgu_name(def_path.krate, components, volatile_suffix)
}).clone() }).clone()

View File

@ -658,7 +658,7 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: DefId) {
let mut unsafe_blocks: Vec<_> = unsafe_blocks.into_iter().collect(); let mut unsafe_blocks: Vec<_> = unsafe_blocks.into_iter().collect();
unsafe_blocks.sort_by_cached_key(|(hir_id, _)| tcx.hir().hir_to_node_id(*hir_id)); unsafe_blocks.sort_by_cached_key(|(hir_id, _)| tcx.hir().hir_to_node_id(*hir_id));
let used_unsafe: FxHashSet<_> = unsafe_blocks.iter() let used_unsafe: FxHashSet<_> = unsafe_blocks.iter()
.flat_map(|&&(id, used)| if used { Some(id) } else { None }) .flat_map(|&&(id, used)| used.to_option(id))
.collect(); .collect();
for &(block_id, is_used) in unsafe_blocks { for &(block_id, is_used) in unsafe_blocks {
if !is_used { if !is_used {

View File

@ -75,7 +75,7 @@ macro_rules! configure {
impl<'a> StripUnconfigured<'a> { impl<'a> StripUnconfigured<'a> {
pub fn configure<T: HasAttrs>(&mut self, mut node: T) -> Option<T> { pub fn configure<T: HasAttrs>(&mut self, mut node: T) -> Option<T> {
self.process_cfg_attrs(&mut node); self.process_cfg_attrs(&mut node);
if self.in_cfg(node.attrs()) { Some(node) } else { None } self.in_cfg(node.attrs()).to_option(node)
} }
/// Parse and expand all `cfg_attr` attributes into a list of attributes /// Parse and expand all `cfg_attr` attributes into a list of attributes

View File

@ -422,11 +422,7 @@ impl<'a> Resolver<'a> {
Scope::MacroUsePrelude => { Scope::MacroUsePrelude => {
suggestions.extend(this.macro_use_prelude.iter().filter_map(|(name, binding)| { suggestions.extend(this.macro_use_prelude.iter().filter_map(|(name, binding)| {
let res = binding.res(); let res = binding.res();
if filter_fn(res) { filter_fn(res).to_option(TypoSuggestion::from_res(*name, res))
Some(TypoSuggestion::from_res(*name, res))
} else {
None
}
})); }));
} }
Scope::BuiltinAttrs => { Scope::BuiltinAttrs => {
@ -440,11 +436,7 @@ impl<'a> Resolver<'a> {
Scope::ExternPrelude => { Scope::ExternPrelude => {
suggestions.extend(this.extern_prelude.iter().filter_map(|(ident, _)| { suggestions.extend(this.extern_prelude.iter().filter_map(|(ident, _)| {
let res = Res::Def(DefKind::Mod, DefId::local(CRATE_DEF_INDEX)); let res = Res::Def(DefKind::Mod, DefId::local(CRATE_DEF_INDEX));
if filter_fn(res) { filter_fn(res).to_option(TypoSuggestion::from_res(ident.name, res))
Some(TypoSuggestion::from_res(ident.name, res))
} else {
None
}
})); }));
} }
Scope::ToolPrelude => { Scope::ToolPrelude => {
@ -467,11 +459,7 @@ impl<'a> Resolver<'a> {
suggestions.extend( suggestions.extend(
primitive_types.iter().flat_map(|(name, prim_ty)| { primitive_types.iter().flat_map(|(name, prim_ty)| {
let res = Res::PrimTy(*prim_ty); let res = Res::PrimTy(*prim_ty);
if filter_fn(res) { filter_fn(res).to_option(TypoSuggestion::from_res(*name, res))
Some(TypoSuggestion::from_res(*name, res))
} else {
None
}
}) })
) )
} }

View File

@ -496,11 +496,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LateResolutionVisitor<'a, '_> {
GenericParamKind::Lifetime { .. } => None, GenericParamKind::Lifetime { .. } => None,
GenericParamKind::Type { ref default, .. } => { GenericParamKind::Type { ref default, .. } => {
found_default |= default.is_some(); found_default |= default.is_some();
if found_default { found_default.to_option((Ident::with_dummy_span(param.ident.name), Res::Err))
Some((Ident::with_dummy_span(param.ident.name), Res::Err))
} else {
None
}
} }
})); }));

View File

@ -9,6 +9,7 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
#![feature(bool_to_option)]
#![feature(crate_visibility_modifier)] #![feature(crate_visibility_modifier)]
#![feature(label_break_value)] #![feature(label_break_value)]
#![feature(nll)] #![feature(nll)]

View File

@ -752,11 +752,7 @@ impl Session {
} }
pub fn incr_comp_session_dir_opt(&self) -> Option<cell::Ref<'_, PathBuf>> { pub fn incr_comp_session_dir_opt(&self) -> Option<cell::Ref<'_, PathBuf>> {
if self.opts.incremental.is_some() { self.opts.incremental.is_some().to_option(self.incr_comp_session_dir())
Some(self.incr_comp_session_dir())
} else {
None
}
} }
pub fn print_perf_stats(&self) { pub fn print_perf_stats(&self) {
@ -1079,8 +1075,9 @@ fn build_session_(
None None
} }
} }
} } else {
else { None }; None
};
let host_triple = TargetTriple::from_triple(config::host_triple()); let host_triple = TargetTriple::from_triple(config::host_triple());
let host = Target::search(&host_triple).unwrap_or_else(|e| let host = Target::search(&host_triple).unwrap_or_else(|e|

View File

@ -20,14 +20,7 @@ fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>)
RegKind::Vector => size.bits() == 64 || size.bits() == 128 RegKind::Vector => size.bits() == 64 || size.bits() == 128
}; };
if valid_unit { valid_unit.to_option(Uniform { unit, total: size })
Some(Uniform {
unit,
total: size
})
} else {
None
}
}) })
} }

View File

@ -21,14 +21,7 @@ fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>)
RegKind::Vector => size.bits() == 64 || size.bits() == 128 RegKind::Vector => size.bits() == 64 || size.bits() == 128
}; };
if valid_unit { valid_unit.to_option(Uniform { unit, total: size })
Some(Uniform {
unit,
total: size
})
} else {
None
}
}) })
} }

View File

@ -416,11 +416,7 @@ impl<'a, Ty> ArgAbi<'a, Ty> {
// i686-pc-windows-msvc, it results in wrong stack offsets. // i686-pc-windows-msvc, it results in wrong stack offsets.
// attrs.pointee_align = Some(self.layout.align.abi); // attrs.pointee_align = Some(self.layout.align.abi);
let extra_attrs = if self.layout.is_unsized() { let extra_attrs = self.layout.is_unsized().to_option(ArgAttributes::new());
Some(ArgAttributes::new())
} else {
None
};
self.mode = PassMode::Indirect(attrs, extra_attrs); self.mode = PassMode::Indirect(attrs, extra_attrs);
} }

View File

@ -32,14 +32,7 @@ fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, abi: AB
RegKind::Vector => arg.layout.size.bits() == 128 RegKind::Vector => arg.layout.size.bits() == 128
}; };
if valid_unit { valid_unit.to_option(Uniform { unit, total: arg.layout.size })
Some(Uniform {
unit,
total: arg.layout.size
})
} else {
None
}
}) })
} }

View File

@ -20,14 +20,7 @@ fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>)
RegKind::Vector => arg.layout.size.bits() == 128 RegKind::Vector => arg.layout.size.bits() == 128
}; };
if valid_unit { valid_unit.to_option(Uniform { unit, total: arg.layout.size })
Some(Uniform {
unit,
total: arg.layout.size
})
} else {
None
}
}) })
} }

View File

@ -10,6 +10,7 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
#![feature(box_syntax)] #![feature(box_syntax)]
#![feature(bool_to_option)]
#![feature(nll)] #![feature(nll)]
#![feature(slice_patterns)] #![feature(slice_patterns)]

View File

@ -1105,11 +1105,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
r.map(|mut pick| { r.map(|mut pick| {
pick.autoderefs = step.autoderefs; pick.autoderefs = step.autoderefs;
pick.autoref = Some(mutbl); pick.autoref = Some(mutbl);
pick.unsize = if step.unsize { pick.unsize = step.unsize.to_option(self_ty);
Some(self_ty)
} else {
None
};
pick pick
}) })
}) })

View File

@ -114,11 +114,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}; };
let infer_kind = if let UpvarSubsts::Closure(closure_substs) = substs { let infer_kind = if let UpvarSubsts::Closure(closure_substs) = substs {
if self.closure_kind(closure_def_id, closure_substs).is_none() { self.closure_kind(closure_def_id, closure_substs).is_none().to_option(closure_substs)
Some(closure_substs)
} else {
None
}
} else { } else {
None None
}; };

View File

@ -59,6 +59,7 @@ This API is completely unstable and subject to change.
#![allow(non_camel_case_types)] #![allow(non_camel_case_types)]
#![feature(bool_to_option)]
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(box_syntax)] #![feature(box_syntax)]
#![feature(crate_visibility_modifier)] #![feature(crate_visibility_modifier)]

View File

@ -7,6 +7,7 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/", #![doc(html_root_url = "https://doc.rust-lang.org/nightly/",
test(attr(deny(warnings))))] test(attr(deny(warnings))))]
#![feature(bool_to_option)]
#![feature(box_syntax)] #![feature(box_syntax)]
#![feature(const_fn)] #![feature(const_fn)]
#![feature(const_transmute)] #![feature(const_transmute)]

View File

@ -317,7 +317,7 @@ pub fn token_to_string(token: &Token) -> String {
} }
fn token_to_string_ext(token: &Token, convert_dollar_crate: bool) -> String { fn token_to_string_ext(token: &Token, convert_dollar_crate: bool) -> String {
let convert_dollar_crate = if convert_dollar_crate { Some(token.span) } else { None }; let convert_dollar_crate = convert_dollar_crate.to_option(token.span);
token_kind_to_string_ext(&token.kind, convert_dollar_crate) token_kind_to_string_ext(&token.kind, convert_dollar_crate)
} }

View File

@ -77,6 +77,6 @@ pub fn find_best_match_for_name<'a, T>(iter_names: T,
if let Some(candidate) = case_insensitive_match { if let Some(candidate) = case_insensitive_match {
Some(candidate) // exact case insensitive match has a higher priority Some(candidate) // exact case insensitive match has a higher priority
} else { } else {
if let Some((candidate, _)) = levenstein_match { Some(candidate) } else { None } levenstein_match.map(|(candidate, _)| candidate)
} }
} }

View File

@ -95,12 +95,12 @@ pub mod printf {
}; };
// Has a special form in Rust for numbers. // Has a special form in Rust for numbers.
let fill = if c_zero { Some("0") } else { None }; let fill = c_zero.to_option("0");
let align = if c_left { Some("<") } else { None }; let align = c_left.to_option("<");
// Rust doesn't have an equivalent to the `' '` flag. // Rust doesn't have an equivalent to the `' '` flag.
let sign = if c_plus { Some("+") } else { None }; let sign = c_plus.to_option("+");
// Not *quite* the same, depending on the type... // Not *quite* the same, depending on the type...
let alt = c_alt; let alt = c_alt;

View File

@ -3,6 +3,7 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
#![feature(bool_to_option)]
#![feature(crate_visibility_modifier)] #![feature(crate_visibility_modifier)]
#![feature(decl_macro)] #![feature(decl_macro)]
#![feature(nll)] #![feature(nll)]

View File

@ -24,6 +24,7 @@
#![cfg_attr(any(unix, target_os = "cloudabi"), feature(libc))] #![cfg_attr(any(unix, target_os = "cloudabi"), feature(libc))]
#![feature(rustc_private)] #![feature(rustc_private)]
#![feature(nll)] #![feature(nll)]
#![feature(bool_to_option)]
#![feature(set_stdio)] #![feature(set_stdio)]
#![feature(panic_unwind)] #![feature(panic_unwind)]
#![feature(staged_api)] #![feature(staged_api)]
@ -562,11 +563,7 @@ fn run_test_in_process(
None None
}; };
let start = if report_time { let start = report_time.to_option(Instant::now());
Some(Instant::now())
} else {
None
};
let result = catch_unwind(AssertUnwindSafe(testfn)); let result = catch_unwind(AssertUnwindSafe(testfn));
let exec_time = start.map(|start| { let exec_time = start.map(|start| {
let duration = start.elapsed(); let duration = start.elapsed();
@ -597,11 +594,7 @@ fn spawn_test_subprocess(
let args = env::args().collect::<Vec<_>>(); let args = env::args().collect::<Vec<_>>();
let current_exe = &args[0]; let current_exe = &args[0];
let start = if report_time { let start = report_time.to_option(Instant::now());
Some(Instant::now())
} else {
None
};
let output = match Command::new(current_exe) let output = match Command::new(current_exe)
.env(SECONDARY_TEST_INVOKER_VAR, desc.name.as_slice()) .env(SECONDARY_TEST_INVOKER_VAR, desc.name.as_slice())
.output() { .output() {