Skip to content

Rollup of 10 pull requests #75999

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
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
acd3962
Fix typo in release notes
camelid Aug 25, 2020
1727c7a
Improve helper wording
GuillaumeGomez Aug 27, 2020
86e42c2
Delay help popup creation to when it's needed
GuillaumeGomez Aug 27, 2020
b71c8b6
should not try to apply field accessing on enum
csmoe Aug 27, 2020
230b10b
Rollup merge of #75881 - pickfire:patch-5, r=GuillaumeGomez
Dylan-DPC Aug 27, 2020
a94bff8
Rollup merge of #75885 - jumbatm:issue75739-clashing-extern-declarati…
Dylan-DPC Aug 27, 2020
eb5ff67
Rollup merge of #75892 - ArekPiekarz:unstable_book_tls_model_typo, r=…
Dylan-DPC Aug 27, 2020
e187ea9
Rollup merge of #75901 - GuillaumeGomez:ayu-theme-button-hover-backgr…
Dylan-DPC Aug 27, 2020
b7ab651
Rollup merge of #75910 - bugadani:testcase, r=oli-obk
Dylan-DPC Aug 27, 2020
6ff7f7e
Rollup merge of #75917 - poliorcetics:intra-doc-core-nonnull, r=jyn514
Dylan-DPC Aug 27, 2020
ed771ce
Rollup merge of #75919 - rust-lang:jonas-schievink-patch-1, r=ehuss
Dylan-DPC Aug 27, 2020
33b9361
Rollup merge of #75926 - camelid:patch-5, r=jonas-schievink
Dylan-DPC Aug 27, 2020
72c8fb4
Rollup merge of #75976 - GuillaumeGomez:help-popup, r=jyn514
Dylan-DPC Aug 27, 2020
e23290f
Rollup merge of #75985 - csmoe:issue-61076-1, r=estebank
Dylan-DPC Aug 27, 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
2 changes: 1 addition & 1 deletion RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Language
function's caller's location information for panic messages.][72445]
- [Recursively indexing into tuples no longer needs parentheses.][71322] E.g.
`x.0.0` over `(x.0).0`.
- [`mem::transmute` can now be used in static and constants.][72920] **Note**
- [`mem::transmute` can now be used in statics and constants.][72920] **Note**
You currently can't use `mem::transmute` in constant functions.

Compiler
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.
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
18 changes: 11 additions & 7 deletions src/librustc_typeck/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1545,13 +1545,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
normalized_ty.kind,
);
if let ty::Adt(def, _) = normalized_ty.kind {
if def.non_enum_variant().fields.iter().any(|field| field.ident == field_ident) {
err.span_suggestion_verbose(
base.span.shrink_to_hi(),
"consider awaiting before field access",
".await".to_string(),
Applicability::MaybeIncorrect,
);
// no field access on enum type
if !def.is_enum() {
if def.non_enum_variant().fields.iter().any(|field| field.ident == field_ident)
{
err.span_suggestion_verbose(
base.span.shrink_to_hi(),
"consider awaiting before field access",
".await".to_string(),
Applicability::MaybeIncorrect,
);
}
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ function defocusSearchBar() {
}

function getHelpElement() {
buildHelperPopup();
return document.getElementById("help");
}

Expand Down Expand Up @@ -2807,8 +2808,8 @@ function defocusSearchBar() {

var infos = [
"Prefix searches with a type followed by a colon (e.g., <code>fn:</code>) to \
restrict the search to a given type.",
"Accepted types are: <code>fn</code>, <code>mod</code>, <code>struct</code>, \
restrict the search to a given item kind.",
"Accepted kinds are: <code>fn</code>, <code>mod</code>, <code>struct</code>, \
<code>enum</code>, <code>trait</code>, <code>type</code>, <code>macro</code>, \
and <code>const</code>.",
"Search functions by type signature (e.g., <code>vec -&gt; usize</code> or \
Expand All @@ -2828,12 +2829,12 @@ function defocusSearchBar() {

popup.appendChild(container);
insertAfter(popup, getSearchElement());
// So that it's only built once and then it'll do nothing when called!
buildHelperPopup = function() {};
}

onHashChange(null);
window.onhashchange = onHashChange;

buildHelperPopup();
}());

// This is required in firefox. Explanations: when going back in the history, firefox doesn't re-run
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
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[1..];
}
}
Loading