Skip to content

Commit

Permalink
Auto merge of rust-lang#132551 - workingjubilee:rollup-eeeqzxw, r=wor…
Browse files Browse the repository at this point in the history
…kingjubilee

Rollup of 15 pull requests

Successful merges:

 - rust-lang#129329 (Implement `From<&mut {slice}>` for `Box/Rc/Arc<{slice}>`)
 - rust-lang#131377 (Add LowerExp and UpperExp implementations to NonZero)
 - rust-lang#132275 (Register `~const` preds for `Deref` adjustments in HIR typeck)
 - rust-lang#132393 (Docs: added brief colon explanation)
 - rust-lang#132437 (coverage: Regression test for inlining into an uninstrumented crate)
 - rust-lang#132499 (unicode_data.rs: show command for generating file)
 - rust-lang#132503 (better test for const HashMap; remove const_hash leftovers)
 - rust-lang#132520 (NFC add known bug nr to test)
 - rust-lang#132522 (make codegen help output more consistent)
 - rust-lang#132523 (Added regression test for generics index out of bounds)
 - rust-lang#132528 (Use `*_opt` typeck results fns to not ICE in fallback suggestion)
 - rust-lang#132537 (PassWrapper: adapt for llvm/llvm-project@5445edb5d)
 - rust-lang#132540 (Do not format generic consts)
 - rust-lang#132543 (add and update some crashtests)
 - rust-lang#132550 (compiler: Continue introducing rustc_abi to the compiler)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Nov 3, 2024
2 parents 89ab655 + eb2185c commit 77eb86c
Show file tree
Hide file tree
Showing 64 changed files with 693 additions and 237 deletions.
7 changes: 5 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3346,6 +3346,7 @@ dependencies = [
"either",
"itertools",
"polonius-engine",
"rustc_abi",
"rustc_data_structures",
"rustc_errors",
"rustc_fluent_macro",
Expand All @@ -3359,7 +3360,6 @@ dependencies = [
"rustc_mir_dataflow",
"rustc_session",
"rustc_span",
"rustc_target",
"rustc_trait_selection",
"rustc_traits",
"smallvec",
Expand Down Expand Up @@ -3706,6 +3706,7 @@ name = "rustc_hir"
version = "0.0.0"
dependencies = [
"odht",
"rustc_abi",
"rustc_arena",
"rustc_ast",
"rustc_data_structures",
Expand Down Expand Up @@ -4131,6 +4132,7 @@ dependencies = [
name = "rustc_monomorphize"
version = "0.0.0"
dependencies = [
"rustc_abi",
"rustc_data_structures",
"rustc_errors",
"rustc_fluent_macro",
Expand Down Expand Up @@ -4335,6 +4337,7 @@ name = "rustc_sanitizers"
version = "0.0.0"
dependencies = [
"bitflags 2.6.0",
"rustc_abi",
"rustc_data_structures",
"rustc_hir",
"rustc_middle",
Expand Down Expand Up @@ -4467,6 +4470,7 @@ name = "rustc_trait_selection"
version = "0.0.0"
dependencies = [
"itertools",
"rustc_abi",
"rustc_ast",
"rustc_ast_ir",
"rustc_attr",
Expand All @@ -4483,7 +4487,6 @@ dependencies = [
"rustc_serialize",
"rustc_session",
"rustc_span",
"rustc_target",
"rustc_transmute",
"rustc_type_ir",
"smallvec",
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,12 @@ pub struct WhereClause {
pub span: Span,
}

impl WhereClause {
pub fn is_empty(&self) -> bool {
!self.has_where_token && self.predicates.is_empty()
}
}

impl Default for WhereClause {
fn default() -> WhereClause {
WhereClause { has_where_token: false, predicates: ThinVec::new(), span: DUMMY_SP }
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ edition = "2021"
either = "1.5.0"
itertools = "0.12"
polonius-engine = "0.13.0"
rustc_abi = { path = "../rustc_abi" }
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_errors = { path = "../rustc_errors" }
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
Expand All @@ -21,7 +22,6 @@ rustc_middle = { path = "../rustc_middle" }
rustc_mir_dataflow = { path = "../rustc_mir_dataflow" }
rustc_session = { path = "../rustc_session" }
rustc_span = { path = "../rustc_span" }
rustc_target = { path = "../rustc_target" }
rustc_trait_selection = { path = "../rustc_trait_selection" }
rustc_traits = { path = "../rustc_traits" }
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Borrow checker diagnostics.

use rustc_abi::{FieldIdx, VariantIdx};
use rustc_errors::{Applicability, Diag, MultiSpan};
use rustc_hir::def::{CtorKind, Namespace};
use rustc_hir::{self as hir, CoroutineKind, LangItem};
Expand All @@ -21,7 +22,6 @@ use rustc_span::def_id::LocalDefId;
use rustc_span::source_map::Spanned;
use rustc_span::symbol::sym;
use rustc_span::{DUMMY_SP, Span, Symbol};
use rustc_target::abi::{FieldIdx, VariantIdx};
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
use rustc_trait_selection::infer::InferCtxtExt;
use rustc_trait_selection::traits::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use core::ops::ControlFlow;

use hir::{ExprKind, Param};
use rustc_abi::FieldIdx;
use rustc_errors::{Applicability, Diag};
use rustc_hir::intravisit::Visitor;
use rustc_hir::{self as hir, BindingMode, ByRef, Node};
Expand All @@ -16,7 +17,6 @@ use rustc_middle::mir::{
use rustc_middle::ty::{self, InstanceKind, Ty, TyCtxt, Upcast};
use rustc_span::symbol::{Symbol, kw};
use rustc_span::{BytePos, DesugaringKind, Span, sym};
use rustc_target::abi::FieldIdx;
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
use rustc_trait_selection::infer::InferCtxtExt;
use rustc_trait_selection::traits;
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 @@ -1103,7 +1103,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
peeled_ty,
liberated_sig.c_variadic,
hir::Safety::Safe,
rustc_target::spec::abi::Abi::Rust,
rustc_abi::ExternAbi::Rust,
)),
);
let closure_ty = Ty::new_closure(
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 @@ -21,6 +21,7 @@ use std::marker::PhantomData;
use std::ops::Deref;

use consumers::{BodyWithBorrowckFacts, ConsumerOptions};
use rustc_abi::FieldIdx;
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_data_structures::graph::dominators::Dominators;
use rustc_errors::Diag;
Expand All @@ -45,7 +46,6 @@ use rustc_mir_dataflow::move_paths::{
};
use rustc_session::lint::builtin::UNUSED_MUT;
use rustc_span::{Span, Symbol};
use rustc_target::abi::FieldIdx;
use smallvec::SmallVec;
use tracing::{debug, instrument};

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
@@ -1,7 +1,7 @@
use rustc_abi::FieldIdx;
use rustc_data_structures::graph::dominators::Dominators;
use rustc_middle::mir::{BasicBlock, Body, BorrowKind, Location, Place, PlaceRef, ProjectionElem};
use rustc_middle::ty::TyCtxt;
use rustc_target::abi::FieldIdx;
use tracing::debug;

use crate::borrow_set::{BorrowData, BorrowSet, TwoPhaseActivation};
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::rc::Rc;
use std::{fmt, iter, mem};

use either::Either;
use rustc_abi::{FIRST_VARIANT, FieldIdx};
use rustc_data_structures::frozen::Frozen;
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_errors::ErrorGuaranteed;
Expand Down Expand Up @@ -40,7 +41,6 @@ use rustc_span::def_id::CRATE_DEF_ID;
use rustc_span::source_map::Spanned;
use rustc_span::symbol::sym;
use rustc_span::{DUMMY_SP, Span};
use rustc_target::abi::{FIRST_VARIANT, FieldIdx};
use rustc_trait_selection::traits::query::type_op::custom::{
CustomTypeOp, scrape_region_constraints,
};
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2021"
[dependencies]
# tidy-alphabetical-start
odht = { version = "0.3.1", features = ["nightly"] }
rustc_abi = { path = "../rustc_abi" }
rustc_arena = { path = "../rustc_arena" }
rustc_ast = { path = "../rustc_ast" }
rustc_data_structures = { path = "../rustc_data_structures" }
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::fmt;

use rustc_abi::ExternAbi;
use rustc_ast::util::parser::ExprPrecedence;
use rustc_ast::{
self as ast, Attribute, FloatTy, InlineAsmOptions, InlineAsmTemplatePiece, IntTy, Label,
Expand All @@ -19,7 +20,6 @@ use rustc_span::source_map::Spanned;
use rustc_span::symbol::{Ident, Symbol, kw, sym};
use rustc_span::{BytePos, DUMMY_SP, ErrorGuaranteed, Span};
use rustc_target::asm::InlineAsmRegOrRegClass;
use rustc_target::spec::abi::Abi;
use smallvec::SmallVec;
use tracing::debug;

Expand Down Expand Up @@ -2735,7 +2735,7 @@ impl PrimTy {
#[derive(Debug, Clone, Copy, HashStable_Generic)]
pub struct BareFnTy<'hir> {
pub safety: Safety,
pub abi: Abi,
pub abi: ExternAbi,
pub generic_params: &'hir [GenericParam<'hir>],
pub decl: &'hir FnDecl<'hir>,
pub param_names: &'hir [Ident],
Expand Down Expand Up @@ -3313,7 +3313,7 @@ impl<'hir> Item<'hir> {

expect_mod, &'hir Mod<'hir>, ItemKind::Mod(m), m;

expect_foreign_mod, (Abi, &'hir [ForeignItemRef]),
expect_foreign_mod, (ExternAbi, &'hir [ForeignItemRef]),
ItemKind::ForeignMod { abi, items }, (*abi, items);

expect_global_asm, &'hir InlineAsm<'hir>, ItemKind::GlobalAsm(asm), asm;
Expand Down Expand Up @@ -3386,7 +3386,7 @@ pub struct FnHeader {
pub safety: Safety,
pub constness: Constness,
pub asyncness: IsAsync,
pub abi: Abi,
pub abi: ExternAbi,
}

impl FnHeader {
Expand Down Expand Up @@ -3428,7 +3428,7 @@ pub enum ItemKind<'hir> {
/// A module.
Mod(&'hir Mod<'hir>),
/// An external module, e.g. `extern { .. }`.
ForeignMod { abi: Abi, items: &'hir [ForeignItemRef] },
ForeignMod { abi: ExternAbi, items: &'hir [ForeignItemRef] },
/// Module-level inline assembly (from `global_asm!`).
GlobalAsm(&'hir InlineAsm<'hir>),
/// A type alias, e.g., `type Foo = Bar<u8>`.
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_hir_typeck/src/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
fn visit_ty(&mut self, hir_ty: &'tcx hir::Ty<'tcx>) -> Self::Result {
// Try to replace `_` with `()`.
if let hir::TyKind::Infer = hir_ty.kind
&& let ty = self.fcx.typeck_results.borrow().node_type(hir_ty.hir_id)
&& let Some(ty) = self.fcx.typeck_results.borrow().node_type_opt(hir_ty.hir_id)
&& let Some(vid) = self.fcx.root_vid(ty)
&& self.reachable_vids.contains(&vid)
{
Expand Down Expand Up @@ -680,7 +680,8 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
if let hir::ExprKind::Path(hir::QPath::Resolved(None, path)) = expr.kind
&& let Res::Def(DefKind::AssocFn, def_id) = path.res
&& self.fcx.tcx.trait_of_item(def_id).is_some()
&& let self_ty = self.fcx.typeck_results.borrow().node_args(expr.hir_id).type_at(0)
&& let Some(args) = self.fcx.typeck_results.borrow().node_args_opt(expr.hir_id)
&& let self_ty = args.type_at(0)
&& let Some(vid) = self.fcx.root_vid(self_ty)
&& self.reachable_vids.contains(&vid)
&& let [.., trait_segment, _method_segment] = path.segments
Expand All @@ -701,7 +702,7 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
fn visit_local(&mut self, local: &'tcx hir::LetStmt<'tcx>) -> Self::Result {
// For a local, try suggest annotating the type if it's missing.
if let None = local.ty
&& let ty = self.fcx.typeck_results.borrow().node_type(local.hir_id)
&& let Some(ty) = self.fcx.typeck_results.borrow().node_type_opt(local.hir_id)
&& let Some(vid) = self.fcx.root_vid(ty)
&& self.reachable_vids.contains(&vid)
{
Expand Down
30 changes: 26 additions & 4 deletions compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,32 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}

for a in &adj {
if let Adjust::NeverToAny = a.kind {
if a.target.is_ty_var() {
self.diverging_type_vars.borrow_mut().insert(a.target);
debug!("apply_adjustments: adding `{:?}` as diverging type var", a.target);
match a.kind {
Adjust::NeverToAny => {
if a.target.is_ty_var() {
self.diverging_type_vars.borrow_mut().insert(a.target);
debug!("apply_adjustments: adding `{:?}` as diverging type var", a.target);
}
}
Adjust::Deref(Some(overloaded_deref)) => {
self.enforce_context_effects(
expr.span,
overloaded_deref.method_call(self.tcx),
self.tcx.mk_args(&[a.target.into()]),
);
}
Adjust::Deref(None) => {
// FIXME(effects): We *could* enforce `&T: ~const Deref` here.
}
Adjust::Pointer(_pointer_coercion) => {
// FIXME(effects): We should probably enforce these.
}
Adjust::ReborrowPin(_mutability) => {
// FIXME(effects): We could enforce these; they correspond to
// `&mut T: DerefMut` tho, so it's kinda moot.
}
Adjust::Borrow(_) => {
// No effects to enforce here.
}
}
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir_typeck/src/place_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
);
};
*deref = OverloadedDeref { mutbl, span: deref.span };
self.enforce_context_effects(expr.span, method.def_id, method.args);
// If this is a union field, also throw an error for `DerefMut` of `ManuallyDrop` (see RFC 2514).
// This helps avoid accidental drops.
if inside_union
Expand Down
13 changes: 6 additions & 7 deletions compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -777,10 +777,8 @@ extern "C" LLVMRustResult LLVMRustOptimize(
CGSCCAnalysisManager CGAM;
ModuleAnalysisManager MAM;

// FIXME: We may want to expose this as an option.
bool DebugPassManager = false;

StandardInstrumentations SI(TheModule->getContext(), DebugPassManager);
StandardInstrumentations SI(TheModule->getContext(),
/*DebugLogging=*/false);
SI.registerCallbacks(PIC, &MAM);

if (LLVMPluginsLen) {
Expand Down Expand Up @@ -932,8 +930,9 @@ extern "C" LLVMRustResult LLVMRustOptimize(
for (const auto &C : OptimizerLastEPCallbacks)
PB.registerOptimizerLastEPCallback(C);

// Pass false as we manually schedule ThinLTOBufferPasses below.
MPM = PB.buildO0DefaultPipeline(OptLevel, /* PreLinkLTO */ false);
// We manually schedule ThinLTOBufferPasses below, so don't pass the value
// to enable it here.
MPM = PB.buildO0DefaultPipeline(OptLevel);
} else {
for (const auto &C : PipelineStartEPCallbacks)
PB.registerPipelineStartEPCallback(C);
Expand All @@ -942,7 +941,7 @@ extern "C" LLVMRustResult LLVMRustOptimize(

switch (OptStage) {
case LLVMRustOptStage::PreLinkNoLTO:
MPM = PB.buildPerModuleDefaultPipeline(OptLevel, DebugPassManager);
MPM = PB.buildPerModuleDefaultPipeline(OptLevel);
break;
case LLVMRustOptStage::PreLinkThinLTO:
MPM = PB.buildThinLTOPreLinkDefaultPipeline(OptLevel);
Expand Down
14 changes: 7 additions & 7 deletions compiler/rustc_middle/src/ty/adjustment.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::lang_items::LangItem;
use rustc_hir::{self as hir};
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
use rustc_span::Span;
use rustc_target::abi::FieldIdx;
Expand Down Expand Up @@ -123,19 +124,18 @@ pub struct OverloadedDeref {
}

impl OverloadedDeref {
/// Get the zst function item type for this method call.
pub fn method_call<'tcx>(&self, tcx: TyCtxt<'tcx>, source: Ty<'tcx>) -> Ty<'tcx> {
/// Get the [`DefId`] of the method call for the given `Deref`/`DerefMut` trait
/// for this overloaded deref's mutability.
pub fn method_call<'tcx>(&self, tcx: TyCtxt<'tcx>) -> DefId {
let trait_def_id = match self.mutbl {
hir::Mutability::Not => tcx.require_lang_item(LangItem::Deref, None),
hir::Mutability::Mut => tcx.require_lang_item(LangItem::DerefMut, None),
};
let method_def_id = tcx
.associated_items(trait_def_id)
tcx.associated_items(trait_def_id)
.in_definition_order()
.find(|m| m.kind == ty::AssocKind::Fn)
.unwrap()
.def_id;
Ty::new_fn_def(tcx, method_def_id, [source])
.def_id
}
}

Expand Down
12 changes: 10 additions & 2 deletions compiler/rustc_mir_build/src/thir/cx/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ impl<'tcx> Cx<'tcx> {
Adjust::Deref(Some(deref)) => {
// We don't need to do call adjust_span here since
// deref coercions always start with a built-in deref.
let call = deref.method_call(self.tcx(), expr.ty);
let call_def_id = deref.method_call(self.tcx());
let overloaded_callee =
Ty::new_fn_def(self.tcx(), call_def_id, self.tcx().mk_args(&[expr.ty.into()]));

expr = Expr {
temp_lifetime,
Expand All @@ -150,7 +152,13 @@ impl<'tcx> Cx<'tcx> {

let expr = Box::new([self.thir.exprs.push(expr)]);

self.overloaded_place(hir_expr, adjustment.target, Some(call), expr, deref.span)
self.overloaded_place(
hir_expr,
adjustment.target,
Some(overloaded_callee),
expr,
deref.span,
)
}
Adjust::Borrow(AutoBorrow::Ref(m)) => ExprKind::Borrow {
borrow_kind: m.to_borrow_kind(),
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_monomorphize/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ edition = "2021"

[dependencies]
# tidy-alphabetical-start
rustc_abi = { path = "../rustc_abi" }
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_errors = { path = "../rustc_errors" }
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
Expand Down
Loading

0 comments on commit 77eb86c

Please sign in to comment.