Skip to content
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

Rollup of 6 pull requests #70966

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
9d13520
Replace "rc"/"arc" lang items with Rc/Arc diagnostic items.
eddyb Apr 8, 2020
f9a691f
de-abuse TyKind::Error: handle empty slices in array patterns
mark-i-m Apr 8, 2020
e1c838d
de-abuse TyKind::Error: ice on missing slice type
mark-i-m Apr 8, 2020
15f8d89
rustc_target::abi: add Primitive variant to FieldsShape.
anyska Mar 31, 2020
44daa45
Clean up E0511 explanation
GuillaumeGomez Apr 9, 2020
f2e4709
improve comments
mark-i-m Apr 9, 2020
444ad62
Add utility to find locals that don't use `Storage*` annotations
ecstatic-morse Mar 29, 2020
fcd1f5b
Make `MaybeStorageLive` correct for all kinds of MIR bodies
ecstatic-morse Mar 29, 2020
335fd6b
Use new utility in `eval_context`
ecstatic-morse Mar 29, 2020
02c65e1
Use new utility in `transform/generator.rs`
ecstatic-morse Mar 29, 2020
7154860
Explain why we remove `self` from storage live locals
ecstatic-morse Apr 9, 2020
209087b
Use `Visitor` for `AlwaysLiveLocals`
ecstatic-morse Apr 9, 2020
1761a65
mark a temporary hack as such
RalfJung Apr 9, 2020
23425d6
Rollup merge of #70447 - ecstatic-morse:storage-live-always, r=tmandry
Dylan-DPC Apr 9, 2020
58c7615
Rollup merge of #70629 - anyska:fields-variant, r=oli-obk
Dylan-DPC Apr 9, 2020
7c5fef9
Rollup merge of #70913 - eddyb:rc-arc-diagnostic-items, r=matthewjasper
Dylan-DPC Apr 9, 2020
853d3bc
Rollup merge of #70932 - mark-i-m:de-abuse-err-2, r=Centril
Dylan-DPC Apr 9, 2020
fbe3977
Rollup merge of #70952 - GuillaumeGomez:cleanup-e0511, r=Dylan-DPC
Dylan-DPC Apr 9, 2020
f124d7f
Rollup merge of #70964 - RalfJung:mark-cli-lint-hack, r=petrochenkov
Dylan-DPC Apr 9, 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
3 changes: 2 additions & 1 deletion src/liballoc/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ struct RcBox<T: ?Sized> {
/// type `T`.
///
/// [get_mut]: #method.get_mut
#[cfg_attr(not(test), lang = "rc")]
#[cfg_attr(all(bootstrap, not(test)), lang = "rc")]
#[cfg_attr(not(test), rustc_diagnostic_item = "Rc")]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Rc<T: ?Sized> {
ptr: NonNull<RcBox<T>>,
Expand Down
3 changes: 2 additions & 1 deletion src/liballoc/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ macro_rules! acquire {
/// counting in general.
///
/// [rc_examples]: ../../std/rc/index.html#examples
#[cfg_attr(not(test), lang = "arc")]
#[cfg_attr(all(bootstrap, not(test)), lang = "arc")]
#[cfg_attr(not(test), rustc_diagnostic_item = "Arc")]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Arc<T: ?Sized> {
ptr: NonNull<ArcInner<T>>,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_llvm/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn uncached_llvm_type<'a, 'tcx>(
};

match layout.fields {
FieldsShape::Union(_) => {
FieldsShape::Primitive | FieldsShape::Union(_) => {
let fill = cx.type_padding_filler(layout.size, layout.align.abi);
let packed = false;
match name {
Expand Down Expand Up @@ -368,7 +368,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
_ => {}
}
match self.fields {
FieldsShape::Union(_) => {
FieldsShape::Primitive | FieldsShape::Union(_) => {
bug!("TyAndLayout::llvm_field_index({:?}): not applicable", self)
}

Expand Down
6 changes: 6 additions & 0 deletions src/librustc_data_structures/stable_hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ impl<CTX> HashStable<CTX> for ::std::num::NonZeroU32 {
}
}

impl<CTX> HashStable<CTX> for ::std::num::NonZeroUsize {
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
self.get().hash_stable(ctx, hasher)
}
}

impl<CTX> HashStable<CTX> for f32 {
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
let val: u32 = unsafe { ::std::mem::transmute(*self) };
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_error_codes/error_codes/E0152.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Erroneous code example:
```compile_fail,E0152
#![feature(lang_items)]

#[lang = "arc"]
struct Foo; // error: duplicate lang item found: `arc`
#[lang = "owned_box"]
struct Foo; // error: duplicate lang item found: `owned_box`
```

Lang items are already implemented in the standard library. Unless you are
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_error_codes/error_codes/E0511.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Invalid monomorphization of an intrinsic function was used. Erroneous code
example:
Invalid monomorphization of an intrinsic function was used.

Erroneous code example:

```compile_fail,E0511
#![feature(platform_intrinsics)]
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_error_codes/error_codes/E0718.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ Examples of erroneous code:
```compile_fail,E0718
#![feature(lang_items)]

#[lang = "arc"]
#[lang = "owned_box"]
static X: u32 = 42;
```
3 changes: 0 additions & 3 deletions src/librustc_hir/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,4 @@ language_item_table! {
AlignOffsetLangItem, "align_offset", align_offset_fn, Target::Fn;

TerminationTraitLangItem, "termination", termination, Target::Trait;

Arc, "arc", arc, Target::Struct;
Rc, "rc", rc, Target::Struct;
}
6 changes: 6 additions & 0 deletions src/librustc_middle/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2209,6 +2209,12 @@ impl<'tcx> TyCtxt<'tcx> {
Some(self.mk_generic_adt(def_id, ty))
}

#[inline]
pub fn mk_diagnostic_item(self, ty: Ty<'tcx>, name: Symbol) -> Option<Ty<'tcx>> {
let def_id = self.get_diagnostic_item(name)?;
Some(self.mk_generic_adt(def_id, ty))
}

#[inline]
pub fn mk_maybe_uninit(self, ty: Ty<'tcx>) -> Ty<'tcx> {
let def_id = self.require_lang_item(lang_items::MaybeUninitLangItem, None);
Expand Down
15 changes: 11 additions & 4 deletions src/librustc_middle/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use std::cmp;
use std::fmt;
use std::iter;
use std::mem;
use std::num::NonZeroUsize;
use std::ops::Bound;

pub trait IntegerExt {
Expand Down Expand Up @@ -518,7 +519,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
// The never type.
ty::Never => tcx.intern_layout(Layout {
variants: Variants::Single { index: VariantIdx::new(0) },
fields: FieldsShape::Union(0),
fields: FieldsShape::Primitive,
abi: Abi::Uninhabited,
largest_niche: None,
align: dl.i8_align,
Expand Down Expand Up @@ -744,7 +745,10 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {

return Ok(tcx.intern_layout(Layout {
variants: Variants::Single { index },
fields: FieldsShape::Union(variants[index].len()),
fields: FieldsShape::Union(
NonZeroUsize::new(variants[index].len())
.ok_or(LayoutError::Unknown(ty))?,
),
abi,
largest_niche: None,
align,
Expand Down Expand Up @@ -1988,7 +1992,7 @@ where
if index == variant_index &&
// Don't confuse variants of uninhabited enums with the enum itself.
// For more details see https://github.com/rust-lang/rust/issues/69763.
this.fields != FieldsShape::Union(0) =>
this.fields != FieldsShape::Primitive =>
{
this.layout
}
Expand All @@ -2006,7 +2010,10 @@ where
let tcx = cx.tcx();
tcx.intern_layout(Layout {
variants: Variants::Single { index: variant_index },
fields: FieldsShape::Union(fields),
fields: match NonZeroUsize::new(fields) {
Some(fields) => FieldsShape::Union(fields),
None => FieldsShape::Arbitrary { offsets: vec![], memory_index: vec![] },
},
abi: Abi::Uninhabited,
largest_niche: None,
align: tcx.data_layout.i8_align,
Expand Down
23 changes: 1 addition & 22 deletions src/librustc_middle/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1829,14 +1829,9 @@ bitflags! {
const IS_BOX = 1 << 6;
/// Indicates whether the type is `ManuallyDrop`.
const IS_MANUALLY_DROP = 1 << 7;
// FIXME(matthewjasper) replace these with diagnostic items
/// Indicates whether the type is an `Arc`.
const IS_ARC = 1 << 8;
/// Indicates whether the type is an `Rc`.
const IS_RC = 1 << 9;
/// Indicates whether the variant list of this ADT is `#[non_exhaustive]`.
/// (i.e., this flag is never set unless this ADT is an enum).
const IS_VARIANT_LIST_NON_EXHAUSTIVE = 1 << 10;
const IS_VARIANT_LIST_NON_EXHAUSTIVE = 1 << 8;
}
}

Expand Down Expand Up @@ -2221,12 +2216,6 @@ impl<'tcx> AdtDef {
if Some(did) == tcx.lang_items().manually_drop() {
flags |= AdtFlags::IS_MANUALLY_DROP;
}
if Some(did) == tcx.lang_items().arc() {
flags |= AdtFlags::IS_ARC;
}
if Some(did) == tcx.lang_items().rc() {
flags |= AdtFlags::IS_RC;
}

AdtDef { did, variants, flags, repr }
}
Expand Down Expand Up @@ -2305,16 +2294,6 @@ impl<'tcx> AdtDef {
self.flags.contains(AdtFlags::IS_PHANTOM_DATA)
}

/// Returns `true` if this is `Arc<T>`.
pub fn is_arc(&self) -> bool {
self.flags.contains(AdtFlags::IS_ARC)
}

/// Returns `true` if this is `Rc<T>`.
pub fn is_rc(&self) -> bool {
self.flags.contains(AdtFlags::IS_RC)
}

/// Returns `true` if this is Box<T>.
#[inline]
pub fn is_box(&self) -> bool {
Expand Down
18 changes: 0 additions & 18 deletions src/librustc_middle/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1864,24 +1864,6 @@ impl<'tcx> TyS<'tcx> {
self.is_region_ptr() || self.is_unsafe_ptr() || self.is_fn_ptr()
}

/// Returns `true` if this type is an `Arc<T>`.
#[inline]
pub fn is_arc(&self) -> bool {
match self.kind {
Adt(def, _) => def.is_arc(),
_ => false,
}
}

/// Returns `true` if this type is an `Rc<T>`.
#[inline]
pub fn is_rc(&self) -> bool {
match self.kind {
Adt(def, _) => def.is_rc(),
_ => false,
}
}

#[inline]
pub fn is_box(&self) -> bool {
match self.kind {
Expand Down
30 changes: 15 additions & 15 deletions src/librustc_mir/borrow_check/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc_middle::mir::{
};
use rustc_middle::ty::print::Print;
use rustc_middle::ty::{self, DefIdTree, Ty, TyCtxt};
use rustc_span::Span;
use rustc_span::{symbol::sym, Span};
use rustc_target::abi::VariantIdx;

use super::borrow_set::BorrowData;
Expand Down Expand Up @@ -632,20 +632,20 @@ pub(super) enum BorrowedContentSource<'tcx> {
}

impl BorrowedContentSource<'tcx> {
pub(super) fn describe_for_unnamed_place(&self) -> String {
pub(super) fn describe_for_unnamed_place(&self, tcx: TyCtxt<'_>) -> String {
match *self {
BorrowedContentSource::DerefRawPointer => "a raw pointer".to_string(),
BorrowedContentSource::DerefSharedRef => "a shared reference".to_string(),
BorrowedContentSource::DerefMutableRef => "a mutable reference".to_string(),
BorrowedContentSource::OverloadedDeref(ty) => {
if ty.is_rc() {
BorrowedContentSource::OverloadedDeref(ty) => match ty.kind {
ty::Adt(def, _) if tcx.is_diagnostic_item(sym::Rc, def.did) => {
"an `Rc`".to_string()
} else if ty.is_arc() {
}
ty::Adt(def, _) if tcx.is_diagnostic_item(sym::Arc, def.did) => {
"an `Arc`".to_string()
} else {
format!("dereference of `{}`", ty)
}
}
_ => format!("dereference of `{}`", ty),
},
BorrowedContentSource::OverloadedIndex(ty) => format!("index of `{}`", ty),
}
}
Expand All @@ -662,22 +662,22 @@ impl BorrowedContentSource<'tcx> {
}
}

pub(super) fn describe_for_immutable_place(&self) -> String {
pub(super) fn describe_for_immutable_place(&self, tcx: TyCtxt<'_>) -> String {
match *self {
BorrowedContentSource::DerefRawPointer => "a `*const` pointer".to_string(),
BorrowedContentSource::DerefSharedRef => "a `&` reference".to_string(),
BorrowedContentSource::DerefMutableRef => {
bug!("describe_for_immutable_place: DerefMutableRef isn't immutable")
}
BorrowedContentSource::OverloadedDeref(ty) => {
if ty.is_rc() {
BorrowedContentSource::OverloadedDeref(ty) => match ty.kind {
ty::Adt(def, _) if tcx.is_diagnostic_item(sym::Rc, def.did) => {
"an `Rc`".to_string()
} else if ty.is_arc() {
}
ty::Adt(def, _) if tcx.is_diagnostic_item(sym::Arc, def.did) => {
"an `Arc`".to_string()
} else {
format!("a dereference of `{}`", ty)
}
}
_ => format!("a dereference of `{}`", ty),
},
BorrowedContentSource::OverloadedIndex(ty) => format!("an index of `{}`", ty),
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/librustc_mir/borrow_check/diagnostics/move_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
span,
&format!("`{}` which is behind a {}", place_desc, source_desc),
),
(_, _) => self.cannot_move_out_of(span, &source.describe_for_unnamed_place()),
(_, _) => self.cannot_move_out_of(
span,
&source.describe_for_unnamed_place(self.infcx.tcx),
),
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
local: the_place_err.local,
projection: proj_base,
});
let pointer_type = source.describe_for_immutable_place();
let pointer_type = source.describe_for_immutable_place(self.infcx.tcx);
opt_source = Some(source);
if let Some(desc) = access_place_desc {
item_msg = format!("`{}`", desc);
Expand Down
22 changes: 17 additions & 5 deletions src/librustc_mir/dataflow/impls/storage_liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@ pub use super::*;

use crate::dataflow::BottomValue;
use crate::dataflow::{self, GenKill, Results, ResultsRefCursor};
use crate::util::storage::AlwaysLiveLocals;
use rustc_middle::mir::visit::{NonMutatingUseContext, PlaceContext, Visitor};
use rustc_middle::mir::*;
use std::cell::RefCell;

#[derive(Copy, Clone)]
pub struct MaybeStorageLive;
#[derive(Clone)]
pub struct MaybeStorageLive {
always_live_locals: AlwaysLiveLocals,
}

impl MaybeStorageLive {
pub fn new(always_live_locals: AlwaysLiveLocals) -> Self {
MaybeStorageLive { always_live_locals }
}
}

impl dataflow::AnalysisDomain<'tcx> for MaybeStorageLive {
type Idx = Local;
Expand All @@ -19,9 +28,12 @@ impl dataflow::AnalysisDomain<'tcx> for MaybeStorageLive {
}

fn initialize_start_block(&self, body: &mir::Body<'tcx>, on_entry: &mut BitSet<Self::Idx>) {
// The resume argument is live on function entry (we don't care about
// the `self` argument)
for arg in body.args_iter().skip(1) {
assert_eq!(body.local_decls.len(), self.always_live_locals.domain_size());
for local in self.always_live_locals.iter() {
on_entry.insert(local);
}

for arg in body.args_iter() {
on_entry.insert(arg);
}
}
Expand Down
19 changes: 10 additions & 9 deletions src/librustc_mir/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use super::{
Immediate, MPlaceTy, Machine, MemPlace, MemPlaceMeta, Memory, OpTy, Operand, Place, PlaceTy,
ScalarMaybeUndef, StackPopJump,
};
use crate::util::storage::AlwaysLiveLocals;

pub struct InterpCx<'mir, 'tcx, M: Machine<'mir, 'tcx>> {
/// Stores the `Machine` instance.
Expand Down Expand Up @@ -610,17 +611,17 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
// Now mark those locals as dead that we do not want to initialize
match self.tcx.def_kind(instance.def_id()) {
// statics and constants don't have `Storage*` statements, no need to look for them
//
// FIXME: The above is likely untrue. See
// <https://github.com/rust-lang/rust/pull/70004#issuecomment-602022110>. Is it
// okay to ignore `StorageDead`/`StorageLive` annotations during CTFE?
Some(DefKind::Static) | Some(DefKind::Const) | Some(DefKind::AssocConst) => {}
_ => {
for block in body.basic_blocks() {
for stmt in block.statements.iter() {
use rustc_middle::mir::StatementKind::{StorageDead, StorageLive};
match stmt.kind {
StorageLive(local) | StorageDead(local) => {
locals[local].value = LocalValue::Dead;
}
_ => {}
}
// Mark locals that use `Storage*` annotations as dead on function entry.
let always_live = AlwaysLiveLocals::new(self.body());
for local in locals.indices() {
if !always_live.contains(local) {
locals[local].value = LocalValue::Dead;
}
}
}
Expand Down
Loading