Skip to content
Open
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
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ impl Pat {
pub fn contains_never_pattern(&self) -> bool {
let mut contains_never_pattern = false;
self.walk(&mut |pat| {
if matches!(pat.kind, PatKind::Never) {
if let PatKind::Never = pat.kind {
contains_never_pattern = true;
}
true
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/expand/autodiff_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ pub fn valid_ty_for_activity(ty: &Box<Ty>, activity: DiffActivity) -> bool {
}
// FIXME(ZuseZ4) We should make this more robust to also
// handle type aliases. Once that is done, we can be more restrictive here.
if matches!(activity, Active | ActiveOnly) {
if let Active | ActiveOnly = activity {
return true;
}
matches!(ty.kind, TyKind::Ptr(_) | TyKind::Ref(..))
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ fn expr_to_lit(
}
}
} else {
if matches!(should_emit, ShouldEmit::Nothing) {
if let ShouldEmit::Nothing = should_emit {
return None;
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/safety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
emit_lint: &mut impl FnMut(AttributeLint<S::Id>),
target_id: S::Id,
) {
if matches!(self.stage.should_emit(), ShouldEmit::Nothing) {
if let ShouldEmit::Nothing = self.stage.should_emit() {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/borrowck_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ impl<'infcx, 'tcx> crate::MirBorrowckCtxt<'_, 'infcx, 'tcx> {
format!("within this {coroutine_kind:#}"),
);
diag.span_label(yield_span, "possible yield occurs here");
if matches!(coroutine_kind, hir::CoroutineKind::Coroutine(_)) {
if let hir::CoroutineKind::Coroutine(_) = coroutine_kind {
let hir::Closure { capture_clause, fn_decl_span, .. } = self
.infcx
.tcx
Expand Down
36 changes: 18 additions & 18 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1440,7 +1440,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
}
inner_expr = inner;
if let Some(inner_type) = typeck_result.node_type_opt(inner.hir_id) {
if matches!(inner_type.kind(), ty::RawPtr(..)) {
if let ty::RawPtr(..) = inner_type.kind() {
is_raw_ptr = true;
break;
}
Expand Down Expand Up @@ -2063,10 +2063,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
debug!("not later used in call");
return;
}
if matches!(
self.body.local_decls[issued_borrow.borrowed_place.local].local_info(),
LocalInfo::IfThenRescopeTemp { .. }
) {
if let LocalInfo::IfThenRescopeTemp { .. } =
self.body.local_decls[issued_borrow.borrowed_place.local].local_info()
{
// A better suggestion will be issued by the `if_let_rescope` lint
return;
}
Expand Down Expand Up @@ -3325,7 +3324,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
);
}

let mutability = if matches!(borrow.kind(), BorrowKind::Mut { .. }) {
let mutability = if let BorrowKind::Mut { .. } = borrow.kind() {
"mut "
} else {
""
Expand Down Expand Up @@ -3559,10 +3558,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
}
ConstraintCategory::CallArgument(_) => {
fr_name.highlight_region_name(&mut err);
if matches!(
use_span.coroutine_kind(),
Some(CoroutineKind::Desugared(CoroutineDesugaring::Async, _))
) {
if let Some(CoroutineKind::Desugared(CoroutineDesugaring::Async, _)) =
use_span.coroutine_kind()
{
err.note(
"async blocks are not executed immediately and must either take a \
reference or ownership of outside variables they use",
Expand Down Expand Up @@ -4622,10 +4620,11 @@ impl<'v, 'tcx> Visitor<'v> for ConditionVisitor<'tcx> {
),
));
} else if let Some(guard) = &arm.guard {
if matches!(
self.tcx.hir_node(arm.body.hir_id),
hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Ret(_), .. })
) {
if let hir::Node::Expr(hir::Expr {
kind: hir::ExprKind::Ret(_),
..
}) = self.tcx.hir_node(arm.body.hir_id)
{
continue;
}
self.errors.push((
Expand All @@ -4637,10 +4636,11 @@ impl<'v, 'tcx> Visitor<'v> for ConditionVisitor<'tcx> {
),
));
} else {
if matches!(
self.tcx.hir_node(arm.body.hir_id),
hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Ret(_), .. })
) {
if let hir::Node::Expr(hir::Expr {
kind: hir::ExprKind::Ret(_),
..
}) = self.tcx.hir_node(arm.body.hir_id)
{
continue;
}
self.errors.push((
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/diagnostics/region_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
let outlived_fr_name = self.give_region_a_name(*outlived_fr).unwrap();
outlived_fr_name.highlight_region_name(&mut diag);

let err_category = if matches!(category, ConstraintCategory::Return(_))
let err_category = if let ConstraintCategory::Return(_) = category
&& self.regioncx.universal_regions().is_local_free_region(*outlived_fr)
{
LifetimeReturnCategoryErr::WrongReturn {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/handle_placeholders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub(crate) struct RegionTracker {
impl RegionTracker {
pub(crate) fn new(rvid: RegionVid, definition: &RegionDefinition<'_>) -> Self {
let reachable_placeholders =
if matches!(definition.origin, NllRegionVariableOrigin::Placeholder(_)) {
if let NllRegionVariableOrigin::Placeholder(_) = definition.origin {
PlaceholderReachability::Placeholders {
max_universe: (definition.universe, rvid),
min_placeholder: rvid,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
self.borrow_set,
|borrow_index| borrows_in_scope.contains(borrow_index),
|this, _borrow_index, borrow| {
if matches!(borrow.kind, BorrowKind::Fake(_)) {
if let BorrowKind::Fake(_) = borrow.kind {
return ControlFlow::Continue(());
}
let borrowed = this.retrieve_borrow_spans(borrow).var_or_use_path_span();
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/path_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub(super) fn each_borrow_involving_path<'tcx, F, I, S>(
i, borrowed, place, access
);
let ctrl = op(s, i, borrowed);
if matches!(ctrl, ControlFlow::Break(_)) {
if let ControlFlow::Break(_) = ctrl {
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/renumber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for RegionRenumberer<'a, 'tcx> {

#[instrument(skip(self), level = "debug")]
fn visit_ty(&mut self, ty: &mut Ty<'tcx>, ty_context: TyContext) {
if matches!(ty_context, TyContext::ReturnTy(_)) {
if let TyContext::ReturnTy(_) = ty_context {
// We will renumber the return ty when called again with `TyContext::LocalDecl`
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
}

// Add implied bounds from impl header.
if matches!(tcx.def_kind(defining_ty_def_id), DefKind::AssocFn | DefKind::AssocConst) {
if let DefKind::AssocFn | DefKind::AssocConst = tcx.def_kind(defining_ty_def_id) {
for &(ty, _) in tcx.assumed_wf_types(tcx.local_parent(defining_ty_def_id)) {
let result: Result<_, ErrorGuaranteed> = param_env
.and(DeeplyNormalize { value: ty })
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_const_eval/src/check_consts/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
let mut transient = DenseBitSet::new_filled(ccx.body.local_decls.len());
// Make sure to only visit reachable blocks, the dataflow engine can ICE otherwise.
for (bb, data) in traversal::reachable(&ccx.body) {
if matches!(data.terminator().kind, TerminatorKind::Return) {
if data.terminator().kind == TerminatorKind::Return {
let location = ccx.body.terminator_loc(bb);
maybe_storage_live.seek_after_primary_effect(location);
// If a local may be live here, it is definitely not transient.
Expand Down Expand Up @@ -835,8 +835,9 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
// const-eval of `panic_display` assumes the argument is `&&str`
if tcx.is_lang_item(callee, LangItem::PanicDisplay) {
match args[0].node.ty(&self.ccx.body.local_decls, tcx).kind() {
ty::Ref(_, ty, _) if matches!(ty.kind(), ty::Ref(_, ty, _) if ty.is_str()) =>
{}
ty::Ref(_, ty, _)
if let ty::Ref(_, ty, _) = ty.kind()
&& ty.is_str() => {}
_ => {
self.check_op(ops::PanicNonStr);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/check_consts/qualifs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ where
// i.e., we treat all qualifs as non-structural for deref projections. Generally,
// we can say very little about `*ptr` even if we know that `ptr` satisfies all
// sorts of properties.
if matches!(elem, ProjectionElem::Deref) {
if elem == ProjectionElem::Deref {
// We have to assume that this qualifies.
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/interpret/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
'tcx: 'y,
{
assert_eq!(callee_ty, callee_abi.layout.ty);
if matches!(callee_abi.mode, PassMode::Ignore) {
if callee_abi.mode == PassMode::Ignore {
// This one is skipped. Still must be made live though!
if !already_live {
self.storage_live(callee_arg.as_local().unwrap())?;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/interpret/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
}
} else {
// unsigned
if matches!(mir_op, BinOp::Add) {
if mir_op == BinOp::Add {
// max unsigned
Scalar::from_uint(size.unsigned_int_max(), size)
} else {
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_const_eval/src/interpret/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
return Err(ConstEvalErrKind::ConstMakeGlobalWithOffset(ptr)).into();
}

if matches!(self.tcx.try_get_global_alloc(alloc_id), Some(_)) {
if self.tcx.try_get_global_alloc(alloc_id).is_some() {
// This points to something outside the current interpreter.
return Err(ConstEvalErrKind::ConstMakeGlobalPtrIsNonHeap(ptr)).into();
}
Expand Down Expand Up @@ -981,7 +981,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
msg: CheckInAllocMsg,
) -> InterpResult<'tcx, (Size, Align)> {
let info = self.get_alloc_info(id);
if matches!(info.kind, AllocKind::Dead) {
if info.kind == AllocKind::Dead {
throw_ub!(PointerUseAfterFree(id, msg))
}
interp_ok((info.size, info.align))
Expand Down Expand Up @@ -1072,7 +1072,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
// Recurse, if there is data here.
// Do this *before* invoking the callback, as the callback might mutate the
// allocation and e.g. replace all provenance by wildcards!
if matches!(info.kind, AllocKind::LiveData) {
if info.kind == AllocKind::LiveData {
let alloc = self.get_alloc_raw(id)?;
for prov in alloc.provenance().provenances() {
if let Some(id) = prov.get_alloc_id() {
Expand Down Expand Up @@ -1605,7 +1605,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
match self.ptr_try_get_alloc_id(ptr, 0) {
Ok((alloc_id, offset, _)) => {
let info = self.get_alloc_info(alloc_id);
if matches!(info.kind, AllocKind::TypeId) {
if info.kind == AllocKind::TypeId {
// We *could* actually precisely answer this question since here,
// the offset *is* the integer value. But the entire point of making
// this a pointer is not to leak the integer value, so we say everything
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_const_eval/src/interpret/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
span_bug!(self.cur_span(), "primitive read not possible for type: {}", op.layout().ty);
}
let imm = self.read_immediate_raw(op)?.right().unwrap();
if matches!(*imm, Immediate::Uninit) {
if let Immediate::Uninit = *imm {
throw_ub!(InvalidUninitBytes(None));
}
interp_ok(imm)
Expand Down Expand Up @@ -748,7 +748,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
let layout = self.layout_of_local(frame, local, layout)?;
let op = *frame.locals[local].access()?;
if matches!(op, Operand::Immediate(_)) {
if let Operand::Immediate(_) = op {
assert!(!layout.is_unsized());
}
M::after_local_read(self, frame, local)?;
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_const_eval/src/interpret/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,10 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> {
// Reset provenance: ensure slice tail metadata does not preserve provenance,
// and ensure all pointers do not preserve partial provenance.
if self.reset_provenance_and_padding {
if matches!(imm.layout.backend_repr, BackendRepr::Scalar(..)) {
if let BackendRepr::Scalar(..) = imm.layout.backend_repr {
// A thin pointer. If it has provenance, we don't have to do anything.
// If it does not, ensure we clear the provenance in memory.
if matches!(imm.to_scalar(), Scalar::Int(..)) {
if let Scalar::Int(..) = imm.to_scalar() {
self.ecx.clear_provenance(val)?;
}
} else {
Expand Down Expand Up @@ -651,7 +651,7 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> {
// and then puts the value in there, so briefly we have a box with uninit contents.
// FIXME: should we also skip `UnsafeCell` behind shared references? Currently that is not
// needed since validation reads bypass Stacked Borrows and data race checks.
if matches!(ptr_kind, PointerKind::Box) {
if let PointerKind::Box = ptr_kind {
return interp_ok(());
}
}
Expand Down Expand Up @@ -714,7 +714,7 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> {
// types below!
self.read_scalar(
value,
if matches!(ty.kind(), ty::Float(..)) {
if let ty::Float(..) = ty.kind() {
ExpectedKind::Float
} else {
ExpectedKind::Int
Expand Down Expand Up @@ -762,7 +762,7 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> {
if self.reset_provenance_and_padding {
// Make sure we do not preserve partial provenance. This matches the thin
// pointer handling in `deref_pointer`.
if matches!(scalar, Scalar::Int(..)) {
if let Scalar::Int(..) = scalar {
self.ecx.clear_provenance(value)?;
}
self.add_data_range_place(value);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2534,7 +2534,7 @@ impl HumanEmitter {
{
// We'll continue the vertical bar to point into the next note.
self.draw_col_separator_no_space(&mut buffer, 0, max_line_num_len + 1);
} else if matches!(code_window_status, CodeWindowStatus::Open) {
} else if let CodeWindowStatus::Open = code_window_status {
// We'll close the vertical bar to visually end the code window.
self.draw_col_separator_end(&mut buffer, 0, max_line_num_len + 1);
}
Expand Down Expand Up @@ -3482,7 +3482,7 @@ pub fn stderr_destination(color: ColorConfig) -> Destination {

pub fn get_stderr_color_choice(color: ColorConfig, stderr: &std::io::Stderr) -> ColorChoice {
let choice = color.to_color_choice();
if matches!(choice, ColorChoice::Auto) { AutoStream::choice(stderr) } else { choice }
if let ColorChoice::Auto = choice { AutoStream::choice(stderr) } else { choice }
}

/// On Windows, BRIGHT_BLUE is hard to read on black. Use cyan instead.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_errors/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl Emitter for JsonEmitter {
//
// So to avoid ICEs and confused users we "upgrade" the lint level for
// those `FutureBreakageItem` to warn.
if matches!(diag.level, crate::Level::Allow | crate::Level::Expect) {
if let crate::Level::Allow | crate::Level::Expect = diag.level {
diag.level = crate::Level::Warning;
}
FutureBreakageItem {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1658,7 +1658,7 @@ impl DiagCtxtInner {

if is_error {
self.deduplicated_err_count += 1;
} else if matches!(diagnostic.level, ForceWarning | Warning) {
} else if let ForceWarning | Warning = diagnostic.level {
self.deduplicated_warn_count += 1;
}
self.has_printed = true;
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ fn check_static_inhabited(tcx: TyCtxt<'_>, def_id: LocalDefId) {
Ok(l) => l,
// Foreign statics that overflow their allowed size should emit an error
Err(LayoutError::SizeOverflow(_))
if matches!(tcx.def_kind(def_id), DefKind::Static{ .. }
if tcx.def_kind(tcx.local_parent(def_id)) == DefKind::ForeignMod) =>
if let DefKind::Static { .. } = tcx.def_kind(def_id)
&& tcx.def_kind(tcx.local_parent(def_id)) == DefKind::ForeignMod =>
{
tcx.dcx().emit_err(errors::TooLargeStatic { span });
return;
Expand Down Expand Up @@ -673,7 +673,7 @@ fn check_opaque_precise_captures<'tcx>(tcx: TyCtxt<'tcx>, opaque_def_id: LocalDe
}
}
ty::GenericParamDefKind::Type { .. } => {
if matches!(tcx.def_kind(param.def_id), DefKind::Trait | DefKind::TraitAlias) {
if let DefKind::Trait | DefKind::TraitAlias = tcx.def_kind(param.def_id) {
// FIXME(precise_capturing): Structured suggestion for this would be useful
tcx.dcx().emit_err(errors::SelfTyNotCaptured {
trait_span: tcx.def_span(param.def_id),
Expand Down
Loading
Loading