Skip to content

Commit

Permalink
Auto merge of #67485 - Centril:rollup-gt0opvr, r=Centril
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Dec 21, 2019
2 parents c64eecf + 466fdea commit 0a440b1
Show file tree
Hide file tree
Showing 113 changed files with 1,301 additions and 376 deletions.
6 changes: 4 additions & 2 deletions src/libcore/ptr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ pub(crate) struct FatPtr<T> {
/// ```
#[inline]
#[unstable(feature = "slice_from_raw_parts", reason = "recently added", issue = "36925")]
pub fn slice_from_raw_parts<T>(data: *const T, len: usize) -> *const [T] {
#[rustc_const_unstable(feature = "const_slice_from_raw_parts", issue = "67456")]
pub const fn slice_from_raw_parts<T>(data: *const T, len: usize) -> *const [T] {
unsafe { Repr { raw: FatPtr { data, len } }.rust }
}

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

Expand Down
2 changes: 1 addition & 1 deletion src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2325,7 +2325,7 @@ impl str {
i.get_mut(self)
}

/// Returns a unchecked subslice of `str`.
/// Returns an unchecked subslice of `str`.
///
/// This is the unchecked alternative to indexing the `str`.
///
Expand Down
3 changes: 3 additions & 0 deletions src/libcore/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
#![feature(iter_is_partitioned)]
#![feature(iter_order_by)]
#![feature(cmp_min_max_by)]
#![feature(slice_from_raw_parts)]
#![feature(const_slice_from_raw_parts)]
#![feature(const_raw_ptr_deref)]

extern crate test;

Expand Down
11 changes: 11 additions & 0 deletions src/libcore/tests/ptr.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
use core::cell::RefCell;
use core::ptr::*;

#[test]
fn test_const_from_raw_parts() {
const SLICE: &[u8] = &[1, 2, 3, 4];
const FROM_RAW: &[u8] = unsafe { &*slice_from_raw_parts(SLICE.as_ptr(), SLICE.len()) };
assert_eq!(SLICE, FROM_RAW);

let slice = &[1, 2, 3, 4, 5];
let from_raw = unsafe { &*slice_from_raw_parts(slice.as_ptr(), 2) } ;
assert_eq!(&slice[..2], from_raw);
}

#[test]
fn test() {
unsafe {
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2253,7 +2253,7 @@ impl<'a> LoweringContext<'a> {
let is_mutable_pat = match arg.pat.kind {
PatKind::Ident(BindingMode::ByValue(mt), _, _) |
PatKind::Ident(BindingMode::ByRef(mt), _, _) =>
mt == Mutability::Mutable,
mt == Mutability::Mut,
_ => false,
};

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

fn lower_binding_mode(&mut self, b: &BindingMode) -> hir::BindingAnnotation {
match *b {
BindingMode::ByValue(Mutability::Immutable) => hir::BindingAnnotation::Unannotated,
BindingMode::ByRef(Mutability::Immutable) => hir::BindingAnnotation::Ref,
BindingMode::ByValue(Mutability::Mutable) => hir::BindingAnnotation::Mutable,
BindingMode::ByRef(Mutability::Mutable) => hir::BindingAnnotation::RefMut,
BindingMode::ByValue(Mutability::Not) => hir::BindingAnnotation::Unannotated,
BindingMode::ByRef(Mutability::Not) => hir::BindingAnnotation::Ref,
BindingMode::ByValue(Mutability::Mut) => hir::BindingAnnotation::Mutable,
BindingMode::ByRef(Mutability::Mut) => hir::BindingAnnotation::RefMut,
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/lowering/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1340,7 +1340,7 @@ impl LoweringContext<'_> {
fn expr_mut_addr_of(&mut self, span: Span, e: P<hir::Expr>) -> hir::Expr {
self.expr(
span,
hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Mutable, e),
hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Mut, e),
ThinVec::new(),
)
}
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/hir/pat_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,10 @@ impl hir::Pat {
self.each_binding(|annotation, _, _, _| {
match annotation {
hir::BindingAnnotation::Ref => match result {
None | Some(hir::Mutability::Immutable) =>
result = Some(hir::Mutability::Immutable),
None | Some(hir::Mutability::Not) => result = Some(hir::Mutability::Not),
_ => {}
}
hir::BindingAnnotation::RefMut => result = Some(hir::Mutability::Mutable),
hir::BindingAnnotation::RefMut => result = Some(hir::Mutability::Mut),
_ => {}
}
});
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/hir/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ impl<'a> State<'a> {
}
hir::ForeignItemKind::Static(ref t, m) => {
self.head(visibility_qualified(&item.vis, "static"));
if m == hir::Mutability::Mutable {
if m == hir::Mutability::Mut {
self.word_space("mut");
}
self.print_ident(item.ident);
Expand Down Expand Up @@ -502,7 +502,7 @@ impl<'a> State<'a> {
}
hir::ItemKind::Static(ref ty, m, expr) => {
self.head(visibility_qualified(&item.vis, "static"));
if m == hir::Mutability::Mutable {
if m == hir::Mutability::Mut {
self.word_space("mut");
}
self.print_ident(item.ident);
Expand Down Expand Up @@ -1632,11 +1632,11 @@ impl<'a> State<'a> {
match binding_mode {
hir::BindingAnnotation::Ref => {
self.word_nbsp("ref");
self.print_mutability(hir::Mutability::Immutable, false);
self.print_mutability(hir::Mutability::Not, false);
}
hir::BindingAnnotation::RefMut => {
self.word_nbsp("ref");
self.print_mutability(hir::Mutability::Mutable, false);
self.print_mutability(hir::Mutability::Mut, false);
}
hir::BindingAnnotation::Unannotated => {}
hir::BindingAnnotation::Mutable => {
Expand Down Expand Up @@ -2065,8 +2065,8 @@ impl<'a> State<'a> {

pub fn print_mutability(&mut self, mutbl: hir::Mutability, print_const: bool) {
match mutbl {
hir::Mutability::Mutable => self.word_nbsp("mut"),
hir::Mutability::Immutable => if print_const { self.word_nbsp("const") },
hir::Mutability::Mut => self.word_nbsp("mut"),
hir::Mutability::Not => if print_const { self.word_nbsp("const") },
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/lint/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TyTyKind {
}
}
}
TyKind::Rptr(_, MutTy { ty: inner_ty, mutbl: Mutability::Immutable }) => {
TyKind::Rptr(_, MutTy { ty: inner_ty, mutbl: Mutability::Not }) => {
if let Some(impl_did) = cx.tcx.impl_of_method(ty.hir_id.owner_def_id()) {
if cx.tcx.impl_trait_ref(impl_did).is_some() {
return;
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/mir/interpret/allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl<Tag> Allocation<Tag> {
undef_mask: UndefMask::new(size, true),
size,
align,
mutability: Mutability::Immutable,
mutability: Mutability::Not,
extra: (),
}
}
Expand All @@ -123,7 +123,7 @@ impl<Tag> Allocation<Tag> {
undef_mask: UndefMask::new(size, false),
size,
align,
mutability: Mutability::Mutable,
mutability: Mutability::Mut,
extra: (),
}
}
Expand Down
19 changes: 2 additions & 17 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use std::ops::Index;
use std::slice;
use std::{iter, mem, option, u32};
use syntax::ast::Name;
pub use syntax::ast::Mutability;
use syntax::symbol::Symbol;
use syntax_pos::{Span, DUMMY_SP};

Expand Down Expand Up @@ -396,22 +397,7 @@ pub struct SourceInfo {
}

///////////////////////////////////////////////////////////////////////////
// Mutability and borrow kinds

#[derive(Copy, Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)]
pub enum Mutability {
Mut,
Not,
}

impl From<Mutability> for hir::Mutability {
fn from(m: Mutability) -> Self {
match m {
Mutability::Mut => hir::Mutability::Mutable,
Mutability::Not => hir::Mutability::Immutable,
}
}
}
// Borrow kinds

#[derive(
Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable, HashStable,
Expand Down Expand Up @@ -2886,7 +2872,6 @@ pub enum ClosureOutlivesSubject<'tcx> {
CloneTypeFoldableAndLiftImpls! {
BlockTailInfo,
MirPhase,
Mutability,
SourceInfo,
FakeReadCause,
RetagKind,
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/mir/tcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,17 +279,17 @@ impl<'tcx> BinOp {
impl BorrowKind {
pub fn to_mutbl_lossy(self) -> hir::Mutability {
match self {
BorrowKind::Mut { .. } => hir::Mutability::Mutable,
BorrowKind::Shared => hir::Mutability::Immutable,
BorrowKind::Mut { .. } => hir::Mutability::Mut,
BorrowKind::Shared => hir::Mutability::Not,

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

// We have no type corresponding to a shallow borrow, so use
// `&` as an approximation.
BorrowKind::Shallow => hir::Mutability::Immutable,
BorrowKind::Shallow => hir::Mutability::Not,
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1548,8 +1548,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {

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

let new_obligation = self.mk_obligation_for_def_id(
Expand All @@ -1565,7 +1565,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
let sp = self.tcx.sess.source_map()
.span_take_while(span, |c| c.is_whitespace() || *c == '&');
if points_at_arg &&
mutability == hir::Mutability::Immutable &&
mutability == hir::Mutability::Not &&
refs_number > 0
{
err.span_suggestion(
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2622,7 +2622,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
| ty::Char
| ty::RawPtr(..)
| ty::Never
| ty::Ref(_, _, hir::Mutability::Immutable) => {
| ty::Ref(_, _, hir::Mutability::Not) => {
// Implementations provided in libcore
None
}
Expand All @@ -2633,7 +2633,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
| ty::Generator(..)
| ty::GeneratorWitness(..)
| ty::Foreign(..)
| ty::Ref(_, _, hir::Mutability::Mutable) => None,
| ty::Ref(_, _, hir::Mutability::Mut) => None,

ty::Array(element_ty, _) => {
// (*) binder moved here
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/ty/adjustment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ pub struct OverloadedDeref<'tcx> {
impl<'tcx> OverloadedDeref<'tcx> {
pub fn method_call(&self, tcx: TyCtxt<'tcx>, source: Ty<'tcx>) -> (DefId, SubstsRef<'tcx>) {
let trait_def_id = match self.mutbl {
hir::Mutability::Immutable => tcx.lang_items().deref_trait(),
hir::Mutability::Mutable => tcx.lang_items().deref_mut_trait()
hir::Mutability::Not => tcx.lang_items().deref_trait(),
hir::Mutability::Mut => tcx.lang_items().deref_mut_trait()
};
let method_def_id = tcx.associated_items(trait_def_id.unwrap())
.find(|m| m.kind == ty::AssocKind::Method).unwrap().def_id;
Expand Down Expand Up @@ -138,15 +138,15 @@ pub enum AllowTwoPhase {

#[derive(Copy, Clone, PartialEq, Debug, RustcEncodable, RustcDecodable, HashStable)]
pub enum AutoBorrowMutability {
Mutable { allow_two_phase_borrow: AllowTwoPhase },
Immutable,
Mut { allow_two_phase_borrow: AllowTwoPhase },
Not,
}

impl From<AutoBorrowMutability> for hir::Mutability {
fn from(m: AutoBorrowMutability) -> Self {
match m {
AutoBorrowMutability::Mutable { .. } => hir::Mutability::Mutable,
AutoBorrowMutability::Immutable => hir::Mutability::Immutable,
AutoBorrowMutability::Mut { .. } => hir::Mutability::Mut,
AutoBorrowMutability::Not => hir::Mutability::Not,
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/ty/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ CloneTypeFoldableAndLiftImpls! { BindingMode, }
impl BindingMode {
pub fn convert(ba: BindingAnnotation) -> BindingMode {
match ba {
Unannotated => BindingMode::BindByValue(Mutability::Immutable),
Mutable => BindingMode::BindByValue(Mutability::Mutable),
Ref => BindingMode::BindByReference(Mutability::Immutable),
RefMut => BindingMode::BindByReference(Mutability::Mutable),
Unannotated => BindingMode::BindByValue(Mutability::Not),
Mutable => BindingMode::BindByValue(Mutability::Mut),
Ref => BindingMode::BindByReference(Mutability::Not),
RefMut => BindingMode::BindByReference(Mutability::Mut),
}
}
}
8 changes: 4 additions & 4 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2406,22 +2406,22 @@ impl<'tcx> TyCtxt<'tcx> {

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

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

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

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

#[inline]
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ impl<'tcx> ty::TyS<'tcx> {
format!("`&{}`", tymut_string).into()
} else { // Unknown type name, it's long or has type arguments
match mutbl {
hir::Mutability::Mutable => "mutable reference",
hir::Mutability::Mut => "mutable reference",
_ => "reference",
}.into()
}
Expand Down Expand Up @@ -293,7 +293,7 @@ impl<'tcx> ty::TyS<'tcx> {
ty::Slice(_) => "slice".into(),
ty::RawPtr(_) => "raw pointer".into(),
ty::Ref(.., mutbl) => match mutbl {
hir::Mutability::Mutable => "mutable reference",
hir::Mutability::Mut => "mutable reference",
_ => "reference"
}.into(),
ty::FnDef(..) => "fn item".into(),
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2221,12 +2221,12 @@ where
let tcx = cx.tcx();
let is_freeze = ty.is_freeze(tcx, cx.param_env(), DUMMY_SP);
let kind = match mt {
hir::Mutability::Immutable => if is_freeze {
hir::Mutability::Not => if is_freeze {
PointerKind::Frozen
} else {
PointerKind::Shared
},
hir::Mutability::Mutable => {
hir::Mutability::Mut => {
// Previously we would only emit noalias annotations for LLVM >= 6 or in
// panic=abort mode. That was deemed right, as prior versions had many bugs
// in conjunction with unwinding, but later versions didn’t seem to have
Expand Down
Loading

0 comments on commit 0a440b1

Please sign in to comment.