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

+4-2
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

+1-1
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

+3
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

+11
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

+6-6
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

+1-1
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

+2-3
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

+6-6
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

+1-1
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

+2-2
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
}

src/librustc/mir/mod.rs

+2-17
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use std::ops::Index;
3434
use std::slice;
3535
use std::{iter, mem, option, u32};
3636
use syntax::ast::Name;
37+
pub use syntax::ast::Mutability;
3738
use syntax::symbol::Symbol;
3839
use syntax_pos::{Span, DUMMY_SP};
3940

@@ -396,22 +397,7 @@ pub struct SourceInfo {
396397
}
397398

398399
///////////////////////////////////////////////////////////////////////////
399-
// Mutability and borrow kinds
400-
401-
#[derive(Copy, Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)]
402-
pub enum Mutability {
403-
Mut,
404-
Not,
405-
}
406-
407-
impl From<Mutability> for hir::Mutability {
408-
fn from(m: Mutability) -> Self {
409-
match m {
410-
Mutability::Mut => hir::Mutability::Mutable,
411-
Mutability::Not => hir::Mutability::Immutable,
412-
}
413-
}
414-
}
400+
// Borrow kinds
415401

416402
#[derive(
417403
Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable, HashStable,
@@ -2886,7 +2872,6 @@ pub enum ClosureOutlivesSubject<'tcx> {
28862872
CloneTypeFoldableAndLiftImpls! {
28872873
BlockTailInfo,
28882874
MirPhase,
2889-
Mutability,
28902875
SourceInfo,
28912876
FakeReadCause,
28922877
RetagKind,

src/librustc/mir/tcx.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -279,17 +279,17 @@ impl<'tcx> BinOp {
279279
impl BorrowKind {
280280
pub fn to_mutbl_lossy(self) -> hir::Mutability {
281281
match self {
282-
BorrowKind::Mut { .. } => hir::Mutability::Mutable,
283-
BorrowKind::Shared => hir::Mutability::Immutable,
282+
BorrowKind::Mut { .. } => hir::Mutability::Mut,
283+
BorrowKind::Shared => hir::Mutability::Not,
284284

285285
// We have no type corresponding to a unique imm borrow, so
286286
// use `&mut`. It gives all the capabilities of an `&uniq`
287287
// and hence is a safe "over approximation".
288-
BorrowKind::Unique => hir::Mutability::Mutable,
288+
BorrowKind::Unique => hir::Mutability::Mut,
289289

290290
// We have no type corresponding to a shallow borrow, so use
291291
// `&` as an approximation.
292-
BorrowKind::Shallow => hir::Mutability::Immutable,
292+
BorrowKind::Shallow => hir::Mutability::Not,
293293
}
294294
}
295295
}

src/librustc/traits/error_reporting.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1548,8 +1548,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
15481548

15491549
if let ty::Ref(region, t_type, mutability) = trait_ref.skip_binder().self_ty().kind {
15501550
let trait_type = match mutability {
1551-
hir::Mutability::Mutable => self.tcx.mk_imm_ref(region, t_type),
1552-
hir::Mutability::Immutable => self.tcx.mk_mut_ref(region, t_type),
1551+
hir::Mutability::Mut => self.tcx.mk_imm_ref(region, t_type),
1552+
hir::Mutability::Not => self.tcx.mk_mut_ref(region, t_type),
15531553
};
15541554

15551555
let new_obligation = self.mk_obligation_for_def_id(
@@ -1565,7 +1565,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
15651565
let sp = self.tcx.sess.source_map()
15661566
.span_take_while(span, |c| c.is_whitespace() || *c == '&');
15671567
if points_at_arg &&
1568-
mutability == hir::Mutability::Immutable &&
1568+
mutability == hir::Mutability::Not &&
15691569
refs_number > 0
15701570
{
15711571
err.span_suggestion(

src/librustc/traits/select.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2622,7 +2622,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
26222622
| ty::Char
26232623
| ty::RawPtr(..)
26242624
| ty::Never
2625-
| ty::Ref(_, _, hir::Mutability::Immutable) => {
2625+
| ty::Ref(_, _, hir::Mutability::Not) => {
26262626
// Implementations provided in libcore
26272627
None
26282628
}
@@ -2633,7 +2633,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
26332633
| ty::Generator(..)
26342634
| ty::GeneratorWitness(..)
26352635
| ty::Foreign(..)
2636-
| ty::Ref(_, _, hir::Mutability::Mutable) => None,
2636+
| ty::Ref(_, _, hir::Mutability::Mut) => None,
26372637

26382638
ty::Array(element_ty, _) => {
26392639
// (*) binder moved here

src/librustc/ty/adjustment.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ pub struct OverloadedDeref<'tcx> {
109109
impl<'tcx> OverloadedDeref<'tcx> {
110110
pub fn method_call(&self, tcx: TyCtxt<'tcx>, source: Ty<'tcx>) -> (DefId, SubstsRef<'tcx>) {
111111
let trait_def_id = match self.mutbl {
112-
hir::Mutability::Immutable => tcx.lang_items().deref_trait(),
113-
hir::Mutability::Mutable => tcx.lang_items().deref_mut_trait()
112+
hir::Mutability::Not => tcx.lang_items().deref_trait(),
113+
hir::Mutability::Mut => tcx.lang_items().deref_mut_trait()
114114
};
115115
let method_def_id = tcx.associated_items(trait_def_id.unwrap())
116116
.find(|m| m.kind == ty::AssocKind::Method).unwrap().def_id;
@@ -138,15 +138,15 @@ pub enum AllowTwoPhase {
138138

139139
#[derive(Copy, Clone, PartialEq, Debug, RustcEncodable, RustcDecodable, HashStable)]
140140
pub enum AutoBorrowMutability {
141-
Mutable { allow_two_phase_borrow: AllowTwoPhase },
142-
Immutable,
141+
Mut { allow_two_phase_borrow: AllowTwoPhase },
142+
Not,
143143
}
144144

145145
impl From<AutoBorrowMutability> for hir::Mutability {
146146
fn from(m: AutoBorrowMutability) -> Self {
147147
match m {
148-
AutoBorrowMutability::Mutable { .. } => hir::Mutability::Mutable,
149-
AutoBorrowMutability::Immutable => hir::Mutability::Immutable,
148+
AutoBorrowMutability::Mut { .. } => hir::Mutability::Mut,
149+
AutoBorrowMutability::Not => hir::Mutability::Not,
150150
}
151151
}
152152
}

src/librustc/ty/binding.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ CloneTypeFoldableAndLiftImpls! { BindingMode, }
1313
impl BindingMode {
1414
pub fn convert(ba: BindingAnnotation) -> BindingMode {
1515
match ba {
16-
Unannotated => BindingMode::BindByValue(Mutability::Immutable),
17-
Mutable => BindingMode::BindByValue(Mutability::Mutable),
18-
Ref => BindingMode::BindByReference(Mutability::Immutable),
19-
RefMut => BindingMode::BindByReference(Mutability::Mutable),
16+
Unannotated => BindingMode::BindByValue(Mutability::Not),
17+
Mutable => BindingMode::BindByValue(Mutability::Mut),
18+
Ref => BindingMode::BindByReference(Mutability::Not),
19+
RefMut => BindingMode::BindByReference(Mutability::Mut),
2020
}
2121
}
2222
}

src/librustc/ty/context.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2406,22 +2406,22 @@ impl<'tcx> TyCtxt<'tcx> {
24062406

24072407
#[inline]
24082408
pub fn mk_mut_ref(self, r: Region<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
2409-
self.mk_ref(r, TypeAndMut {ty: ty, mutbl: hir::Mutability::Mutable})
2409+
self.mk_ref(r, TypeAndMut {ty: ty, mutbl: hir::Mutability::Mut })
24102410
}
24112411

24122412
#[inline]
24132413
pub fn mk_imm_ref(self, r: Region<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
2414-
self.mk_ref(r, TypeAndMut {ty: ty, mutbl: hir::Mutability::Immutable})
2414+
self.mk_ref(r, TypeAndMut {ty: ty, mutbl: hir::Mutability::Not })
24152415
}
24162416

24172417
#[inline]
24182418
pub fn mk_mut_ptr(self, ty: Ty<'tcx>) -> Ty<'tcx> {
2419-
self.mk_ptr(TypeAndMut {ty: ty, mutbl: hir::Mutability::Mutable})
2419+
self.mk_ptr(TypeAndMut {ty: ty, mutbl: hir::Mutability::Mut })
24202420
}
24212421

24222422
#[inline]
24232423
pub fn mk_imm_ptr(self, ty: Ty<'tcx>) -> Ty<'tcx> {
2424-
self.mk_ptr(TypeAndMut {ty: ty, mutbl: hir::Mutability::Immutable})
2424+
self.mk_ptr(TypeAndMut {ty: ty, mutbl: hir::Mutability::Not })
24252425
}
24262426

24272427
#[inline]

src/librustc/ty/error.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ impl<'tcx> ty::TyS<'tcx> {
248248
format!("`&{}`", tymut_string).into()
249249
} else { // Unknown type name, it's long or has type arguments
250250
match mutbl {
251-
hir::Mutability::Mutable => "mutable reference",
251+
hir::Mutability::Mut => "mutable reference",
252252
_ => "reference",
253253
}.into()
254254
}
@@ -293,7 +293,7 @@ impl<'tcx> ty::TyS<'tcx> {
293293
ty::Slice(_) => "slice".into(),
294294
ty::RawPtr(_) => "raw pointer".into(),
295295
ty::Ref(.., mutbl) => match mutbl {
296-
hir::Mutability::Mutable => "mutable reference",
296+
hir::Mutability::Mut => "mutable reference",
297297
_ => "reference"
298298
}.into(),
299299
ty::FnDef(..) => "fn item".into(),

src/librustc/ty/layout.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2221,12 +2221,12 @@ where
22212221
let tcx = cx.tcx();
22222222
let is_freeze = ty.is_freeze(tcx, cx.param_env(), DUMMY_SP);
22232223
let kind = match mt {
2224-
hir::Mutability::Immutable => if is_freeze {
2224+
hir::Mutability::Not => if is_freeze {
22252225
PointerKind::Frozen
22262226
} else {
22272227
PointerKind::Shared
22282228
},
2229-
hir::Mutability::Mutable => {
2229+
hir::Mutability::Mut => {
22302230
// Previously we would only emit noalias annotations for LLVM >= 6 or in
22312231
// panic=abort mode. That was deemed right, as prior versions had many bugs
22322232
// in conjunction with unwinding, but later versions didn’t seem to have

0 commit comments

Comments
 (0)