Skip to content

Commit aabb52e

Browse files
committed
Auto merge of #126821 - matthiaskrgr:rollup-cg3le1f, r=matthiaskrgr
Rollup of 3 pull requests Successful merges: - #116113 ( Generalize `{Rc,Arc}::make_mut()` to unsized types.) - #126686 (Add `#[rustc_dump_{predicates,item_bounds}]`) - #126731 (Bootstrap command refactoring: refactor `BootstrapCommand` (step 1)) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f1b0d54 + ec876dd commit aabb52e

File tree

30 files changed

+809
-268
lines changed

30 files changed

+809
-268
lines changed

compiler/rustc_feature/src/builtin_attrs.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,14 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
10881088
ErrorFollowing, EncodeCrossCrate::No,
10891089
"the `#[custom_mir]` attribute is just used for the Rust test suite",
10901090
),
1091+
rustc_attr!(
1092+
TEST, rustc_dump_item_bounds, Normal, template!(Word),
1093+
WarnFollowing, EncodeCrossCrate::No
1094+
),
1095+
rustc_attr!(
1096+
TEST, rustc_dump_predicates, Normal, template!(Word),
1097+
WarnFollowing, EncodeCrossCrate::No
1098+
),
10911099
rustc_attr!(
10921100
TEST, rustc_object_lifetime_default, Normal, template!(Word),
10931101
WarnFollowing, EncodeCrossCrate::No

compiler/rustc_hir_analysis/messages.ftl

+2-2
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ hir_analysis_ty_param_some = type parameter `{$param}` must be used as the type
510510
.note = implementing a foreign trait is only possible if at least one of the types for which it is implemented is local
511511
.only_note = only traits defined in the current crate can be implemented for a type parameter
512512
513-
hir_analysis_type_of = {$type_of}
513+
hir_analysis_type_of = {$ty}
514514
515515
hir_analysis_typeof_reserved_keyword_used =
516516
`typeof` is a reserved keyword but unimplemented
@@ -566,7 +566,7 @@ hir_analysis_value_of_associated_struct_already_specified =
566566
hir_analysis_variadic_function_compatible_convention = C-variadic function must have a compatible calling convention, like {$conventions}
567567
.label = C-variadic function must have a compatible calling convention
568568
569-
hir_analysis_variances_of = {$variances_of}
569+
hir_analysis_variances_of = {$variances}
570570
571571
hir_analysis_where_clause_on_main = `main` function is not allowed to have a `where` clause
572572
.label = `main` cannot have a `where` clause

compiler/rustc_hir_analysis/src/collect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ use std::ops::Bound;
4545
use crate::check::intrinsic::intrinsic_operation_unsafety;
4646
use crate::errors;
4747
use crate::hir_ty_lowering::{HirTyLowerer, RegionInferReason};
48-
pub use type_of::test_opaque_hidden_types;
4948

49+
pub(crate) mod dump;
5050
mod generics_of;
5151
mod item_bounds;
5252
mod predicates_of;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
use rustc_hir::def::DefKind;
2+
use rustc_hir::def_id::CRATE_DEF_ID;
3+
use rustc_middle::ty::TyCtxt;
4+
use rustc_span::sym;
5+
6+
pub(crate) fn opaque_hidden_types(tcx: TyCtxt<'_>) {
7+
if !tcx.has_attr(CRATE_DEF_ID, sym::rustc_hidden_type_of_opaques) {
8+
return;
9+
}
10+
11+
for id in tcx.hir().items() {
12+
let DefKind::OpaqueTy = tcx.def_kind(id.owner_id) else { continue };
13+
14+
let ty = tcx.type_of(id.owner_id).instantiate_identity();
15+
16+
tcx.dcx().emit_err(crate::errors::TypeOf { span: tcx.def_span(id.owner_id), ty });
17+
}
18+
}
19+
20+
pub(crate) fn predicates_and_item_bounds(tcx: TyCtxt<'_>) {
21+
for id in tcx.hir_crate_items(()).owners() {
22+
if tcx.has_attr(id, sym::rustc_dump_predicates) {
23+
let preds = tcx.predicates_of(id).instantiate_identity(tcx).predicates;
24+
let span = tcx.def_span(id);
25+
26+
let mut diag = tcx.dcx().struct_span_err(span, sym::rustc_dump_predicates.as_str());
27+
for pred in preds {
28+
diag.note(format!("{pred:?}"));
29+
}
30+
diag.emit();
31+
}
32+
if tcx.has_attr(id, sym::rustc_dump_item_bounds) {
33+
let bounds = tcx.item_bounds(id).instantiate_identity();
34+
let span = tcx.def_span(id);
35+
36+
let mut diag = tcx.dcx().struct_span_err(span, sym::rustc_dump_item_bounds.as_str());
37+
for bound in bounds {
38+
diag.note(format!("{bound:?}"));
39+
}
40+
diag.emit();
41+
}
42+
}
43+
}

compiler/rustc_hir_analysis/src/collect/type_of.rs

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use crate::errors::TypeofReservedKeywordUsed;
1515

1616
use super::bad_placeholder;
1717
use super::ItemCtxt;
18-
pub use opaque::test_opaque_hidden_types;
1918

2019
mod opaque;
2120

compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs

+3-17
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,14 @@
11
use rustc_errors::StashKey;
22
use rustc_hir::def::DefKind;
3-
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
3+
use rustc_hir::def_id::LocalDefId;
44
use rustc_hir::intravisit::{self, Visitor};
55
use rustc_hir::{self as hir, def, Expr, ImplItem, Item, Node, TraitItem};
66
use rustc_middle::bug;
77
use rustc_middle::hir::nested_filter;
88
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
9-
use rustc_span::{sym, ErrorGuaranteed, DUMMY_SP};
9+
use rustc_span::DUMMY_SP;
1010

11-
use crate::errors::{TaitForwardCompat, TaitForwardCompat2, TypeOf, UnconstrainedOpaqueType};
12-
13-
pub fn test_opaque_hidden_types(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
14-
let mut res = Ok(());
15-
if tcx.has_attr(CRATE_DEF_ID, sym::rustc_hidden_type_of_opaques) {
16-
for id in tcx.hir().items() {
17-
if matches!(tcx.def_kind(id.owner_id), DefKind::OpaqueTy) {
18-
let type_of = tcx.type_of(id.owner_id).instantiate_identity();
19-
20-
res = Err(tcx.dcx().emit_err(TypeOf { span: tcx.def_span(id.owner_id), type_of }));
21-
}
22-
}
23-
}
24-
res
25-
}
11+
use crate::errors::{TaitForwardCompat, TaitForwardCompat2, UnconstrainedOpaqueType};
2612

2713
/// Checks "defining uses" of opaque `impl Trait` in associated types.
2814
/// These can only be defined by associated items of the same trait.

compiler/rustc_hir_analysis/src/errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -682,15 +682,15 @@ pub(crate) enum CannotCaptureLateBound {
682682
pub(crate) struct VariancesOf {
683683
#[primary_span]
684684
pub span: Span,
685-
pub variances_of: String,
685+
pub variances: String,
686686
}
687687

688688
#[derive(Diagnostic)]
689689
#[diag(hir_analysis_type_of)]
690690
pub(crate) struct TypeOf<'tcx> {
691691
#[primary_span]
692692
pub span: Span,
693-
pub type_of: Ty<'tcx>,
693+
pub ty: Ty<'tcx>,
694694
}
695695

696696
#[derive(Diagnostic)]

compiler/rustc_hir_analysis/src/lib.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,6 @@ pub fn provide(providers: &mut Providers) {
151151
pub fn check_crate(tcx: TyCtxt<'_>) {
152152
let _prof_timer = tcx.sess.timer("type_check_crate");
153153

154-
if tcx.features().rustc_attrs {
155-
let _ = tcx.sess.time("outlives_testing", || outlives::test::test_inferred_outlives(tcx));
156-
}
157-
158154
tcx.sess.time("coherence_checking", || {
159155
tcx.hir().par_for_each_module(|module| {
160156
let _ = tcx.ensure().check_mod_type_wf(module);
@@ -169,11 +165,10 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
169165
});
170166

171167
if tcx.features().rustc_attrs {
172-
let _ = tcx.sess.time("variance_testing", || variance::test::test_variance(tcx));
173-
}
174-
175-
if tcx.features().rustc_attrs {
176-
let _ = collect::test_opaque_hidden_types(tcx);
168+
tcx.sess.time("outlives_dumping", || outlives::dump::inferred_outlives(tcx));
169+
tcx.sess.time("variance_dumping", || variance::dump::variances(tcx));
170+
collect::dump::opaque_hidden_types(tcx);
171+
collect::dump::predicates_and_item_bounds(tcx);
177172
}
178173

179174
// Make sure we evaluate all static and (non-associated) const items, even if unused.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use rustc_middle::bug;
2+
use rustc_middle::ty::{self, TyCtxt};
3+
use rustc_span::sym;
4+
5+
pub(crate) fn inferred_outlives(tcx: TyCtxt<'_>) {
6+
for id in tcx.hir().items() {
7+
if !tcx.has_attr(id.owner_id, sym::rustc_outlives) {
8+
continue;
9+
}
10+
11+
let preds = tcx.inferred_outlives_of(id.owner_id);
12+
let mut preds: Vec<_> = preds
13+
.iter()
14+
.map(|(pred, _)| match pred.kind().skip_binder() {
15+
ty::ClauseKind::RegionOutlives(p) => p.to_string(),
16+
ty::ClauseKind::TypeOutlives(p) => p.to_string(),
17+
err => bug!("unexpected clause {:?}", err),
18+
})
19+
.collect();
20+
preds.sort();
21+
22+
let span = tcx.def_span(id.owner_id);
23+
let mut err = tcx.dcx().struct_span_err(span, sym::rustc_outlives.as_str());
24+
for pred in preds {
25+
err.note(pred);
26+
}
27+
err.emit();
28+
}
29+
}

compiler/rustc_hir_analysis/src/outlives/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ use rustc_middle::ty::GenericArgKind;
55
use rustc_middle::ty::{self, CratePredicatesMap, TyCtxt, Upcast};
66
use rustc_span::Span;
77

8+
pub(crate) mod dump;
89
mod explicit;
910
mod implicit_infer;
10-
/// Code to write unit test for outlives.
11-
pub mod test;
1211
mod utils;
1312

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

compiler/rustc_hir_analysis/src/outlives/test.rs

-31
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use rustc_hir::def::DefKind;
2+
use rustc_hir::def_id::CRATE_DEF_ID;
3+
use rustc_middle::ty::TyCtxt;
4+
use rustc_span::symbol::sym;
5+
6+
pub(crate) fn variances(tcx: TyCtxt<'_>) {
7+
if tcx.has_attr(CRATE_DEF_ID, sym::rustc_variance_of_opaques) {
8+
for id in tcx.hir().items() {
9+
let DefKind::OpaqueTy = tcx.def_kind(id.owner_id) else { continue };
10+
11+
let variances = tcx.variances_of(id.owner_id);
12+
13+
tcx.dcx().emit_err(crate::errors::VariancesOf {
14+
span: tcx.def_span(id.owner_id),
15+
variances: format!("{variances:?}"),
16+
});
17+
}
18+
}
19+
20+
for id in tcx.hir().items() {
21+
if !tcx.has_attr(id.owner_id, sym::rustc_variance) {
22+
continue;
23+
}
24+
25+
let variances = tcx.variances_of(id.owner_id);
26+
27+
tcx.dcx().emit_err(crate::errors::VariancesOf {
28+
span: tcx.def_span(id.owner_id),
29+
variances: format!("{variances:?}"),
30+
});
31+
}
32+
}

compiler/rustc_hir_analysis/src/variance/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ mod constraints;
2222
/// Code to solve constraints and write out the results.
2323
mod solve;
2424

25-
/// Code to write unit tests of variance.
26-
pub mod test;
25+
pub(crate) mod dump;
2726

2827
/// Code for transforming variances.
2928
mod xform;

compiler/rustc_hir_analysis/src/variance/test.rs

-37
This file was deleted.

compiler/rustc_span/src/symbol.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1593,6 +1593,8 @@ symbols! {
15931593
rustc_do_not_const_check,
15941594
rustc_doc_primitive,
15951595
rustc_dummy,
1596+
rustc_dump_item_bounds,
1597+
rustc_dump_predicates,
15961598
rustc_dump_user_args,
15971599
rustc_dump_vtable,
15981600
rustc_effective_visibility,

library/alloc/src/alloc.rs

-26
Original file line numberDiff line numberDiff line change
@@ -424,29 +424,3 @@ pub mod __alloc_error_handler {
424424
}
425425
}
426426
}
427-
428-
#[cfg(not(no_global_oom_handling))]
429-
/// Specialize clones into pre-allocated, uninitialized memory.
430-
/// Used by `Box::clone` and `Rc`/`Arc::make_mut`.
431-
pub(crate) trait WriteCloneIntoRaw: Sized {
432-
unsafe fn write_clone_into_raw(&self, target: *mut Self);
433-
}
434-
435-
#[cfg(not(no_global_oom_handling))]
436-
impl<T: Clone> WriteCloneIntoRaw for T {
437-
#[inline]
438-
default unsafe fn write_clone_into_raw(&self, target: *mut Self) {
439-
// Having allocated *first* may allow the optimizer to create
440-
// the cloned value in-place, skipping the local and move.
441-
unsafe { target.write(self.clone()) };
442-
}
443-
}
444-
445-
#[cfg(not(no_global_oom_handling))]
446-
impl<T: Copy> WriteCloneIntoRaw for T {
447-
#[inline]
448-
unsafe fn write_clone_into_raw(&self, target: *mut Self) {
449-
// We can always copy in-place, without ever involving a local value.
450-
unsafe { target.copy_from_nonoverlapping(self, 1) };
451-
}
452-
}

library/alloc/src/boxed.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@
188188
use core::any::Any;
189189
use core::async_iter::AsyncIterator;
190190
use core::borrow;
191+
#[cfg(not(no_global_oom_handling))]
192+
use core::clone::CloneToUninit;
191193
use core::cmp::Ordering;
192194
use core::error::Error;
193195
use core::fmt;
@@ -207,7 +209,7 @@ use core::slice;
207209
use core::task::{Context, Poll};
208210

209211
#[cfg(not(no_global_oom_handling))]
210-
use crate::alloc::{handle_alloc_error, WriteCloneIntoRaw};
212+
use crate::alloc::handle_alloc_error;
211213
use crate::alloc::{AllocError, Allocator, Global, Layout};
212214
#[cfg(not(no_global_oom_handling))]
213215
use crate::borrow::Cow;
@@ -1346,7 +1348,7 @@ impl<T: Clone, A: Allocator + Clone> Clone for Box<T, A> {
13461348
// Pre-allocate memory to allow writing the cloned value directly.
13471349
let mut boxed = Self::new_uninit_in(self.1.clone());
13481350
unsafe {
1349-
(**self).write_clone_into_raw(boxed.as_mut_ptr());
1351+
(**self).clone_to_uninit(boxed.as_mut_ptr());
13501352
boxed.assume_init()
13511353
}
13521354
}

0 commit comments

Comments
 (0)