diff --git a/src/libcore/bool.rs b/src/libcore/bool.rs index aa1ba7affc1..1b3c254a05f 100644 --- a/src/libcore/bool.rs +++ b/src/libcore/bool.rs @@ -9,12 +9,12 @@ impl bool { /// ``` /// #![feature(bool_to_option)] /// - /// assert_eq!(false.to_option(0), None); - /// assert_eq!(true.to_option(0), Some(0)); + /// assert_eq!(false.then_some(0), None); + /// assert_eq!(true.then_some(0), Some(0)); /// ``` #[unstable(feature = "bool_to_option", issue = "64260")] #[inline] - pub fn to_option(self, t: T) -> Option { + pub fn then_some(self, t: T) -> Option { if self { Some(t) } else { @@ -29,12 +29,12 @@ impl bool { /// ``` /// #![feature(bool_to_option)] /// - /// assert_eq!(false.to_option_with(|| 0), None); - /// assert_eq!(true.to_option_with(|| 0), Some(0)); + /// assert_eq!(false.then(|| 0), None); + /// assert_eq!(true.then(|| 0), Some(0)); /// ``` #[unstable(feature = "bool_to_option", issue = "64260")] #[inline] - pub fn to_option_with T>(self, f: F) -> Option { + pub fn then T>(self, f: F) -> Option { if self { Some(f()) } else { diff --git a/src/libcore/tests/bool.rs b/src/libcore/tests/bool.rs index 8ec151b63ff..e89eb2c7f94 100644 --- a/src/libcore/tests/bool.rs +++ b/src/libcore/tests/bool.rs @@ -1,7 +1,7 @@ #[test] fn test_bool_to_option() { - assert_eq!(false.to_option(0), None); - assert_eq!(true.to_option(0), Some(0)); - assert_eq!(false.to_option_with(|| 0), None); - assert_eq!(true.to_option_with(|| 0), Some(0)); + assert_eq!(false.then_some(0), None); + assert_eq!(true.then_some(0), Some(0)); + assert_eq!(false.then(|| 0), None); + assert_eq!(true.then(|| 0), Some(0)); } diff --git a/src/libfmt_macros/lib.rs b/src/libfmt_macros/lib.rs index 2e8837bb63f..2ecbe770729 100644 --- a/src/libfmt_macros/lib.rs +++ b/src/libfmt_macros/lib.rs @@ -645,7 +645,7 @@ impl<'a> Parser<'a> { break; } } - found.to_option(cur) + found.then_some(cur) } } diff --git a/src/librustc/hir/map/blocks.rs b/src/librustc/hir/map/blocks.rs index 5c5ce8c668d..8f9f3983262 100644 --- a/src/librustc/hir/map/blocks.rs +++ b/src/librustc/hir/map/blocks.rs @@ -147,7 +147,7 @@ impl<'a> FnLikeNode<'a> { map::Node::Expr(e) => e.is_fn_like(), _ => false }; - fn_like.to_option(FnLikeNode { node }) + fn_like.then_some(FnLikeNode { node }) } pub fn body(self) -> ast::BodyId { diff --git a/src/librustc/infer/outlives/verify.rs b/src/librustc/infer/outlives/verify.rs index aebf93d85c5..3e28145c0fa 100644 --- a/src/librustc/infer/outlives/verify.rs +++ b/src/librustc/infer/outlives/verify.rs @@ -211,7 +211,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { (r, p) ); let p_ty = p.to_ty(tcx); - compare_ty(p_ty).to_option(ty::OutlivesPredicate(p_ty, r)) + compare_ty(p_ty).then_some(ty::OutlivesPredicate(p_ty, r)) }); param_bounds diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 6f27adf194a..412300f0b10 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -363,7 +363,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { return None }; - tcx.has_attr(impl_def_id, sym::rustc_on_unimplemented).to_option(impl_def_id) + tcx.has_attr(impl_def_id, sym::rustc_on_unimplemented).then_some(impl_def_id) } fn describe_generator(&self, body_id: hir::BodyId) -> Option<&'static str> { diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index ca1758ee78a..05a2704cc5d 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -2784,7 +2784,7 @@ impl<'tcx> TyCtxt<'tcx> { } }; - is_associated_item.to_option_with(|| self.associated_item(def_id)) + is_associated_item.then(|| self.associated_item(def_id)) } fn associated_item_from_trait_item_ref(self, @@ -3249,7 +3249,7 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ParamEnv<'_> { let unnormalized_env = ty::ParamEnv::new( tcx.intern_predicates(&predicates), traits::Reveal::UserFacing, - tcx.sess.opts.debugging_opts.chalk.to_option(def_id), + tcx.sess.opts.debugging_opts.chalk.then_some(def_id), ); let body_id = tcx.hir().as_local_hir_id(def_id).map_or(hir::DUMMY_HIR_ID, |id| { diff --git a/src/librustc/ty/query/job.rs b/src/librustc/ty/query/job.rs index 843222cfcac..2f30b797fb1 100644 --- a/src/librustc/ty/query/job.rs +++ b/src/librustc/ty/query/job.rs @@ -303,7 +303,7 @@ fn connected_to_root<'tcx>( return true; } - visit_waiters(query, |_, successor| connected_to_root(successor, visited).to_option(None)) + visit_waiters(query, |_, successor| connected_to_root(successor, visited).then_some(None)) .is_some() } diff --git a/src/librustc_codegen_llvm/common.rs b/src/librustc_codegen_llvm/common.rs index 369a098a5c6..419e99d55d7 100644 --- a/src/librustc_codegen_llvm/common.rs +++ b/src/librustc_codegen_llvm/common.rs @@ -245,7 +245,7 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> { let (mut lo, mut hi) = (0u64, 0u64); let success = llvm::LLVMRustConstInt128Get(v, sign_ext, &mut hi, &mut lo); - success.to_option(hi_lo_to_u128(lo, hi)) + success.then_some(hi_lo_to_u128(lo, hi)) }) } diff --git a/src/librustc_codegen_ssa/back/rpath.rs b/src/librustc_codegen_ssa/back/rpath.rs index c61f16da264..cd3d99951e2 100644 --- a/src/librustc_codegen_ssa/back/rpath.rs +++ b/src/librustc_codegen_ssa/back/rpath.rs @@ -119,7 +119,7 @@ fn path_relative_from(path: &Path, base: &Path) -> Option { use std::path::Component; if path.is_absolute() != base.is_absolute() { - path.is_absolute().to_option_with(|| PathBuf::from(path)) + path.is_absolute().then(|| PathBuf::from(path)) } else { let mut ita = path.components(); let mut itb = base.components(); diff --git a/src/librustc_codegen_ssa/back/symbol_export.rs b/src/librustc_codegen_ssa/back/symbol_export.rs index 00519814071..cea5dc18c13 100644 --- a/src/librustc_codegen_ssa/back/symbol_export.rs +++ b/src/librustc_codegen_ssa/back/symbol_export.rs @@ -85,7 +85,7 @@ fn reachable_non_generics_provider( match tcx.hir().get(hir_id) { Node::ForeignItem(..) => { let def_id = tcx.hir().local_def_id(hir_id); - tcx.is_statically_included_foreign_item(def_id).to_option(def_id) + tcx.is_statically_included_foreign_item(def_id).then_some(def_id) } // Only consider nodes that actually have exported symbols. diff --git a/src/librustc_codegen_ssa/lib.rs b/src/librustc_codegen_ssa/lib.rs index 2c2150e01a3..9919666027a 100644 --- a/src/librustc_codegen_ssa/lib.rs +++ b/src/librustc_codegen_ssa/lib.rs @@ -70,10 +70,10 @@ impl ModuleCodegen { emit_bc_compressed: bool, outputs: &OutputFilenames) -> CompiledModule { let object = emit_obj - .to_option_with(|| outputs.temp_path(OutputType::Object, Some(&self.name))); + .then(|| outputs.temp_path(OutputType::Object, Some(&self.name))); let bytecode = emit_bc - .to_option_with(|| outputs.temp_path(OutputType::Bitcode, Some(&self.name))); - let bytecode_compressed = emit_bc_compressed.to_option_with(|| { + .then(|| outputs.temp_path(OutputType::Bitcode, Some(&self.name))); + let bytecode_compressed = emit_bc_compressed.then(|| { outputs.temp_path(OutputType::Bitcode, Some(&self.name)) .with_extension(RLIB_BYTECODE_EXTENSION) }); diff --git a/src/librustc_interface/passes.rs b/src/librustc_interface/passes.rs index 753d7b02cca..2a4bc41f850 100644 --- a/src/librustc_interface/passes.rs +++ b/src/librustc_interface/passes.rs @@ -547,7 +547,7 @@ fn output_contains_path(output_paths: &[PathBuf], input_path: &PathBuf) -> bool } fn output_conflicts_with_dir(output_paths: &[PathBuf]) -> Option { - let check = |output_path: &PathBuf| output_path.is_dir().to_option_with(|| output_path.clone()); + let check = |output_path: &PathBuf| output_path.is_dir().then(|| output_path.clone()); check_output(output_paths, check) } diff --git a/src/librustc_interface/queries.rs b/src/librustc_interface/queries.rs index 7413899fac6..061d3854a9a 100644 --- a/src/librustc_interface/queries.rs +++ b/src/librustc_interface/queries.rs @@ -117,7 +117,7 @@ impl<'tcx> Queries<'tcx> { pub fn dep_graph_future(&self) -> Result<&Query>> { self.dep_graph_future.compute(|| { - Ok(self.session().opts.build_dep_graph().to_option_with(|| { + Ok(self.session().opts.build_dep_graph().then(|| { rustc_incremental::load_dep_graph(self.session()) })) }) diff --git a/src/librustc_interface/util.rs b/src/librustc_interface/util.rs index 3d227f91ed6..8c225b83f40 100644 --- a/src/librustc_interface/util.rs +++ b/src/librustc_interface/util.rs @@ -107,7 +107,7 @@ const STACK_SIZE: usize = 16 * 1024 * 1024; fn get_stack_size() -> Option { // FIXME: Hacks on hacks. If the env is trying to override the stack size // then *don't* set it explicitly. - env::var_os("RUST_MIN_STACK").is_none().to_option(STACK_SIZE) + env::var_os("RUST_MIN_STACK").is_none().then_some(STACK_SIZE) } struct Sink(Arc>>); @@ -281,7 +281,7 @@ fn get_rustc_path_inner(bin_path: &str) -> Option { } else { "rustc" }); - candidate.exists().to_option(candidate) + candidate.exists().then_some(candidate) }) .next() } diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 080448911af..10b00d35d9b 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1491,7 +1491,7 @@ impl ExplicitOutlivesRequirements { match pred { ty::Predicate::TypeOutlives(outlives) => { let outlives = outlives.skip_binder(); - outlives.0.is_param(index).to_option(outlives.1) + outlives.0.is_param(index).then_some(outlives.1) } _ => None } @@ -1550,7 +1550,7 @@ impl ExplicitOutlivesRequirements { }), _ => false, }; - is_inferred.to_option((i, bound.span())) + is_inferred.then_some((i, bound.span())) } else { None } diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index 20fd9445f0e..25bd2c45da5 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -803,7 +803,7 @@ impl<'a> CrateLoader<'a> { // and see what's a global allocator, including if we ourselves are a // global allocator. let mut global_allocator = self.cstore.has_global_allocator - .to_option_with(|| Symbol::intern("this crate")); + .then(|| Symbol::intern("this crate")); self.cstore.iter_crate_data(|_, data| { if !data.has_global_allocator() { return diff --git a/src/librustc_mir/borrow_check/nll/mod.rs b/src/librustc_mir/borrow_check/nll/mod.rs index 66ec84e8316..7a5bbb4d892 100644 --- a/src/librustc_mir/borrow_check/nll/mod.rs +++ b/src/librustc_mir/borrow_check/nll/mod.rs @@ -173,7 +173,7 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>( Option>>, Option>, ) { - let mut all_facts = AllFacts::enabled(infcx.tcx).to_option(AllFacts::default()); + let mut all_facts = AllFacts::enabled(infcx.tcx).then_some(AllFacts::default()); let universal_regions = Rc::new(universal_regions); diff --git a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs index 2f99494308a..0b3cb29e39e 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs @@ -493,7 +493,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { // functions below, which will trigger them to report errors // eagerly. let mut outlives_requirements = - infcx.tcx.is_closure(mir_def_id).to_option_with(|| vec![]); + infcx.tcx.is_closure(mir_def_id).then(|| vec![]); self.check_type_tests( infcx, diff --git a/src/librustc_mir/hair/pattern/mod.rs b/src/librustc_mir/hair/pattern/mod.rs index 68cd16490d6..0086c3b0e10 100644 --- a/src/librustc_mir/hair/pattern/mod.rs +++ b/src/librustc_mir/hair/pattern/mod.rs @@ -1154,7 +1154,7 @@ pub fn compare_const_vals<'tcx>( ) -> Option { trace!("compare_const_vals: {:?}, {:?}", a, b); - let from_bool = |v: bool| v.to_option(Ordering::Equal); + let from_bool = |v: bool| v.then_some(Ordering::Equal); let fallback = || from_bool(a == b); diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index 9cb5a8295e0..8f177ad1225 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -324,7 +324,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { size: Size, align: Align, ) -> InterpResult<'tcx, Option>> { - let align = M::CHECK_ALIGN.to_option(align); + let align = M::CHECK_ALIGN.then_some(align); self.check_ptr_access_align(sptr, size, align, CheckInAllocMsg::MemoryAccessTest) } diff --git a/src/librustc_mir/interpret/step.rs b/src/librustc_mir/interpret/step.rs index d285808a975..55b9427a75b 100644 --- a/src/librustc_mir/interpret/step.rs +++ b/src/librustc_mir/interpret/step.rs @@ -157,9 +157,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { } BinaryOp(bin_op, ref left, ref right) => { - let layout = binop_left_homogeneous(bin_op).to_option(dest.layout); + let layout = binop_left_homogeneous(bin_op).then_some(dest.layout); let left = self.read_immediate(self.eval_operand(left, layout)?)?; - let layout = binop_right_homogeneous(bin_op).to_option(left.layout); + let layout = binop_right_homogeneous(bin_op).then_some(left.layout); let right = self.read_immediate(self.eval_operand(right, layout)?)?; self.binop_ignore_overflow( bin_op, @@ -172,7 +172,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { CheckedBinaryOp(bin_op, ref left, ref right) => { // 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 layout = binop_right_homogeneous(bin_op).to_option(left.layout); + let layout = binop_right_homogeneous(bin_op).then_some(left.layout); let right = self.read_immediate(self.eval_operand(right, layout)?)?; self.binop_with_overflow( bin_op, diff --git a/src/librustc_mir/monomorphize/partitioning.rs b/src/librustc_mir/monomorphize/partitioning.rs index 6f2e501fc0e..591f220549d 100644 --- a/src/librustc_mir/monomorphize/partitioning.rs +++ b/src/librustc_mir/monomorphize/partitioning.rs @@ -761,7 +761,7 @@ fn compute_codegen_unit_name( .iter() .map(|part| part.data.as_symbol()); - let volatile_suffix = volatile.to_option("volatile"); + let volatile_suffix = volatile.then_some("volatile"); name_builder.build_cgu_name(def_path.krate, components, volatile_suffix) }).clone() diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index c4d6ada05dc..284285c327c 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -658,7 +658,7 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: DefId) { 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)); let used_unsafe: FxHashSet<_> = unsafe_blocks.iter() - .flat_map(|&&(id, used)| used.to_option(id)) + .flat_map(|&&(id, used)| used.then_some(id)) .collect(); for &(block_id, is_used) in unsafe_blocks { if !is_used { diff --git a/src/librustc_parse/config.rs b/src/librustc_parse/config.rs index bba901a18ef..7dbfd98de75 100644 --- a/src/librustc_parse/config.rs +++ b/src/librustc_parse/config.rs @@ -75,7 +75,7 @@ macro_rules! configure { impl<'a> StripUnconfigured<'a> { pub fn configure(&mut self, mut node: T) -> Option { self.process_cfg_attrs(&mut node); - self.in_cfg(node.attrs()).to_option(node) + self.in_cfg(node.attrs()).then_some(node) } /// Parse and expand all `cfg_attr` attributes into a list of attributes diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index afc43bbb0da..8dd45f5df4c 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -422,7 +422,7 @@ impl<'a> Resolver<'a> { Scope::MacroUsePrelude => { suggestions.extend(this.macro_use_prelude.iter().filter_map(|(name, binding)| { let res = binding.res(); - filter_fn(res).to_option(TypoSuggestion::from_res(*name, res)) + filter_fn(res).then_some(TypoSuggestion::from_res(*name, res)) })); } Scope::BuiltinAttrs => { @@ -436,7 +436,7 @@ impl<'a> Resolver<'a> { Scope::ExternPrelude => { suggestions.extend(this.extern_prelude.iter().filter_map(|(ident, _)| { let res = Res::Def(DefKind::Mod, DefId::local(CRATE_DEF_INDEX)); - filter_fn(res).to_option(TypoSuggestion::from_res(ident.name, res)) + filter_fn(res).then_some(TypoSuggestion::from_res(ident.name, res)) })); } Scope::ToolPrelude => { @@ -459,7 +459,7 @@ impl<'a> Resolver<'a> { suggestions.extend( primitive_types.iter().flat_map(|(name, prim_ty)| { let res = Res::PrimTy(*prim_ty); - filter_fn(res).to_option(TypoSuggestion::from_res(*name, res)) + filter_fn(res).then_some(TypoSuggestion::from_res(*name, res)) }) ) } diff --git a/src/librustc_resolve/late.rs b/src/librustc_resolve/late.rs index bd68e3b8816..4f95d6fe70f 100644 --- a/src/librustc_resolve/late.rs +++ b/src/librustc_resolve/late.rs @@ -496,7 +496,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LateResolutionVisitor<'a, '_> { GenericParamKind::Lifetime { .. } => None, GenericParamKind::Type { ref default, .. } => { found_default |= default.is_some(); - found_default.to_option((Ident::with_dummy_span(param.ident.name), Res::Err)) + found_default.then_some((Ident::with_dummy_span(param.ident.name), Res::Err)) } })); diff --git a/src/librustc_target/abi/call/aarch64.rs b/src/librustc_target/abi/call/aarch64.rs index 524aea05773..06c001e577b 100644 --- a/src/librustc_target/abi/call/aarch64.rs +++ b/src/librustc_target/abi/call/aarch64.rs @@ -20,7 +20,7 @@ fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) RegKind::Vector => size.bits() == 64 || size.bits() == 128 }; - valid_unit.to_option(Uniform { unit, total: size }) + valid_unit.then_some(Uniform { unit, total: size }) }) } diff --git a/src/librustc_target/abi/call/arm.rs b/src/librustc_target/abi/call/arm.rs index e18fe2973c8..36971c1c501 100644 --- a/src/librustc_target/abi/call/arm.rs +++ b/src/librustc_target/abi/call/arm.rs @@ -21,7 +21,7 @@ fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) RegKind::Vector => size.bits() == 64 || size.bits() == 128 }; - valid_unit.to_option(Uniform { unit, total: size }) + valid_unit.then_some(Uniform { unit, total: size }) }) } diff --git a/src/librustc_target/abi/call/mod.rs b/src/librustc_target/abi/call/mod.rs index 16c53fb5503..5119464b1cc 100644 --- a/src/librustc_target/abi/call/mod.rs +++ b/src/librustc_target/abi/call/mod.rs @@ -416,7 +416,7 @@ impl<'a, Ty> ArgAbi<'a, Ty> { // i686-pc-windows-msvc, it results in wrong stack offsets. // attrs.pointee_align = Some(self.layout.align.abi); - let extra_attrs = self.layout.is_unsized().to_option(ArgAttributes::new()); + let extra_attrs = self.layout.is_unsized().then_some(ArgAttributes::new()); self.mode = PassMode::Indirect(attrs, extra_attrs); } diff --git a/src/librustc_target/abi/call/powerpc64.rs b/src/librustc_target/abi/call/powerpc64.rs index 82c9dc323ce..fe4594802f6 100644 --- a/src/librustc_target/abi/call/powerpc64.rs +++ b/src/librustc_target/abi/call/powerpc64.rs @@ -32,7 +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 }; - valid_unit.to_option(Uniform { unit, total: arg.layout.size }) + valid_unit.then_some(Uniform { unit, total: arg.layout.size }) }) } diff --git a/src/librustc_target/abi/call/sparc64.rs b/src/librustc_target/abi/call/sparc64.rs index 97f035be8e5..32be7b89cb0 100644 --- a/src/librustc_target/abi/call/sparc64.rs +++ b/src/librustc_target/abi/call/sparc64.rs @@ -20,7 +20,7 @@ fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) RegKind::Vector => arg.layout.size.bits() == 128 }; - valid_unit.to_option(Uniform { unit, total: arg.layout.size }) + valid_unit.then_some(Uniform { unit, total: arg.layout.size }) }) } diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index cb23a3f1499..992308183b4 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -1105,7 +1105,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { r.map(|mut pick| { pick.autoderefs = step.autoderefs; pick.autoref = Some(mutbl); - pick.unsize = step.unsize.to_option(self_ty); + pick.unsize = step.unsize.then_some(self_ty); pick }) }) diff --git a/src/librustc_typeck/check/upvar.rs b/src/librustc_typeck/check/upvar.rs index fa5546d29c4..c5a6c072979 100644 --- a/src/librustc_typeck/check/upvar.rs +++ b/src/librustc_typeck/check/upvar.rs @@ -114,7 +114,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }; let infer_kind = if let UpvarSubsts::Closure(closure_substs) = substs { - self.closure_kind(closure_def_id, closure_substs).is_none().to_option(closure_substs) + self.closure_kind(closure_def_id, closure_substs).is_none().then_some(closure_substs) } else { None }; diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index b0e13a508ee..b2e8d8526fd 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -317,7 +317,7 @@ pub fn token_to_string(token: &Token) -> String { } fn token_to_string_ext(token: &Token, convert_dollar_crate: bool) -> String { - let convert_dollar_crate = convert_dollar_crate.to_option(token.span); + let convert_dollar_crate = convert_dollar_crate.then_some(token.span); token_kind_to_string_ext(&token.kind, convert_dollar_crate) } diff --git a/src/libsyntax_ext/format_foreign.rs b/src/libsyntax_ext/format_foreign.rs index f6e8b086532..0d1d2926c85 100644 --- a/src/libsyntax_ext/format_foreign.rs +++ b/src/libsyntax_ext/format_foreign.rs @@ -95,12 +95,12 @@ pub mod printf { }; // Has a special form in Rust for numbers. - let fill = c_zero.to_option("0"); + let fill = c_zero.then_some("0"); - let align = c_left.to_option("<"); + let align = c_left.then_some("<"); // Rust doesn't have an equivalent to the `' '` flag. - let sign = c_plus.to_option("+"); + let sign = c_plus.then_some("+"); // Not *quite* the same, depending on the type... let alt = c_alt; diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 9ff9e382c88..2e90750b7a0 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -563,7 +563,7 @@ fn run_test_in_process( None }; - let start = report_time.to_option(Instant::now()); + let start = report_time.then_some(Instant::now()); let result = catch_unwind(AssertUnwindSafe(testfn)); let exec_time = start.map(|start| { let duration = start.elapsed(); @@ -594,7 +594,7 @@ fn spawn_test_subprocess( let args = env::args().collect::>(); let current_exe = &args[0]; - let start = report_time.to_option(Instant::now()); + let start = report_time.then_some(Instant::now()); let output = match Command::new(current_exe) .env(SECONDARY_TEST_INVOKER_VAR, desc.name.as_slice()) .output() {