Skip to content

Commit 0597d65

Browse files
committed
Auto merge of rust-lang#123065 - workingjubilee:rollup-bve45ex, r=workingjubilee
Rollup of 10 pull requests Successful merges: - rust-lang#122707 (Fix a typo in the alloc::string::String docs) - rust-lang#122769 (extend comments for reachability set computation) - rust-lang#122892 (fix(bootstrap/dist): use versioned dirs when vendoring) - rust-lang#122896 (Update stdarch submodule) - rust-lang#122923 (In `pretty_print_type()`, print `async fn` futures' paths instead of spans.) - rust-lang#122950 (Add regression tests for rust-lang#101903) - rust-lang#123039 (Update books) - rust-lang#123042 (Import the 2021 prelude in the core crate) - rust-lang#123044 (`Instance` is `Copy`) - rust-lang#123051 (did I mention that tests are super cool? ) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 5f2c7d2 + 56e8f67 commit 0597d65

Some content is hidden

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

52 files changed

+639
-222
lines changed

compiler/rustc_codegen_llvm/src/builder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1630,7 +1630,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
16301630
}
16311631

16321632
let typeid = if let Some(instance) = instance {
1633-
typeid_for_instance(self.tcx, &instance, options)
1633+
typeid_for_instance(self.tcx, instance, options)
16341634
} else {
16351635
typeid_for_fnabi(self.tcx, fn_abi, options)
16361636
};
@@ -1678,7 +1678,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
16781678
}
16791679

16801680
let kcfi_typeid = if let Some(instance) = instance {
1681-
kcfi_typeid_for_instance(self.tcx, &instance, options)
1681+
kcfi_typeid_for_instance(self.tcx, instance, options)
16821682
} else {
16831683
kcfi_typeid_for_fnabi(self.tcx, fn_abi, options)
16841684
};

compiler/rustc_codegen_llvm/src/declare.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,17 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
141141

142142
if self.tcx.sess.is_sanitizer_cfi_enabled() {
143143
if let Some(instance) = instance {
144-
let typeid = typeid_for_instance(self.tcx, &instance, TypeIdOptions::empty());
144+
let typeid = typeid_for_instance(self.tcx, instance, TypeIdOptions::empty());
145145
self.set_type_metadata(llfn, typeid);
146146
let typeid =
147-
typeid_for_instance(self.tcx, &instance, TypeIdOptions::GENERALIZE_POINTERS);
147+
typeid_for_instance(self.tcx, instance, TypeIdOptions::GENERALIZE_POINTERS);
148148
self.add_type_metadata(llfn, typeid);
149149
let typeid =
150-
typeid_for_instance(self.tcx, &instance, TypeIdOptions::NORMALIZE_INTEGERS);
150+
typeid_for_instance(self.tcx, instance, TypeIdOptions::NORMALIZE_INTEGERS);
151151
self.add_type_metadata(llfn, typeid);
152152
let typeid = typeid_for_instance(
153153
self.tcx,
154-
&instance,
154+
instance,
155155
TypeIdOptions::GENERALIZE_POINTERS | TypeIdOptions::NORMALIZE_INTEGERS,
156156
);
157157
self.add_type_metadata(llfn, typeid);
@@ -182,7 +182,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
182182
}
183183

184184
if let Some(instance) = instance {
185-
let kcfi_typeid = kcfi_typeid_for_instance(self.tcx, &instance, options);
185+
let kcfi_typeid = kcfi_typeid_for_instance(self.tcx, instance, options);
186186
self.set_kcfi_type_metadata(llfn, kcfi_typeid);
187187
} else {
188188
let kcfi_typeid = kcfi_typeid_for_fnabi(self.tcx, fn_abi, options);

compiler/rustc_middle/src/ty/instance.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ impl<'tcx> InstanceDef<'tcx> {
335335

336336
fn fmt_instance(
337337
f: &mut fmt::Formatter<'_>,
338-
instance: &Instance<'_>,
338+
instance: Instance<'_>,
339339
type_length: Option<rustc_session::Limit>,
340340
) -> fmt::Result {
341341
ty::tls::with(|tcx| {
@@ -369,17 +369,17 @@ fn fmt_instance(
369369
}
370370
}
371371

372-
pub struct ShortInstance<'a, 'tcx>(pub &'a Instance<'tcx>, pub usize);
372+
pub struct ShortInstance<'tcx>(pub Instance<'tcx>, pub usize);
373373

374-
impl<'a, 'tcx> fmt::Display for ShortInstance<'a, 'tcx> {
374+
impl<'tcx> fmt::Display for ShortInstance<'tcx> {
375375
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
376376
fmt_instance(f, self.0, Some(rustc_session::Limit(self.1)))
377377
}
378378
}
379379

380380
impl<'tcx> fmt::Display for Instance<'tcx> {
381381
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
382-
fmt_instance(f, self, None)
382+
fmt_instance(f, *self, None)
383383
}
384384
}
385385

compiler/rustc_middle/src/ty/print/pretty.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
804804
}
805805
ty::Str => p!("str"),
806806
ty::Coroutine(did, args) => {
807-
p!(write("{{"));
807+
p!("{{");
808808
let coroutine_kind = self.tcx().coroutine_kind(did).unwrap();
809809
let should_print_movability = self.should_print_verbose()
810810
|| matches!(coroutine_kind, hir::CoroutineKind::Coroutine(_));
@@ -818,17 +818,25 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
818818

819819
if !self.should_print_verbose() {
820820
p!(write("{}", coroutine_kind));
821-
// FIXME(eddyb) should use `def_span`.
822-
if let Some(did) = did.as_local() {
823-
let span = self.tcx().def_span(did);
821+
if coroutine_kind.is_fn_like() {
822+
// If we are printing an `async fn` coroutine type, then give the path
823+
// of the fn, instead of its span, because that will in most cases be
824+
// more helpful for the reader than just a source location.
825+
//
826+
// This will look like:
827+
// {async fn body of some_fn()}
828+
let did_of_the_fn_item = self.tcx().parent(did);
829+
p!(" of ", print_def_path(did_of_the_fn_item, args), "()");
830+
} else if let Some(local_did) = did.as_local() {
831+
let span = self.tcx().def_span(local_did);
824832
p!(write(
825833
"@{}",
826834
// This may end up in stderr diagnostics but it may also be emitted
827835
// into MIR. Hence we use the remapped path if available
828836
self.tcx().sess.source_map().span_to_embeddable_string(span)
829837
));
830838
} else {
831-
p!(write("@"), print_def_path(did, args));
839+
p!("@", print_def_path(did, args));
832840
}
833841
} else {
834842
p!(print_def_path(did, args));

compiler/rustc_mir_transform/src/inline.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl<'tcx> Inliner<'tcx> {
165165
caller_body: &mut Body<'tcx>,
166166
callsite: &CallSite<'tcx>,
167167
) -> Result<std::ops::Range<BasicBlock>, &'static str> {
168-
self.check_mir_is_available(caller_body, &callsite.callee)?;
168+
self.check_mir_is_available(caller_body, callsite.callee)?;
169169

170170
let callee_attrs = self.tcx.codegen_fn_attrs(callsite.callee.def_id());
171171
let cross_crate_inlinable = self.tcx.cross_crate_inlinable(callsite.callee.def_id());
@@ -298,7 +298,7 @@ impl<'tcx> Inliner<'tcx> {
298298
fn check_mir_is_available(
299299
&self,
300300
caller_body: &Body<'tcx>,
301-
callee: &Instance<'tcx>,
301+
callee: Instance<'tcx>,
302302
) -> Result<(), &'static str> {
303303
let caller_def_id = caller_body.source.def_id();
304304
let callee_def_id = callee.def_id();
@@ -354,7 +354,7 @@ impl<'tcx> Inliner<'tcx> {
354354

355355
// If we know for sure that the function we're calling will itself try to
356356
// call us, then we avoid inlining that function.
357-
if self.tcx.mir_callgraph_reachable((*callee, caller_def_id.expect_local())) {
357+
if self.tcx.mir_callgraph_reachable((callee, caller_def_id.expect_local())) {
358358
return Err("caller might be reachable from callee (query cycle avoidance)");
359359
}
360360

compiler/rustc_monomorphize/src/collector.rs

+19-19
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ fn collect_items_rec<'tcx>(
397397
let instance = Instance::mono(tcx, def_id);
398398

399399
// Sanity check whether this ended up being collected accidentally
400-
debug_assert!(should_codegen_locally(tcx, &instance));
400+
debug_assert!(should_codegen_locally(tcx, instance));
401401

402402
let DefKind::Static { nested, .. } = tcx.def_kind(def_id) else { bug!() };
403403
// Nested statics have no type.
@@ -429,7 +429,7 @@ fn collect_items_rec<'tcx>(
429429
}
430430
MonoItem::Fn(instance) => {
431431
// Sanity check whether this ended up being collected accidentally
432-
debug_assert!(should_codegen_locally(tcx, &instance));
432+
debug_assert!(should_codegen_locally(tcx, instance));
433433

434434
// Keep track of the monomorphization recursion depth
435435
recursion_depth_reset = Some(check_recursion_limit(
@@ -474,7 +474,7 @@ fn collect_items_rec<'tcx>(
474474
}
475475
hir::InlineAsmOperand::SymStatic { path: _, def_id } => {
476476
let instance = Instance::mono(tcx, *def_id);
477-
if should_codegen_locally(tcx, &instance) {
477+
if should_codegen_locally(tcx, instance) {
478478
trace!("collecting static {:?}", def_id);
479479
used_items.push(dummy_spanned(MonoItem::Static(*def_id)));
480480
}
@@ -557,7 +557,7 @@ fn collect_items_rec<'tcx>(
557557
/// If the type name is longer than before+after, it will be written to a file.
558558
fn shrunk_instance_name<'tcx>(
559559
tcx: TyCtxt<'tcx>,
560-
instance: &Instance<'tcx>,
560+
instance: Instance<'tcx>,
561561
) -> (String, Option<PathBuf>) {
562562
let s = instance.to_string();
563563

@@ -603,7 +603,7 @@ fn check_recursion_limit<'tcx>(
603603
if !recursion_limit.value_within_limit(adjusted_recursion_depth) {
604604
let def_span = tcx.def_span(def_id);
605605
let def_path_str = tcx.def_path_str(def_id);
606-
let (shrunk, written_to_path) = shrunk_instance_name(tcx, &instance);
606+
let (shrunk, written_to_path) = shrunk_instance_name(tcx, instance);
607607
let mut path = PathBuf::new();
608608
let was_written = if let Some(written_to_path) = written_to_path {
609609
path = written_to_path;
@@ -645,7 +645,7 @@ fn check_type_length_limit<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) {
645645
//
646646
// Bail out in these cases to avoid that bad user experience.
647647
if !tcx.type_length_limit().value_within_limit(type_length) {
648-
let (shrunk, written_to_path) = shrunk_instance_name(tcx, &instance);
648+
let (shrunk, written_to_path) = shrunk_instance_name(tcx, instance);
649649
let span = tcx.def_span(instance.def_id());
650650
let mut path = PathBuf::new();
651651
let was_written = if let Some(path2) = written_to_path {
@@ -892,7 +892,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
892892
if let ty::Closure(def_id, args) = *source_ty.kind() {
893893
let instance =
894894
Instance::resolve_closure(self.tcx, def_id, args, ty::ClosureKind::FnOnce);
895-
if should_codegen_locally(self.tcx, &instance) {
895+
if should_codegen_locally(self.tcx, instance) {
896896
self.used_items.push(create_fn_mono_item(self.tcx, instance, span));
897897
}
898898
} else {
@@ -902,7 +902,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
902902
mir::Rvalue::ThreadLocalRef(def_id) => {
903903
assert!(self.tcx.is_thread_local_static(def_id));
904904
let instance = Instance::mono(self.tcx, def_id);
905-
if should_codegen_locally(self.tcx, &instance) {
905+
if should_codegen_locally(self.tcx, instance) {
906906
trace!("collecting thread-local static {:?}", def_id);
907907
self.used_items.push(respan(span, MonoItem::Static(def_id)));
908908
}
@@ -929,7 +929,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
929929
let tcx = self.tcx;
930930
let push_mono_lang_item = |this: &mut Self, lang_item: LangItem| {
931931
let instance = Instance::mono(tcx, tcx.require_lang_item(lang_item, Some(source)));
932-
if should_codegen_locally(tcx, &instance) {
932+
if should_codegen_locally(tcx, instance) {
933933
this.used_items.push(create_fn_mono_item(tcx, instance, source));
934934
}
935935
};
@@ -962,7 +962,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
962962
}
963963
mir::InlineAsmOperand::SymStatic { def_id } => {
964964
let instance = Instance::mono(self.tcx, def_id);
965-
if should_codegen_locally(self.tcx, &instance) {
965+
if should_codegen_locally(self.tcx, instance) {
966966
trace!("collecting asm sym static {:?}", def_id);
967967
self.used_items.push(respan(source, MonoItem::Static(def_id)));
968968
}
@@ -1051,7 +1051,7 @@ fn visit_instance_use<'tcx>(
10511051
output: &mut MonoItems<'tcx>,
10521052
) {
10531053
debug!("visit_item_use({:?}, is_direct_call={:?})", instance, is_direct_call);
1054-
if !should_codegen_locally(tcx, &instance) {
1054+
if !should_codegen_locally(tcx, instance) {
10551055
return;
10561056
}
10571057
if let ty::InstanceDef::Intrinsic(def_id) = instance.def {
@@ -1063,13 +1063,13 @@ fn visit_instance_use<'tcx>(
10631063
// codegen a call to that function without generating code for the function itself.
10641064
let def_id = tcx.lang_items().get(LangItem::PanicNounwind).unwrap();
10651065
let panic_instance = Instance::mono(tcx, def_id);
1066-
if should_codegen_locally(tcx, &panic_instance) {
1066+
if should_codegen_locally(tcx, panic_instance) {
10671067
output.push(create_fn_mono_item(tcx, panic_instance, source));
10681068
}
10691069
} else if tcx.has_attr(def_id, sym::rustc_intrinsic) {
10701070
// Codegen the fallback body of intrinsics with fallback bodies
10711071
let instance = ty::Instance::new(def_id, instance.args);
1072-
if should_codegen_locally(tcx, &instance) {
1072+
if should_codegen_locally(tcx, instance) {
10731073
output.push(create_fn_mono_item(tcx, instance, source));
10741074
}
10751075
}
@@ -1107,7 +1107,7 @@ fn visit_instance_use<'tcx>(
11071107

11081108
/// Returns `true` if we should codegen an instance in the local crate, or returns `false` if we
11091109
/// can just link to the upstream crate and therefore don't need a mono item.
1110-
pub(crate) fn should_codegen_locally<'tcx>(tcx: TyCtxt<'tcx>, instance: &Instance<'tcx>) -> bool {
1110+
pub(crate) fn should_codegen_locally<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> bool {
11111111
let Some(def_id) = instance.def.def_id_if_not_guaranteed_local_codegen() else {
11121112
return true;
11131113
};
@@ -1304,7 +1304,7 @@ fn create_mono_items_for_vtable_methods<'tcx>(
13041304
None
13051305
}
13061306
VtblEntry::Method(instance) => {
1307-
Some(*instance).filter(|instance| should_codegen_locally(tcx, instance))
1307+
Some(*instance).filter(|instance| should_codegen_locally(tcx, *instance))
13081308
}
13091309
})
13101310
.map(|item| create_fn_mono_item(tcx, item, source));
@@ -1321,7 +1321,7 @@ fn collect_alloc<'tcx>(tcx: TyCtxt<'tcx>, alloc_id: AllocId, output: &mut MonoIt
13211321
GlobalAlloc::Static(def_id) => {
13221322
assert!(!tcx.is_thread_local_static(def_id));
13231323
let instance = Instance::mono(tcx, def_id);
1324-
if should_codegen_locally(tcx, &instance) {
1324+
if should_codegen_locally(tcx, instance) {
13251325
trace!("collecting static {:?}", def_id);
13261326
output.push(dummy_spanned(MonoItem::Static(def_id)));
13271327
}
@@ -1339,7 +1339,7 @@ fn collect_alloc<'tcx>(tcx: TyCtxt<'tcx>, alloc_id: AllocId, output: &mut MonoIt
13391339
}
13401340
}
13411341
GlobalAlloc::Function(fn_instance) => {
1342-
if should_codegen_locally(tcx, &fn_instance) {
1342+
if should_codegen_locally(tcx, fn_instance) {
13431343
trace!("collecting {:?} with {:#?}", alloc_id, fn_instance);
13441344
output.push(create_fn_mono_item(tcx, fn_instance, DUMMY_SP));
13451345
}
@@ -1474,7 +1474,7 @@ fn visit_mentioned_item<'tcx>(
14741474
if let ty::Closure(def_id, args) = *source_ty.kind() {
14751475
let instance =
14761476
Instance::resolve_closure(tcx, def_id, args, ty::ClosureKind::FnOnce);
1477-
if should_codegen_locally(tcx, &instance) {
1477+
if should_codegen_locally(tcx, instance) {
14781478
output.push(create_fn_mono_item(tcx, instance, span));
14791479
}
14801480
} else {
@@ -1736,7 +1736,7 @@ fn create_mono_items_for_default_impls<'tcx>(
17361736
let instance = ty::Instance::expect_resolve(tcx, param_env, method.def_id, args);
17371737

17381738
let mono_item = create_fn_mono_item(tcx, instance, DUMMY_SP);
1739-
if mono_item.node.is_instantiable(tcx) && should_codegen_locally(tcx, &instance) {
1739+
if mono_item.node.is_instantiable(tcx) && should_codegen_locally(tcx, instance) {
17401740
output.push(mono_item);
17411741
}
17421742
}

compiler/rustc_monomorphize/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub fn is_call_from_compiler_builtins_to_upstream_monomorphization<'tcx>(
6464
!instance.def_id().is_local()
6565
&& tcx.is_compiler_builtins(LOCAL_CRATE)
6666
&& tcx.codegen_fn_attrs(instance.def_id()).link_name.is_none()
67-
&& !should_codegen_locally(tcx, &instance)
67+
&& !should_codegen_locally(tcx, instance)
6868
}
6969

7070
pub fn provide(providers: &mut Providers) {

0 commit comments

Comments
 (0)