Skip to content

Rollup of 10 pull requests #76025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
bc7ea6f
Shorten liballoc doc intra link while readable
pickfire Aug 24, 2020
8e0e179
Expand rustdoc theme chooser x padding
pickfire Aug 24, 2020
f38eb93
Fix clashing_extern_declarations false positive.
jumbatm Aug 24, 2020
1831f65
Fix typo in TLS Model in Unstable Book
ArekPiekarz Aug 24, 2020
f20f7f2
Improve theme button hover background color
GuillaumeGomez Aug 25, 2020
671770e
Also handle transparent single-variant enums
jumbatm Aug 25, 2020
2ea86af
Use same name as attr.
jumbatm Aug 25, 2020
352df40
Remove unnecessary assert.
jumbatm Aug 25, 2020
a4090d2
Add test for issue #27130
bugadani Aug 25, 2020
2879813
Move to intra doc links for core::ptr::non_null
poliorcetics Aug 25, 2020
d9b075a
Fix typo (`thumbv8m.main-none-eabihf` is Mainline)
jonas-schievink Aug 25, 2020
178c1bb
Fix a typo in #75781
Amanieu Aug 26, 2020
f0722c0
Switch to intra-doc links in `core::hash`
camelid Aug 23, 2020
046556e
Make sure the functions don't get merged
bugadani Aug 27, 2020
5d0b59a
Rollup merge of #75852 - camelid:patch-3, r=jyn514
pietroalbini Aug 28, 2020
f3f4781
Rollup merge of #75874 - pickfire:patch-3, r=jyn514
pietroalbini Aug 28, 2020
7185766
Rollup merge of #75881 - pickfire:patch-5, r=GuillaumeGomez
pietroalbini Aug 28, 2020
47f296f
Rollup merge of #75885 - jumbatm:issue75739-clashing-extern-declarati…
pietroalbini Aug 28, 2020
4a8b5ab
Rollup merge of #75892 - ArekPiekarz:unstable_book_tls_model_typo, r=…
pietroalbini Aug 28, 2020
a1b440f
Rollup merge of #75901 - GuillaumeGomez:ayu-theme-button-hover-backgr…
pietroalbini Aug 28, 2020
9423b43
Rollup merge of #75910 - bugadani:testcase, r=oli-obk
pietroalbini Aug 28, 2020
a46d463
Rollup merge of #75917 - poliorcetics:intra-doc-core-nonnull, r=jyn514
pietroalbini Aug 28, 2020
e30a8d4
Rollup merge of #75919 - rust-lang:jonas-schievink-patch-1, r=ehuss
pietroalbini Aug 28, 2020
a53fdbe
Rollup merge of #75939 - Amanieu:fix_asm2, r=nagisa
pietroalbini Aug 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions library/alloc/src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//!
//! # Examples
//!
//! You can explicitly create a [`Vec<T>`] with [`new`]:
//! You can explicitly create a [`Vec`] with [`Vec::new`]:
//!
//! ```
//! let v: Vec<i32> = Vec::new();
Expand Down Expand Up @@ -50,8 +50,6 @@
//! v[1] = v[1] + 5;
//! ```
//!
//! [`Vec<T>`]: Vec
//! [`new`]: Vec::new
//! [`push`]: Vec::push

#![stable(feature = "rust1", since = "1.0.0")]
Expand Down
31 changes: 8 additions & 23 deletions library/core/src/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
//! If you need more control over how a value is hashed, you need to implement
//! the [`Hash`] trait:
//!
//! [`Hash`]: trait.Hash.html
//!
//! ```rust
//! use std::collections::hash_map::DefaultHasher;
//! use std::hash::{Hash, Hasher};
Expand Down Expand Up @@ -149,11 +147,9 @@ mod sip;
/// Thankfully, you won't need to worry about upholding this property when
/// deriving both [`Eq`] and `Hash` with `#[derive(PartialEq, Eq, Hash)]`.
///
/// [`Eq`]: ../../std/cmp/trait.Eq.html
/// [`Hasher`]: trait.Hasher.html
/// [`HashMap`]: ../../std/collections/struct.HashMap.html
/// [`HashSet`]: ../../std/collections/struct.HashSet.html
/// [`hash`]: #tymethod.hash
/// [`hash`]: Hash::hash
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Hash {
/// Feeds this value into the given [`Hasher`].
Expand All @@ -168,8 +164,6 @@ pub trait Hash {
/// 7920.hash(&mut hasher);
/// println!("Hash is {:x}!", hasher.finish());
/// ```
///
/// [`Hasher`]: trait.Hasher.html
#[stable(feature = "rust1", since = "1.0.0")]
fn hash<H: Hasher>(&self, state: &mut H);

Expand All @@ -186,8 +180,6 @@ pub trait Hash {
/// Hash::hash_slice(&numbers, &mut hasher);
/// println!("Hash is {:x}!", hasher.finish());
/// ```
///
/// [`Hasher`]: trait.Hasher.html
#[stable(feature = "hash_slice", since = "1.3.0")]
fn hash_slice<H: Hasher>(data: &[Self], state: &mut H)
where
Expand Down Expand Up @@ -239,10 +231,9 @@ pub use macros::Hash;
/// println!("Hash is {:x}!", hasher.finish());
/// ```
///
/// [`Hash`]: trait.Hash.html
/// [`finish`]: #tymethod.finish
/// [`write`]: #tymethod.write
/// [`write_u8`]: #method.write_u8
/// [`finish`]: Hasher::finish
/// [`write`]: Hasher::write
/// [`write_u8`]: Hasher::write_u8
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Hasher {
/// Returns the hash value for the values written so far.
Expand All @@ -264,7 +255,7 @@ pub trait Hasher {
/// println!("Hash is {:x}!", hasher.finish());
/// ```
///
/// [`write`]: #tymethod.write
/// [`write`]: Hasher::write
#[stable(feature = "rust1", since = "1.0.0")]
fn finish(&self) -> u64;

Expand Down Expand Up @@ -433,8 +424,7 @@ impl<H: Hasher + ?Sized> Hasher for &mut H {
/// assert_eq!(hasher_1.finish(), hasher_2.finish());
/// ```
///
/// [`build_hasher`]: #tymethod.build_hasher
/// [`Hasher`]: trait.Hasher.html
/// [`build_hasher`]: BuildHasher::build_hasher
/// [`HashMap`]: ../../std/collections/struct.HashMap.html
#[stable(since = "1.7.0", feature = "build_hasher")]
pub trait BuildHasher {
Expand All @@ -456,8 +446,6 @@ pub trait BuildHasher {
/// let s = RandomState::new();
/// let new_s = s.build_hasher();
/// ```
///
/// [`Hasher`]: trait.Hasher.html
#[stable(since = "1.7.0", feature = "build_hasher")]
fn build_hasher(&self) -> Self::Hasher;
}
Expand All @@ -470,7 +458,7 @@ pub trait BuildHasher {
/// defined.
///
/// Any `BuildHasherDefault` is [zero-sized]. It can be created with
/// [`default`][method.Default]. When using `BuildHasherDefault` with [`HashMap`] or
/// [`default`][method.default]. When using `BuildHasherDefault` with [`HashMap`] or
/// [`HashSet`], this doesn't need to be done, since they implement appropriate
/// [`Default`] instances themselves.
///
Expand Down Expand Up @@ -503,10 +491,7 @@ pub trait BuildHasher {
/// let hash_map = HashMap::<u32, u32, MyBuildHasher>::default();
/// ```
///
/// [`BuildHasher`]: trait.BuildHasher.html
/// [`Default`]: ../default/trait.Default.html
/// [method.default]: #method.default
/// [`Hasher`]: trait.Hasher.html
/// [method.default]: BuildHasherDefault::default
/// [`HashMap`]: ../../std/collections/struct.HashMap.html
/// [`HashSet`]: ../../std/collections/struct.HashSet.html
/// [zero-sized]: https://doc.rust-lang.org/nomicon/exotic-sizes.html#zero-sized-types-zsts
Expand Down
36 changes: 16 additions & 20 deletions library/core/src/ptr/non_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ use crate::slice::{self, SliceIndex};
/// it is your responsibility to ensure that `as_mut` is never called, and `as_ptr`
/// is never used for mutation.
///
/// [`PhantomData`]: ../marker/struct.PhantomData.html
/// [`UnsafeCell<T>`]: ../cell/struct.UnsafeCell.html
/// [`PhantomData`]: crate::marker::PhantomData
/// [`UnsafeCell<T>`]: crate::cell::UnsafeCell
#[stable(feature = "nonnull", since = "1.25.0")]
#[repr(transparent)]
#[rustc_layout_scalar_valid_range_start(1)]
Expand Down Expand Up @@ -82,8 +82,8 @@ impl<T: Sized> NonNull<T> {
///
/// For the mutable counterpart see [`as_uninit_mut`].
///
/// [`as_ref`]: #method.as_ref
/// [`as_uninit_mut`]: #method.as_uninit_mut
/// [`as_ref`]: NonNull::as_ref
/// [`as_uninit_mut`]: NonNull::as_uninit_mut
///
/// # Safety
///
Expand Down Expand Up @@ -114,8 +114,8 @@ impl<T: Sized> NonNull<T> {
///
/// For the shared counterpart see [`as_uninit_ref`].
///
/// [`as_mut`]: #method.as_mut
/// [`as_uninit_ref`]: #method.as_uninit_ref
/// [`as_mut`]: NonNull::as_mut
/// [`as_uninit_ref`]: NonNull::as_uninit_ref
///
/// # Safety
///
Expand Down Expand Up @@ -181,8 +181,8 @@ impl<T: ?Sized> NonNull<T> {
///
/// For the mutable counterpart see [`as_mut`].
///
/// [`as_uninit_ref`]: #method.as_uninit_ref
/// [`as_mut`]: #method.as_mut
/// [`as_uninit_ref`]: NonNull::as_uninit_ref
/// [`as_mut`]: NonNull::as_mut
///
/// # Safety
///
Expand Down Expand Up @@ -217,8 +217,8 @@ impl<T: ?Sized> NonNull<T> {
///
/// For the shared counterpart see [`as_ref`].
///
/// [`as_uninit_mut`]: #method.as_uninit_mut
/// [`as_ref`]: #method.as_ref
/// [`as_uninit_mut`]: NonNull::as_uninit_mut
/// [`as_ref`]: NonNull::as_ref
///
/// # Safety
///
Expand Down Expand Up @@ -266,8 +266,6 @@ impl<T> NonNull<[T]> {
/// This function is safe, but dereferencing the return value is unsafe.
/// See the documentation of [`slice::from_raw_parts`] for slice safety requirements.
///
/// [`slice::from_raw_parts`]: ../../std/slice/fn.from_raw_parts.html
///
/// # Examples
///
/// ```rust
Expand Down Expand Up @@ -357,8 +355,8 @@ impl<T> NonNull<[T]> {
///
/// For the mutable counterpart see [`as_uninit_slice_mut`].
///
/// [`as_ref`]: #method.as_ref
/// [`as_uninit_slice_mut`]: #method.as_uninit_slice_mut
/// [`as_ref`]: NonNull::as_ref
/// [`as_uninit_slice_mut`]: NonNull::as_uninit_slice_mut
///
/// # Safety
///
Expand Down Expand Up @@ -386,10 +384,9 @@ impl<T> NonNull<[T]> {
///
/// This applies even if the result of this method is unused!
///
/// See also [`slice::from_raw_parts`][].
/// See also [`slice::from_raw_parts`].
///
/// [valid]: crate::ptr#safety
/// [`NonNull::dangling()`]: NonNull::dangling
/// [`pointer::offset`]: ../../std/primitive.pointer.html#method.offset
#[inline]
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
Expand All @@ -403,8 +400,8 @@ impl<T> NonNull<[T]> {
///
/// For the shared counterpart see [`as_uninit_slice`].
///
/// [`as_mut`]: #method.as_mut
/// [`as_uninit_slice`]: #method.as_uninit_slice
/// [`as_mut`]: NonNull::as_mut
/// [`as_uninit_slice`]: NonNull::as_uninit_slice
///
/// # Safety
///
Expand Down Expand Up @@ -432,10 +429,9 @@ impl<T> NonNull<[T]> {
///
/// This applies even if the result of this method is unused!
///
/// See also [`slice::from_raw_parts_mut`][].
/// See also [`slice::from_raw_parts_mut`].
///
/// [valid]: crate::ptr#safety
/// [`NonNull::dangling()`]: NonNull::dangling
/// [`pointer::offset`]: ../../std/primitive.pointer.html#method.offset
///
/// # Examples
Expand Down
2 changes: 1 addition & 1 deletion src/doc/rustc/src/platform-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ target | std | host | notes
`thumbv7neon-unknown-linux-gnueabihf` | ✓ | | Thumb2-mode ARMv7a Linux with NEON (kernel 4.4, glibc 2.23)
`thumbv8m.base-none-eabi` | * | | ARMv8-M Baseline
`thumbv8m.main-none-eabi` | * | | ARMv8-M Mainline
`thumbv8m.main-none-eabihf` | * | | ARMv8-M Baseline, hardfloat
`thumbv8m.main-none-eabihf` | * | | ARMv8-M Mainline, hardfloat
`wasm32-unknown-emscripten` | ✓ | | WebAssembly via Emscripten
`wasm32-unknown-unknown` | ✓ | | WebAssembly
`wasm32-wasi` | ✓ | | WebAssembly with WASI
Expand Down
2 changes: 1 addition & 1 deletion src/doc/unstable-book/src/compiler-flags/tls-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ The TLS data must not be in a library loaded after startup (via `dlopen`).
but not in a shared library, and is accessed only from that executable.

`rustc` and LLVM may use a more optimized model than specified if they know that we are producing
and executable rather than a library, or that the `static` item is private enough.
an executable rather than a library, or that the `static` item is private enough.
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'tcx>>)
format!("{{{}{}}}", class, idx)
} else if reg == InlineAsmReg::AArch64(AArch64InlineAsmReg::x30) {
// LLVM doesn't recognize x30
"lr".to_string()
"{lr}".to_string()
} else {
format!("{{{}}}", reg.name())
}
Expand Down
35 changes: 35 additions & 0 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::DefId;
use rustc_hir::{ForeignItemKind, GenericParamKind, PatKind};
use rustc_hir::{HirId, HirIdSet, Node};
use rustc_index::vec::Idx;
use rustc_middle::lint::LintDiagnosticBuilder;
use rustc_middle::ty::subst::{GenericArgKind, Subst};
use rustc_middle::ty::{self, layout::LayoutError, Ty, TyCtxt};
Expand Down Expand Up @@ -2162,6 +2163,40 @@ impl ClashingExternDeclarations {
ckind: CItemKind,
) -> bool {
debug!("structurally_same_type_impl(cx, a = {:?}, b = {:?})", a, b);
let tcx = cx.tcx;

// Given a transparent newtype, reach through and grab the inner
// type unless the newtype makes the type non-null.
let non_transparent_ty = |ty: Ty<'tcx>| -> Ty<'tcx> {
let mut ty = ty;
loop {
if let ty::Adt(def, substs) = ty.kind {
let is_transparent = def.subst(tcx, substs).repr.transparent();
let is_non_null = crate::types::nonnull_optimization_guaranteed(tcx, &def);
debug!(
"non_transparent_ty({:?}) -- type is transparent? {}, type is non-null? {}",
ty, is_transparent, is_non_null
);
if is_transparent && !is_non_null {
debug_assert!(def.variants.len() == 1);
let v = &def.variants[VariantIdx::new(0)];
ty = v
.transparent_newtype_field(tcx)
.expect(
"single-variant transparent structure with zero-sized field",
)
.ty(tcx, substs);
continue;
}
}
debug!("non_transparent_ty -> {:?}", ty);
return ty;
}
};

let a = non_transparent_ty(a);
let b = non_transparent_ty(b);

if !seen_types.insert((a, b)) {
// We've encountered a cycle. There's no point going any further -- the types are
// structurally the same.
Expand Down
18 changes: 11 additions & 7 deletions src/librustc_lint/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc_index::vec::Idx;
use rustc_middle::mir::interpret::{sign_extend, truncate};
use rustc_middle::ty::layout::{IntegerExt, SizeSkeleton};
use rustc_middle::ty::subst::SubstsRef;
use rustc_middle::ty::{self, AdtKind, Ty, TypeFoldable};
use rustc_middle::ty::{self, AdtKind, Ty, TyCtxt, TypeFoldable};
use rustc_span::source_map;
use rustc_span::symbol::sym;
use rustc_span::{Span, DUMMY_SP};
Expand Down Expand Up @@ -527,22 +527,26 @@ enum FfiResult<'tcx> {
FfiUnsafe { ty: Ty<'tcx>, reason: String, help: Option<String> },
}

crate fn nonnull_optimization_guaranteed<'tcx>(tcx: TyCtxt<'tcx>, def: &ty::AdtDef) -> bool {
tcx.get_attrs(def.did)
.iter()
.any(|a| tcx.sess.check_name(a, sym::rustc_nonnull_optimization_guaranteed))
}

/// Is type known to be non-null?
fn ty_is_known_nonnull<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, mode: CItemKind) -> bool {
crate fn ty_is_known_nonnull<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, mode: CItemKind) -> bool {
let tcx = cx.tcx;
match ty.kind {
ty::FnPtr(_) => true,
ty::Ref(..) => true,
ty::Adt(def, _) if def.is_box() && matches!(mode, CItemKind::Definition) => true,
ty::Adt(def, substs) if def.repr.transparent() && !def.is_union() => {
let guaranteed_nonnull_optimization = tcx
.get_attrs(def.did)
.iter()
.any(|a| tcx.sess.check_name(a, sym::rustc_nonnull_optimization_guaranteed));
let marked_non_null = nonnull_optimization_guaranteed(tcx, &def);

if guaranteed_nonnull_optimization {
if marked_non_null {
return true;
}

for variant in &def.variants {
if let Some(field) = variant.transparent_newtype_field(tcx) {
if ty_is_known_nonnull(cx, field.ty(tcx, substs), mode) {
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/static/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,7 @@ h4 > .notable-traits {
#theme-choices > button {
border: none;
width: 100%;
padding: 4px;
padding: 4px 8px;
text-align: center;
background: rgba(0,0,0,0);
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/static/themes/ayu.css
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ kbd {
}

#theme-choices > button:hover, #theme-choices > button:focus {
background-color: rgba(70, 70, 70, 0.33);
background-color: rgba(110, 110, 110, 0.33);
}

@media (max-width: 700px) {
Expand Down
5 changes: 5 additions & 0 deletions src/test/assembly/asm/aarch64-types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,11 @@ check_reg!(v0_f32x4 f32x4 "s0" "fmov");
check_reg!(v0_f64x2 f64x2 "s0" "fmov");

// Regression test for #75761
// CHECK-LABEL: issue_75761:
// CHECK: stp {{{.*}}}lr
// CHECK: //APP
// CHECK: //NO_APP
// CHECK: ldp {{{.*}}}lr
pub unsafe fn issue_75761() {
asm!("", out("v0") _, out("x30") _);
}
22 changes: 22 additions & 0 deletions src/test/codegen/issue-27130.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// compile-flags: -O
// min-llvm-version: 11.0

#![crate_type = "lib"]

// CHECK-LABEL: @trim_in_place
#[no_mangle]
pub fn trim_in_place(a: &mut &[u8]) {
while a.first() == Some(&42) {
// CHECK-NOT: slice_index_order_fail
*a = &a[1..];
}
}

// CHECK-LABEL: @trim_in_place2
#[no_mangle]
pub fn trim_in_place2(a: &mut &[u8]) {
while let Some(&42) = a.first() {
// CHECK-NOT: slice_index_order_fail
*a = &a[2..];
}
}
Loading