Skip to content

Commit 8a778ca

Browse files
committedApr 16, 2023
Auto merge of rust-lang#110405 - fee1-dead-contrib:rollup-9rkree6, r=fee1-dead
Rollup of 4 pull requests Successful merges: - rust-lang#110397 (Move some utils out of `rustc_const_eval`) - rust-lang#110398 (use matches! macro in more places) - rust-lang#110400 (more clippy fixes: clippy::{iter_cloned_collect, unwarp_or_else_defau…) - rust-lang#110402 (Remove the loop in `Align::from_bytes`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1b50ea9 + 38215fb commit 8a778ca

File tree

33 files changed

+91
-114
lines changed

33 files changed

+91
-114
lines changed
 

‎Cargo.lock

-1
Original file line numberDiff line numberDiff line change
@@ -4421,7 +4421,6 @@ dependencies = [
44214421
"either",
44224422
"itertools",
44234423
"polonius-engine",
4424-
"rustc_const_eval",
44254424
"rustc_data_structures",
44264425
"rustc_errors",
44274426
"rustc_graphviz",

‎compiler/rustc_abi/src/lib.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -665,15 +665,12 @@ impl Align {
665665
format!("`{}` is too large", align)
666666
}
667667

668-
let mut bytes = align;
669-
let mut pow2: u8 = 0;
670-
while (bytes & 1) == 0 {
671-
pow2 += 1;
672-
bytes >>= 1;
673-
}
674-
if bytes != 1 {
668+
let tz = align.trailing_zeros();
669+
if align != (1 << tz) {
675670
return Err(not_power_of_2(align));
676671
}
672+
673+
let pow2 = tz as u8;
677674
if pow2 > Self::MAX.pow2 {
678675
return Err(too_large(align));
679676
}

‎compiler/rustc_ast/src/ast.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1298,17 +1298,17 @@ impl Expr {
12981298

12991299
/// To a first-order approximation, is this a pattern?
13001300
pub fn is_approximately_pattern(&self) -> bool {
1301-
match &self.peel_parens().kind {
1301+
matches!(
1302+
&self.peel_parens().kind,
13021303
ExprKind::Array(_)
1303-
| ExprKind::Call(_, _)
1304-
| ExprKind::Tup(_)
1305-
| ExprKind::Lit(_)
1306-
| ExprKind::Range(_, _, _)
1307-
| ExprKind::Underscore
1308-
| ExprKind::Path(_, _)
1309-
| ExprKind::Struct(_) => true,
1310-
_ => false,
1311-
}
1304+
| ExprKind::Call(_, _)
1305+
| ExprKind::Tup(_)
1306+
| ExprKind::Lit(_)
1307+
| ExprKind::Range(_, _, _)
1308+
| ExprKind::Underscore
1309+
| ExprKind::Path(_, _)
1310+
| ExprKind::Struct(_)
1311+
)
13121312
}
13131313
}
13141314

‎compiler/rustc_ast_lowering/src/lib.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,7 @@ enum FnDeclKind {
332332

333333
impl FnDeclKind {
334334
fn param_impl_trait_allowed(&self) -> bool {
335-
match self {
336-
FnDeclKind::Fn | FnDeclKind::Inherent | FnDeclKind::Impl | FnDeclKind::Trait => true,
337-
_ => false,
338-
}
335+
matches!(self, FnDeclKind::Fn | FnDeclKind::Inherent | FnDeclKind::Impl | FnDeclKind::Trait)
339336
}
340337

341338
fn return_impl_trait_allowed(&self, tcx: TyCtxt<'_>) -> bool {

‎compiler/rustc_borrowck/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ rustc_infer = { path = "../rustc_infer" }
2020
rustc_lexer = { path = "../rustc_lexer" }
2121
rustc_macros = { path = "../rustc_macros" }
2222
rustc_middle = { path = "../rustc_middle" }
23-
rustc_const_eval = { path = "../rustc_const_eval" }
2423
rustc_mir_dataflow = { path = "../rustc_mir_dataflow" }
2524
rustc_serialize = { path = "../rustc_serialize" }
2625
rustc_session = { path = "../rustc_session" }

‎compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use either::Either;
2-
use rustc_const_eval::util::CallKind;
32
use rustc_data_structures::captures::Captures;
43
use rustc_data_structures::fx::FxIndexSet;
54
use rustc_errors::{
@@ -18,6 +17,7 @@ use rustc_middle::mir::{
1817
ProjectionElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind, VarBindingForm,
1918
};
2019
use rustc_middle::ty::{self, suggest_constraining_type_params, PredicateKind, Ty};
20+
use rustc_middle::util::CallKind;
2121
use rustc_mir_dataflow::move_paths::{InitKind, MoveOutIndex, MovePathIndex};
2222
use rustc_span::def_id::LocalDefId;
2323
use rustc_span::hygiene::DesugaringKind;
@@ -2424,7 +2424,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
24242424
Some((method_did, method_substs)),
24252425
) = (
24262426
&self.body[loan.reserve_location.block].terminator,
2427-
rustc_const_eval::util::find_self_call(
2427+
rustc_middle::util::find_self_call(
24282428
tcx,
24292429
self.body,
24302430
loan.assigned_place.local,

‎compiler/rustc_borrowck/src/diagnostics/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Borrow checker diagnostics.
22
33
use itertools::Itertools;
4-
use rustc_const_eval::util::{call_kind, CallDesugaringKind};
54
use rustc_errors::{Applicability, Diagnostic};
65
use rustc_hir as hir;
76
use rustc_hir::def::{CtorKind, Namespace};
@@ -15,6 +14,7 @@ use rustc_middle::mir::{
1514
};
1615
use rustc_middle::ty::print::Print;
1716
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
17+
use rustc_middle::util::{call_kind, CallDesugaringKind};
1818
use rustc_mir_dataflow::move_paths::{InitLocation, LookupResult};
1919
use rustc_span::def_id::LocalDefId;
2020
use rustc_span::{symbol::sym, Span, Symbol, DUMMY_SP};
@@ -45,7 +45,7 @@ pub(crate) use mutability_errors::AccessKind;
4545
pub(crate) use outlives_suggestion::OutlivesSuggestionBuilder;
4646
pub(crate) use region_errors::{ErrorConstraintInfo, RegionErrorKind, RegionErrors};
4747
pub(crate) use region_name::{RegionName, RegionNameSource};
48-
pub(crate) use rustc_const_eval::util::CallKind;
48+
pub(crate) use rustc_middle::util::CallKind;
4949

5050
pub(super) struct DescribePlaceOpt {
5151
pub including_downcast: bool,
@@ -874,7 +874,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
874874
}) = &self.body[location.block].terminator
875875
{
876876
let Some((method_did, method_substs)) =
877-
rustc_const_eval::util::find_self_call(
877+
rustc_middle::util::find_self_call(
878878
self.infcx.tcx,
879879
&self.body,
880880
target_temp,

‎compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use rustc_span::{sym, BytePos, Span};
1515
use rustc_target::abi::FieldIdx;
1616

1717
use crate::diagnostics::BorrowedContentSource;
18+
use crate::util::FindAssignments;
1819
use crate::MirBorrowckCtxt;
19-
use rustc_const_eval::util::collect_writes::FindAssignments;
2020

2121
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
2222
pub(crate) enum AccessKind {

‎compiler/rustc_borrowck/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ mod session_diagnostics;
8888
mod type_check;
8989
mod universal_regions;
9090
mod used_muts;
91+
mod util;
9192

9293
/// A public API provided for the Rust compiler consumers.
9394
pub mod consumers;
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mod collect_writes;
2+
3+
pub use collect_writes::FindAssignments;

‎compiler/rustc_const_eval/src/transform/check_consts/ops.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ use rustc_middle::ty::print::with_no_trimmed_paths;
1414
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
1515
use rustc_middle::ty::{suggest_constraining_type_param, Adt, Closure, FnDef, FnPtr, Param, Ty};
1616
use rustc_middle::ty::{Binder, TraitRef};
17+
use rustc_middle::util::{call_kind, CallDesugaringKind, CallKind};
1718
use rustc_session::parse::feature_err;
1819
use rustc_span::symbol::sym;
1920
use rustc_span::{BytePos, Pos, Span, Symbol};
2021
use rustc_trait_selection::traits::SelectionContext;
2122

2223
use super::ConstCx;
2324
use crate::errors;
24-
use crate::util::{call_kind, CallDesugaringKind, CallKind};
2525

2626
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
2727
pub enum Status {
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
mod alignment;
2-
mod call_kind;
32
mod check_validity_requirement;
4-
pub mod collect_writes;
53
mod compare_types;
6-
mod find_self_call;
74
mod type_name;
85

96
pub use self::alignment::is_disaligned;
10-
pub use self::call_kind::{call_kind, CallDesugaringKind, CallKind};
117
pub use self::check_validity_requirement::check_validity_requirement;
128
pub use self::compare_types::{is_equal_up_to_subtyping, is_subtype};
13-
pub use self::find_self_call::find_self_call;
149
pub use self::type_name::type_name;

‎compiler/rustc_hir/src/def.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,7 @@ impl DefKind {
234234

235235
#[inline]
236236
pub fn is_fn_like(self) -> bool {
237-
match self {
238-
DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::Generator => true,
239-
_ => false,
240-
}
237+
matches!(self, DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::Generator)
241238
}
242239

243240
/// Whether `query get_codegen_attrs` should be used with this definition.

‎compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,7 @@ fn compare_number_of_generics<'tcx>(
13171317
impl_count,
13181318
kind,
13191319
pluralize!(impl_count),
1320-
suffix.unwrap_or_else(String::new),
1320+
suffix.unwrap_or_default(),
13211321
),
13221322
);
13231323
}

‎compiler/rustc_hir_analysis/src/collect.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1457,10 +1457,7 @@ fn compute_sig_of_foreign_fn_decl<'tcx>(
14571457
}
14581458

14591459
fn is_foreign_item(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
1460-
match tcx.hir().get_by_def_id(def_id) {
1461-
Node::ForeignItem(..) => true,
1462-
_ => false,
1463-
}
1460+
matches!(tcx.hir().get_by_def_id(def_id), Node::ForeignItem(..))
14641461
}
14651462

14661463
fn generator_kind(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<hir::GeneratorKind> {

‎compiler/rustc_hir_typeck/src/expr.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1735,10 +1735,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17351735
} else {
17361736
self.check_expr_has_type_or_error(base_expr, adt_ty, |_| {
17371737
let base_ty = self.typeck_results.borrow().expr_ty(*base_expr);
1738-
let same_adt = match (adt_ty.kind(), base_ty.kind()) {
1739-
(ty::Adt(adt, _), ty::Adt(base_adt, _)) if adt == base_adt => true,
1740-
_ => false,
1741-
};
1738+
let same_adt = matches!((adt_ty.kind(), base_ty.kind()),
1739+
(ty::Adt(adt, _), ty::Adt(base_adt, _)) if adt == base_adt);
17421740
if self.tcx.sess.is_nightly_build() && same_adt {
17431741
feature_err(
17441742
&self.tcx.sess.parse_sess,

‎compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,10 @@ pub fn suggest_new_region_bound(
312312
Applicability::MaybeIncorrect,
313313
);
314314
}
315-
} else if opaque.bounds.iter().any(|arg| match arg {
316-
GenericBound::Outlives(Lifetime { ident, .. })
317-
if ident.name.to_string() == lifetime_name =>
318-
{
319-
true
320-
}
321-
_ => false,
315+
} else if opaque.bounds.iter().any(|arg| {
316+
matches!(arg,
317+
GenericBound::Outlives(Lifetime { ident, .. })
318+
if ident.name.to_string() == lifetime_name )
322319
}) {
323320
} else {
324321
// get a lifetime name of existing named lifetimes if any

‎compiler/rustc_infer/src/infer/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1577,10 +1577,10 @@ impl<'tcx> InferCtxt<'tcx> {
15771577
(TyOrConstInferVar::Ty(ty_var), Ok(inner)) => {
15781578
use self::type_variable::TypeVariableValue;
15791579

1580-
match inner.try_type_variables_probe_ref(ty_var) {
1581-
Some(TypeVariableValue::Unknown { .. }) => true,
1582-
_ => false,
1583-
}
1580+
matches!(
1581+
inner.try_type_variables_probe_ref(ty_var),
1582+
Some(TypeVariableValue::Unknown { .. })
1583+
)
15841584
}
15851585
_ => false,
15861586
};

‎compiler/rustc_infer/src/traits/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ impl<'tcx> PredicateObligation<'tcx> {
8989
impl<'tcx> TraitObligation<'tcx> {
9090
/// Returns `true` if the trait predicate is considered `const` in its ParamEnv.
9191
pub fn is_const(&self) -> bool {
92-
match (self.predicate.skip_binder().constness, self.param_env.constness()) {
93-
(ty::BoundConstness::ConstIfConst, hir::Constness::Const) => true,
94-
_ => false,
95-
}
92+
matches!(
93+
(self.predicate.skip_binder().constness, self.param_env.constness()),
94+
(ty::BoundConstness::ConstIfConst, hir::Constness::Const)
95+
)
9696
}
9797

9898
pub fn derived_cause(

‎compiler/rustc_middle/src/lib.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,9 @@ pub mod mir;
9999
pub mod thir;
100100
pub mod traits;
101101
pub mod ty;
102+
pub mod util;
102103
mod values;
103104

104-
pub mod util {
105-
pub mod bug;
106-
pub mod common;
107-
}
108-
109105
// Allows macros to refer to this crate as `::rustc_middle`
110106
extern crate self as rustc_middle;
111107

‎compiler/rustc_const_eval/src/util/call_kind.rs renamed to ‎compiler/rustc_middle/src/util/call_kind.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
//! as well as errors when attempting to call a non-const function in a const
33
//! context.
44
5+
use crate::ty::subst::SubstsRef;
6+
use crate::ty::{AssocItemContainer, Instance, ParamEnv, Ty, TyCtxt};
57
use rustc_hir::def_id::DefId;
68
use rustc_hir::{lang_items, LangItem};
7-
use rustc_middle::ty::subst::SubstsRef;
8-
use rustc_middle::ty::{AssocItemContainer, Instance, ParamEnv, Ty, TyCtxt};
99
use rustc_span::symbol::Ident;
1010
use rustc_span::{sym, DesugaringKind, Span};
1111

‎compiler/rustc_const_eval/src/util/find_self_call.rs renamed to ‎compiler/rustc_middle/src/util/find_self_call.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use rustc_middle::mir::*;
2-
use rustc_middle::ty::subst::SubstsRef;
3-
use rustc_middle::ty::{self, TyCtxt};
1+
use crate::mir::*;
2+
use crate::ty::subst::SubstsRef;
3+
use crate::ty::{self, TyCtxt};
44
use rustc_span::def_id::DefId;
55

66
/// Checks if the specified `local` is used as the `self` parameter of a method call

‎compiler/rustc_middle/src/util/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pub mod bug;
2+
pub mod call_kind;
3+
pub mod common;
4+
pub mod find_self_call;
5+
6+
pub use call_kind::{call_kind, CallDesugaringKind, CallKind};
7+
pub use find_self_call::find_self_call;

‎compiler/rustc_mir_build/src/errors.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -384,13 +384,8 @@ impl<'a> IntoDiagnostic<'a> for NonExhaustivePatternsTypeNotEmpty<'_, '_, '_> {
384384
diag.span_note(span, fluent::mir_build_def_note);
385385
}
386386

387-
let is_variant_list_non_exhaustive = match self.ty.kind() {
388-
ty::Adt(def, _) if def.is_variant_list_non_exhaustive() && !def.did().is_local() => {
389-
true
390-
}
391-
_ => false,
392-
};
393-
387+
let is_variant_list_non_exhaustive = matches!(self.ty.kind(),
388+
ty::Adt(def, _) if def.is_variant_list_non_exhaustive() && !def.did().is_local());
394389
if is_variant_list_non_exhaustive {
395390
diag.note(fluent::mir_build_non_exhaustive_type_note);
396391
} else {

‎compiler/rustc_mir_build/src/thir/pattern/check_match.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -671,10 +671,8 @@ fn non_exhaustive_match<'p, 'tcx>(
671671
};
672672
};
673673

674-
let is_variant_list_non_exhaustive = match scrut_ty.kind() {
675-
ty::Adt(def, _) if def.is_variant_list_non_exhaustive() && !def.did().is_local() => true,
676-
_ => false,
677-
};
674+
let is_variant_list_non_exhaustive = matches!(scrut_ty.kind(),
675+
ty::Adt(def, _) if def.is_variant_list_non_exhaustive() && !def.did().is_local());
678676

679677
adt_defined_here(cx, &mut err, scrut_ty, &witnesses);
680678
err.note(&format!(

‎compiler/rustc_mir_transform/src/check_const_item_mutation.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,12 @@ impl<'tcx> Visitor<'tcx> for ConstMutationChecker<'_, 'tcx> {
134134
// the `self` parameter of a method call (as the terminator of our current
135135
// BasicBlock). If so, we emit a more specific lint.
136136
let method_did = self.target_local.and_then(|target_local| {
137-
crate::util::find_self_call(self.tcx, &self.body, target_local, loc.block)
137+
rustc_middle::util::find_self_call(
138+
self.tcx,
139+
&self.body,
140+
target_local,
141+
loc.block,
142+
)
138143
});
139144
let lint_loc =
140145
if method_did.is_some() { self.body.terminator_loc(loc.block) } else { loc };

‎compiler/rustc_mir_transform/src/coverage/debug.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,8 @@ impl DebugCounters {
292292
}
293293

294294
pub fn some_block_label(&self, operand: ExpressionOperandId) -> Option<&String> {
295-
self.some_counters.as_ref().map_or(None, |counters| {
296-
counters
297-
.get(&operand)
298-
.map_or(None, |debug_counter| debug_counter.some_block_label.as_ref())
295+
self.some_counters.as_ref().and_then(|counters| {
296+
counters.get(&operand).and_then(|debug_counter| debug_counter.some_block_label.as_ref())
299297
})
300298
}
301299

0 commit comments

Comments
 (0)