From 4cb649bdb1c5f176c48a692a4271489dd3fe5ef3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sun, 21 Feb 2021 12:52:51 +0100 Subject: [PATCH 1/8] remove unneccessary wrapping of return value of allow_unstable(), it would always return Some(thing) --- compiler/rustc_attr/src/builtin.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_attr/src/builtin.rs b/compiler/rustc_attr/src/builtin.rs index aca3fbbca1357..378911f0c4ebd 100644 --- a/compiler/rustc_attr/src/builtin.rs +++ b/compiler/rustc_attr/src/builtin.rs @@ -1036,21 +1036,21 @@ pub fn allow_internal_unstable<'a>( sess: &'a Session, attrs: &'a [Attribute], ) -> Option + 'a> { - allow_unstable(sess, attrs, sym::allow_internal_unstable) + Some(allow_unstable(sess, attrs, sym::allow_internal_unstable)) } pub fn rustc_allow_const_fn_unstable<'a>( sess: &'a Session, attrs: &'a [Attribute], ) -> Option + 'a> { - allow_unstable(sess, attrs, sym::rustc_allow_const_fn_unstable) + Some(allow_unstable(sess, attrs, sym::rustc_allow_const_fn_unstable)) } fn allow_unstable<'a>( sess: &'a Session, attrs: &'a [Attribute], symbol: Symbol, -) -> Option + 'a> { +) -> impl Iterator + 'a { let attrs = sess.filter_by_name(attrs, symbol); let list = attrs .filter_map(move |attr| { @@ -1064,7 +1064,7 @@ fn allow_unstable<'a>( }) .flatten(); - Some(list.into_iter().filter_map(move |it| { + list.into_iter().filter_map(move |it| { let name = it.ident().map(|ident| ident.name); if name.is_none() { sess.diagnostic().span_err( @@ -1073,5 +1073,5 @@ fn allow_unstable<'a>( ); } name - })) + }) } From 12080dc3a3ebee0e343d528ca15835ac2d4c75c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sun, 21 Feb 2021 12:54:49 +0100 Subject: [PATCH 2/8] rustc_parse: remove unneccessary wrapping of return value in fn mk_range() which would always return Ok(..) --- compiler/rustc_parse/src/parser/expr.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index fa05df6805f51..34b4d3200a9d8 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -426,7 +426,7 @@ impl<'a> Parser<'a> { let span = self.mk_expr_sp(&lhs, lhs.span, rhs_span); let limits = if op == AssocOp::DotDot { RangeLimits::HalfOpen } else { RangeLimits::Closed }; - Ok(self.mk_expr(span, self.mk_range(Some(lhs), rhs, limits)?, AttrVec::new())) + Ok(self.mk_expr(span, self.mk_range(Some(lhs), rhs, limits), AttrVec::new())) } fn is_at_start_of_range_notation_rhs(&self) -> bool { @@ -474,7 +474,7 @@ impl<'a> Parser<'a> { } else { (lo, None) }; - Ok(this.mk_expr(span, this.mk_range(None, opt_end, limits)?, attrs.into())) + Ok(this.mk_expr(span, this.mk_range(None, opt_end, limits), attrs.into())) }) } @@ -2396,12 +2396,12 @@ impl<'a> Parser<'a> { start: Option>, end: Option>, limits: RangeLimits, - ) -> PResult<'a, ExprKind> { + ) -> ExprKind { if end.is_none() && limits == RangeLimits::Closed { self.error_inclusive_range_with_no_end(self.prev_token.span); - Ok(ExprKind::Err) + ExprKind::Err } else { - Ok(ExprKind::Range(start, end, limits)) + ExprKind::Range(start, end, limits) } } From 00bc134e43f30142ea5208dc70dce8ef1e6ac3ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sun, 21 Feb 2021 13:01:01 +0100 Subject: [PATCH 3/8] remove unneccessary wrapping of return value in mk_await_expr() --- compiler/rustc_parse/src/parser/expr.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 34b4d3200a9d8..28bfaea4555b5 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -1041,7 +1041,7 @@ impl<'a> Parser<'a> { /// Assuming we have just parsed `.`, continue parsing into an expression. fn parse_dot_suffix(&mut self, self_arg: P, lo: Span) -> PResult<'a, P> { if self.token.uninterpolated_span().rust_2018() && self.eat_keyword(kw::Await) { - return self.mk_await_expr(self_arg, lo); + return Ok(self.mk_await_expr(self_arg, lo)); } let fn_span_lo = self.token.span; @@ -2421,11 +2421,11 @@ impl<'a> Parser<'a> { ExprKind::Call(f, args) } - fn mk_await_expr(&mut self, self_arg: P, lo: Span) -> PResult<'a, P> { + fn mk_await_expr(&mut self, self_arg: P, lo: Span) -> P { let span = lo.to(self.prev_token.span); let await_expr = self.mk_expr(span, ExprKind::Await(self_arg), AttrVec::new()); self.recover_from_await_method_call(); - Ok(await_expr) + await_expr } crate fn mk_expr(&self, span: Span, kind: ExprKind, attrs: AttrVec) -> P { From 85bd00fd85bd2e00b97ca45f58d7686e44f554e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sun, 21 Feb 2021 13:06:00 +0100 Subject: [PATCH 4/8] parser: remove unneccessary wrapping of return value in parse_extern() --- compiler/rustc_parse/src/parser/item.rs | 2 +- compiler/rustc_parse/src/parser/mod.rs | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 0f907859a19a6..f3f5fc9af64fe 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -1679,7 +1679,7 @@ impl<'a> Parser<'a> { let constness = self.parse_constness(); let asyncness = self.parse_asyncness(); let unsafety = self.parse_unsafety(); - let ext = self.parse_extern()?; + let ext = self.parse_extern(); if let Async::Yes { span, .. } = asyncness { self.ban_async_in_2015(span); diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index ace4134b1f698..1292286bc18b0 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -1202,12 +1202,8 @@ impl<'a> Parser<'a> { } /// Parses `extern string_literal?`. - fn parse_extern(&mut self) -> PResult<'a, Extern> { - Ok(if self.eat_keyword(kw::Extern) { - Extern::from_abi(self.parse_abi()) - } else { - Extern::None - }) + fn parse_extern(&mut self) -> Extern { + if self.eat_keyword(kw::Extern) { Extern::from_abi(self.parse_abi()) } else { Extern::None } } /// Parses a string literal as an ABI spec. From 393878b15bbdf553e678dac3a7dd288bd6af879e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sun, 21 Feb 2021 13:25:28 +0100 Subject: [PATCH 5/8] remove redundant return value Ok(()) of clear_relocations() --- .../rustc_middle/src/mir/interpret/allocation.rs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_middle/src/mir/interpret/allocation.rs b/compiler/rustc_middle/src/mir/interpret/allocation.rs index 5ebe38b2d7e09..449b3a82dcbb7 100644 --- a/compiler/rustc_middle/src/mir/interpret/allocation.rs +++ b/compiler/rustc_middle/src/mir/interpret/allocation.rs @@ -266,7 +266,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra> Allocation { let range = self.check_bounds(ptr.offset, size); self.mark_init(ptr, size, true); - self.clear_relocations(cx, ptr, size)?; + self.clear_relocations(cx, ptr, size); AllocationExtra::memory_written(self, ptr, size)?; @@ -484,18 +484,13 @@ impl<'tcx, Tag: Copy, Extra> Allocation { /// uninitialized. This is a somewhat odd "spooky action at a distance", /// but it allows strictly more code to run than if we would just error /// immediately in that case. - fn clear_relocations( - &mut self, - cx: &impl HasDataLayout, - ptr: Pointer, - size: Size, - ) -> InterpResult<'tcx> { + fn clear_relocations(&mut self, cx: &impl HasDataLayout, ptr: Pointer, size: Size) { // Find the start and end of the given range and its outermost relocations. let (first, last) = { // Find all relocations overlapping the given range. let relocations = self.get_relocations(cx, ptr, size); if relocations.is_empty() { - return Ok(()); + return; } ( @@ -517,8 +512,6 @@ impl<'tcx, Tag: Copy, Extra> Allocation { // Forget all the relocations. self.relocations.remove_range(first..last); - - Ok(()) } /// Errors if there are relocations overlapping with the edges of the From 76b9b16b4d589a72364b3be1c3a61816a99c3715 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sun, 21 Feb 2021 13:40:39 +0100 Subject: [PATCH 6/8] rustc_codegen_ssa: remove unneeded wrapping of return type of execute_copy_from_cache_work_item (always returns Ok(..)) --- compiler/rustc_codegen_ssa/src/back/write.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index b0aed81246007..f5ae406faec2d 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -735,7 +735,7 @@ fn execute_work_item( match work_item { WorkItem::Optimize(module) => execute_optimize_work_item(cgcx, module, module_config), WorkItem::CopyPostLtoArtifacts(module) => { - execute_copy_from_cache_work_item(cgcx, module, module_config) + Ok(execute_copy_from_cache_work_item(cgcx, module, module_config)) } WorkItem::LTO(module) => execute_lto_work_item(cgcx, module, module_config), } @@ -844,7 +844,7 @@ fn execute_copy_from_cache_work_item( cgcx: &CodegenContext, module: CachedModuleCodegen, module_config: &ModuleConfig, -) -> Result, FatalError> { +) -> WorkItemResult { let incr_comp_session_dir = cgcx.incr_comp_session_dir.as_ref().unwrap(); let mut object = None; if let Some(saved_file) = module.source.saved_file { @@ -870,13 +870,13 @@ fn execute_copy_from_cache_work_item( assert_eq!(object.is_some(), module_config.emit_obj != EmitObj::None); - Ok(WorkItemResult::Compiled(CompiledModule { + WorkItemResult::Compiled(CompiledModule { name: module.name, kind: ModuleKind::Regular, object, dwarf_object: None, bytecode: None, - })) + }) } fn execute_lto_work_item( From a9b90c02a2aaa53881aa650d3792726135402403 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sun, 21 Feb 2021 13:44:16 +0100 Subject: [PATCH 7/8] rustc_mir: remove redundant wrapping of return type in numeric_intrinsic() --- compiler/rustc_mir/src/interpret/intrinsics.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_mir/src/interpret/intrinsics.rs b/compiler/rustc_mir/src/interpret/intrinsics.rs index c4039f2f15e94..d36b3a7d9b56e 100644 --- a/compiler/rustc_mir/src/interpret/intrinsics.rs +++ b/compiler/rustc_mir/src/interpret/intrinsics.rs @@ -23,11 +23,7 @@ use super::{ mod caller_location; mod type_name; -fn numeric_intrinsic<'tcx, Tag>( - name: Symbol, - bits: u128, - kind: Primitive, -) -> InterpResult<'tcx, Scalar> { +fn numeric_intrinsic(name: Symbol, bits: u128, kind: Primitive) -> Scalar { let size = match kind { Primitive::Int(integer, _) => integer.size(), _ => bug!("invalid `{}` argument: {:?}", name, bits), @@ -41,7 +37,7 @@ fn numeric_intrinsic<'tcx, Tag>( sym::bitreverse => (bits << extra).reverse_bits(), _ => bug!("not a numeric intrinsic: {}", name), }; - Ok(Scalar::from_uint(bits_out, size)) + Scalar::from_uint(bits_out, size) } /// The logic for all nullary intrinsics is implemented here. These intrinsics don't get evaluated @@ -208,7 +204,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { if nonzero && bits == 0 { throw_ub_format!("`{}_nonzero` called on 0", intrinsic_name); } - let out_val = numeric_intrinsic(intrinsic_name, bits, kind)?; + let out_val = numeric_intrinsic(intrinsic_name, bits, kind); self.write_scalar(out_val, dest)?; } sym::add_with_overflow | sym::sub_with_overflow | sym::mul_with_overflow => { From da9a588d4fda02c2fe6d52db651ec4c83b2b3e49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sun, 21 Feb 2021 18:11:27 +0100 Subject: [PATCH 8/8] remove redundant wrapping of return types of allow_internal_unstable() and rustc_allow_const_fn_unstable() --- compiler/rustc_attr/src/builtin.rs | 8 ++++---- compiler/rustc_expand/src/base.rs | 4 ++-- compiler/rustc_mir/src/transform/check_consts/mod.rs | 3 +-- compiler/rustc_passes/src/check_const.rs | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_attr/src/builtin.rs b/compiler/rustc_attr/src/builtin.rs index 378911f0c4ebd..24da75114a656 100644 --- a/compiler/rustc_attr/src/builtin.rs +++ b/compiler/rustc_attr/src/builtin.rs @@ -1035,15 +1035,15 @@ pub fn find_transparency( pub fn allow_internal_unstable<'a>( sess: &'a Session, attrs: &'a [Attribute], -) -> Option + 'a> { - Some(allow_unstable(sess, attrs, sym::allow_internal_unstable)) +) -> impl Iterator + 'a { + allow_unstable(sess, attrs, sym::allow_internal_unstable) } pub fn rustc_allow_const_fn_unstable<'a>( sess: &'a Session, attrs: &'a [Attribute], -) -> Option + 'a> { - Some(allow_unstable(sess, attrs, sym::rustc_allow_const_fn_unstable)) +) -> impl Iterator + 'a { + allow_unstable(sess, attrs, sym::rustc_allow_const_fn_unstable) } fn allow_unstable<'a>( diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index e3dc793a7fac4..ca304c05cdce3 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -756,8 +756,8 @@ impl SyntaxExtension { name: Symbol, attrs: &[ast::Attribute], ) -> SyntaxExtension { - let allow_internal_unstable = attr::allow_internal_unstable(sess, &attrs) - .map(|features| features.collect::>().into()); + let allow_internal_unstable = + Some(attr::allow_internal_unstable(sess, &attrs).collect::>().into()); let mut local_inner_macros = false; if let Some(macro_export) = sess.find_by_name(attrs, sym::macro_export) { diff --git a/compiler/rustc_mir/src/transform/check_consts/mod.rs b/compiler/rustc_mir/src/transform/check_consts/mod.rs index ba7bea4ac54e1..19aee033a6923 100644 --- a/compiler/rustc_mir/src/transform/check_consts/mod.rs +++ b/compiler/rustc_mir/src/transform/check_consts/mod.rs @@ -85,8 +85,7 @@ pub fn rustc_allow_const_fn_unstable( feature_gate: Symbol, ) -> bool { let attrs = tcx.get_attrs(def_id); - attr::rustc_allow_const_fn_unstable(&tcx.sess, attrs) - .map_or(false, |mut features| features.any(|name| name == feature_gate)) + attr::rustc_allow_const_fn_unstable(&tcx.sess, attrs).any(|name| name == feature_gate) } // Returns `true` if the given `const fn` is "const-stable". diff --git a/compiler/rustc_passes/src/check_const.rs b/compiler/rustc_passes/src/check_const.rs index 9328f7cd9ec7b..da713566c3121 100644 --- a/compiler/rustc_passes/src/check_const.rs +++ b/compiler/rustc_passes/src/check_const.rs @@ -106,7 +106,7 @@ impl<'tcx> CheckConstVisitor<'tcx> { // However, we cannot allow stable `const fn`s to use unstable features without an explicit // opt-in via `rustc_allow_const_fn_unstable`. attr::rustc_allow_const_fn_unstable(&tcx.sess, &tcx.get_attrs(def_id)) - .map_or(false, |mut features| features.any(|name| name == feature_gate)) + .any(|name| name == feature_gate) }; match required_gates {