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 7 pull requests #50345

Merged
merged 22 commits into from
Apr 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
256096d
Make Vec::new const
mark-i-m Apr 25, 2018
a2105b8
make RawVec::empty const
mark-i-m Apr 25, 2018
20ef0e0
make Vec::new const :P
mark-i-m Apr 26, 2018
c122b3a
not insta-stable
mark-i-m Apr 27, 2018
0212e02
feature on test
mark-i-m Apr 29, 2018
368fe37
Add more links in panic docs
Pazzaz Apr 29, 2018
269d279
Fix some broken links in docs.
ehuss Apr 29, 2018
e5280e4
use const trick
mark-i-m Apr 29, 2018
0a6e91b
Add a few more tests for proc macro feature gating
petrochenkov Apr 29, 2018
f9f9923
heh, logic is hard
mark-i-m Apr 29, 2018
cc53db8
Correct unused field warning on &struct match
varkor Apr 29, 2018
8e8fe90
Correct unused field warning on box struct match
varkor Apr 29, 2018
2eb8343
Correct unused field warning on struct match container patterns
varkor Apr 30, 2018
bd4ebf2
check that #[used] is used only on statics
japaric Apr 30, 2018
21941c8
Update Cargo to 2018-04-28 122fd5be5201913d42e219e132d6569493583bca
SimonSapin Apr 30, 2018
b88c152
Rollup merge of #50233 - mark-i-m:const_vec, r=kennytm
kennytm Apr 30, 2018
1308d99
Rollup merge of #50312 - Pazzaz:master, r=GuillaumeGomez
kennytm Apr 30, 2018
b239293
Rollup merge of #50316 - ehuss:fix-doc-links, r=frewsxcv
kennytm Apr 30, 2018
30c990b
Rollup merge of #50325 - petrochenkov:pmgate, r=alexcrichton
kennytm Apr 30, 2018
cbbdf99
Rollup merge of #50327 - varkor:match-unused-struct-field, r=estebank
kennytm Apr 30, 2018
909ba8a
Rollup merge of #50330 - japaric:used, r=nagisa
kennytm Apr 30, 2018
6166f20
Rollup merge of #50344 - SimonSapin:cargo, r=alexcrichton
kennytm Apr 30, 2018
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
1 change: 1 addition & 0 deletions src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
#![feature(pointer_methods)]
#![feature(inclusive_range_fields)]
#![cfg_attr(stage0, feature(generic_param_attrs))]
#![feature(rustc_const_unstable)]

#![cfg_attr(not(test), feature(fn_traits, i128))]
#![cfg_attr(test, feature(test))]
Expand Down
10 changes: 6 additions & 4 deletions src/liballoc/raw_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,16 @@ pub struct RawVec<T, A: Alloc = Global> {
impl<T, A: Alloc> RawVec<T, A> {
/// Like `new` but parameterized over the choice of allocator for
/// the returned RawVec.
pub fn new_in(a: A) -> Self {
pub const fn new_in(a: A) -> Self {
// !0 is usize::MAX. This branch should be stripped at compile time.
let cap = if mem::size_of::<T>() == 0 { !0 } else { 0 };
// FIXME(mark-i-m): use this line when `if`s are allowed in `const`
//let cap = if mem::size_of::<T>() == 0 { !0 } else { 0 };

// Unique::empty() doubles as "unallocated" and "zero-sized allocation"
RawVec {
ptr: Unique::empty(),
cap,
// FIXME(mark-i-m): use `cap` when ifs are allowed in const
cap: [0, !0][(mem::size_of::<T>() == 0) as usize],
a,
}
}
Expand Down Expand Up @@ -120,7 +122,7 @@ impl<T> RawVec<T, Global> {
/// RawVec with capacity 0. If T has 0 size, then it makes a
/// RawVec with capacity `usize::MAX`. Useful for implementing
/// delayed allocation.
pub fn new() -> Self {
pub const fn new() -> Self {
Self::new_in(Global)
}

Expand Down
3 changes: 2 additions & 1 deletion src/liballoc/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@ impl<T> Vec<T> {
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new() -> Vec<T> {
#[rustc_const_unstable(feature = "const_vec_new")]
pub const fn new() -> Vec<T> {
Vec {
buf: RawVec::new(),
len: 0,
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/iter/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,8 @@ pub trait Iterator {
/// `flatten()` a three-dimensional array the result will be
/// two-dimensional and not one-dimensional. To get a one-dimensional
/// structure, you have to `flatten()` again.
///
/// [`flat_map()`]: #method.flat_map
#[inline]
#[unstable(feature = "iterator_flatten", issue = "48213")]
fn flatten(self) -> Flatten<Self>
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,8 @@ unsafe impl<'a, T: ?Sized> Freeze for &'a mut T {}
/// `Pin` pointer.
///
/// This trait is automatically implemented for almost every type.
///
/// [`Pin`]: ../mem/struct.Pin.html
#[unstable(feature = "pin", issue = "49150")]
pub unsafe auto trait Unpin {}

Expand Down
5 changes: 2 additions & 3 deletions src/libcore/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2552,10 +2552,9 @@ impl<T: Sized> Unique<T> {
/// This is useful for initializing types which lazily allocate, like
/// `Vec::new` does.
// FIXME: rename to dangling() to match NonNull?
pub fn empty() -> Self {
pub const fn empty() -> Self {
unsafe {
let ptr = mem::align_of::<T>() as *mut T;
Unique::new_unchecked(ptr)
Unique::new_unchecked(mem::align_of::<T>() as *mut T)
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/librustc/hir/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ enum Target {
Expression,
Statement,
Closure,
Static,
Other,
}

Expand All @@ -43,6 +44,7 @@ impl Target {
hir::ItemEnum(..) => Target::Enum,
hir::ItemConst(..) => Target::Const,
hir::ItemForeignMod(..) => Target::ForeignMod,
hir::ItemStatic(..) => Target::Static,
_ => Target::Other,
}
}
Expand Down Expand Up @@ -102,6 +104,7 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
}

self.check_repr(item, target);
self.check_used(item, target);
}

/// Check if an `#[inline]` is applied to a function or a closure.
Expand Down Expand Up @@ -305,6 +308,15 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
}
}
}

fn check_used(&self, item: &hir::Item, target: Target) {
for attr in &item.attrs {
if attr.name().map(|name| name == "used").unwrap_or(false) && target != Target::Static {
self.tcx.sess
.span_err(attr.span, "attribute must be applied to a `static` variable");
}
}
}
}

impl<'a, 'tcx> Visitor<'tcx> for CheckAttrVisitor<'a, 'tcx> {
Expand Down
44 changes: 35 additions & 9 deletions src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ use ty::{self, TyCtxt};
use lint;
use util::nodemap::{NodeMap, NodeSet};

use std::collections::VecDeque;
use std::{fmt, usize};
use std::io::prelude::*;
use std::io;
Expand Down Expand Up @@ -412,18 +413,43 @@ fn visit_local<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, local: &'tcx hir::Local) {
}

fn visit_arm<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, arm: &'tcx hir::Arm) {
for pat in &arm.pats {
// for struct patterns, take note of which fields used shorthand (`x` rather than `x: x`)
for mut pat in &arm.pats {
// For struct patterns, take note of which fields used shorthand
// (`x` rather than `x: x`).
//
// FIXME: according to the rust-lang-nursery/rustc-guide book, `NodeId`s are to be phased
// out in favor of `HirId`s; however, we need to match the signature of `each_binding`,
// which uses `NodeIds`.
// FIXME: according to the rust-lang-nursery/rustc-guide book, `NodeId`s are to be
// phased out in favor of `HirId`s; however, we need to match the signature of
// `each_binding`, which uses `NodeIds`.
let mut shorthand_field_ids = NodeSet();
if let hir::PatKind::Struct(_, ref fields, _) = pat.node {
for field in fields {
if field.node.is_shorthand {
shorthand_field_ids.insert(field.node.pat.id);
let mut pats = VecDeque::new();
pats.push_back(pat);
while let Some(pat) = pats.pop_front() {
use hir::PatKind::*;
match pat.node {
Binding(_, _, _, ref inner_pat) => {
pats.extend(inner_pat.iter());
}
Struct(_, ref fields, _) => {
for field in fields {
if field.node.is_shorthand {
shorthand_field_ids.insert(field.node.pat.id);
}
}
}
Ref(ref inner_pat, _) |
Box(ref inner_pat) => {
pats.push_back(inner_pat);
}
TupleStruct(_, ref inner_pats, _) |
Tuple(ref inner_pats, _) => {
pats.extend(inner_pats.iter());
}
Slice(ref pre_pats, ref inner_pat, ref post_pats) => {
pats.extend(pre_pats.iter());
pats.extend(inner_pat.iter());
pats.extend(post_pats.iter());
}
_ => {}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/libstd/collections/hash/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl TaggedHashUintPtr {
///
/// Essential invariants of this structure:
///
/// - if t.hashes[i] == EMPTY_BUCKET, then `Bucket::at_index(&t, i).raw`
/// - if `t.hashes[i] == EMPTY_BUCKET`, then `Bucket::at_index(&t, i).raw`
/// points to 'undefined' contents. Don't read from it. This invariant is
/// enforced outside this module with the `EmptyBucket`, `FullBucket`,
/// and `SafeHash` types.
Expand Down
1 change: 1 addition & 0 deletions src/libstd/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,7 @@ impl CStr {
///
/// [`Cow`]: ../borrow/enum.Cow.html
/// [`Borrowed`]: ../borrow/enum.Cow.html#variant.Borrowed
/// [`Owned`]: ../borrow/enum.Cow.html#variant.Owned
/// [`str`]: ../primitive.str.html
/// [`String`]: ../string/struct.String.html
///
Expand Down
51 changes: 33 additions & 18 deletions src/libstd/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ pub use core::panic::{PanicInfo, Location};
/// A marker trait which represents "panic safe" types in Rust.
///
/// This trait is implemented by default for many types and behaves similarly in
/// terms of inference of implementation to the `Send` and `Sync` traits. The
/// purpose of this trait is to encode what types are safe to cross a `catch_unwind`
/// terms of inference of implementation to the [`Send`] and [`Sync`] traits. The
/// purpose of this trait is to encode what types are safe to cross a [`catch_unwind`]
/// boundary with no fear of unwind safety.
///
/// [`Send`]: ../marker/trait.Send.html
/// [`Sync`]: ../marker/trait.Sync.html
/// [`catch_unwind`]: ./fn.catch_unwind.html
///
/// ## What is unwind safety?
///
/// In Rust a function can "return" early if it either panics or calls a
Expand Down Expand Up @@ -95,12 +99,13 @@ pub use core::panic::{PanicInfo, Location};
///
/// ## When should `UnwindSafe` be used?
///
/// Is not intended that most types or functions need to worry about this trait.
/// It is only used as a bound on the `catch_unwind` function and as mentioned above,
/// the lack of `unsafe` means it is mostly an advisory. The `AssertUnwindSafe`
/// wrapper struct in this module can be used to force this trait to be
/// implemented for any closed over variables passed to the `catch_unwind` function
/// (more on this below).
/// It is not intended that most types or functions need to worry about this trait.
/// It is only used as a bound on the `catch_unwind` function and as mentioned
/// above, the lack of `unsafe` means it is mostly an advisory. The
/// [`AssertUnwindSafe`] wrapper struct can be used to force this trait to be
/// implemented for any closed over variables passed to `catch_unwind`.
///
/// [`AssertUnwindSafe`]: ./struct.AssertUnwindSafe.html
#[stable(feature = "catch_unwind", since = "1.9.0")]
#[rustc_on_unimplemented = "the type {Self} may not be safely transferred \
across an unwind boundary"]
Expand All @@ -109,11 +114,14 @@ pub auto trait UnwindSafe {}
/// A marker trait representing types where a shared reference is considered
/// unwind safe.
///
/// This trait is namely not implemented by `UnsafeCell`, the root of all
/// This trait is namely not implemented by [`UnsafeCell`], the root of all
/// interior mutability.
///
/// This is a "helper marker trait" used to provide impl blocks for the
/// `UnwindSafe` trait, for more information see that documentation.
/// [`UnwindSafe`] trait, for more information see that documentation.
///
/// [`UnsafeCell`]: ../cell/struct.UnsafeCell.html
/// [`UnwindSafe`]: ./trait.UnwindSafe.html
#[stable(feature = "catch_unwind", since = "1.9.0")]
#[rustc_on_unimplemented = "the type {Self} may contain interior mutability \
and a reference may not be safely transferrable \
Expand All @@ -122,14 +130,15 @@ pub auto trait RefUnwindSafe {}

/// A simple wrapper around a type to assert that it is unwind safe.
///
/// When using `catch_unwind` it may be the case that some of the closed over
/// When using [`catch_unwind`] it may be the case that some of the closed over
/// variables are not unwind safe. For example if `&mut T` is captured the
/// compiler will generate a warning indicating that it is not unwind safe. It
/// may not be the case, however, that this is actually a problem due to the
/// specific usage of `catch_unwind` if unwind safety is specifically taken into
/// specific usage of [`catch_unwind`] if unwind safety is specifically taken into
/// account. This wrapper struct is useful for a quick and lightweight
/// annotation that a variable is indeed unwind safe.
///
/// [`catch_unwind`]: ./fn.catch_unwind.html
/// # Examples
///
/// One way to use `AssertUnwindSafe` is to assert that the entire closure
Expand Down Expand Up @@ -318,18 +327,22 @@ impl<T: fmt::Debug> fmt::Debug for AssertUnwindSafe<T> {
/// panic and allowing a graceful handling of the error.
///
/// It is **not** recommended to use this function for a general try/catch
/// mechanism. The `Result` type is more appropriate to use for functions that
/// mechanism. The [`Result`] type is more appropriate to use for functions that
/// can fail on a regular basis. Additionally, this function is not guaranteed
/// to catch all panics, see the "Notes" section below.
///
/// The closure provided is required to adhere to the `UnwindSafe` trait to ensure
/// [`Result`]: ../result/enum.Result.html
///
/// The closure provided is required to adhere to the [`UnwindSafe`] trait to ensure
/// that all captured variables are safe to cross this boundary. The purpose of
/// this bound is to encode the concept of [exception safety][rfc] in the type
/// system. Most usage of this function should not need to worry about this
/// bound as programs are naturally unwind safe without `unsafe` code. If it
/// becomes a problem the associated `AssertUnwindSafe` wrapper type in this
/// module can be used to quickly assert that the usage here is indeed unwind
/// safe.
/// becomes a problem the [`AssertUnwindSafe`] wrapper struct can be used to quickly
/// assert that the usage here is indeed unwind safe.
///
/// [`AssertUnwindSafe`]: ./struct.AssertUnwindSafe.html
/// [`UnwindSafe`]: ./trait.UnwindSafe.html
///
/// [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/1236-stabilize-catch-panic.md
///
Expand Down Expand Up @@ -364,9 +377,11 @@ pub fn catch_unwind<F: FnOnce() -> R + UnwindSafe, R>(f: F) -> Result<R> {

/// Triggers a panic without invoking the panic hook.
///
/// This is designed to be used in conjunction with `catch_unwind` to, for
/// This is designed to be used in conjunction with [`catch_unwind`] to, for
/// example, carry a panic across a layer of C code.
///
/// [`catch_unwind`]: ./fn.catch_unwind.html
///
/// # Notes
///
/// Note that panics in Rust are not always implemented via unwinding, but they
Expand Down
8 changes: 7 additions & 1 deletion src/libstd/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ static mut HOOK: Hook = Hook::Default;
/// is invoked. As such, the hook will run with both the aborting and unwinding
/// runtimes. The default hook prints a message to standard error and generates
/// a backtrace if requested, but this behavior can be customized with the
/// `set_hook` and `take_hook` functions.
/// `set_hook` and [`take_hook`] functions.
///
/// [`take_hook`]: ./fn.take_hook.html
///
/// The hook is provided with a `PanicInfo` struct which contains information
/// about the origin of the panic, including the payload passed to `panic!` and
Expand Down Expand Up @@ -121,6 +123,10 @@ pub fn set_hook(hook: Box<Fn(&PanicInfo) + 'static + Sync + Send>) {

/// Unregisters the current panic hook, returning it.
///
/// *See also the function [`set_hook`].*
///
/// [`set_hook`]: ./fn.set_hook.html
///
/// If no custom hook is registered, the default hook will be returned.
///
/// # Panics
Expand Down
Loading