Skip to content

Commit 17841cc

Browse files
committed
Auto merge of #50345 - kennytm:rollup, r=kennytm
Rollup of 7 pull requests Successful merges: - #50233 (Make `Vec::new` a `const fn`) - #50312 (Add more links in panic docs) - #50316 (Fix some broken links in docs.) - #50325 (Add a few more tests for proc macro feature gating) - #50327 (Display correct unused field suggestion for nested struct patterns) - #50330 (check that #[used] is used only on statics) - #50344 (Update Cargo to 2018-04-28 122fd5be5201913d42e219e132d6569493583bca) Failed merges:
2 parents 4745092 + 6166f20 commit 17841cc

File tree

18 files changed

+277
-57
lines changed

18 files changed

+277
-57
lines changed

src/liballoc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
#![feature(pointer_methods)]
125125
#![feature(inclusive_range_fields)]
126126
#![cfg_attr(stage0, feature(generic_param_attrs))]
127+
#![feature(rustc_const_unstable)]
127128

128129
#![cfg_attr(not(test), feature(fn_traits, i128))]
129130
#![cfg_attr(test, feature(test))]

src/liballoc/raw_vec.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,16 @@ pub struct RawVec<T, A: Alloc = Global> {
5656
impl<T, A: Alloc> RawVec<T, A> {
5757
/// Like `new` but parameterized over the choice of allocator for
5858
/// the returned RawVec.
59-
pub fn new_in(a: A) -> Self {
59+
pub const fn new_in(a: A) -> Self {
6060
// !0 is usize::MAX. This branch should be stripped at compile time.
61-
let cap = if mem::size_of::<T>() == 0 { !0 } else { 0 };
61+
// FIXME(mark-i-m): use this line when `if`s are allowed in `const`
62+
//let cap = if mem::size_of::<T>() == 0 { !0 } else { 0 };
6263

6364
// Unique::empty() doubles as "unallocated" and "zero-sized allocation"
6465
RawVec {
6566
ptr: Unique::empty(),
66-
cap,
67+
// FIXME(mark-i-m): use `cap` when ifs are allowed in const
68+
cap: [0, !0][(mem::size_of::<T>() == 0) as usize],
6769
a,
6870
}
6971
}
@@ -120,7 +122,7 @@ impl<T> RawVec<T, Global> {
120122
/// RawVec with capacity 0. If T has 0 size, then it makes a
121123
/// RawVec with capacity `usize::MAX`. Useful for implementing
122124
/// delayed allocation.
123-
pub fn new() -> Self {
125+
pub const fn new() -> Self {
124126
Self::new_in(Global)
125127
}
126128

src/liballoc/vec.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,8 @@ impl<T> Vec<T> {
322322
/// ```
323323
#[inline]
324324
#[stable(feature = "rust1", since = "1.0.0")]
325-
pub fn new() -> Vec<T> {
325+
#[rustc_const_unstable(feature = "const_vec_new")]
326+
pub const fn new() -> Vec<T> {
326327
Vec {
327328
buf: RawVec::new(),
328329
len: 0,

src/libcore/iter/iterator.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,8 @@ pub trait Iterator {
10941094
/// `flatten()` a three-dimensional array the result will be
10951095
/// two-dimensional and not one-dimensional. To get a one-dimensional
10961096
/// structure, you have to `flatten()` again.
1097+
///
1098+
/// [`flat_map()`]: #method.flat_map
10971099
#[inline]
10981100
#[unstable(feature = "iterator_flatten", issue = "48213")]
10991101
fn flatten(self) -> Flatten<Self>

src/libcore/marker.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,8 @@ unsafe impl<'a, T: ?Sized> Freeze for &'a mut T {}
602602
/// `Pin` pointer.
603603
///
604604
/// This trait is automatically implemented for almost every type.
605+
///
606+
/// [`Pin`]: ../mem/struct.Pin.html
605607
#[unstable(feature = "pin", issue = "49150")]
606608
pub unsafe auto trait Unpin {}
607609

src/libcore/ptr.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2552,10 +2552,9 @@ impl<T: Sized> Unique<T> {
25522552
/// This is useful for initializing types which lazily allocate, like
25532553
/// `Vec::new` does.
25542554
// FIXME: rename to dangling() to match NonNull?
2555-
pub fn empty() -> Self {
2555+
pub const fn empty() -> Self {
25562556
unsafe {
2557-
let ptr = mem::align_of::<T>() as *mut T;
2558-
Unique::new_unchecked(ptr)
2557+
Unique::new_unchecked(mem::align_of::<T>() as *mut T)
25592558
}
25602559
}
25612560
}

src/librustc/hir/check_attr.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ enum Target {
3131
Expression,
3232
Statement,
3333
Closure,
34+
Static,
3435
Other,
3536
}
3637

@@ -43,6 +44,7 @@ impl Target {
4344
hir::ItemEnum(..) => Target::Enum,
4445
hir::ItemConst(..) => Target::Const,
4546
hir::ItemForeignMod(..) => Target::ForeignMod,
47+
hir::ItemStatic(..) => Target::Static,
4648
_ => Target::Other,
4749
}
4850
}
@@ -102,6 +104,7 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
102104
}
103105

104106
self.check_repr(item, target);
107+
self.check_used(item, target);
105108
}
106109

107110
/// Check if an `#[inline]` is applied to a function or a closure.
@@ -305,6 +308,15 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
305308
}
306309
}
307310
}
311+
312+
fn check_used(&self, item: &hir::Item, target: Target) {
313+
for attr in &item.attrs {
314+
if attr.name().map(|name| name == "used").unwrap_or(false) && target != Target::Static {
315+
self.tcx.sess
316+
.span_err(attr.span, "attribute must be applied to a `static` variable");
317+
}
318+
}
319+
}
308320
}
309321

310322
impl<'a, 'tcx> Visitor<'tcx> for CheckAttrVisitor<'a, 'tcx> {

src/librustc/middle/liveness.rs

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ use ty::{self, TyCtxt};
111111
use lint;
112112
use util::nodemap::{NodeMap, NodeSet};
113113

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

414415
fn visit_arm<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, arm: &'tcx hir::Arm) {
415-
for pat in &arm.pats {
416-
// for struct patterns, take note of which fields used shorthand (`x` rather than `x: x`)
416+
for mut pat in &arm.pats {
417+
// For struct patterns, take note of which fields used shorthand
418+
// (`x` rather than `x: x`).
417419
//
418-
// FIXME: according to the rust-lang-nursery/rustc-guide book, `NodeId`s are to be phased
419-
// out in favor of `HirId`s; however, we need to match the signature of `each_binding`,
420-
// which uses `NodeIds`.
420+
// FIXME: according to the rust-lang-nursery/rustc-guide book, `NodeId`s are to be
421+
// phased out in favor of `HirId`s; however, we need to match the signature of
422+
// `each_binding`, which uses `NodeIds`.
421423
let mut shorthand_field_ids = NodeSet();
422-
if let hir::PatKind::Struct(_, ref fields, _) = pat.node {
423-
for field in fields {
424-
if field.node.is_shorthand {
425-
shorthand_field_ids.insert(field.node.pat.id);
424+
let mut pats = VecDeque::new();
425+
pats.push_back(pat);
426+
while let Some(pat) = pats.pop_front() {
427+
use hir::PatKind::*;
428+
match pat.node {
429+
Binding(_, _, _, ref inner_pat) => {
430+
pats.extend(inner_pat.iter());
426431
}
432+
Struct(_, ref fields, _) => {
433+
for field in fields {
434+
if field.node.is_shorthand {
435+
shorthand_field_ids.insert(field.node.pat.id);
436+
}
437+
}
438+
}
439+
Ref(ref inner_pat, _) |
440+
Box(ref inner_pat) => {
441+
pats.push_back(inner_pat);
442+
}
443+
TupleStruct(_, ref inner_pats, _) |
444+
Tuple(ref inner_pats, _) => {
445+
pats.extend(inner_pats.iter());
446+
}
447+
Slice(ref pre_pats, ref inner_pat, ref post_pats) => {
448+
pats.extend(pre_pats.iter());
449+
pats.extend(inner_pat.iter());
450+
pats.extend(post_pats.iter());
451+
}
452+
_ => {}
427453
}
428454
}
429455

src/libstd/collections/hash/table.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl TaggedHashUintPtr {
7979
///
8080
/// Essential invariants of this structure:
8181
///
82-
/// - if t.hashes[i] == EMPTY_BUCKET, then `Bucket::at_index(&t, i).raw`
82+
/// - if `t.hashes[i] == EMPTY_BUCKET`, then `Bucket::at_index(&t, i).raw`
8383
/// points to 'undefined' contents. Don't read from it. This invariant is
8484
/// enforced outside this module with the `EmptyBucket`, `FullBucket`,
8585
/// and `SafeHash` types.

src/libstd/ffi/c_str.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,7 @@ impl CStr {
11181118
///
11191119
/// [`Cow`]: ../borrow/enum.Cow.html
11201120
/// [`Borrowed`]: ../borrow/enum.Cow.html#variant.Borrowed
1121+
/// [`Owned`]: ../borrow/enum.Cow.html#variant.Owned
11211122
/// [`str`]: ../primitive.str.html
11221123
/// [`String`]: ../string/struct.String.html
11231124
///

0 commit comments

Comments
 (0)