Skip to content

Commit e631891

Browse files
committed
Auto merge of rust-lang#104370 - matthiaskrgr:rollup-c3b38sm, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#103996 (Add small clarification around using pointers derived from references) - rust-lang#104315 (Improve spans with `use crate::{self}`) - rust-lang#104320 (Use `derive_const` and rm manual StructuralEq impl) - rust-lang#104357 (add is_sized method on Abi and Layout, and use it) - rust-lang#104365 (Add x tool to triagebot) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents e4d6307 + 39ff9d2 commit e631891

File tree

29 files changed

+73
-32
lines changed

29 files changed

+73
-32
lines changed

compiler/rustc_codegen_cranelift/src/constant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ pub(crate) fn codegen_const_value<'tcx>(
128128
ty: Ty<'tcx>,
129129
) -> CValue<'tcx> {
130130
let layout = fx.layout_of(ty);
131-
assert!(!layout.is_unsized(), "sized const value");
131+
assert!(layout.is_sized(), "unsized const value");
132132

133133
if layout.is_zst() {
134134
return CValue::by_ref(crate::Pointer::dangling(layout.align.pref), layout);

compiler/rustc_codegen_cranelift/src/value_and_place.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn codegen_field<'tcx>(
1919
};
2020

2121
if let Some(extra) = extra {
22-
if !field_layout.is_unsized() {
22+
if field_layout.is_sized() {
2323
return simple(fx);
2424
}
2525
match field_layout.ty.kind() {
@@ -364,7 +364,7 @@ impl<'tcx> CPlace<'tcx> {
364364
fx: &mut FunctionCx<'_, '_, 'tcx>,
365365
layout: TyAndLayout<'tcx>,
366366
) -> CPlace<'tcx> {
367-
assert!(!layout.is_unsized());
367+
assert!(layout.is_sized());
368368
if layout.size.bytes() == 0 {
369369
return CPlace {
370370
inner: CPlaceInner::Addr(Pointer::dangling(layout.align.pref), None),
@@ -825,7 +825,7 @@ impl<'tcx> CPlace<'tcx> {
825825
fx: &FunctionCx<'_, '_, 'tcx>,
826826
variant: VariantIdx,
827827
) -> Self {
828-
assert!(!self.layout().is_unsized());
828+
assert!(self.layout().is_sized());
829829
let layout = self.layout().for_variant(fx, variant);
830830
CPlace { inner: self.inner, layout }
831831
}

compiler/rustc_codegen_gcc/src/type_.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ pub fn struct_fields<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, layout: TyAndLayout
277277
offset = target_offset + field.size;
278278
prev_effective_align = effective_field_align;
279279
}
280-
if !layout.is_unsized() && field_count > 0 {
280+
if layout.is_sized() && field_count > 0 {
281281
if offset > layout.size {
282282
bug!("layout: {:#?} stride: {:?} offset: {:?}", layout, layout.size, offset);
283283
}

compiler/rustc_codegen_llvm/src/debuginfo/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub(crate) fn fat_pointer_kind<'ll, 'tcx>(
7272
layout.is_unsized()
7373
);
7474

75-
if !layout.is_unsized() {
75+
if layout.is_sized() {
7676
return None;
7777
}
7878

compiler/rustc_codegen_llvm/src/type_of.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ fn struct_llfields<'a, 'tcx>(
140140
prev_effective_align = effective_field_align;
141141
}
142142
let padding_used = result.len() > field_count;
143-
if !layout.is_unsized() && field_count > 0 {
143+
if layout.is_sized() && field_count > 0 {
144144
if offset > layout.size {
145145
bug!("layout: {:#?} stride: {:?} offset: {:?}", layout, layout.size, offset);
146146
}

compiler/rustc_codegen_ssa/src/glue.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub fn size_and_align_of_dst<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
1515
) -> (Bx::Value, Bx::Value) {
1616
let layout = bx.layout_of(t);
1717
debug!("size_and_align_of_dst(ty={}, info={:?}): layout: {:?}", t, info, layout);
18-
if !layout.is_unsized() {
18+
if layout.is_sized() {
1919
let size = bx.const_usize(layout.size.bytes());
2020
let align = bx.const_usize(layout.align.abi.bytes());
2121
return (size, align);

compiler/rustc_codegen_ssa/src/mir/place.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub struct PlaceRef<'tcx, V> {
2929

3030
impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
3131
pub fn new_sized(llval: V, layout: TyAndLayout<'tcx>) -> PlaceRef<'tcx, V> {
32-
assert!(!layout.is_unsized());
32+
assert!(layout.is_sized());
3333
PlaceRef { llval, llextra: None, layout, align: layout.align.abi }
3434
}
3535

@@ -38,7 +38,7 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
3838
layout: TyAndLayout<'tcx>,
3939
align: Align,
4040
) -> PlaceRef<'tcx, V> {
41-
assert!(!layout.is_unsized());
41+
assert!(layout.is_sized());
4242
PlaceRef { llval, llextra: None, layout, align }
4343
}
4444

@@ -48,7 +48,7 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
4848
bx: &mut Bx,
4949
layout: TyAndLayout<'tcx>,
5050
) -> Self {
51-
assert!(!layout.is_unsized(), "tried to statically allocate unsized place");
51+
assert!(layout.is_sized(), "tried to statically allocate unsized place");
5252
let tmp = bx.alloca(bx.cx().backend_type(layout), layout.align.abi);
5353
Self::new_sized(tmp, layout)
5454
}
@@ -145,7 +145,7 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
145145
);
146146
return simple();
147147
}
148-
_ if !field.is_unsized() => return simple(),
148+
_ if field.is_sized() => return simple(),
149149
ty::Slice(..) | ty::Str | ty::Foreign(..) => return simple(),
150150
ty::Adt(def, _) => {
151151
if def.repr().packed() {

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fn eval_body_using_ecx<'mir, 'tcx>(
4646
ecx.tcx.def_kind(cid.instance.def_id())
4747
);
4848
let layout = ecx.layout_of(body.bound_return_ty().subst(tcx, cid.instance.substs))?;
49-
assert!(!layout.is_unsized());
49+
assert!(layout.is_sized());
5050
let ret = ecx.allocate(layout, MemoryKind::Stack)?;
5151

5252
trace!(

compiler/rustc_const_eval/src/interpret/eval_context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
572572
metadata: &MemPlaceMeta<M::Provenance>,
573573
layout: &TyAndLayout<'tcx>,
574574
) -> InterpResult<'tcx, Option<(Size, Align)>> {
575-
if !layout.is_unsized() {
575+
if layout.is_sized() {
576576
return Ok(Some((layout.size, layout.align.abi)));
577577
}
578578
match layout.ty.kind() {

compiler/rustc_const_eval/src/interpret/intrinsics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
713713
rhs: &OpTy<'tcx, <M as Machine<'mir, 'tcx>>::Provenance>,
714714
) -> InterpResult<'tcx, Scalar<M::Provenance>> {
715715
let layout = self.layout_of(lhs.layout.ty.builtin_deref(true).unwrap().ty)?;
716-
assert!(!layout.is_unsized());
716+
assert!(layout.is_sized());
717717

718718
let get_bytes = |this: &InterpCx<'mir, 'tcx, M>,
719719
op: &OpTy<'tcx, <M as Machine<'mir, 'tcx>>::Provenance>,

compiler/rustc_const_eval/src/interpret/memory.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
683683
// Use size and align of the type.
684684
let ty = self.tcx.type_of(def_id);
685685
let layout = self.tcx.layout_of(ParamEnv::empty().and(ty)).unwrap();
686-
assert!(!layout.is_unsized());
686+
assert!(layout.is_sized());
687687
(layout.size, layout.align.abi, AllocKind::LiveData)
688688
}
689689
Some(GlobalAlloc::Memory(alloc)) => {

compiler/rustc_const_eval/src/interpret/operand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ impl<'tcx, Prov: Provenance> OpTy<'tcx, Prov> {
280280
layout: TyAndLayout<'tcx>,
281281
cx: &impl HasDataLayout,
282282
) -> InterpResult<'tcx, Self> {
283-
assert!(!layout.is_unsized());
283+
assert!(layout.is_sized());
284284
self.offset_with_meta(offset, MemPlaceMeta::None, layout, cx)
285285
}
286286
}

compiler/rustc_const_eval/src/interpret/place.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ impl<'tcx, Prov: Provenance> MPlaceTy<'tcx, Prov> {
201201
layout: TyAndLayout<'tcx>,
202202
cx: &impl HasDataLayout,
203203
) -> InterpResult<'tcx, Self> {
204-
assert!(!layout.is_unsized());
204+
assert!(layout.is_sized());
205205
self.offset_with_meta(offset, MemPlaceMeta::None, layout, cx)
206206
}
207207

@@ -340,7 +340,7 @@ where
340340
&self,
341341
place: &MPlaceTy<'tcx, M::Provenance>,
342342
) -> InterpResult<'tcx, Option<AllocRef<'_, 'tcx, M::Provenance, M::AllocExtra>>> {
343-
assert!(!place.layout.is_unsized());
343+
assert!(place.layout.is_sized());
344344
assert!(!place.meta.has_meta());
345345
let size = place.layout.size;
346346
self.get_ptr_alloc(place.ptr, size, place.align)
@@ -351,7 +351,7 @@ where
351351
&mut self,
352352
place: &MPlaceTy<'tcx, M::Provenance>,
353353
) -> InterpResult<'tcx, Option<AllocRefMut<'_, 'tcx, M::Provenance, M::AllocExtra>>> {
354-
assert!(!place.layout.is_unsized());
354+
assert!(place.layout.is_sized());
355355
assert!(!place.meta.has_meta());
356356
let size = place.layout.size;
357357
self.get_ptr_alloc_mut(place.ptr, size, place.align)
@@ -485,7 +485,7 @@ where
485485
src: Immediate<M::Provenance>,
486486
dest: &PlaceTy<'tcx, M::Provenance>,
487487
) -> InterpResult<'tcx> {
488-
assert!(!dest.layout.is_unsized(), "Cannot write unsized data");
488+
assert!(dest.layout.is_sized(), "Cannot write unsized data");
489489
trace!("write_immediate: {:?} <- {:?}: {}", *dest, src, dest.layout.ty);
490490

491491
// See if we can avoid an allocation. This is the counterpart to `read_immediate_raw`,
@@ -746,7 +746,7 @@ where
746746
layout: TyAndLayout<'tcx>,
747747
kind: MemoryKind<M::MemoryKind>,
748748
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>> {
749-
assert!(!layout.is_unsized());
749+
assert!(layout.is_sized());
750750
let ptr = self.allocate_ptr(layout.size, layout.align.abi, kind)?;
751751
Ok(MPlaceTy::from_aligned_ptr(ptr.into(), layout))
752752
}

compiler/rustc_const_eval/src/interpret/step.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
209209

210210
Repeat(ref operand, _) => {
211211
let src = self.eval_operand(operand, None)?;
212-
assert!(!src.layout.is_unsized());
212+
assert!(src.layout.is_sized());
213213
let dest = self.force_allocation(&dest)?;
214214
let length = dest.len(self)?;
215215

compiler/rustc_const_eval/src/interpret/traits.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
5353
) -> InterpResult<'tcx, (Size, Align)> {
5454
let (ty, _trait_ref) = self.get_ptr_vtable(vtable)?;
5555
let layout = self.layout_of(ty)?;
56-
assert!(!layout.is_unsized(), "there are no vtables for unsized types");
56+
assert!(layout.is_sized(), "there are no vtables for unsized types");
5757
Ok((layout.size, layout.align.abi))
5858
}
5959
}

compiler/rustc_middle/src/ty/vtable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub(super) fn vtable_allocation_provider<'tcx>(
6666
let layout = tcx
6767
.layout_of(ty::ParamEnv::reveal_all().and(ty))
6868
.expect("failed to build vtable representation");
69-
assert!(!layout.is_unsized(), "can't create a vtable for an unsized type");
69+
assert!(layout.is_sized(), "can't create a vtable for an unsized type");
7070
let size = layout.size.bytes();
7171
let align = layout.align.abi.bytes();
7272

compiler/rustc_mir_transform/src/const_prop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
385385
// I don't know how return types can seem to be unsized but this happens in the
386386
// `type/type-unsatisfiable.rs` test.
387387
.filter(|ret_layout| {
388-
!ret_layout.is_unsized() && ret_layout.size < Size::from_bytes(MAX_ALLOC_LIMIT)
388+
ret_layout.is_sized() && ret_layout.size < Size::from_bytes(MAX_ALLOC_LIMIT)
389389
})
390390
.unwrap_or_else(|| ecx.layout_of(tcx.types.unit).unwrap());
391391

compiler/rustc_mir_transform/src/const_prop_lint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
199199
// I don't know how return types can seem to be unsized but this happens in the
200200
// `type/type-unsatisfiable.rs` test.
201201
.filter(|ret_layout| {
202-
!ret_layout.is_unsized() && ret_layout.size < Size::from_bytes(MAX_ALLOC_LIMIT)
202+
ret_layout.is_sized() && ret_layout.size < Size::from_bytes(MAX_ALLOC_LIMIT)
203203
})
204204
.unwrap_or_else(|| ecx.layout_of(tcx.types.unit).unwrap());
205205

compiler/rustc_passes/src/stability.rs

+8
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,14 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> {
536536
return;
537537
}
538538

539+
// if the const impl is derived using the `derive_const` attribute,
540+
// then it would be "stable" at least for the impl.
541+
// We gate usages of it using `feature(const_trait_impl)` anyways
542+
// so there is no unstable leakage
543+
if self.tcx.is_builtin_derive(def_id.to_def_id()) {
544+
return;
545+
}
546+
539547
let is_const = self.tcx.is_const_fn(def_id.to_def_id())
540548
|| self.tcx.is_const_trait_impl_raw(def_id.to_def_id());
541549
let is_stable = self

compiler/rustc_resolve/src/build_reduced_graph.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -469,9 +469,11 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
469469
}
470470

471471
// Replace `use foo::{ self };` with `use foo;`
472+
let self_span = source.ident.span;
472473
source = module_path.pop().unwrap();
473474
if rename.is_none() {
474-
ident = source.ident;
475+
// Keep the span of `self`, but the name of `foo`
476+
ident = Ident { name: source.ident.name, span: self_span };
475477
}
476478
}
477479
} else {

compiler/rustc_target/src/abi/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,11 @@ impl Abi {
10831083
}
10841084
}
10851085

1086+
#[inline]
1087+
pub fn is_sized(&self) -> bool {
1088+
!self.is_unsized()
1089+
}
1090+
10861091
/// Returns `true` if this is a single signed integer scalar
10871092
#[inline]
10881093
pub fn is_signed(&self) -> bool {
@@ -1490,6 +1495,11 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
14901495
self.abi.is_unsized()
14911496
}
14921497

1498+
#[inline]
1499+
pub fn is_sized(&self) -> bool {
1500+
self.abi.is_sized()
1501+
}
1502+
14931503
/// Returns `true` if the type is a ZST and not unsized.
14941504
pub fn is_zst(&self) -> bool {
14951505
match self.abi {

compiler/rustc_ty_utils/src/layout.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ fn layout_of_uncached<'tcx>(
668668
let mut abi = Abi::Aggregate { sized: true };
669669
let index = VariantIdx::new(0);
670670
for field in &variants[index] {
671-
assert!(!field.is_unsized());
671+
assert!(field.is_sized());
672672
align = align.max(field.align);
673673

674674
// If all non-ZST fields have the same ABI, forward this ABI

library/core/src/cmp.rs

+6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
use crate::const_closure::ConstFnMutClosure;
2626
use crate::marker::Destruct;
27+
#[cfg(bootstrap)]
2728
use crate::marker::StructuralPartialEq;
2829

2930
use self::Ordering::*;
@@ -331,6 +332,7 @@ pub struct AssertParamIsEq<T: Eq + ?Sized> {
331332
/// assert_eq!(Ordering::Greater, result);
332333
/// ```
333334
#[derive(Clone, Copy, Eq, Debug, Hash)]
335+
#[cfg_attr(not(bootstrap), derive_const(PartialOrd, Ord, PartialEq))]
334336
#[stable(feature = "rust1", since = "1.0.0")]
335337
#[repr(i8)]
336338
pub enum Ordering {
@@ -877,10 +879,12 @@ pub macro Ord($item:item) {
877879
}
878880

879881
#[stable(feature = "rust1", since = "1.0.0")]
882+
#[cfg(bootstrap)]
880883
impl StructuralPartialEq for Ordering {}
881884

882885
#[stable(feature = "rust1", since = "1.0.0")]
883886
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
887+
#[cfg(bootstrap)]
884888
impl const PartialEq for Ordering {
885889
#[inline]
886890
fn eq(&self, other: &Self) -> bool {
@@ -890,6 +894,7 @@ impl const PartialEq for Ordering {
890894

891895
#[stable(feature = "rust1", since = "1.0.0")]
892896
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
897+
#[cfg(bootstrap)]
893898
impl const Ord for Ordering {
894899
#[inline]
895900
fn cmp(&self, other: &Ordering) -> Ordering {
@@ -899,6 +904,7 @@ impl const Ord for Ordering {
899904

900905
#[stable(feature = "rust1", since = "1.0.0")]
901906
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
907+
#[cfg(bootstrap)]
902908
impl const PartialOrd for Ordering {
903909
#[inline]
904910
fn partial_cmp(&self, other: &Ordering) -> Option<Ordering> {

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@
185185
#![feature(const_refs_to_cell)]
186186
#![feature(decl_macro)]
187187
#![feature(deprecated_suggestion)]
188+
#![cfg_attr(not(bootstrap), feature(derive_const))]
188189
#![feature(doc_cfg)]
189190
#![feature(doc_notable_trait)]
190191
#![feature(rustdoc_internals)]

library/core/src/ptr/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
//! be used for inter-thread synchronization.
3636
//! * The result of casting a reference to a pointer is valid for as long as the
3737
//! underlying object is live and no reference (just raw pointers) is used to
38-
//! access the same memory.
38+
//! access the same memory. That is, reference and pointer accesses cannot be
39+
//! interleaved.
3940
//!
4041
//! These axioms, along with careful use of [`offset`] for pointer arithmetic,
4142
//! are enough to correctly implement many useful things in unsafe code. Stronger guarantees
@@ -64,7 +65,6 @@
6465
//! separate allocated object), heap allocations (each allocation created by the global allocator is
6566
//! a separate allocated object), and `static` variables.
6667
//!
67-
//!
6868
//! # Strict Provenance
6969
//!
7070
//! **The following text is non-normative, insufficiently formal, and is an extremely strict

src/test/ui/use/use-crate-self.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
use crate::{self};
2+
//~^ ERROR crate root imports need to be explicitly named: `use crate as name;`
3+
4+
fn main() {}

src/test/ui/use/use-crate-self.stderr

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: crate root imports need to be explicitly named: `use crate as name;`
2+
--> $DIR/use-crate-self.rs:1:13
3+
|
4+
LL | use crate::{self};
5+
| ^^^^
6+
7+
error: aborting due to previous error
8+

src/tools/miri/src/stacked_borrows/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
10531053
// pointers we need to retag, so we can stop recursion early.
10541054
// This optimization is crucial for ZSTs, because they can contain way more fields
10551055
// than we can ever visit.
1056-
if !place.layout.is_unsized() && place.layout.size < self.ecx.pointer_size() {
1056+
if place.layout.is_sized() && place.layout.size < self.ecx.pointer_size() {
10571057
return Ok(());
10581058
}
10591059

0 commit comments

Comments
 (0)