Auto merge of #116688 - compiler-errors:rustfmt-up, r=WaffleLapkin,Nilstrieb
Format all the let-chains in compiler crates Since rust-lang/rustfmt#5910 has landed, soon we will have support for formatting let-chains (as soon as rustfmt syncs and beta gets bumped). This PR applies the changes [from master rustfmt to rust-lang/rust eagerly](https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/out.20formatting.20of.20prs/near/374997516), so that the next beta bump does not have to deal with a 200+ file diff and can remain concerned with other things like `cfg(bootstrap)` -- #113637 was a pain to land, for example, because of let-else. I will also add this commit to the ignore list after it has landed. The commands that were run -- I'm not great at bash-foo, but this applies rustfmt to every compiler crate, and then reverts the two crates that should probably be formatted out-of-tree. ``` ~/rustfmt $ ls -1d ~/rust/compiler/* | xargs -I@ cargo run --bin rustfmt -- `@/src/lib.rs` --config-path ~/rust --edition=2021 # format all of the compiler crates ~/rust $ git checkout HEAD -- compiler/rustc_codegen_{gcc,cranelift} # revert changes to cg-gcc and cg-clif ``` cc `@rust-lang/rustfmt` r? `@WaffleLapkin` or `@Nilstrieb` who said they may be able to review this purely mechanical PR :> cc `@Mark-Simulacrum` and `@petrochenkov,` who had some thoughts on the order of operations with big formatting changes in https://github.com/rust-lang/rust/pull/95262#issue-1178993801. I think the situation has changed since then, given that let-chains support exists on master rustfmt now, and I'm fairly confident that this formatting PR should land even if *bootstrap* rustfmt doesn't yet format let-chains in order to lessen the burden of the next beta bump.
This commit is contained in:
commit
a48396984a
207 changed files with 3121 additions and 2229 deletions
|
@ -213,7 +213,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
// Casting an enum to an integer is equivalent to computing the discriminant and casting the
|
||||
// discriminant. Previously every backend had to repeat the logic for this operation. Now we
|
||||
// create all the steps directly in MIR with operations all backends need to support anyway.
|
||||
let (source, ty) = if let ty::Adt(adt_def, ..) = source.ty.kind() && adt_def.is_enum() {
|
||||
let (source, ty) = if let ty::Adt(adt_def, ..) = source.ty.kind()
|
||||
&& adt_def.is_enum()
|
||||
{
|
||||
let discr_ty = adt_def.repr().discr_type().to_ty(this.tcx);
|
||||
let temp = unpack!(block = this.as_temp(block, scope, source, Mutability::Not));
|
||||
let layout = this.tcx.layout_of(this.param_env.and(source.ty));
|
||||
|
@ -224,7 +226,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
discr,
|
||||
Rvalue::Discriminant(temp.into()),
|
||||
);
|
||||
let (op,ty) = (Operand::Move(discr), discr_ty);
|
||||
let (op, ty) = (Operand::Move(discr), discr_ty);
|
||||
|
||||
if let Abi::Scalar(scalar) = layout.unwrap().abi
|
||||
&& !scalar.is_always_valid(&this.tcx)
|
||||
|
@ -236,27 +238,30 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
block,
|
||||
source_info,
|
||||
unsigned_place,
|
||||
Rvalue::Cast(CastKind::IntToInt, Operand::Copy(discr), unsigned_ty));
|
||||
Rvalue::Cast(CastKind::IntToInt, Operand::Copy(discr), unsigned_ty),
|
||||
);
|
||||
|
||||
let bool_ty = this.tcx.types.bool;
|
||||
let range = scalar.valid_range(&this.tcx);
|
||||
let merge_op =
|
||||
if range.start <= range.end {
|
||||
BinOp::BitAnd
|
||||
} else {
|
||||
BinOp::BitOr
|
||||
};
|
||||
if range.start <= range.end { BinOp::BitAnd } else { BinOp::BitOr };
|
||||
|
||||
let mut comparer = |range: u128, bin_op: BinOp| -> Place<'tcx> {
|
||||
let range_val =
|
||||
Const::from_bits(this.tcx, range, ty::ParamEnv::empty().and(unsigned_ty));
|
||||
let range_val = Const::from_bits(
|
||||
this.tcx,
|
||||
range,
|
||||
ty::ParamEnv::empty().and(unsigned_ty),
|
||||
);
|
||||
let lit_op = this.literal_operand(expr.span, range_val);
|
||||
let is_bin_op = this.temp(bool_ty, expr_span);
|
||||
this.cfg.push_assign(
|
||||
block,
|
||||
source_info,
|
||||
is_bin_op,
|
||||
Rvalue::BinaryOp(bin_op, Box::new((Operand::Copy(unsigned_place), lit_op))),
|
||||
Rvalue::BinaryOp(
|
||||
bin_op,
|
||||
Box::new((Operand::Copy(unsigned_place), lit_op)),
|
||||
),
|
||||
);
|
||||
is_bin_op
|
||||
};
|
||||
|
@ -270,7 +275,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
block,
|
||||
source_info,
|
||||
merge_place,
|
||||
Rvalue::BinaryOp(merge_op, Box::new((Operand::Move(start_place), Operand::Move(end_place)))),
|
||||
Rvalue::BinaryOp(
|
||||
merge_op,
|
||||
Box::new((
|
||||
Operand::Move(start_place),
|
||||
Operand::Move(end_place),
|
||||
)),
|
||||
),
|
||||
);
|
||||
merge_place
|
||||
};
|
||||
|
@ -278,19 +289,24 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
block,
|
||||
Statement {
|
||||
source_info,
|
||||
kind: StatementKind::Intrinsic(Box::new(NonDivergingIntrinsic::Assume(
|
||||
Operand::Move(assert_place),
|
||||
))),
|
||||
kind: StatementKind::Intrinsic(Box::new(
|
||||
NonDivergingIntrinsic::Assume(Operand::Move(assert_place)),
|
||||
)),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
(op,ty)
|
||||
|
||||
(op, ty)
|
||||
} else {
|
||||
let ty = source.ty;
|
||||
let source = unpack!(
|
||||
block = this.as_operand(block, scope, source, LocalInfo::Boring, NeedsTemporary::No)
|
||||
block = this.as_operand(
|
||||
block,
|
||||
scope,
|
||||
source,
|
||||
LocalInfo::Boring,
|
||||
NeedsTemporary::No
|
||||
)
|
||||
);
|
||||
(source, ty)
|
||||
};
|
||||
|
|
|
@ -120,32 +120,31 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
//
|
||||
// it is usually better to focus on `the_value` rather
|
||||
// than the entirety of block(s) surrounding it.
|
||||
let adjusted_span =
|
||||
if let ExprKind::Block { block } = expr.kind
|
||||
&& let Some(tail_ex) = this.thir[block].expr
|
||||
{
|
||||
let mut expr = &this.thir[tail_ex];
|
||||
loop {
|
||||
match expr.kind {
|
||||
ExprKind::Block { block }
|
||||
if let Some(nested_expr) = this.thir[block].expr =>
|
||||
{
|
||||
expr = &this.thir[nested_expr];
|
||||
}
|
||||
ExprKind::Scope { value: nested_expr, .. } => {
|
||||
expr = &this.thir[nested_expr];
|
||||
}
|
||||
_ => break,
|
||||
let adjusted_span = if let ExprKind::Block { block } = expr.kind
|
||||
&& let Some(tail_ex) = this.thir[block].expr
|
||||
{
|
||||
let mut expr = &this.thir[tail_ex];
|
||||
loop {
|
||||
match expr.kind {
|
||||
ExprKind::Block { block }
|
||||
if let Some(nested_expr) = this.thir[block].expr =>
|
||||
{
|
||||
expr = &this.thir[nested_expr];
|
||||
}
|
||||
ExprKind::Scope { value: nested_expr, .. } => {
|
||||
expr = &this.thir[nested_expr];
|
||||
}
|
||||
_ => break,
|
||||
}
|
||||
this.block_context.push(BlockFrame::TailExpr {
|
||||
tail_result_is_ignored: true,
|
||||
span: expr.span,
|
||||
});
|
||||
Some(expr.span)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
}
|
||||
this.block_context.push(BlockFrame::TailExpr {
|
||||
tail_result_is_ignored: true,
|
||||
span: expr.span,
|
||||
});
|
||||
Some(expr.span)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let temp =
|
||||
unpack!(block = this.as_temp(block, statement_scope, expr, Mutability::Not));
|
||||
|
|
|
@ -736,7 +736,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
self.cfg.push(block, Statement { source_info, kind: StatementKind::StorageLive(local_id) });
|
||||
// Although there is almost always scope for given variable in corner cases
|
||||
// like #92893 we might get variable with no scope.
|
||||
if let Some(region_scope) = self.region_scope_tree.var_scope(var.0.local_id) && schedule_drop {
|
||||
if let Some(region_scope) = self.region_scope_tree.var_scope(var.0.local_id)
|
||||
&& schedule_drop
|
||||
{
|
||||
self.schedule_drop(span, region_scope, local_id, DropKind::Storage);
|
||||
}
|
||||
Place::from(local_id)
|
||||
|
|
|
@ -238,18 +238,27 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
|
||||
TestKind::Eq { value, ty } => {
|
||||
let tcx = self.tcx;
|
||||
if let ty::Adt(def, _) = ty.kind() && Some(def.did()) == tcx.lang_items().string() {
|
||||
if let ty::Adt(def, _) = ty.kind()
|
||||
&& Some(def.did()) == tcx.lang_items().string()
|
||||
{
|
||||
if !tcx.features().string_deref_patterns {
|
||||
bug!("matching on `String` went through without enabling string_deref_patterns");
|
||||
bug!(
|
||||
"matching on `String` went through without enabling string_deref_patterns"
|
||||
);
|
||||
}
|
||||
let re_erased = tcx.lifetimes.re_erased;
|
||||
let ref_string = self.temp(Ty::new_imm_ref(tcx,re_erased, ty), test.span);
|
||||
let ref_str_ty = Ty::new_imm_ref(tcx,re_erased, tcx.types.str_);
|
||||
let ref_string = self.temp(Ty::new_imm_ref(tcx, re_erased, ty), test.span);
|
||||
let ref_str_ty = Ty::new_imm_ref(tcx, re_erased, tcx.types.str_);
|
||||
let ref_str = self.temp(ref_str_ty, test.span);
|
||||
let deref = tcx.require_lang_item(LangItem::Deref, None);
|
||||
let method = trait_method(tcx, deref, sym::deref, [ty]);
|
||||
let eq_block = self.cfg.start_new_block();
|
||||
self.cfg.push_assign(block, source_info, ref_string, Rvalue::Ref(re_erased, BorrowKind::Shared, place));
|
||||
self.cfg.push_assign(
|
||||
block,
|
||||
source_info,
|
||||
ref_string,
|
||||
Rvalue::Ref(re_erased, BorrowKind::Shared, place),
|
||||
);
|
||||
self.cfg.terminate(
|
||||
block,
|
||||
source_info,
|
||||
|
@ -264,10 +273,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
target: Some(eq_block),
|
||||
unwind: UnwindAction::Continue,
|
||||
call_source: CallSource::Misc,
|
||||
fn_span: source_info.span
|
||||
}
|
||||
fn_span: source_info.span,
|
||||
},
|
||||
);
|
||||
self.non_scalar_compare(
|
||||
eq_block,
|
||||
make_target_blocks,
|
||||
source_info,
|
||||
value,
|
||||
ref_str,
|
||||
ref_str_ty,
|
||||
);
|
||||
self.non_scalar_compare(eq_block, make_target_blocks, source_info, value, ref_str, ref_str_ty);
|
||||
return;
|
||||
}
|
||||
if !ty.is_scalar() {
|
||||
|
|
|
@ -847,7 +847,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
self.local_decls.push(LocalDecl::with_source_info(param.ty, source_info));
|
||||
|
||||
// If this is a simple binding pattern, give debuginfo a nice name.
|
||||
if let Some(ref pat) = param.pat && let Some(name) = pat.simple_ident() {
|
||||
if let Some(ref pat) = param.pat
|
||||
&& let Some(name) = pat.simple_ident()
|
||||
{
|
||||
self.var_debug_info.push(VarDebugInfo {
|
||||
name,
|
||||
source_info,
|
||||
|
|
|
@ -412,7 +412,9 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
|
|||
}
|
||||
ExprKind::Field { lhs, .. } => {
|
||||
let lhs = &self.thir[lhs];
|
||||
if let ty::Adt(adt_def, _) = lhs.ty.kind() && adt_def.is_union() {
|
||||
if let ty::Adt(adt_def, _) = lhs.ty.kind()
|
||||
&& adt_def.is_union()
|
||||
{
|
||||
if let Some((assigned_ty, assignment_span)) = self.assignment_info {
|
||||
if assigned_ty.needs_drop(self.tcx, self.param_env) {
|
||||
// This would be unsafe, but should be outright impossible since we reject such unions.
|
||||
|
@ -461,7 +463,9 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
|
|||
}
|
||||
ExprKind::Let { expr: expr_id, .. } => {
|
||||
let let_expr = &self.thir[expr_id];
|
||||
if let ty::Adt(adt_def, _) = let_expr.ty.kind() && adt_def.is_union() {
|
||||
if let ty::Adt(adt_def, _) = let_expr.ty.kind()
|
||||
&& adt_def.is_union()
|
||||
{
|
||||
self.requires_unsafe(expr.span, AccessToUnionField);
|
||||
}
|
||||
}
|
||||
|
@ -617,8 +621,7 @@ impl UnsafeOpKind {
|
|||
&& let hir::BlockCheckMode::UnsafeBlock(_) = block.rules
|
||||
{
|
||||
true
|
||||
}
|
||||
else if let Some(sig) = tcx.hir().fn_sig_by_hir_id(*id)
|
||||
} else if let Some(sig) = tcx.hir().fn_sig_by_hir_id(*id)
|
||||
&& sig.header.is_unsafe()
|
||||
{
|
||||
true
|
||||
|
|
|
@ -67,16 +67,21 @@ pub fn check_drop_recursion<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
|
|||
let def_id = body.source.def_id().expect_local();
|
||||
|
||||
// First check if `body` is an `fn drop()` of `Drop`
|
||||
if let DefKind::AssocFn = tcx.def_kind(def_id) &&
|
||||
let Some(trait_ref) = tcx.impl_of_method(def_id.to_def_id()).and_then(|def_id| tcx.impl_trait_ref(def_id)) &&
|
||||
let Some(drop_trait) = tcx.lang_items().drop_trait() && drop_trait == trait_ref.instantiate_identity().def_id {
|
||||
|
||||
if let DefKind::AssocFn = tcx.def_kind(def_id)
|
||||
&& let Some(trait_ref) =
|
||||
tcx.impl_of_method(def_id.to_def_id()).and_then(|def_id| tcx.impl_trait_ref(def_id))
|
||||
&& let Some(drop_trait) = tcx.lang_items().drop_trait()
|
||||
&& drop_trait == trait_ref.instantiate_identity().def_id
|
||||
{
|
||||
// It was. Now figure out for what type `Drop` is implemented and then
|
||||
// check for recursion.
|
||||
if let ty::Ref(_, dropped_ty, _) = tcx.liberate_late_bound_regions(
|
||||
def_id.to_def_id(),
|
||||
tcx.fn_sig(def_id).instantiate_identity().input(0),
|
||||
).kind() {
|
||||
if let ty::Ref(_, dropped_ty, _) = tcx
|
||||
.liberate_late_bound_regions(
|
||||
def_id.to_def_id(),
|
||||
tcx.fn_sig(def_id).instantiate_identity().input(0),
|
||||
)
|
||||
.kind()
|
||||
{
|
||||
check_recursion(tcx, body, RecursiveDrop { drop_for: *dropped_ty });
|
||||
}
|
||||
}
|
||||
|
|
|
@ -320,17 +320,23 @@ impl<'tcx> Cx<'tcx> {
|
|||
reason: errors::RustcBoxAttrReason::Attributes,
|
||||
});
|
||||
} else if let Some(box_item) = tcx.lang_items().owned_box() {
|
||||
if let hir::ExprKind::Path(hir::QPath::TypeRelative(ty, fn_path)) = fun.kind
|
||||
if let hir::ExprKind::Path(hir::QPath::TypeRelative(ty, fn_path)) =
|
||||
fun.kind
|
||||
&& let hir::TyKind::Path(hir::QPath::Resolved(_, path)) = ty.kind
|
||||
&& path.res.opt_def_id().is_some_and(|did| did == box_item)
|
||||
&& fn_path.ident.name == sym::new
|
||||
&& let [value] = args
|
||||
{
|
||||
return Expr { temp_lifetime, ty: expr_ty, span: expr.span, kind: ExprKind::Box { value: self.mirror_expr(value) } }
|
||||
return Expr {
|
||||
temp_lifetime,
|
||||
ty: expr_ty,
|
||||
span: expr.span,
|
||||
kind: ExprKind::Box { value: self.mirror_expr(value) },
|
||||
};
|
||||
} else {
|
||||
tcx.sess.emit_err(errors::RustcBoxAttributeError {
|
||||
span: expr.span,
|
||||
reason: errors::RustcBoxAttrReason::NotBoxNew
|
||||
reason: errors::RustcBoxAttrReason::NotBoxNew,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
|
@ -343,17 +349,16 @@ impl<'tcx> Cx<'tcx> {
|
|||
|
||||
// Tuple-like ADTs are represented as ExprKind::Call. We convert them here.
|
||||
let adt_data = if let hir::ExprKind::Path(ref qpath) = fun.kind
|
||||
&& let Some(adt_def) = expr_ty.ty_adt_def() {
|
||||
&& let Some(adt_def) = expr_ty.ty_adt_def()
|
||||
{
|
||||
match qpath {
|
||||
hir::QPath::Resolved(_, ref path) => {
|
||||
match path.res {
|
||||
Res::Def(DefKind::Ctor(_, CtorKind::Fn), ctor_id) => {
|
||||
Some((adt_def, adt_def.variant_index_with_ctor_id(ctor_id)))
|
||||
}
|
||||
Res::SelfCtor(..) => Some((adt_def, FIRST_VARIANT)),
|
||||
_ => None,
|
||||
hir::QPath::Resolved(_, ref path) => match path.res {
|
||||
Res::Def(DefKind::Ctor(_, CtorKind::Fn), ctor_id) => {
|
||||
Some((adt_def, adt_def.variant_index_with_ctor_id(ctor_id)))
|
||||
}
|
||||
}
|
||||
Res::SelfCtor(..) => Some((adt_def, FIRST_VARIANT)),
|
||||
_ => None,
|
||||
},
|
||||
hir::QPath::TypeRelative(_ty, _) => {
|
||||
if let Some((DefKind::Ctor(_, CtorKind::Fn), ctor_id)) =
|
||||
self.typeck_results().type_dependent_def(fun.hir_id)
|
||||
|
@ -362,7 +367,6 @@ impl<'tcx> Cx<'tcx> {
|
|||
} else {
|
||||
None
|
||||
}
|
||||
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
|
|
|
@ -168,7 +168,9 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for MatchVisitor<'a, '_, 'tcx> {
|
|||
self.lint_level = lint_level;
|
||||
}
|
||||
|
||||
if let Some(initializer) = initializer && else_block.is_some() {
|
||||
if let Some(initializer) = initializer
|
||||
&& else_block.is_some()
|
||||
{
|
||||
self.check_let(pattern, initializer, LetSource::LetElse, span);
|
||||
}
|
||||
|
||||
|
@ -411,7 +413,10 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
|
|||
return;
|
||||
}
|
||||
|
||||
if let Some(until) = chain_refutabilities.iter().position(|r| !matches!(*r, Some((_, false)))) && until > 0 {
|
||||
if let Some(until) =
|
||||
chain_refutabilities.iter().position(|r| !matches!(*r, Some((_, false))))
|
||||
&& until > 0
|
||||
{
|
||||
// The chain has a non-zero prefix of irrefutable `let` statements.
|
||||
|
||||
// Check if the let source is while, for there is no alternative place to put a prefix,
|
||||
|
@ -427,18 +432,31 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
|
|||
let span_end = prefix.last().unwrap().unwrap().0;
|
||||
let span = span_start.to(span_end);
|
||||
let count = prefix.len();
|
||||
self.tcx.emit_spanned_lint(IRREFUTABLE_LET_PATTERNS, self.lint_level, span, LeadingIrrefutableLetPatterns { count });
|
||||
self.tcx.emit_spanned_lint(
|
||||
IRREFUTABLE_LET_PATTERNS,
|
||||
self.lint_level,
|
||||
span,
|
||||
LeadingIrrefutableLetPatterns { count },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(from) = chain_refutabilities.iter().rposition(|r| !matches!(*r, Some((_, false)))) && from != (chain_refutabilities.len() - 1) {
|
||||
if let Some(from) =
|
||||
chain_refutabilities.iter().rposition(|r| !matches!(*r, Some((_, false))))
|
||||
&& from != (chain_refutabilities.len() - 1)
|
||||
{
|
||||
// The chain has a non-empty suffix of irrefutable `let` statements
|
||||
let suffix = &chain_refutabilities[from + 1..];
|
||||
let span_start = suffix[0].unwrap().0;
|
||||
let span_end = suffix.last().unwrap().unwrap().0;
|
||||
let span = span_start.to(span_end);
|
||||
let count = suffix.len();
|
||||
self.tcx.emit_spanned_lint(IRREFUTABLE_LET_PATTERNS, self.lint_level, span, TrailingIrrefutableLetPatterns { count });
|
||||
self.tcx.emit_spanned_lint(
|
||||
IRREFUTABLE_LET_PATTERNS,
|
||||
self.lint_level,
|
||||
span,
|
||||
TrailingIrrefutableLetPatterns { count },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -472,23 +490,21 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
|
|||
let mut interpreted_as_const = None;
|
||||
|
||||
if let PatKind::Constant { .. }
|
||||
| PatKind::AscribeUserType {
|
||||
subpattern: box Pat { kind: PatKind::Constant { .. }, .. },
|
||||
..
|
||||
} = pat.kind
|
||||
| PatKind::AscribeUserType {
|
||||
subpattern: box Pat { kind: PatKind::Constant { .. }, .. },
|
||||
..
|
||||
} = pat.kind
|
||||
&& let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(pat.span)
|
||||
{
|
||||
// If the pattern to match is an integer literal:
|
||||
if snippet.chars().all(|c| c.is_digit(10)) {
|
||||
// Then give a suggestion, the user might've meant to create a binding instead.
|
||||
misc_suggestion = Some(MiscPatternSuggestion::AttemptedIntegerLiteral {
|
||||
start_span: pat.span.shrink_to_lo()
|
||||
start_span: pat.span.shrink_to_lo(),
|
||||
});
|
||||
} else if snippet.chars().all(|c| c.is_alphanumeric() || c == '_') {
|
||||
interpreted_as_const = Some(InterpretedAsConst {
|
||||
span: pat.span,
|
||||
variable: snippet,
|
||||
});
|
||||
interpreted_as_const =
|
||||
Some(InterpretedAsConst { span: pat.span, variable: snippet });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -525,20 +541,19 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
|
|||
|
||||
// Emit an extra note if the first uncovered witness would be uninhabited
|
||||
// if we disregard visibility.
|
||||
let witness_1_is_privately_uninhabited =
|
||||
if cx.tcx.features().exhaustive_patterns
|
||||
&& let Some(witness_1) = witnesses.get(0)
|
||||
&& let ty::Adt(adt, args) = witness_1.ty().kind()
|
||||
&& adt.is_enum()
|
||||
&& let Constructor::Variant(variant_index) = witness_1.ctor()
|
||||
{
|
||||
let variant = adt.variant(*variant_index);
|
||||
let inhabited = variant.inhabited_predicate(cx.tcx, *adt).instantiate(cx.tcx, args);
|
||||
assert!(inhabited.apply(cx.tcx, cx.param_env, cx.module));
|
||||
!inhabited.apply_ignore_module(cx.tcx, cx.param_env)
|
||||
} else {
|
||||
false
|
||||
};
|
||||
let witness_1_is_privately_uninhabited = if cx.tcx.features().exhaustive_patterns
|
||||
&& let Some(witness_1) = witnesses.get(0)
|
||||
&& let ty::Adt(adt, args) = witness_1.ty().kind()
|
||||
&& adt.is_enum()
|
||||
&& let Constructor::Variant(variant_index) = witness_1.ctor()
|
||||
{
|
||||
let variant = adt.variant(*variant_index);
|
||||
let inhabited = variant.inhabited_predicate(cx.tcx, *adt).instantiate(cx.tcx, args);
|
||||
assert!(inhabited.apply(cx.tcx, cx.param_env, cx.module));
|
||||
!inhabited.apply_ignore_module(cx.tcx, cx.param_env)
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
self.error = Err(self.tcx.sess.emit_err(PatternNotCovered {
|
||||
span: pat.span,
|
||||
|
@ -563,23 +578,22 @@ fn check_for_bindings_named_same_as_variants(
|
|||
) {
|
||||
pat.walk_always(|p| {
|
||||
if let PatKind::Binding {
|
||||
name,
|
||||
mode: BindingMode::ByValue,
|
||||
mutability: Mutability::Not,
|
||||
subpattern: None,
|
||||
ty,
|
||||
..
|
||||
} = p.kind
|
||||
name,
|
||||
mode: BindingMode::ByValue,
|
||||
mutability: Mutability::Not,
|
||||
subpattern: None,
|
||||
ty,
|
||||
..
|
||||
} = p.kind
|
||||
&& let ty::Adt(edef, _) = ty.peel_refs().kind()
|
||||
&& edef.is_enum()
|
||||
&& edef.variants().iter().any(|variant| {
|
||||
variant.name == name && variant.ctor_kind() == Some(CtorKind::Const)
|
||||
})
|
||||
&& edef
|
||||
.variants()
|
||||
.iter()
|
||||
.any(|variant| variant.name == name && variant.ctor_kind() == Some(CtorKind::Const))
|
||||
{
|
||||
let variant_count = edef.variants().len();
|
||||
let ty_path = with_no_trimmed_paths!({
|
||||
cx.tcx.def_path_str(edef.did())
|
||||
});
|
||||
let ty_path = with_no_trimmed_paths!(cx.tcx.def_path_str(edef.did()));
|
||||
cx.tcx.emit_spanned_lint(
|
||||
BINDINGS_WITH_VARIANT_NAME,
|
||||
cx.lint_level,
|
||||
|
@ -590,7 +604,9 @@ fn check_for_bindings_named_same_as_variants(
|
|||
// suggestion would produce code that breaks on `check_irrefutable`.
|
||||
suggestion: if rf == Refutable || variant_count == 1 {
|
||||
Some(p.span)
|
||||
} else { None },
|
||||
} else {
|
||||
None
|
||||
},
|
||||
ty_path,
|
||||
name,
|
||||
},
|
||||
|
@ -794,8 +810,10 @@ fn non_exhaustive_match<'p, 'tcx>(
|
|||
}
|
||||
[only] => {
|
||||
let only = &thir[*only];
|
||||
let (pre_indentation, is_multiline) = if let Some(snippet) = sm.indentation_before(only.span)
|
||||
&& let Ok(with_trailing) = sm.span_extend_while(only.span, |c| c.is_whitespace() || c == ',')
|
||||
let (pre_indentation, is_multiline) = if let Some(snippet) =
|
||||
sm.indentation_before(only.span)
|
||||
&& let Ok(with_trailing) =
|
||||
sm.span_extend_while(only.span, |c| c.is_whitespace() || c == ',')
|
||||
&& sm.is_multiline(with_trailing)
|
||||
{
|
||||
(format!("\n{snippet}"), true)
|
||||
|
@ -946,7 +964,9 @@ fn maybe_point_at_variant<'a, 'p: 'a, 'tcx: 'a>(
|
|||
let mut covered = vec![];
|
||||
for pattern in patterns {
|
||||
if let Variant(variant_index) = pattern.ctor() {
|
||||
if let ty::Adt(this_def, _) = pattern.ty().kind() && this_def.did() != def.did() {
|
||||
if let ty::Adt(this_def, _) = pattern.ty().kind()
|
||||
&& this_def.did() != def.did()
|
||||
{
|
||||
continue;
|
||||
}
|
||||
let sp = def.variant(*variant_index).ident(cx.tcx).span;
|
||||
|
|
|
@ -500,7 +500,7 @@ impl<'tcx> ConstToPat<'tcx> {
|
|||
lint::builtin::NONTRIVIAL_STRUCTURAL_MATCH,
|
||||
id,
|
||||
span,
|
||||
NontrivialStructuralMatch {non_sm_ty}
|
||||
NontrivialStructuralMatch { non_sm_ty },
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue