Skip to content

Commit 089a016

Browse files
committed
Auto merge of rust-lang#90661 - matthiaskrgr:rollup-1umbdlx, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#90487 (Add a chapter on reading Rustdoc output) - rust-lang#90508 (Apply adjustments for field expression even if inaccessible) - rust-lang#90627 (Suggest dereference of `Box` when inner type is expected) - rust-lang#90642 (use matches!() macro in more places) - rust-lang#90646 (type error go brrrrrrrr) - rust-lang#90649 (Run reveal_all on MIR when inlining is activated.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0727994 + ec471de commit 089a016

File tree

36 files changed

+304
-93
lines changed

36 files changed

+304
-93
lines changed

compiler/rustc_ast/src/util/parser.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ impl AssocOp {
212212
/// parentheses while having a high degree of confidence on the correctness of the suggestion.
213213
pub fn can_continue_expr_unambiguously(&self) -> bool {
214214
use AssocOp::*;
215-
match self {
215+
matches!(
216+
self,
216217
BitXor | // `{ 42 } ^ 3`
217218
Assign | // `{ 42 } = { 42 }`
218219
Divide | // `{ 42 } / 42`
@@ -225,9 +226,8 @@ impl AssocOp {
225226
As | // `{ 42 } as usize`
226227
// Equal | // `{ 42 } == { 42 }` Accepting these here would regress incorrect
227228
// NotEqual | // `{ 42 } != { 42 } struct literals parser recovery.
228-
Colon => true, // `{ 42 }: usize`
229-
_ => false,
230-
}
229+
Colon, // `{ 42 }: usize`
230+
)
231231
}
232232
}
233233

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ pub(crate) enum LaterUseKind {
5353

5454
impl BorrowExplanation {
5555
pub(crate) fn is_explained(&self) -> bool {
56-
match self {
57-
BorrowExplanation::Unexplained => false,
58-
_ => true,
59-
}
56+
!matches!(self, BorrowExplanation::Unexplained)
6057
}
6158
pub(crate) fn add_explanation_to_diagnostic<'tcx>(
6259
&self,

compiler/rustc_borrowck/src/region_infer/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -2110,14 +2110,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
21102110
_ => constraint_sup_scc != target_scc,
21112111
}
21122112
} else {
2113-
match categorized_path[*i].category {
2113+
!matches!(
2114+
categorized_path[*i].category,
21142115
ConstraintCategory::OpaqueType
2115-
| ConstraintCategory::Boring
2116-
| ConstraintCategory::BoringNoLocation
2117-
| ConstraintCategory::Internal
2118-
| ConstraintCategory::Predicate(_) => false,
2119-
_ => true,
2120-
}
2116+
| ConstraintCategory::Boring
2117+
| ConstraintCategory::BoringNoLocation
2118+
| ConstraintCategory::Internal
2119+
| ConstraintCategory::Predicate(_)
2120+
)
21212121
}
21222122
};
21232123

compiler/rustc_borrowck/src/universal_regions.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,11 @@ impl<'tcx> DefiningTy<'tcx> {
138138
}
139139

140140
pub fn is_fn_def(&self) -> bool {
141-
match *self {
142-
DefiningTy::FnDef(..) => true,
143-
_ => false,
144-
}
141+
matches!(*self, DefiningTy::FnDef(..))
145142
}
146143

147144
pub fn is_const(&self) -> bool {
148-
match *self {
149-
DefiningTy::Const(..) => true,
150-
_ => false,
151-
}
145+
matches!(*self, DefiningTy::Const(..))
152146
}
153147

154148
pub fn def_id(&self) -> DefId {

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,7 @@ fn push_debuginfo_type_name<'tcx>(
124124
// info for MSVC debugger. However, wrapping these types' names in a synthetic type
125125
// causes the .natvis engine for WinDbg to fail to display their data, so we opt these
126126
// types out to aid debugging in MSVC.
127-
let is_slice_or_str = match *inner_type.kind() {
128-
ty::Slice(_) | ty::Str => true,
129-
_ => false,
130-
};
127+
let is_slice_or_str = matches!(*inner_type.kind(), ty::Slice(_) | ty::Str);
131128

132129
if !cpp_like_names {
133130
output.push('&');

compiler/rustc_const_eval/src/const_eval/error.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ pub enum ConstEvalErrKind {
2525

2626
impl MachineStopType for ConstEvalErrKind {
2727
fn is_hard_err(&self) -> bool {
28-
match self {
29-
Self::Panic { .. } => true,
30-
_ => false,
31-
}
28+
matches!(self, Self::Panic { .. })
3229
}
3330
}
3431

compiler/rustc_const_eval/src/const_eval/fn_queries.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,8 @@ fn is_const_fn_raw(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
5151
// If the function itself is not annotated with `const`, it may still be a `const fn`
5252
// if it resides in a const trait impl.
5353
is_parent_const_impl_raw(tcx, hir_id)
54-
} else if let hir::Node::Ctor(_) = node {
55-
true
5654
} else {
57-
false
55+
matches!(node, hir::Node::Ctor(_))
5856
}
5957
}
6058

compiler/rustc_const_eval/src/interpret/intrinsics/type_name.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,8 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
138138
args: &[GenericArg<'tcx>],
139139
) -> Result<Self::Path, Self::Error> {
140140
self = print_prefix(self)?;
141-
let args = args.iter().cloned().filter(|arg| match arg.unpack() {
142-
GenericArgKind::Lifetime(_) => false,
143-
_ => true,
144-
});
141+
let args =
142+
args.iter().cloned().filter(|arg| !matches!(arg.unpack(), GenericArgKind::Lifetime(_)));
145143
if args.clone().next().is_some() {
146144
self.generic_delimiters(|cx| cx.comma_sep(args))
147145
} else {

compiler/rustc_const_eval/src/interpret/terminator.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
345345

346346
// Figure out how to pass which arguments.
347347
// The Rust ABI is special: ZST get skipped.
348-
let rust_abi = match caller_abi {
349-
Abi::Rust | Abi::RustCall => true,
350-
_ => false,
351-
};
348+
let rust_abi = matches!(caller_abi, Abi::Rust | Abi::RustCall);
349+
352350
// We have two iterators: Where the arguments come from,
353351
// and where they go to.
354352

compiler/rustc_const_eval/src/transform/check_consts/check.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,7 @@ impl Qualifs<'mir, 'tcx> {
131131
.body
132132
.basic_blocks()
133133
.iter_enumerated()
134-
.find(|(_, block)| match block.terminator().kind {
135-
TerminatorKind::Return => true,
136-
_ => false,
137-
})
134+
.find(|(_, block)| matches!(block.terminator().kind, TerminatorKind::Return))
138135
.map(|(bb, _)| bb);
139136

140137
let return_block = match return_block {

compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,12 @@ impl Qualif for NeedsNonConstDrop {
170170
let mut selcx = SelectionContext::with_constness(&infcx, hir::Constness::Const);
171171
selcx.select(&obligation)
172172
});
173-
match implsrc {
174-
Ok(Some(ImplSource::ConstDrop(_)))
175-
| Ok(Some(ImplSource::Param(_, ty::BoundConstness::ConstIfConst))) => false,
176-
_ => true,
177-
}
173+
!matches!(
174+
implsrc,
175+
Ok(Some(
176+
ImplSource::ConstDrop(_) | ImplSource::Param(_, ty::BoundConstness::ConstIfConst)
177+
))
178+
)
178179
}
179180

180181
fn in_adt_inherently(cx: &ConstCx<'_, 'tcx>, adt: &'tcx AdtDef, _: SubstsRef<'tcx>) -> bool {

compiler/rustc_lexer/src/unescape.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,10 @@ pub enum EscapeError {
6868
impl EscapeError {
6969
/// Returns true for actual errors, as opposed to warnings.
7070
pub fn is_fatal(&self) -> bool {
71-
match self {
72-
EscapeError::UnskippedWhitespaceWarning => false,
73-
EscapeError::MultipleSkippedLinesWarning => false,
74-
_ => true,
75-
}
71+
!matches!(
72+
self,
73+
EscapeError::UnskippedWhitespaceWarning | EscapeError::MultipleSkippedLinesWarning
74+
)
7675
}
7776
}
7877

compiler/rustc_middle/src/mir/interpret/error.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -538,12 +538,12 @@ impl InterpError<'_> {
538538
/// To avoid performance issues, there are places where we want to be sure to never raise these formatting errors,
539539
/// so this method lets us detect them and `bug!` on unexpected errors.
540540
pub fn formatted_string(&self) -> bool {
541-
match self {
541+
matches!(
542+
self,
542543
InterpError::Unsupported(UnsupportedOpInfo::Unsupported(_))
543-
| InterpError::UndefinedBehavior(UndefinedBehaviorInfo::ValidationFailure { .. })
544-
| InterpError::UndefinedBehavior(UndefinedBehaviorInfo::Ub(_)) => true,
545-
_ => false,
546-
}
544+
| InterpError::UndefinedBehavior(UndefinedBehaviorInfo::ValidationFailure { .. })
545+
| InterpError::UndefinedBehavior(UndefinedBehaviorInfo::Ub(_))
546+
)
547547
}
548548

549549
/// Should this error be reported as a hard error, preventing compilation, or a soft error,

compiler/rustc_middle/src/ty/relate.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,12 @@ impl<'tcx> Relate<'tcx> for ty::FnSig<'tcx> {
187187
})
188188
.enumerate()
189189
.map(|(i, r)| match r {
190-
Err(TypeError::Sorts(exp_found)) => Err(TypeError::ArgumentSorts(exp_found, i)),
191-
Err(TypeError::Mutability) => Err(TypeError::ArgumentMutability(i)),
190+
Err(TypeError::Sorts(exp_found) | TypeError::ArgumentSorts(exp_found, _)) => {
191+
Err(TypeError::ArgumentSorts(exp_found, i))
192+
}
193+
Err(TypeError::Mutability | TypeError::ArgumentMutability(_)) => {
194+
Err(TypeError::ArgumentMutability(i))
195+
}
192196
r => r,
193197
});
194198
Ok(ty::FnSig {

compiler/rustc_mir_transform/src/coverage/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ fn inject_statement(
485485

486486
// Non-code expressions are injected into the coverage map, without generating executable code.
487487
fn inject_intermediate_expression(mir_body: &mut mir::Body<'tcx>, expression: CoverageKind) {
488-
debug_assert!(if let CoverageKind::Expression { .. } = expression { true } else { false });
488+
debug_assert!(matches!(expression, CoverageKind::Expression { .. }));
489489
debug!(" injecting non-code expression {:?}", expression);
490490
let inject_in_bb = mir::START_BLOCK;
491491
let data = &mut mir_body[inject_in_bb];

compiler/rustc_mir_transform/src/coverage/spans.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,9 @@ impl CoverageSpan {
9494
stmt_index: usize,
9595
) -> Self {
9696
let is_closure = match statement.kind {
97-
StatementKind::Assign(box (_, Rvalue::Aggregate(box ref kind, _))) => match kind {
98-
AggregateKind::Closure(_, _) | AggregateKind::Generator(_, _, _) => true,
99-
_ => false,
100-
},
97+
StatementKind::Assign(box (_, Rvalue::Aggregate(box ref kind, _))) => {
98+
matches!(kind, AggregateKind::Closure(_, _) | AggregateKind::Generator(_, _, _))
99+
}
101100
_ => false,
102101
};
103102

compiler/rustc_mir_transform/src/reveal_all.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ impl<'tcx> MirPass<'tcx> for RevealAll {
1111
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
1212
// This pass must run before inlining, since we insert callee bodies in RevealAll mode.
1313
// Do not apply this transformation to generators.
14-
if (tcx.sess.mir_opt_level() >= 3 || !super::inline::is_enabled(tcx))
14+
if (tcx.sess.mir_opt_level() >= 3 || super::inline::is_enabled(tcx))
1515
&& body.generator.is_none()
1616
{
1717
let param_env = tcx.param_env_reveal_all_normalized(body.source.def_id());

compiler/rustc_mir_transform/src/unreachable_prop.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ impl MirPass<'_> for UnreachablePropagation {
2727
// This is a temporary solution that handles possibly diverging asm statements.
2828
// Accompanying testcases: mir-opt/unreachable_asm.rs and mir-opt/unreachable_asm_2.rs
2929
let asm_stmt_in_block = || {
30-
bb_data.statements.iter().any(|stmt: &Statement<'_>| match stmt.kind {
31-
StatementKind::LlvmInlineAsm(..) => true,
32-
_ => false,
30+
bb_data.statements.iter().any(|stmt: &Statement<'_>| {
31+
matches!(stmt.kind, StatementKind::LlvmInlineAsm(..))
3332
})
3433
};
3534

compiler/rustc_trait_selection/src/traits/select/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
320320

321321
/// Returns `true` if the trait predicate is considerd `const` to this selection context.
322322
pub fn is_trait_predicate_const(&self, pred: ty::TraitPredicate<'_>) -> bool {
323-
match pred.constness {
324-
ty::BoundConstness::ConstIfConst if self.is_in_const_context => true,
325-
_ => false,
326-
}
323+
matches!(pred.constness, ty::BoundConstness::ConstIfConst) && self.is_in_const_context
327324
}
328325

329326
/// Returns `true` if the predicate is considered `const` to

compiler/rustc_typeck/src/check/cast.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -436,11 +436,8 @@ impl<'a, 'tcx> CastCheck<'tcx> {
436436
// Very crude check to see whether the expression must be wrapped
437437
// in parentheses for the suggestion to work (issue #89497).
438438
// Can/should be extended in the future.
439-
let needs_parens = !has_parens
440-
&& match self.expr.kind {
441-
hir::ExprKind::Cast(..) => true,
442-
_ => false,
443-
};
439+
let needs_parens =
440+
!has_parens && matches!(self.expr.kind, hir::ExprKind::Cast(..));
444441

445442
let mut suggestion = vec![(self.expr.span.shrink_to_lo(), sugg)];
446443
if needs_parens {

compiler/rustc_typeck/src/check/compare_method.rs

+1
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ fn check_region_bounds_on_impl_item<'tcx>(
453453
Ok(())
454454
}
455455

456+
#[instrument(level = "debug", skip(infcx))]
456457
fn extract_spans_for_error_reporting<'a, 'tcx>(
457458
infcx: &infer::InferCtxt<'a, 'tcx>,
458459
terr: &TypeError<'_>,

compiler/rustc_typeck/src/check/demand.rs

+18
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2929
expected_ty_expr: Option<&'tcx hir::Expr<'tcx>>,
3030
) {
3131
self.annotate_expected_due_to_let_ty(err, expr);
32+
self.suggest_box_deref(err, expr, expected, expr_ty);
3233
self.suggest_compatible_variants(err, expr, expected, expr_ty);
3334
self.suggest_deref_ref_or_into(err, expr, expected, expr_ty, expected_ty_expr);
3435
if self.suggest_calling_boxed_future_when_appropriate(err, expr, expected, expr_ty) {
@@ -167,6 +168,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
167168
}
168169
}
169170

171+
fn suggest_box_deref(
172+
&self,
173+
err: &mut DiagnosticBuilder<'_>,
174+
expr: &hir::Expr<'_>,
175+
expected: Ty<'tcx>,
176+
expr_ty: Ty<'tcx>,
177+
) {
178+
if expr_ty.is_box() && expr_ty.boxed_ty() == expected {
179+
err.span_suggestion_verbose(
180+
expr.span.shrink_to_lo(),
181+
"try dereferencing the `Box`",
182+
"*".to_string(),
183+
Applicability::MachineApplicable,
184+
);
185+
}
186+
}
187+
170188
/// If the expected type is an enum (Issue #55250) with any variants whose
171189
/// sole field is of the found type, suggest such variants. (Issue #42764)
172190
fn suggest_compatible_variants(

compiler/rustc_typeck/src/check/expr.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1698,15 +1698,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16981698
// Save the index of all fields regardless of their visibility in case
16991699
// of error recovery.
17001700
self.write_field_index(expr.hir_id, index);
1701+
let adjustments = self.adjust_steps(&autoderef);
17011702
if field.vis.is_accessible_from(def_scope, self.tcx) {
1702-
let adjustments = self.adjust_steps(&autoderef);
17031703
self.apply_adjustments(base, adjustments);
17041704
self.register_predicates(autoderef.into_obligations());
17051705

17061706
self.tcx.check_stability(field.did, Some(expr.hir_id), expr.span, None);
17071707
return field_ty;
17081708
}
1709-
private_candidate = Some((base_def.did, field_ty));
1709+
private_candidate = Some((adjustments, base_def.did, field_ty));
17101710
}
17111711
}
17121712
ty::Tuple(tys) => {
@@ -1729,7 +1729,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17291729
}
17301730
self.structurally_resolved_type(autoderef.span(), autoderef.final_ty(false));
17311731

1732-
if let Some((did, field_ty)) = private_candidate {
1732+
if let Some((adjustments, did, field_ty)) = private_candidate {
1733+
// (#90483) apply adjustments to avoid ExprUseVisitor from
1734+
// creating erroneous projection.
1735+
self.apply_adjustments(base, adjustments);
17331736
self.ban_private_field_access(expr, expr_t, field, did);
17341737
return field_ty;
17351738
}

compiler/rustc_typeck/src/structured_errors/wrong_number_of_generic_args.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
300300
hir::TyKind::Path(hir::QPath::Resolved(
301301
None,
302302
hir::Path { res: hir::def::Res::Def(_, id), .. },
303-
)) if *id == def_id => true,
303+
)) => *id == def_id,
304304
_ => false,
305305
})
306306
})

library/std/src/net/ip.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -878,12 +878,7 @@ impl Ipv4Addr {
878878
#[must_use]
879879
#[inline]
880880
pub const fn is_documentation(&self) -> bool {
881-
match self.octets() {
882-
[192, 0, 2, _] => true,
883-
[198, 51, 100, _] => true,
884-
[203, 0, 113, _] => true,
885-
_ => false,
886-
}
881+
matches!(self.octets(), [192, 0, 2, _] | [198, 51, 100, _] | [203, 0, 113, _])
887882
}
888883

889884
/// Converts this address to an [IPv4-compatible] [`IPv6` address].

library/std/src/os/unix/net/addr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ impl SocketAddr {
159159
#[must_use]
160160
#[stable(feature = "unix_socket", since = "1.10.0")]
161161
pub fn is_unnamed(&self) -> bool {
162-
if let AddressKind::Unnamed = self.address() { true } else { false }
162+
matches!(self.address(), AddressKind::Unnamed)
163163
}
164164

165165
/// Returns the contents of this address if it is a `pathname` address.

src/doc/rustdoc/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# The Rustdoc Book
22

33
- [What is rustdoc?](what-is-rustdoc.md)
4+
- [How to read rustdoc output](how-to-read-rustdoc.md)
45
- [How to write documentation](how-to-write-documentation.md)
56
- [What to include (and exclude)](what-to-include.md)
67
- [Command-line arguments](command-line-arguments.md)

0 commit comments

Comments
 (0)