Skip to content

Commit b07d59f

Browse files
committed
Auto merge of rust-lang#94431 - matthiaskrgr:rollup-1jsj0wu, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#94396 (1 - Make more use of `let_chains`) - rust-lang#94397 (Document that pre-expansion lint passes are softly deprecated) - rust-lang#94399 (Add test for rust-lang#79465 to prevent regression) - rust-lang#94409 (avoid rebuilding bootstrap when PATH changes) - rust-lang#94415 (Use the first codegen backend in the config.toml as default) - rust-lang#94417 (Fix duplicated impl links) - rust-lang#94420 (3 - Make more use of `let_chains`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9fbff89 + 5570b1d commit b07d59f

File tree

26 files changed

+250
-238
lines changed

26 files changed

+250
-238
lines changed

Diff for: compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -1921,17 +1921,16 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
19211921
err.span_label(assigned_span, format!("first assignment to {}", place_description));
19221922
}
19231923
}
1924-
if let Some(decl) = local_decl {
1925-
if let Some(name) = local_name {
1926-
if decl.can_be_made_mutable() {
1927-
err.span_suggestion(
1928-
decl.source_info.span,
1929-
"consider making this binding mutable",
1930-
format!("mut {}", name),
1931-
Applicability::MachineApplicable,
1932-
);
1933-
}
1934-
}
1924+
if let Some(decl) = local_decl
1925+
&& let Some(name) = local_name
1926+
&& decl.can_be_made_mutable()
1927+
{
1928+
err.span_suggestion(
1929+
decl.source_info.span,
1930+
"consider making this binding mutable",
1931+
format!("mut {}", name),
1932+
Applicability::MachineApplicable,
1933+
);
19351934
}
19361935
err.span_label(span, msg);
19371936
self.buffer_error(err);

Diff for: compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -375,15 +375,12 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
375375

376376
Some(Cause::DropVar(local, location)) => {
377377
let mut should_note_order = false;
378-
if self.local_names[local].is_some() {
379-
if let Some((WriteKind::StorageDeadOrDrop, place)) = kind_place {
380-
if let Some(borrowed_local) = place.as_local() {
381-
if self.local_names[borrowed_local].is_some() && local != borrowed_local
382-
{
383-
should_note_order = true;
384-
}
385-
}
386-
}
378+
if self.local_names[local].is_some()
379+
&& let Some((WriteKind::StorageDeadOrDrop, place)) = kind_place
380+
&& let Some(borrowed_local) = place.as_local()
381+
&& self.local_names[borrowed_local].is_some() && local != borrowed_local
382+
{
383+
should_note_order = true;
387384
}
388385

389386
BorrowExplanation::UsedLaterWhenDropped {

Diff for: compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+11-15
Original file line numberDiff line numberDiff line change
@@ -1086,21 +1086,17 @@ fn get_mut_span_in_struct_field<'tcx>(
10861086
field: &mir::Field,
10871087
) -> Option<Span> {
10881088
// Expect our local to be a reference to a struct of some kind.
1089-
if let ty::Ref(_, ty, _) = ty.kind() {
1090-
if let ty::Adt(def, _) = ty.kind() {
1091-
let field = def.all_fields().nth(field.index())?;
1092-
// Use the HIR types to construct the diagnostic message.
1093-
let node = tcx.hir().find_by_def_id(field.did.as_local()?)?;
1094-
// Now we're dealing with the actual struct that we're going to suggest a change to,
1095-
// we can expect a field that is an immutable reference to a type.
1096-
if let hir::Node::Field(field) = node {
1097-
if let hir::TyKind::Rptr(lifetime, hir::MutTy { mutbl: hir::Mutability::Not, ty }) =
1098-
field.ty.kind
1099-
{
1100-
return Some(lifetime.span.between(ty.span));
1101-
}
1102-
}
1103-
}
1089+
if let ty::Ref(_, ty, _) = ty.kind()
1090+
&& let ty::Adt(def, _) = ty.kind()
1091+
&& let field = def.all_fields().nth(field.index())?
1092+
// Use the HIR types to construct the diagnostic message.
1093+
&& let node = tcx.hir().find_by_def_id(field.did.as_local()?)?
1094+
// Now we're dealing with the actual struct that we're going to suggest a change to,
1095+
// we can expect a field that is an immutable reference to a type.
1096+
&& let hir::Node::Field(field) = node
1097+
&& let hir::TyKind::Rptr(lt, hir::MutTy { mutbl: hir::Mutability::Not, ty }) = field.ty.kind
1098+
{
1099+
return Some(lt.span.between(ty.span));
11041100
}
11051101

11061102
None

Diff for: compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,11 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
140140

141141
/// Returns `true` if a closure is inferred to be an `FnMut` closure.
142142
fn is_closure_fn_mut(&self, fr: RegionVid) -> bool {
143-
if let Some(ty::ReFree(free_region)) = self.to_error_region(fr).as_deref() {
144-
if let ty::BoundRegionKind::BrEnv = free_region.bound_region {
145-
if let DefiningTy::Closure(_, substs) =
146-
self.regioncx.universal_regions().defining_ty
147-
{
148-
return substs.as_closure().kind() == ty::ClosureKind::FnMut;
149-
}
150-
}
143+
if let Some(ty::ReFree(free_region)) = self.to_error_region(fr).as_deref()
144+
&& let ty::BoundRegionKind::BrEnv = free_region.bound_region
145+
&& let DefiningTy::Closure(_, substs) = self.regioncx.universal_regions().defining_ty
146+
{
147+
return substs.as_closure().kind() == ty::ClosureKind::FnMut;
151148
}
152149

153150
false

Diff for: compiler/rustc_borrowck/src/lib.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
//! This query borrow-checks the MIR to (further) ensure it is not broken.
22
3+
#![allow(rustc::potential_query_instability)]
34
#![feature(bool_to_option)]
45
#![feature(box_patterns)]
56
#![feature(crate_visibility_modifier)]
7+
#![feature(let_chains)]
68
#![feature(let_else)]
79
#![feature(min_specialization)]
810
#![feature(stmt_expr_attributes)]
911
#![feature(trusted_step)]
1012
#![feature(try_blocks)]
1113
#![recursion_limit = "256"]
12-
#![allow(rustc::potential_query_instability)]
1314

1415
#[macro_use]
1516
extern crate rustc_middle;
@@ -159,16 +160,14 @@ fn do_mir_borrowck<'a, 'tcx>(
159160
for var_debug_info in &input_body.var_debug_info {
160161
if let VarDebugInfoContents::Place(place) = var_debug_info.value {
161162
if let Some(local) = place.as_local() {
162-
if let Some(prev_name) = local_names[local] {
163-
if var_debug_info.name != prev_name {
164-
span_bug!(
165-
var_debug_info.source_info.span,
166-
"local {:?} has many names (`{}` vs `{}`)",
167-
local,
168-
prev_name,
169-
var_debug_info.name
170-
);
171-
}
163+
if let Some(prev_name) = local_names[local] && var_debug_info.name != prev_name {
164+
span_bug!(
165+
var_debug_info.source_info.span,
166+
"local {:?} has many names (`{}` vs `{}`)",
167+
local,
168+
prev_name,
169+
var_debug_info.name
170+
);
172171
}
173172
local_names[local] = Some(var_debug_info.name);
174173
}

Diff for: compiler/rustc_borrowck/src/places_conflict.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,8 @@ pub(super) fn borrow_conflicts_with_place<'tcx>(
6060

6161
// This Local/Local case is handled by the more general code below, but
6262
// it's so common that it's a speed win to check for it first.
63-
if let Some(l1) = borrow_place.as_local() {
64-
if let Some(l2) = access_place.as_local() {
65-
return l1 == l2;
66-
}
63+
if let Some(l1) = borrow_place.as_local() && let Some(l2) = access_place.as_local() {
64+
return l1 == l2;
6765
}
6866

6967
place_components_conflict(tcx, body, borrow_place, borrow_kind, access_place, access, bias)

Diff for: compiler/rustc_interface/src/util.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,9 @@ pub fn get_codegen_backend(
236236
static LOAD: SyncOnceCell<unsafe fn() -> Box<dyn CodegenBackend>> = SyncOnceCell::new();
237237

238238
let load = LOAD.get_or_init(|| {
239-
#[cfg(feature = "llvm")]
240-
const DEFAULT_CODEGEN_BACKEND: &str = "llvm";
239+
let default_codegen_backend = option_env!("CFG_DEFAULT_CODEGEN_BACKEND").unwrap_or("llvm");
241240

242-
#[cfg(not(feature = "llvm"))]
243-
const DEFAULT_CODEGEN_BACKEND: &str = "cranelift";
244-
245-
match backend_name.unwrap_or(DEFAULT_CODEGEN_BACKEND) {
241+
match backend_name.unwrap_or(default_codegen_backend) {
246242
filename if filename.contains('.') => load_backend_from_dylib(filename.as_ref()),
247243
#[cfg(feature = "llvm")]
248244
"llvm" => rustc_codegen_llvm::LlvmCodegenBackend::new,

Diff for: compiler/rustc_lint/src/context.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,12 @@ impl LintStore {
166166
self.early_passes.push(Box::new(pass));
167167
}
168168

169-
/// Used by clippy.
169+
/// This lint pass is softly deprecated. It misses expanded code and has caused a few
170+
/// errors in the past. Currently, it is only used in Clippy. New implementations
171+
/// should avoid using this interface, as it might be removed in the future.
172+
///
173+
/// * See [rust#69838](https://github.com/rust-lang/rust/pull/69838)
174+
/// * See [rust-clippy#5518](https://github.com/rust-lang/rust-clippy/pull/5518)
170175
pub fn register_pre_expansion_pass(
171176
&mut self,
172177
pass: impl Fn() -> EarlyLintPassObject + 'static + sync::Send + sync::Sync,

Diff for: compiler/rustc_typeck/src/astconv/mod.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -1054,12 +1054,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
10541054
let mut result = Vec::new();
10551055

10561056
for ast_bound in ast_bounds {
1057-
if let Some(trait_ref) = ast_bound.trait_ref() {
1058-
if let Some(trait_did) = trait_ref.trait_def_id() {
1059-
if self.tcx().trait_may_define_assoc_type(trait_did, assoc_name) {
1060-
result.push(ast_bound.clone());
1061-
}
1062-
}
1057+
if let Some(trait_ref) = ast_bound.trait_ref()
1058+
&& let Some(trait_did) = trait_ref.trait_def_id()
1059+
&& self.tcx().trait_may_define_assoc_type(trait_did, assoc_name)
1060+
{
1061+
result.push(ast_bound.clone());
10631062
}
10641063
}
10651064

Diff for: compiler/rustc_typeck/src/check/check.rs

+17-22
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,12 @@ pub(super) fn check_fn<'a, 'tcx>(
282282
sess.span_err(decl.inputs[0].span, "argument should be `&PanicInfo`");
283283
}
284284

285-
if let Node::Item(item) = hir.get(fn_id) {
286-
if let ItemKind::Fn(_, ref generics, _) = item.kind {
287-
if !generics.params.is_empty() {
285+
if let Node::Item(item) = hir.get(fn_id)
286+
&& let ItemKind::Fn(_, ref generics, _) = item.kind
287+
&& !generics.params.is_empty()
288+
{
288289
sess.span_err(span, "should have no type parameters");
289290
}
290-
}
291-
}
292291
} else {
293292
let span = sess.source_map().guess_head_span(span);
294293
sess.span_err(span, "function should have one argument");
@@ -319,17 +318,15 @@ pub(super) fn check_fn<'a, 'tcx>(
319318
sess.span_err(decl.inputs[0].span, "argument should be `Layout`");
320319
}
321320

322-
if let Node::Item(item) = hir.get(fn_id) {
323-
if let ItemKind::Fn(_, ref generics, _) = item.kind {
324-
if !generics.params.is_empty() {
321+
if let Node::Item(item) = hir.get(fn_id)
322+
&& let ItemKind::Fn(_, ref generics, _) = item.kind
323+
&& !generics.params.is_empty()
324+
{
325325
sess.span_err(
326326
span,
327-
"`#[alloc_error_handler]` function should have no type \
328-
parameters",
327+
"`#[alloc_error_handler]` function should have no type parameters",
329328
);
330329
}
331-
}
332-
}
333330
} else {
334331
let span = sess.source_map().guess_head_span(span);
335332
sess.span_err(span, "function should have one argument");
@@ -1146,18 +1143,17 @@ pub(super) fn check_packed(tcx: TyCtxt<'_>, sp: Span, def: &ty::AdtDef) {
11461143
if repr.packed() {
11471144
for attr in tcx.get_attrs(def.did).iter() {
11481145
for r in attr::find_repr_attrs(&tcx.sess, attr) {
1149-
if let attr::ReprPacked(pack) = r {
1150-
if let Some(repr_pack) = repr.pack {
1151-
if pack as u64 != repr_pack.bytes() {
1146+
if let attr::ReprPacked(pack) = r
1147+
&& let Some(repr_pack) = repr.pack
1148+
&& pack as u64 != repr_pack.bytes()
1149+
{
11521150
struct_span_err!(
11531151
tcx.sess,
11541152
sp,
11551153
E0634,
11561154
"type has conflicting packed representation hints"
11571155
)
11581156
.emit();
1159-
}
1160-
}
11611157
}
11621158
}
11631159
}
@@ -1399,12 +1395,11 @@ fn display_discriminant_value<'tcx>(
13991395
) -> String {
14001396
if let Some(expr) = &variant.disr_expr {
14011397
let body = &tcx.hir().body(expr.body).value;
1402-
if let hir::ExprKind::Lit(lit) = &body.kind {
1403-
if let rustc_ast::LitKind::Int(lit_value, _int_kind) = &lit.node {
1404-
if evaluated != *lit_value {
1398+
if let hir::ExprKind::Lit(lit) = &body.kind
1399+
&& let rustc_ast::LitKind::Int(lit_value, _int_kind) = &lit.node
1400+
&& evaluated != *lit_value
1401+
{
14051402
return format!("`{}` (overflowed from `{}`)", evaluated, lit_value);
1406-
}
1407-
}
14081403
}
14091404
}
14101405
format!("`{}`", evaluated)

Diff for: compiler/rustc_typeck/src/check/coercion.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -1696,13 +1696,12 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
16961696
}
16971697

16981698
fn is_return_ty_unsized<'a>(&self, fcx: &FnCtxt<'a, 'tcx>, blk_id: hir::HirId) -> bool {
1699-
if let Some((fn_decl, _)) = fcx.get_fn_decl(blk_id) {
1700-
if let hir::FnRetTy::Return(ty) = fn_decl.output {
1701-
let ty = <dyn AstConv<'_>>::ast_ty_to_ty(fcx, ty);
1702-
if let ty::Dynamic(..) = ty.kind() {
1699+
if let Some((fn_decl, _)) = fcx.get_fn_decl(blk_id)
1700+
&& let hir::FnRetTy::Return(ty) = fn_decl.output
1701+
&& let ty = <dyn AstConv<'_>>::ast_ty_to_ty(fcx, ty)
1702+
&& let ty::Dynamic(..) = ty.kind()
1703+
{
17031704
return true;
1704-
}
1705-
}
17061705
}
17071706
false
17081707
}

Diff for: compiler/rustc_typeck/src/check/demand.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -587,9 +587,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
587587
match (&expr.kind, expected.kind(), checked_ty.kind()) {
588588
(_, &ty::Ref(_, exp, _), &ty::Ref(_, check, _)) => match (exp.kind(), check.kind()) {
589589
(&ty::Str, &ty::Array(arr, _) | &ty::Slice(arr)) if arr == self.tcx.types.u8 => {
590-
if let hir::ExprKind::Lit(_) = expr.kind {
591-
if let Ok(src) = sm.span_to_snippet(sp) {
592-
if replace_prefix(&src, "b\"", "\"").is_some() {
590+
if let hir::ExprKind::Lit(_) = expr.kind
591+
&& let Ok(src) = sm.span_to_snippet(sp)
592+
&& replace_prefix(&src, "b\"", "\"").is_some()
593+
{
593594
let pos = sp.lo() + BytePos(1);
594595
return Some((
595596
sp.with_hi(pos),
@@ -600,21 +601,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
600601
));
601602
}
602603
}
603-
}
604-
}
605604
(&ty::Array(arr, _) | &ty::Slice(arr), &ty::Str) if arr == self.tcx.types.u8 => {
606-
if let hir::ExprKind::Lit(_) = expr.kind {
607-
if let Ok(src) = sm.span_to_snippet(sp) {
608-
if replace_prefix(&src, "\"", "b\"").is_some() {
605+
if let hir::ExprKind::Lit(_) = expr.kind
606+
&& let Ok(src) = sm.span_to_snippet(sp)
607+
&& replace_prefix(&src, "\"", "b\"").is_some()
608+
{
609609
return Some((
610610
sp.shrink_to_lo(),
611611
"consider adding a leading `b`",
612612
"b".to_string(),
613613
Applicability::MachineApplicable,
614614
true,
615615
));
616-
}
617-
}
616+
618617
}
619618
}
620619
_ => {}

Diff for: compiler/rustc_typeck/src/check/expr.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -810,10 +810,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
810810
// Use the span of the trailing expression for our cause,
811811
// not the span of the entire function
812812
if !explicit_return {
813-
if let ExprKind::Block(body, _) = return_expr.kind {
814-
if let Some(last_expr) = body.expr {
815-
span = last_expr.span;
816-
}
813+
if let ExprKind::Block(body, _) = return_expr.kind && let Some(last_expr) = body.expr {
814+
span = last_expr.span;
817815
}
818816
}
819817
ret_coercion.borrow_mut().coerce(

0 commit comments

Comments
 (0)