Skip to content

Commit 62ef90c

Browse files
committed
Auto merge of #3684 - rust-lang:rustup-2024-06-18, r=RalfJung
Automatic Rustup
2 parents af55a4a + ca06b3b commit 62ef90c

File tree

167 files changed

+2091
-1538
lines changed

Some content is hidden

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

167 files changed

+2091
-1538
lines changed

RELEASES.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ Cargo
9797
- [Prevent dashes in `lib.name`, always normalizing to `_`.](https://github.com/rust-lang/cargo/pull/12783/)
9898
- [Stabilize MSRV-aware version requirement selection in `cargo add`.](https://github.com/rust-lang/cargo/pull/13608/)
9999
- [Switch to using `gitoxide` by default for listing files.](https://github.com/rust-lang/cargo/pull/13696/)
100-
- [Error on `[project]` in Edition 2024; `cargo fix --edition` will change it to `[package]`.](https://github.com/rust-lang/cargo/pull/13747/)
101100

102101
<a id="1.79.0-Rustdoc"></a>
103102

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 71 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_hir::intravisit::Visitor;
88
use rustc_hir::{self as hir, BindingMode, ByRef, Node};
99
use rustc_middle::bug;
1010
use rustc_middle::mir::{Mutability, Place, PlaceRef, ProjectionElem};
11-
use rustc_middle::ty::{self, InstanceDef, Ty, TyCtxt, Upcast};
11+
use rustc_middle::ty::{self, InstanceKind, Ty, TyCtxt, Upcast};
1212
use rustc_middle::{
1313
hir::place::PlaceBase,
1414
mir::{self, BindingForm, Local, LocalDecl, LocalInfo, LocalKind, Location},
@@ -937,56 +937,81 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
937937
let node = self.infcx.tcx.hir_node(fn_call_id);
938938
let def_id = hir.enclosing_body_owner(fn_call_id);
939939
let mut look_at_return = true;
940-
// If we can detect the expression to be an `fn` call where the closure was an argument,
941-
// we point at the `fn` definition argument...
942-
if let hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Call(func, args), .. }) = node {
943-
let arg_pos = args
940+
941+
// If the HIR node is a function or method call gets the def ID
942+
// of the called function or method and the span and args of the call expr
943+
let get_call_details = || {
944+
let hir::Node::Expr(hir::Expr { hir_id, kind, .. }) = node else {
945+
return None;
946+
};
947+
948+
let typeck_results = self.infcx.tcx.typeck(def_id);
949+
950+
match kind {
951+
hir::ExprKind::Call(expr, args) => {
952+
if let Some(ty::FnDef(def_id, _)) =
953+
typeck_results.node_type_opt(expr.hir_id).as_ref().map(|ty| ty.kind())
954+
{
955+
Some((*def_id, expr.span, *args))
956+
} else {
957+
None
958+
}
959+
}
960+
hir::ExprKind::MethodCall(_, _, args, span) => {
961+
if let Some(def_id) = typeck_results.type_dependent_def_id(*hir_id) {
962+
Some((def_id, *span, *args))
963+
} else {
964+
None
965+
}
966+
}
967+
_ => None,
968+
}
969+
};
970+
971+
// If we can detect the expression to be an function or method call where the closure was an argument,
972+
// we point at the function or method definition argument...
973+
if let Some((callee_def_id, call_span, call_args)) = get_call_details() {
974+
let arg_pos = call_args
944975
.iter()
945976
.enumerate()
946977
.filter(|(_, arg)| arg.hir_id == closure_id)
947978
.map(|(pos, _)| pos)
948979
.next();
949-
let tables = self.infcx.tcx.typeck(def_id);
950-
if let Some(ty::FnDef(def_id, _)) =
951-
tables.node_type_opt(func.hir_id).as_ref().map(|ty| ty.kind())
952-
{
953-
let arg = match hir.get_if_local(*def_id) {
954-
Some(
955-
hir::Node::Item(hir::Item {
956-
ident, kind: hir::ItemKind::Fn(sig, ..), ..
957-
})
958-
| hir::Node::TraitItem(hir::TraitItem {
959-
ident,
960-
kind: hir::TraitItemKind::Fn(sig, _),
961-
..
980+
981+
let arg = match hir.get_if_local(callee_def_id) {
982+
Some(
983+
hir::Node::Item(hir::Item { ident, kind: hir::ItemKind::Fn(sig, ..), .. })
984+
| hir::Node::TraitItem(hir::TraitItem {
985+
ident,
986+
kind: hir::TraitItemKind::Fn(sig, _),
987+
..
988+
})
989+
| hir::Node::ImplItem(hir::ImplItem {
990+
ident,
991+
kind: hir::ImplItemKind::Fn(sig, _),
992+
..
993+
}),
994+
) => Some(
995+
arg_pos
996+
.and_then(|pos| {
997+
sig.decl.inputs.get(
998+
pos + if sig.decl.implicit_self.has_implicit_self() {
999+
1
1000+
} else {
1001+
0
1002+
},
1003+
)
9621004
})
963-
| hir::Node::ImplItem(hir::ImplItem {
964-
ident,
965-
kind: hir::ImplItemKind::Fn(sig, _),
966-
..
967-
}),
968-
) => Some(
969-
arg_pos
970-
.and_then(|pos| {
971-
sig.decl.inputs.get(
972-
pos + if sig.decl.implicit_self.has_implicit_self() {
973-
1
974-
} else {
975-
0
976-
},
977-
)
978-
})
979-
.map(|arg| arg.span)
980-
.unwrap_or(ident.span),
981-
),
982-
_ => None,
983-
};
984-
if let Some(span) = arg {
985-
err.span_label(span, "change this to accept `FnMut` instead of `Fn`");
986-
err.span_label(func.span, "expects `Fn` instead of `FnMut`");
987-
err.span_label(closure_span, "in this closure");
988-
look_at_return = false;
989-
}
1005+
.map(|arg| arg.span)
1006+
.unwrap_or(ident.span),
1007+
),
1008+
_ => None,
1009+
};
1010+
if let Some(span) = arg {
1011+
err.span_label(span, "change this to accept `FnMut` instead of `Fn`");
1012+
err.span_label(call_span, "expects `Fn` instead of `FnMut`");
1013+
err.span_label(closure_span, "in this closure");
1014+
look_at_return = false;
9901015
}
9911016
}
9921017

@@ -1020,7 +1045,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
10201045
fn suggest_using_iter_mut(&self, err: &mut Diag<'_>) {
10211046
let source = self.body.source;
10221047
let hir = self.infcx.tcx.hir();
1023-
if let InstanceDef::Item(def_id) = source.instance
1048+
if let InstanceKind::Item(def_id) = source.instance
10241049
&& let Some(Node::Expr(hir::Expr { hir_id, kind, .. })) = hir.get_if_local(def_id)
10251050
&& let ExprKind::Closure(hir::Closure { kind: hir::ClosureKind::Closure, .. }) = kind
10261051
&& let Node::Expr(expr) = self.infcx.tcx.parent_hir_node(*hir_id)

compiler/rustc_borrowck/src/diagnostics/region_name.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -628,9 +628,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
628628
| GenericArgKind::Const(_),
629629
_,
630630
) => {
631-
// This was previously a `span_delayed_bug` and could be
632-
// reached by the test for #82126, but no longer.
633-
self.dcx().span_bug(
631+
self.dcx().span_delayed_bug(
634632
hir_arg.span(),
635633
format!("unmatched arg and hir arg: found {kind:?} vs {hir_arg:?}"),
636634
);

compiler/rustc_codegen_cranelift/src/abi/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
399399
}
400400

401401
match instance.def {
402-
InstanceDef::Intrinsic(_) => {
402+
InstanceKind::Intrinsic(_) => {
403403
match crate::intrinsics::codegen_intrinsic_call(
404404
fx,
405405
instance,
@@ -412,7 +412,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
412412
Err(instance) => Some(instance),
413413
}
414414
}
415-
InstanceDef::DropGlue(_, None) | ty::InstanceDef::AsyncDropGlueCtorShim(_, None) => {
415+
InstanceKind::DropGlue(_, None) | ty::InstanceKind::AsyncDropGlueCtorShim(_, None) => {
416416
// empty drop glue - a nop.
417417
let dest = target.expect("Non terminating drop_in_place_real???");
418418
let ret_block = fx.get_block(dest);
@@ -494,7 +494,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
494494

495495
let (func_ref, first_arg_override) = match instance {
496496
// Trait object call
497-
Some(Instance { def: InstanceDef::Virtual(_, idx), .. }) => {
497+
Some(Instance { def: InstanceKind::Virtual(_, idx), .. }) => {
498498
if fx.clif_comments.enabled() {
499499
let nop_inst = fx.bcx.ins().nop();
500500
fx.add_comment(
@@ -598,7 +598,7 @@ pub(crate) fn codegen_drop<'tcx>(
598598
let ty = drop_place.layout().ty;
599599
let drop_instance = Instance::resolve_drop_in_place(fx.tcx, ty).polymorphize(fx.tcx);
600600

601-
if let ty::InstanceDef::DropGlue(_, None) | ty::InstanceDef::AsyncDropGlueCtorShim(_, None) =
601+
if let ty::InstanceKind::DropGlue(_, None) | ty::InstanceKind::AsyncDropGlueCtorShim(_, None) =
602602
drop_instance.def
603603
{
604604
// we don't actually need to drop anything
@@ -630,7 +630,7 @@ pub(crate) fn codegen_drop<'tcx>(
630630
// FIXME(eddyb) perhaps move some of this logic into
631631
// `Instance::resolve_drop_in_place`?
632632
let virtual_drop = Instance {
633-
def: ty::InstanceDef::Virtual(drop_instance.def_id(), 0),
633+
def: ty::InstanceKind::Virtual(drop_instance.def_id(), 0),
634634
args: drop_instance.args,
635635
};
636636
let fn_abi =
@@ -673,7 +673,7 @@ pub(crate) fn codegen_drop<'tcx>(
673673
fx.bcx.switch_to_block(continued);
674674

675675
let virtual_drop = Instance {
676-
def: ty::InstanceDef::Virtual(drop_instance.def_id(), 0),
676+
def: ty::InstanceKind::Virtual(drop_instance.def_id(), 0),
677677
args: drop_instance.args,
678678
};
679679
let fn_abi =
@@ -684,7 +684,7 @@ pub(crate) fn codegen_drop<'tcx>(
684684
fx.bcx.ins().call_indirect(sig, drop_fn, &[data]);
685685
}
686686
_ => {
687-
assert!(!matches!(drop_instance.def, InstanceDef::Virtual(_, _)));
687+
assert!(!matches!(drop_instance.def, InstanceKind::Virtual(_, _)));
688688

689689
let fn_abi =
690690
RevealAllLayoutCx(fx.tcx).fn_abi_of_instance(drop_instance, ty::List::empty());

compiler/rustc_codegen_cranelift/src/constant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub(crate) fn codegen_tls_ref<'tcx>(
5050
) -> CValue<'tcx> {
5151
let tls_ptr = if !def_id.is_local() && fx.tcx.needs_thread_local_shim(def_id) {
5252
let instance = ty::Instance {
53-
def: ty::InstanceDef::ThreadLocalShim(def_id),
53+
def: ty::InstanceKind::ThreadLocalShim(def_id),
5454
args: ty::GenericArgs::empty(),
5555
};
5656
let func_ref = fx.get_function_ref(instance);

compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
12611261
}
12621262

12631263
// Unimplemented intrinsics must have a fallback body. The fallback body is obtained
1264-
// by converting the `InstanceDef::Intrinsic` to an `InstanceDef::Item`.
1264+
// by converting the `InstanceKind::Intrinsic` to an `InstanceKind::Item`.
12651265
_ => {
12661266
let intrinsic = fx.tcx.intrinsic(instance.def_id()).unwrap();
12671267
if intrinsic.must_be_overridden {

compiler/rustc_codegen_cranelift/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ mod prelude {
9898
pub(crate) use rustc_middle::mir::{self, *};
9999
pub(crate) use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
100100
pub(crate) use rustc_middle::ty::{
101-
self, FloatTy, Instance, InstanceDef, IntTy, ParamEnv, Ty, TyCtxt, UintTy,
101+
self, FloatTy, Instance, InstanceKind, IntTy, ParamEnv, Ty, TyCtxt, UintTy,
102102
};
103103
pub(crate) use rustc_span::Span;
104104
pub(crate) use rustc_target::abi::{Abi, FieldIdx, Scalar, Size, VariantIdx, FIRST_VARIANT};

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ fn exported_symbols_provider_local(
310310

311311
if tcx.sess.opts.share_generics() && tcx.local_crate_exports_generics() {
312312
use rustc_middle::mir::mono::{Linkage, MonoItem, Visibility};
313-
use rustc_middle::ty::InstanceDef;
313+
use rustc_middle::ty::InstanceKind;
314314

315315
// Normally, we require that shared monomorphizations are not hidden,
316316
// because if we want to re-use a monomorphization from a Rust dylib, it
@@ -337,7 +337,7 @@ fn exported_symbols_provider_local(
337337
}
338338

339339
match *mono_item {
340-
MonoItem::Fn(Instance { def: InstanceDef::Item(def), args }) => {
340+
MonoItem::Fn(Instance { def: InstanceKind::Item(def), args }) => {
341341
if args.non_erasable_generics(tcx, def).next().is_some() {
342342
let symbol = ExportedSymbol::Generic(def, args);
343343
symbols.push((
@@ -350,7 +350,7 @@ fn exported_symbols_provider_local(
350350
));
351351
}
352352
}
353-
MonoItem::Fn(Instance { def: InstanceDef::DropGlue(def_id, Some(ty)), args }) => {
353+
MonoItem::Fn(Instance { def: InstanceKind::DropGlue(def_id, Some(ty)), args }) => {
354354
// A little sanity-check
355355
debug_assert_eq!(
356356
args.non_erasable_generics(tcx, def_id).next(),
@@ -366,7 +366,7 @@ fn exported_symbols_provider_local(
366366
));
367367
}
368368
MonoItem::Fn(Instance {
369-
def: InstanceDef::AsyncDropGlueCtorShim(def_id, Some(ty)),
369+
def: InstanceKind::AsyncDropGlueCtorShim(def_id, Some(ty)),
370370
args,
371371
}) => {
372372
// A little sanity-check
@@ -556,7 +556,7 @@ pub fn symbol_name_for_instance_in_crate<'tcx>(
556556
rustc_symbol_mangling::symbol_name_for_instance_in_crate(
557557
tcx,
558558
ty::Instance {
559-
def: ty::InstanceDef::ThreadLocalShim(def_id),
559+
def: ty::InstanceKind::ThreadLocalShim(def_id),
560560
args: ty::GenericArgs::empty(),
561561
},
562562
instantiating_crate,

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
510510
let ty = self.monomorphize(ty);
511511
let drop_fn = Instance::resolve_drop_in_place(bx.tcx(), ty);
512512

513-
if let ty::InstanceDef::DropGlue(_, None) = drop_fn.def {
513+
if let ty::InstanceKind::DropGlue(_, None) = drop_fn.def {
514514
// we don't actually need to drop anything.
515515
return helper.funclet_br(self, bx, target, mergeable_succ);
516516
}
@@ -541,7 +541,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
541541
// \-------/
542542
//
543543
let virtual_drop = Instance {
544-
def: ty::InstanceDef::Virtual(drop_fn.def_id(), 0), // idx 0: the drop function
544+
def: ty::InstanceKind::Virtual(drop_fn.def_id(), 0), // idx 0: the drop function
545545
args: drop_fn.args,
546546
};
547547
debug!("ty = {:?}", ty);
@@ -583,7 +583,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
583583
//
584584
// SO THEN WE CAN USE THE ABOVE CODE.
585585
let virtual_drop = Instance {
586-
def: ty::InstanceDef::Virtual(drop_fn.def_id(), 0), // idx 0: the drop function
586+
def: ty::InstanceKind::Virtual(drop_fn.def_id(), 0), // idx 0: the drop function
587587
args: drop_fn.args,
588588
};
589589
debug!("ty = {:?}", ty);
@@ -855,7 +855,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
855855
let def = instance.map(|i| i.def);
856856

857857
if let Some(
858-
ty::InstanceDef::DropGlue(_, None) | ty::InstanceDef::AsyncDropGlueCtorShim(_, None),
858+
ty::InstanceKind::DropGlue(_, None) | ty::InstanceKind::AsyncDropGlueCtorShim(_, None),
859859
) = def
860860
{
861861
// Empty drop glue; a no-op.
@@ -871,7 +871,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
871871

872872
// Handle intrinsics old codegen wants Expr's for, ourselves.
873873
let intrinsic = match def {
874-
Some(ty::InstanceDef::Intrinsic(def_id)) => Some(bx.tcx().intrinsic(def_id).unwrap()),
874+
Some(ty::InstanceKind::Intrinsic(def_id)) => Some(bx.tcx().intrinsic(def_id).unwrap()),
875875
_ => None,
876876
};
877877

@@ -1026,7 +1026,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
10261026
'make_args: for (i, arg) in first_args.iter().enumerate() {
10271027
let mut op = self.codegen_operand(bx, &arg.node);
10281028

1029-
if let (0, Some(ty::InstanceDef::Virtual(_, idx))) = (i, def) {
1029+
if let (0, Some(ty::InstanceKind::Virtual(_, idx))) = (i, def) {
10301030
match op.val {
10311031
Pair(data_ptr, meta) => {
10321032
// In the case of Rc<Self>, we need to explicitly pass a

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
704704
let static_ = if !def_id.is_local() && bx.cx().tcx().needs_thread_local_shim(def_id)
705705
{
706706
let instance = ty::Instance {
707-
def: ty::InstanceDef::ThreadLocalShim(def_id),
707+
def: ty::InstanceKind::ThreadLocalShim(def_id),
708708
args: ty::GenericArgs::empty(),
709709
};
710710
let fn_ptr = bx.get_fn_addr(instance);

compiler/rustc_const_eval/messages.ftl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,6 @@ const_eval_unwind_past_top =
399399
400400
## The `front_matter`s here refer to either `const_eval_front_matter_invalid_value` or `const_eval_front_matter_invalid_value_with_path`.
401401
## (We'd love to sort this differently to make that more clear but tidy won't let us...)
402-
const_eval_validation_box_to_static = {$front_matter}: encountered a box pointing to a static variable in a constant
403402
const_eval_validation_box_to_uninhabited = {$front_matter}: encountered a box pointing to uninhabited type {$ty}
404403
405404
const_eval_validation_const_ref_to_extern = {$front_matter}: encountered reference to `extern` static in `const`
@@ -454,7 +453,6 @@ const_eval_validation_out_of_range = {$front_matter}: encountered {$value}, but
454453
const_eval_validation_partial_pointer = {$front_matter}: encountered a partial pointer or a mix of pointers
455454
const_eval_validation_pointer_as_int = {$front_matter}: encountered a pointer, but {$expected}
456455
const_eval_validation_ptr_out_of_range = {$front_matter}: encountered a pointer, but expected something that cannot possibly fail to be {$in_range}
457-
const_eval_validation_ref_to_static = {$front_matter}: encountered a reference pointing to a static variable in a constant
458456
const_eval_validation_ref_to_uninhabited = {$front_matter}: encountered a reference pointing to uninhabited type {$ty}
459457
const_eval_validation_unaligned_box = {$front_matter}: encountered an unaligned box (required {$required_bytes} byte alignment but found {$found_bytes})
460458
const_eval_validation_unaligned_ref = {$front_matter}: encountered an unaligned reference (required {$required_bytes} byte alignment but found {$found_bytes})

0 commit comments

Comments
 (0)