Skip to content

Commit 77eb86c

Browse files
committed
Auto merge of rust-lang#132551 - workingjubilee:rollup-eeeqzxw, r=workingjubilee
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
2 parents 89ab655 + eb2185c commit 77eb86c

File tree

64 files changed

+693
-237
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+693
-237
lines changed

Cargo.lock

+5-2
Original file line numberDiff line numberDiff line change
@@ -3346,6 +3346,7 @@ dependencies = [
33463346
"either",
33473347
"itertools",
33483348
"polonius-engine",
3349+
"rustc_abi",
33493350
"rustc_data_structures",
33503351
"rustc_errors",
33513352
"rustc_fluent_macro",
@@ -3359,7 +3360,6 @@ dependencies = [
33593360
"rustc_mir_dataflow",
33603361
"rustc_session",
33613362
"rustc_span",
3362-
"rustc_target",
33633363
"rustc_trait_selection",
33643364
"rustc_traits",
33653365
"smallvec",
@@ -3706,6 +3706,7 @@ name = "rustc_hir"
37063706
version = "0.0.0"
37073707
dependencies = [
37083708
"odht",
3709+
"rustc_abi",
37093710
"rustc_arena",
37103711
"rustc_ast",
37113712
"rustc_data_structures",
@@ -4131,6 +4132,7 @@ dependencies = [
41314132
name = "rustc_monomorphize"
41324133
version = "0.0.0"
41334134
dependencies = [
4135+
"rustc_abi",
41344136
"rustc_data_structures",
41354137
"rustc_errors",
41364138
"rustc_fluent_macro",
@@ -4335,6 +4337,7 @@ name = "rustc_sanitizers"
43354337
version = "0.0.0"
43364338
dependencies = [
43374339
"bitflags 2.6.0",
4340+
"rustc_abi",
43384341
"rustc_data_structures",
43394342
"rustc_hir",
43404343
"rustc_middle",
@@ -4467,6 +4470,7 @@ name = "rustc_trait_selection"
44674470
version = "0.0.0"
44684471
dependencies = [
44694472
"itertools",
4473+
"rustc_abi",
44704474
"rustc_ast",
44714475
"rustc_ast_ir",
44724476
"rustc_attr",
@@ -4483,7 +4487,6 @@ dependencies = [
44834487
"rustc_serialize",
44844488
"rustc_session",
44854489
"rustc_span",
4486-
"rustc_target",
44874490
"rustc_transmute",
44884491
"rustc_type_ir",
44894492
"smallvec",

compiler/rustc_ast/src/ast.rs

+6
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,12 @@ pub struct WhereClause {
414414
pub span: Span,
415415
}
416416

417+
impl WhereClause {
418+
pub fn is_empty(&self) -> bool {
419+
!self.has_where_token && self.predicates.is_empty()
420+
}
421+
}
422+
417423
impl Default for WhereClause {
418424
fn default() -> WhereClause {
419425
WhereClause { has_where_token: false, predicates: ThinVec::new(), span: DUMMY_SP }

compiler/rustc_borrowck/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ edition = "2021"
88
either = "1.5.0"
99
itertools = "0.12"
1010
polonius-engine = "0.13.0"
11+
rustc_abi = { path = "../rustc_abi" }
1112
rustc_data_structures = { path = "../rustc_data_structures" }
1213
rustc_errors = { path = "../rustc_errors" }
1314
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
@@ -21,7 +22,6 @@ rustc_middle = { path = "../rustc_middle" }
2122
rustc_mir_dataflow = { path = "../rustc_mir_dataflow" }
2223
rustc_session = { path = "../rustc_session" }
2324
rustc_span = { path = "../rustc_span" }
24-
rustc_target = { path = "../rustc_target" }
2525
rustc_trait_selection = { path = "../rustc_trait_selection" }
2626
rustc_traits = { path = "../rustc_traits" }
2727
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }

compiler/rustc_borrowck/src/diagnostics/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Borrow checker diagnostics.
22
3+
use rustc_abi::{FieldIdx, VariantIdx};
34
use rustc_errors::{Applicability, Diag, MultiSpan};
45
use rustc_hir::def::{CtorKind, Namespace};
56
use rustc_hir::{self as hir, CoroutineKind, LangItem};
@@ -21,7 +22,6 @@ use rustc_span::def_id::LocalDefId;
2122
use rustc_span::source_map::Spanned;
2223
use rustc_span::symbol::sym;
2324
use rustc_span::{DUMMY_SP, Span, Symbol};
24-
use rustc_target::abi::{FieldIdx, VariantIdx};
2525
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
2626
use rustc_trait_selection::infer::InferCtxtExt;
2727
use rustc_trait_selection::traits::{

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use core::ops::ControlFlow;
55

66
use hir::{ExprKind, Param};
7+
use rustc_abi::FieldIdx;
78
use rustc_errors::{Applicability, Diag};
89
use rustc_hir::intravisit::Visitor;
910
use rustc_hir::{self as hir, BindingMode, ByRef, Node};
@@ -16,7 +17,6 @@ use rustc_middle::mir::{
1617
use rustc_middle::ty::{self, InstanceKind, Ty, TyCtxt, Upcast};
1718
use rustc_span::symbol::{Symbol, kw};
1819
use rustc_span::{BytePos, DesugaringKind, Span, sym};
19-
use rustc_target::abi::FieldIdx;
2020
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
2121
use rustc_trait_selection::infer::InferCtxtExt;
2222
use rustc_trait_selection::traits;

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
11031103
peeled_ty,
11041104
liberated_sig.c_variadic,
11051105
hir::Safety::Safe,
1106-
rustc_target::spec::abi::Abi::Rust,
1106+
rustc_abi::ExternAbi::Rust,
11071107
)),
11081108
);
11091109
let closure_ty = Ty::new_closure(

compiler/rustc_borrowck/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use std::marker::PhantomData;
2121
use std::ops::Deref;
2222

2323
use consumers::{BodyWithBorrowckFacts, ConsumerOptions};
24+
use rustc_abi::FieldIdx;
2425
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
2526
use rustc_data_structures::graph::dominators::Dominators;
2627
use rustc_errors::Diag;
@@ -45,7 +46,6 @@ use rustc_mir_dataflow::move_paths::{
4546
};
4647
use rustc_session::lint::builtin::UNUSED_MUT;
4748
use rustc_span::{Span, Symbol};
48-
use rustc_target::abi::FieldIdx;
4949
use smallvec::SmallVec;
5050
use tracing::{debug, instrument};
5151

compiler/rustc_borrowck/src/path_utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
use rustc_abi::FieldIdx;
12
use rustc_data_structures::graph::dominators::Dominators;
23
use rustc_middle::mir::{BasicBlock, Body, BorrowKind, Location, Place, PlaceRef, ProjectionElem};
34
use rustc_middle::ty::TyCtxt;
4-
use rustc_target::abi::FieldIdx;
55
use tracing::debug;
66

77
use crate::borrow_set::{BorrowData, BorrowSet, TwoPhaseActivation};

compiler/rustc_borrowck/src/type_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::rc::Rc;
44
use std::{fmt, iter, mem};
55

66
use either::Either;
7+
use rustc_abi::{FIRST_VARIANT, FieldIdx};
78
use rustc_data_structures::frozen::Frozen;
89
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
910
use rustc_errors::ErrorGuaranteed;
@@ -40,7 +41,6 @@ use rustc_span::def_id::CRATE_DEF_ID;
4041
use rustc_span::source_map::Spanned;
4142
use rustc_span::symbol::sym;
4243
use rustc_span::{DUMMY_SP, Span};
43-
use rustc_target::abi::{FIRST_VARIANT, FieldIdx};
4444
use rustc_trait_selection::traits::query::type_op::custom::{
4545
CustomTypeOp, scrape_region_constraints,
4646
};

compiler/rustc_hir/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition = "2021"
66
[dependencies]
77
# tidy-alphabetical-start
88
odht = { version = "0.3.1", features = ["nightly"] }
9+
rustc_abi = { path = "../rustc_abi" }
910
rustc_arena = { path = "../rustc_arena" }
1011
rustc_ast = { path = "../rustc_ast" }
1112
rustc_data_structures = { path = "../rustc_data_structures" }

compiler/rustc_hir/src/hir.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::fmt;
22

3+
use rustc_abi::ExternAbi;
34
use rustc_ast::util::parser::ExprPrecedence;
45
use rustc_ast::{
56
self as ast, Attribute, FloatTy, InlineAsmOptions, InlineAsmTemplatePiece, IntTy, Label,
@@ -19,7 +20,6 @@ use rustc_span::source_map::Spanned;
1920
use rustc_span::symbol::{Ident, Symbol, kw, sym};
2021
use rustc_span::{BytePos, DUMMY_SP, ErrorGuaranteed, Span};
2122
use rustc_target::asm::InlineAsmRegOrRegClass;
22-
use rustc_target::spec::abi::Abi;
2323
use smallvec::SmallVec;
2424
use tracing::debug;
2525

@@ -2735,7 +2735,7 @@ impl PrimTy {
27352735
#[derive(Debug, Clone, Copy, HashStable_Generic)]
27362736
pub struct BareFnTy<'hir> {
27372737
pub safety: Safety,
2738-
pub abi: Abi,
2738+
pub abi: ExternAbi,
27392739
pub generic_params: &'hir [GenericParam<'hir>],
27402740
pub decl: &'hir FnDecl<'hir>,
27412741
pub param_names: &'hir [Ident],
@@ -3313,7 +3313,7 @@ impl<'hir> Item<'hir> {
33133313

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

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

33193319
expect_global_asm, &'hir InlineAsm<'hir>, ItemKind::GlobalAsm(asm), asm;
@@ -3386,7 +3386,7 @@ pub struct FnHeader {
33863386
pub safety: Safety,
33873387
pub constness: Constness,
33883388
pub asyncness: IsAsync,
3389-
pub abi: Abi,
3389+
pub abi: ExternAbi,
33903390
}
33913391

33923392
impl FnHeader {
@@ -3428,7 +3428,7 @@ pub enum ItemKind<'hir> {
34283428
/// A module.
34293429
Mod(&'hir Mod<'hir>),
34303430
/// An external module, e.g. `extern { .. }`.
3431-
ForeignMod { abi: Abi, items: &'hir [ForeignItemRef] },
3431+
ForeignMod { abi: ExternAbi, items: &'hir [ForeignItemRef] },
34323432
/// Module-level inline assembly (from `global_asm!`).
34333433
GlobalAsm(&'hir InlineAsm<'hir>),
34343434
/// A type alias, e.g., `type Foo = Bar<u8>`.

compiler/rustc_hir_typeck/src/fallback.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
643643
fn visit_ty(&mut self, hir_ty: &'tcx hir::Ty<'tcx>) -> Self::Result {
644644
// Try to replace `_` with `()`.
645645
if let hir::TyKind::Infer = hir_ty.kind
646-
&& let ty = self.fcx.typeck_results.borrow().node_type(hir_ty.hir_id)
646+
&& let Some(ty) = self.fcx.typeck_results.borrow().node_type_opt(hir_ty.hir_id)
647647
&& let Some(vid) = self.fcx.root_vid(ty)
648648
&& self.reachable_vids.contains(&vid)
649649
{
@@ -680,7 +680,8 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
680680
if let hir::ExprKind::Path(hir::QPath::Resolved(None, path)) = expr.kind
681681
&& let Res::Def(DefKind::AssocFn, def_id) = path.res
682682
&& self.fcx.tcx.trait_of_item(def_id).is_some()
683-
&& let self_ty = self.fcx.typeck_results.borrow().node_args(expr.hir_id).type_at(0)
683+
&& let Some(args) = self.fcx.typeck_results.borrow().node_args_opt(expr.hir_id)
684+
&& let self_ty = args.type_at(0)
684685
&& let Some(vid) = self.fcx.root_vid(self_ty)
685686
&& self.reachable_vids.contains(&vid)
686687
&& let [.., trait_segment, _method_segment] = path.segments
@@ -701,7 +702,7 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
701702
fn visit_local(&mut self, local: &'tcx hir::LetStmt<'tcx>) -> Self::Result {
702703
// For a local, try suggest annotating the type if it's missing.
703704
if let None = local.ty
704-
&& let ty = self.fcx.typeck_results.borrow().node_type(local.hir_id)
705+
&& let Some(ty) = self.fcx.typeck_results.borrow().node_type_opt(local.hir_id)
705706
&& let Some(vid) = self.fcx.root_vid(ty)
706707
&& self.reachable_vids.contains(&vid)
707708
{

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+26-4
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,32 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
254254
}
255255

256256
for a in &adj {
257-
if let Adjust::NeverToAny = a.kind {
258-
if a.target.is_ty_var() {
259-
self.diverging_type_vars.borrow_mut().insert(a.target);
260-
debug!("apply_adjustments: adding `{:?}` as diverging type var", a.target);
257+
match a.kind {
258+
Adjust::NeverToAny => {
259+
if a.target.is_ty_var() {
260+
self.diverging_type_vars.borrow_mut().insert(a.target);
261+
debug!("apply_adjustments: adding `{:?}` as diverging type var", a.target);
262+
}
263+
}
264+
Adjust::Deref(Some(overloaded_deref)) => {
265+
self.enforce_context_effects(
266+
expr.span,
267+
overloaded_deref.method_call(self.tcx),
268+
self.tcx.mk_args(&[a.target.into()]),
269+
);
270+
}
271+
Adjust::Deref(None) => {
272+
// FIXME(effects): We *could* enforce `&T: ~const Deref` here.
273+
}
274+
Adjust::Pointer(_pointer_coercion) => {
275+
// FIXME(effects): We should probably enforce these.
276+
}
277+
Adjust::ReborrowPin(_mutability) => {
278+
// FIXME(effects): We could enforce these; they correspond to
279+
// `&mut T: DerefMut` tho, so it's kinda moot.
280+
}
281+
Adjust::Borrow(_) => {
282+
// No effects to enforce here.
261283
}
262284
}
263285
}

compiler/rustc_hir_typeck/src/place_op.rs

+1
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
296296
);
297297
};
298298
*deref = OverloadedDeref { mutbl, span: deref.span };
299+
self.enforce_context_effects(expr.span, method.def_id, method.args);
299300
// If this is a union field, also throw an error for `DerefMut` of `ManuallyDrop` (see RFC 2514).
300301
// This helps avoid accidental drops.
301302
if inside_union

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+6-7
Original file line numberDiff line numberDiff line change
@@ -777,10 +777,8 @@ extern "C" LLVMRustResult LLVMRustOptimize(
777777
CGSCCAnalysisManager CGAM;
778778
ModuleAnalysisManager MAM;
779779

780-
// FIXME: We may want to expose this as an option.
781-
bool DebugPassManager = false;
782-
783-
StandardInstrumentations SI(TheModule->getContext(), DebugPassManager);
780+
StandardInstrumentations SI(TheModule->getContext(),
781+
/*DebugLogging=*/false);
784782
SI.registerCallbacks(PIC, &MAM);
785783

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

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

943942
switch (OptStage) {
944943
case LLVMRustOptStage::PreLinkNoLTO:
945-
MPM = PB.buildPerModuleDefaultPipeline(OptLevel, DebugPassManager);
944+
MPM = PB.buildPerModuleDefaultPipeline(OptLevel);
946945
break;
947946
case LLVMRustOptStage::PreLinkThinLTO:
948947
MPM = PB.buildThinLTOPreLinkDefaultPipeline(OptLevel);

compiler/rustc_middle/src/ty/adjustment.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
use rustc_hir as hir;
1+
use rustc_hir::def_id::DefId;
22
use rustc_hir::lang_items::LangItem;
3+
use rustc_hir::{self as hir};
34
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
45
use rustc_span::Span;
56
use rustc_target::abi::FieldIdx;
@@ -123,19 +124,18 @@ pub struct OverloadedDeref {
123124
}
124125

125126
impl OverloadedDeref {
126-
/// Get the zst function item type for this method call.
127-
pub fn method_call<'tcx>(&self, tcx: TyCtxt<'tcx>, source: Ty<'tcx>) -> Ty<'tcx> {
127+
/// Get the [`DefId`] of the method call for the given `Deref`/`DerefMut` trait
128+
/// for this overloaded deref's mutability.
129+
pub fn method_call<'tcx>(&self, tcx: TyCtxt<'tcx>) -> DefId {
128130
let trait_def_id = match self.mutbl {
129131
hir::Mutability::Not => tcx.require_lang_item(LangItem::Deref, None),
130132
hir::Mutability::Mut => tcx.require_lang_item(LangItem::DerefMut, None),
131133
};
132-
let method_def_id = tcx
133-
.associated_items(trait_def_id)
134+
tcx.associated_items(trait_def_id)
134135
.in_definition_order()
135136
.find(|m| m.kind == ty::AssocKind::Fn)
136137
.unwrap()
137-
.def_id;
138-
Ty::new_fn_def(tcx, method_def_id, [source])
138+
.def_id
139139
}
140140
}
141141

compiler/rustc_mir_build/src/thir/cx/expr.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ impl<'tcx> Cx<'tcx> {
136136
Adjust::Deref(Some(deref)) => {
137137
// We don't need to do call adjust_span here since
138138
// deref coercions always start with a built-in deref.
139-
let call = deref.method_call(self.tcx(), expr.ty);
139+
let call_def_id = deref.method_call(self.tcx());
140+
let overloaded_callee =
141+
Ty::new_fn_def(self.tcx(), call_def_id, self.tcx().mk_args(&[expr.ty.into()]));
140142

141143
expr = Expr {
142144
temp_lifetime,
@@ -150,7 +152,13 @@ impl<'tcx> Cx<'tcx> {
150152

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

153-
self.overloaded_place(hir_expr, adjustment.target, Some(call), expr, deref.span)
155+
self.overloaded_place(
156+
hir_expr,
157+
adjustment.target,
158+
Some(overloaded_callee),
159+
expr,
160+
deref.span,
161+
)
154162
}
155163
Adjust::Borrow(AutoBorrow::Ref(m)) => ExprKind::Borrow {
156164
borrow_kind: m.to_borrow_kind(),

compiler/rustc_monomorphize/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
# tidy-alphabetical-start
8+
rustc_abi = { path = "../rustc_abi" }
89
rustc_data_structures = { path = "../rustc_data_structures" }
910
rustc_errors = { path = "../rustc_errors" }
1011
rustc_fluent_macro = { path = "../rustc_fluent_macro" }

0 commit comments

Comments
 (0)