Skip to content

Commit

Permalink
Auto merge of #94431 - matthiaskrgr:rollup-1jsj0wu, r=matthiaskrgr
Browse files Browse the repository at this point in the history
Rollup of 7 pull requests

Successful merges:

 - #94396 (1 - Make more use of `let_chains`)
 - #94397 (Document that pre-expansion lint passes are softly deprecated)
 - #94399 (Add test for #79465 to prevent regression)
 - #94409 (avoid rebuilding bootstrap when PATH changes)
 - #94415 (Use the first codegen backend in the config.toml as default)
 - #94417 (Fix duplicated impl links)
 - #94420 (3 - Make more use of `let_chains`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Feb 28, 2022
2 parents 9fbff89 + 5570b1d commit b07d59f
Show file tree
Hide file tree
Showing 26 changed files with 250 additions and 238 deletions.
21 changes: 10 additions & 11 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1921,17 +1921,16 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
err.span_label(assigned_span, format!("first assignment to {}", place_description));
}
}
if let Some(decl) = local_decl {
if let Some(name) = local_name {
if decl.can_be_made_mutable() {
err.span_suggestion(
decl.source_info.span,
"consider making this binding mutable",
format!("mut {}", name),
Applicability::MachineApplicable,
);
}
}
if let Some(decl) = local_decl
&& let Some(name) = local_name
&& decl.can_be_made_mutable()
{
err.span_suggestion(
decl.source_info.span,
"consider making this binding mutable",
format!("mut {}", name),
Applicability::MachineApplicable,
);
}
err.span_label(span, msg);
self.buffer_error(err);
Expand Down
15 changes: 6 additions & 9 deletions compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,15 +375,12 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {

Some(Cause::DropVar(local, location)) => {
let mut should_note_order = false;
if self.local_names[local].is_some() {
if let Some((WriteKind::StorageDeadOrDrop, place)) = kind_place {
if let Some(borrowed_local) = place.as_local() {
if self.local_names[borrowed_local].is_some() && local != borrowed_local
{
should_note_order = true;
}
}
}
if self.local_names[local].is_some()
&& let Some((WriteKind::StorageDeadOrDrop, place)) = kind_place
&& let Some(borrowed_local) = place.as_local()
&& self.local_names[borrowed_local].is_some() && local != borrowed_local
{
should_note_order = true;
}

BorrowExplanation::UsedLaterWhenDropped {
Expand Down
26 changes: 11 additions & 15 deletions compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1086,21 +1086,17 @@ fn get_mut_span_in_struct_field<'tcx>(
field: &mir::Field,
) -> Option<Span> {
// Expect our local to be a reference to a struct of some kind.
if let ty::Ref(_, ty, _) = ty.kind() {
if let ty::Adt(def, _) = ty.kind() {
let field = def.all_fields().nth(field.index())?;
// Use the HIR types to construct the diagnostic message.
let node = tcx.hir().find_by_def_id(field.did.as_local()?)?;
// Now we're dealing with the actual struct that we're going to suggest a change to,
// we can expect a field that is an immutable reference to a type.
if let hir::Node::Field(field) = node {
if let hir::TyKind::Rptr(lifetime, hir::MutTy { mutbl: hir::Mutability::Not, ty }) =
field.ty.kind
{
return Some(lifetime.span.between(ty.span));
}
}
}
if let ty::Ref(_, ty, _) = ty.kind()
&& let ty::Adt(def, _) = ty.kind()
&& let field = def.all_fields().nth(field.index())?
// Use the HIR types to construct the diagnostic message.
&& let node = tcx.hir().find_by_def_id(field.did.as_local()?)?
// Now we're dealing with the actual struct that we're going to suggest a change to,
// we can expect a field that is an immutable reference to a type.
&& let hir::Node::Field(field) = node
&& let hir::TyKind::Rptr(lt, hir::MutTy { mutbl: hir::Mutability::Not, ty }) = field.ty.kind
{
return Some(lt.span.between(ty.span));
}

None
Expand Down
13 changes: 5 additions & 8 deletions compiler/rustc_borrowck/src/diagnostics/region_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,11 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {

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

false
Expand Down
21 changes: 10 additions & 11 deletions compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
//! This query borrow-checks the MIR to (further) ensure it is not broken.

#![allow(rustc::potential_query_instability)]
#![feature(bool_to_option)]
#![feature(box_patterns)]
#![feature(crate_visibility_modifier)]
#![feature(let_chains)]
#![feature(let_else)]
#![feature(min_specialization)]
#![feature(stmt_expr_attributes)]
#![feature(trusted_step)]
#![feature(try_blocks)]
#![recursion_limit = "256"]
#![allow(rustc::potential_query_instability)]

#[macro_use]
extern crate rustc_middle;
Expand Down Expand Up @@ -159,16 +160,14 @@ fn do_mir_borrowck<'a, 'tcx>(
for var_debug_info in &input_body.var_debug_info {
if let VarDebugInfoContents::Place(place) = var_debug_info.value {
if let Some(local) = place.as_local() {
if let Some(prev_name) = local_names[local] {
if var_debug_info.name != prev_name {
span_bug!(
var_debug_info.source_info.span,
"local {:?} has many names (`{}` vs `{}`)",
local,
prev_name,
var_debug_info.name
);
}
if let Some(prev_name) = local_names[local] && var_debug_info.name != prev_name {
span_bug!(
var_debug_info.source_info.span,
"local {:?} has many names (`{}` vs `{}`)",
local,
prev_name,
var_debug_info.name
);
}
local_names[local] = Some(var_debug_info.name);
}
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_borrowck/src/places_conflict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,8 @@ pub(super) fn borrow_conflicts_with_place<'tcx>(

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

place_components_conflict(tcx, body, borrow_place, borrow_kind, access_place, access, bias)
Expand Down
8 changes: 2 additions & 6 deletions compiler/rustc_interface/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,9 @@ pub fn get_codegen_backend(
static LOAD: SyncOnceCell<unsafe fn() -> Box<dyn CodegenBackend>> = SyncOnceCell::new();

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

#[cfg(not(feature = "llvm"))]
const DEFAULT_CODEGEN_BACKEND: &str = "cranelift";

match backend_name.unwrap_or(DEFAULT_CODEGEN_BACKEND) {
match backend_name.unwrap_or(default_codegen_backend) {
filename if filename.contains('.') => load_backend_from_dylib(filename.as_ref()),
#[cfg(feature = "llvm")]
"llvm" => rustc_codegen_llvm::LlvmCodegenBackend::new,
Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,12 @@ impl LintStore {
self.early_passes.push(Box::new(pass));
}

/// Used by clippy.
/// This lint pass is softly deprecated. It misses expanded code and has caused a few
/// errors in the past. Currently, it is only used in Clippy. New implementations
/// should avoid using this interface, as it might be removed in the future.
///
/// * See [rust#69838](https://github.com/rust-lang/rust/pull/69838)
/// * See [rust-clippy#5518](https://github.com/rust-lang/rust-clippy/pull/5518)
pub fn register_pre_expansion_pass(
&mut self,
pass: impl Fn() -> EarlyLintPassObject + 'static + sync::Send + sync::Sync,
Expand Down
11 changes: 5 additions & 6 deletions compiler/rustc_typeck/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,12 +1054,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let mut result = Vec::new();

for ast_bound in ast_bounds {
if let Some(trait_ref) = ast_bound.trait_ref() {
if let Some(trait_did) = trait_ref.trait_def_id() {
if self.tcx().trait_may_define_assoc_type(trait_did, assoc_name) {
result.push(ast_bound.clone());
}
}
if let Some(trait_ref) = ast_bound.trait_ref()
&& let Some(trait_did) = trait_ref.trait_def_id()
&& self.tcx().trait_may_define_assoc_type(trait_did, assoc_name)
{
result.push(ast_bound.clone());
}
}

Expand Down
39 changes: 17 additions & 22 deletions compiler/rustc_typeck/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,12 @@ pub(super) fn check_fn<'a, 'tcx>(
sess.span_err(decl.inputs[0].span, "argument should be `&PanicInfo`");
}

if let Node::Item(item) = hir.get(fn_id) {
if let ItemKind::Fn(_, ref generics, _) = item.kind {
if !generics.params.is_empty() {
if let Node::Item(item) = hir.get(fn_id)
&& let ItemKind::Fn(_, ref generics, _) = item.kind
&& !generics.params.is_empty()
{
sess.span_err(span, "should have no type parameters");
}
}
}
} else {
let span = sess.source_map().guess_head_span(span);
sess.span_err(span, "function should have one argument");
Expand Down Expand Up @@ -319,17 +318,15 @@ pub(super) fn check_fn<'a, 'tcx>(
sess.span_err(decl.inputs[0].span, "argument should be `Layout`");
}

if let Node::Item(item) = hir.get(fn_id) {
if let ItemKind::Fn(_, ref generics, _) = item.kind {
if !generics.params.is_empty() {
if let Node::Item(item) = hir.get(fn_id)
&& let ItemKind::Fn(_, ref generics, _) = item.kind
&& !generics.params.is_empty()
{
sess.span_err(
span,
"`#[alloc_error_handler]` function should have no type \
parameters",
"`#[alloc_error_handler]` function should have no type parameters",
);
}
}
}
} else {
let span = sess.source_map().guess_head_span(span);
sess.span_err(span, "function should have one argument");
Expand Down Expand Up @@ -1146,18 +1143,17 @@ pub(super) fn check_packed(tcx: TyCtxt<'_>, sp: Span, def: &ty::AdtDef) {
if repr.packed() {
for attr in tcx.get_attrs(def.did).iter() {
for r in attr::find_repr_attrs(&tcx.sess, attr) {
if let attr::ReprPacked(pack) = r {
if let Some(repr_pack) = repr.pack {
if pack as u64 != repr_pack.bytes() {
if let attr::ReprPacked(pack) = r
&& let Some(repr_pack) = repr.pack
&& pack as u64 != repr_pack.bytes()
{
struct_span_err!(
tcx.sess,
sp,
E0634,
"type has conflicting packed representation hints"
)
.emit();
}
}
}
}
}
Expand Down Expand Up @@ -1399,12 +1395,11 @@ fn display_discriminant_value<'tcx>(
) -> String {
if let Some(expr) = &variant.disr_expr {
let body = &tcx.hir().body(expr.body).value;
if let hir::ExprKind::Lit(lit) = &body.kind {
if let rustc_ast::LitKind::Int(lit_value, _int_kind) = &lit.node {
if evaluated != *lit_value {
if let hir::ExprKind::Lit(lit) = &body.kind
&& let rustc_ast::LitKind::Int(lit_value, _int_kind) = &lit.node
&& evaluated != *lit_value
{
return format!("`{}` (overflowed from `{}`)", evaluated, lit_value);
}
}
}
}
format!("`{}`", evaluated)
Expand Down
11 changes: 5 additions & 6 deletions compiler/rustc_typeck/src/check/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1696,13 +1696,12 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
}

fn is_return_ty_unsized<'a>(&self, fcx: &FnCtxt<'a, 'tcx>, blk_id: hir::HirId) -> bool {
if let Some((fn_decl, _)) = fcx.get_fn_decl(blk_id) {
if let hir::FnRetTy::Return(ty) = fn_decl.output {
let ty = <dyn AstConv<'_>>::ast_ty_to_ty(fcx, ty);
if let ty::Dynamic(..) = ty.kind() {
if let Some((fn_decl, _)) = fcx.get_fn_decl(blk_id)
&& let hir::FnRetTy::Return(ty) = fn_decl.output
&& let ty = <dyn AstConv<'_>>::ast_ty_to_ty(fcx, ty)
&& let ty::Dynamic(..) = ty.kind()
{
return true;
}
}
}
false
}
Expand Down
19 changes: 9 additions & 10 deletions compiler/rustc_typeck/src/check/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,9 +587,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
match (&expr.kind, expected.kind(), checked_ty.kind()) {
(_, &ty::Ref(_, exp, _), &ty::Ref(_, check, _)) => match (exp.kind(), check.kind()) {
(&ty::Str, &ty::Array(arr, _) | &ty::Slice(arr)) if arr == self.tcx.types.u8 => {
if let hir::ExprKind::Lit(_) = expr.kind {
if let Ok(src) = sm.span_to_snippet(sp) {
if replace_prefix(&src, "b\"", "\"").is_some() {
if let hir::ExprKind::Lit(_) = expr.kind
&& let Ok(src) = sm.span_to_snippet(sp)
&& replace_prefix(&src, "b\"", "\"").is_some()
{
let pos = sp.lo() + BytePos(1);
return Some((
sp.with_hi(pos),
Expand All @@ -600,21 +601,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
));
}
}
}
}
(&ty::Array(arr, _) | &ty::Slice(arr), &ty::Str) if arr == self.tcx.types.u8 => {
if let hir::ExprKind::Lit(_) = expr.kind {
if let Ok(src) = sm.span_to_snippet(sp) {
if replace_prefix(&src, "\"", "b\"").is_some() {
if let hir::ExprKind::Lit(_) = expr.kind
&& let Ok(src) = sm.span_to_snippet(sp)
&& replace_prefix(&src, "\"", "b\"").is_some()
{
return Some((
sp.shrink_to_lo(),
"consider adding a leading `b`",
"b".to_string(),
Applicability::MachineApplicable,
true,
));
}
}

}
}
_ => {}
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_typeck/src/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -810,10 +810,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Use the span of the trailing expression for our cause,
// not the span of the entire function
if !explicit_return {
if let ExprKind::Block(body, _) = return_expr.kind {
if let Some(last_expr) = body.expr {
span = last_expr.span;
}
if let ExprKind::Block(body, _) = return_expr.kind && let Some(last_expr) = body.expr {
span = last_expr.span;
}
}
ret_coercion.borrow_mut().coerce(
Expand Down
Loading

0 comments on commit b07d59f

Please sign in to comment.