Skip to content

Commit 0a440b1

Browse files
committed
Auto merge of #67485 - Centril:rollup-gt0opvr, r=Centril
Rollup of 7 pull requests Successful merges: - #67059 (Fix too restrictive checks on Drop impls) - #67355 (Merge `ast::Mutability` and `mir::Mutability`) - #67393 (Enable opting out of specific default LLVM arguments.) - #67422 (Cleanup err codes) - #67462 (Make ptr::slice_from_raw_parts a const fn available under a feature flag) - #67467 (Test slice patterns more) - #67478 (Fix src/libcore/str/mod.rs doc comments) Failed merges: r? @ghost
2 parents c64eecf + 466fdea commit 0a440b1

File tree

113 files changed

+1301
-376
lines changed

Some content is hidden

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

113 files changed

+1301
-376
lines changed

src/libcore/ptr/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ pub(crate) struct FatPtr<T> {
259259
/// ```
260260
#[inline]
261261
#[unstable(feature = "slice_from_raw_parts", reason = "recently added", issue = "36925")]
262-
pub fn slice_from_raw_parts<T>(data: *const T, len: usize) -> *const [T] {
262+
#[rustc_const_unstable(feature = "const_slice_from_raw_parts", issue = "67456")]
263+
pub const fn slice_from_raw_parts<T>(data: *const T, len: usize) -> *const [T] {
263264
unsafe { Repr { raw: FatPtr { data, len } }.rust }
264265
}
265266

@@ -275,7 +276,8 @@ pub fn slice_from_raw_parts<T>(data: *const T, len: usize) -> *const [T] {
275276
/// [`from_raw_parts_mut`]: ../../std/slice/fn.from_raw_parts_mut.html
276277
#[inline]
277278
#[unstable(feature = "slice_from_raw_parts", reason = "recently added", issue = "36925")]
278-
pub fn slice_from_raw_parts_mut<T>(data: *mut T, len: usize) -> *mut [T] {
279+
#[rustc_const_unstable(feature = "const_slice_from_raw_parts", issue = "67456")]
280+
pub const fn slice_from_raw_parts_mut<T>(data: *mut T, len: usize) -> *mut [T] {
279281
unsafe { Repr { raw: FatPtr { data, len } }.rust_mut }
280282
}
281283

src/libcore/str/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2325,7 +2325,7 @@ impl str {
23252325
i.get_mut(self)
23262326
}
23272327

2328-
/// Returns a unchecked subslice of `str`.
2328+
/// Returns an unchecked subslice of `str`.
23292329
///
23302330
/// This is the unchecked alternative to indexing the `str`.
23312331
///

src/libcore/tests/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
#![feature(iter_is_partitioned)]
3737
#![feature(iter_order_by)]
3838
#![feature(cmp_min_max_by)]
39+
#![feature(slice_from_raw_parts)]
40+
#![feature(const_slice_from_raw_parts)]
41+
#![feature(const_raw_ptr_deref)]
3942

4043
extern crate test;
4144

src/libcore/tests/ptr.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
use core::cell::RefCell;
22
use core::ptr::*;
33

4+
#[test]
5+
fn test_const_from_raw_parts() {
6+
const SLICE: &[u8] = &[1, 2, 3, 4];
7+
const FROM_RAW: &[u8] = unsafe { &*slice_from_raw_parts(SLICE.as_ptr(), SLICE.len()) };
8+
assert_eq!(SLICE, FROM_RAW);
9+
10+
let slice = &[1, 2, 3, 4, 5];
11+
let from_raw = unsafe { &*slice_from_raw_parts(slice.as_ptr(), 2) } ;
12+
assert_eq!(&slice[..2], from_raw);
13+
}
14+
415
#[test]
516
fn test() {
617
unsafe {

src/librustc/hir/lowering.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2253,7 +2253,7 @@ impl<'a> LoweringContext<'a> {
22532253
let is_mutable_pat = match arg.pat.kind {
22542254
PatKind::Ident(BindingMode::ByValue(mt), _, _) |
22552255
PatKind::Ident(BindingMode::ByRef(mt), _, _) =>
2256-
mt == Mutability::Mutable,
2256+
mt == Mutability::Mut,
22572257
_ => false,
22582258
};
22592259

@@ -2264,7 +2264,7 @@ impl<'a> LoweringContext<'a> {
22642264
// the case where we have a mutable pattern to a reference as that would
22652265
// no longer be an `ImplicitSelf`.
22662266
TyKind::Rptr(_, ref mt) if mt.ty.kind.is_implicit_self() &&
2267-
mt.mutbl == ast::Mutability::Mutable =>
2267+
mt.mutbl == ast::Mutability::Mut =>
22682268
hir::ImplicitSelfKind::MutRef,
22692269
TyKind::Rptr(_, ref mt) if mt.ty.kind.is_implicit_self() =>
22702270
hir::ImplicitSelfKind::ImmRef,
@@ -3068,10 +3068,10 @@ impl<'a> LoweringContext<'a> {
30683068

30693069
fn lower_binding_mode(&mut self, b: &BindingMode) -> hir::BindingAnnotation {
30703070
match *b {
3071-
BindingMode::ByValue(Mutability::Immutable) => hir::BindingAnnotation::Unannotated,
3072-
BindingMode::ByRef(Mutability::Immutable) => hir::BindingAnnotation::Ref,
3073-
BindingMode::ByValue(Mutability::Mutable) => hir::BindingAnnotation::Mutable,
3074-
BindingMode::ByRef(Mutability::Mutable) => hir::BindingAnnotation::RefMut,
3071+
BindingMode::ByValue(Mutability::Not) => hir::BindingAnnotation::Unannotated,
3072+
BindingMode::ByRef(Mutability::Not) => hir::BindingAnnotation::Ref,
3073+
BindingMode::ByValue(Mutability::Mut) => hir::BindingAnnotation::Mutable,
3074+
BindingMode::ByRef(Mutability::Mut) => hir::BindingAnnotation::RefMut,
30753075
}
30763076
}
30773077

src/librustc/hir/lowering/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,7 @@ impl LoweringContext<'_> {
13401340
fn expr_mut_addr_of(&mut self, span: Span, e: P<hir::Expr>) -> hir::Expr {
13411341
self.expr(
13421342
span,
1343-
hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Mutable, e),
1343+
hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Mut, e),
13441344
ThinVec::new(),
13451345
)
13461346
}

src/librustc/hir/pat_util.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,10 @@ impl hir::Pat {
169169
self.each_binding(|annotation, _, _, _| {
170170
match annotation {
171171
hir::BindingAnnotation::Ref => match result {
172-
None | Some(hir::Mutability::Immutable) =>
173-
result = Some(hir::Mutability::Immutable),
172+
None | Some(hir::Mutability::Not) => result = Some(hir::Mutability::Not),
174173
_ => {}
175174
}
176-
hir::BindingAnnotation::RefMut => result = Some(hir::Mutability::Mutable),
175+
hir::BindingAnnotation::RefMut => result = Some(hir::Mutability::Mut),
177176
_ => {}
178177
}
179178
});

src/librustc/hir/print.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ impl<'a> State<'a> {
386386
}
387387
hir::ForeignItemKind::Static(ref t, m) => {
388388
self.head(visibility_qualified(&item.vis, "static"));
389-
if m == hir::Mutability::Mutable {
389+
if m == hir::Mutability::Mut {
390390
self.word_space("mut");
391391
}
392392
self.print_ident(item.ident);
@@ -502,7 +502,7 @@ impl<'a> State<'a> {
502502
}
503503
hir::ItemKind::Static(ref ty, m, expr) => {
504504
self.head(visibility_qualified(&item.vis, "static"));
505-
if m == hir::Mutability::Mutable {
505+
if m == hir::Mutability::Mut {
506506
self.word_space("mut");
507507
}
508508
self.print_ident(item.ident);
@@ -1632,11 +1632,11 @@ impl<'a> State<'a> {
16321632
match binding_mode {
16331633
hir::BindingAnnotation::Ref => {
16341634
self.word_nbsp("ref");
1635-
self.print_mutability(hir::Mutability::Immutable, false);
1635+
self.print_mutability(hir::Mutability::Not, false);
16361636
}
16371637
hir::BindingAnnotation::RefMut => {
16381638
self.word_nbsp("ref");
1639-
self.print_mutability(hir::Mutability::Mutable, false);
1639+
self.print_mutability(hir::Mutability::Mut, false);
16401640
}
16411641
hir::BindingAnnotation::Unannotated => {}
16421642
hir::BindingAnnotation::Mutable => {
@@ -2065,8 +2065,8 @@ impl<'a> State<'a> {
20652065

20662066
pub fn print_mutability(&mut self, mutbl: hir::Mutability, print_const: bool) {
20672067
match mutbl {
2068-
hir::Mutability::Mutable => self.word_nbsp("mut"),
2069-
hir::Mutability::Immutable => if print_const { self.word_nbsp("const") },
2068+
hir::Mutability::Mut => self.word_nbsp("mut"),
2069+
hir::Mutability::Not => if print_const { self.word_nbsp("const") },
20702070
}
20712071
}
20722072

src/librustc/lint/internal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TyTyKind {
132132
}
133133
}
134134
}
135-
TyKind::Rptr(_, MutTy { ty: inner_ty, mutbl: Mutability::Immutable }) => {
135+
TyKind::Rptr(_, MutTy { ty: inner_ty, mutbl: Mutability::Not }) => {
136136
if let Some(impl_did) = cx.tcx.impl_of_method(ty.hir_id.owner_def_id()) {
137137
if cx.tcx.impl_trait_ref(impl_did).is_some() {
138138
return;

src/librustc/mir/interpret/allocation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl<Tag> Allocation<Tag> {
106106
undef_mask: UndefMask::new(size, true),
107107
size,
108108
align,
109-
mutability: Mutability::Immutable,
109+
mutability: Mutability::Not,
110110
extra: (),
111111
}
112112
}
@@ -123,7 +123,7 @@ impl<Tag> Allocation<Tag> {
123123
undef_mask: UndefMask::new(size, false),
124124
size,
125125
align,
126-
mutability: Mutability::Mutable,
126+
mutability: Mutability::Mut,
127127
extra: (),
128128
}
129129
}

0 commit comments

Comments
 (0)