Skip to content

Commit 47965f5

Browse files
committed
Auto merge of #39180 - GuillaumeGomez:rollup, r=GuillaumeGomez
Rollup of 11 pull requests - Successful merges: #38457, #38922, #38970, #39039, #39091, #39115, #39121, #39149, #39150, #39151, #39165 - Failed merges:
2 parents 74c42ac + 3946079 commit 47965f5

28 files changed

+236
-42
lines changed

RELEASES.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3371,7 +3371,7 @@ Version 1.0.0-alpha (2015-01-09)
33713371
platforms.
33723372
* Rust comes with rust-gdb and rust-lldb scripts that launch their
33733373
respective debuggers with Rust-appropriate pretty-printing.
3374-
* The Windows installation of Rust is distributed with the the
3374+
* The Windows installation of Rust is distributed with the
33753375
MinGW components currently required to link binaries on that
33763376
platform.
33773377

src/libcollections/slice.rs

+41-18
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ impl<T> [T] {
181181
core_slice::SliceExt::len(self)
182182
}
183183

184-
/// Returns true if the slice has a length of 0.
184+
/// Returns `true` if the slice has a length of 0.
185185
///
186186
/// # Example
187187
///
@@ -342,15 +342,22 @@ impl<T> [T] {
342342
core_slice::SliceExt::last_mut(self)
343343
}
344344

345-
/// Returns the element of a slice at the given index, or `None` if the
346-
/// index is out of bounds.
345+
/// Returns a reference to an element or subslice depending on the type of
346+
/// index.
347+
///
348+
/// - If given a position, returns a reference to the element at that
349+
/// position or `None` if out of bounds.
350+
/// - If given a range, returns the subslice corresponding to that range,
351+
/// or `None` if out of bounds.
347352
///
348353
/// # Examples
349354
///
350355
/// ```
351356
/// let v = [10, 40, 30];
352357
/// assert_eq!(Some(&40), v.get(1));
358+
/// assert_eq!(Some(&[10, 40][..]), v.get(0..2));
353359
/// assert_eq!(None, v.get(3));
360+
/// assert_eq!(None, v.get(0..4));
354361
/// ```
355362
#[stable(feature = "rust1", since = "1.0.0")]
356363
#[inline]
@@ -360,7 +367,10 @@ impl<T> [T] {
360367
core_slice::SliceExt::get(self, index)
361368
}
362369

363-
/// Returns a mutable reference to the element at the given index.
370+
/// Returns a mutable reference to an element or subslice depending on the
371+
/// type of index (see [`get()`]) or `None` if the index is out of bounds.
372+
///
373+
/// [`get()`]: #method.get
364374
///
365375
/// # Examples
366376
///
@@ -372,7 +382,6 @@ impl<T> [T] {
372382
/// }
373383
/// assert_eq!(x, &[0, 42, 2]);
374384
/// ```
375-
/// or `None` if the index is out of bounds
376385
#[stable(feature = "rust1", since = "1.0.0")]
377386
#[inline]
378387
pub fn get_mut<I>(&mut self, index: I) -> Option<&mut I::Output>
@@ -381,8 +390,8 @@ impl<T> [T] {
381390
core_slice::SliceExt::get_mut(self, index)
382391
}
383392

384-
/// Returns a pointer to the element at the given index, without doing
385-
/// bounds checking. So use it very carefully!
393+
/// Returns a reference to an element or subslice, without doing bounds
394+
/// checking. So use it very carefully!
386395
///
387396
/// # Examples
388397
///
@@ -401,8 +410,8 @@ impl<T> [T] {
401410
core_slice::SliceExt::get_unchecked(self, index)
402411
}
403412

404-
/// Returns an unsafe mutable pointer to the element in index. So use it
405-
/// very carefully!
413+
/// Returns a mutable reference to an element or subslice, without doing
414+
/// bounds checking. So use it very carefully!
406415
///
407416
/// # Examples
408417
///
@@ -540,12 +549,8 @@ impl<T> [T] {
540549
///
541550
/// ```
542551
/// let x = &mut [1, 2, 4];
543-
/// {
544-
/// let iterator = x.iter_mut();
545-
///
546-
/// for elem in iterator {
547-
/// *elem += 2;
548-
/// }
552+
/// for elem in x.iter_mut() {
553+
/// *elem += 2;
549554
/// }
550555
/// assert_eq!(x, &[3, 4, 6]);
551556
/// ```
@@ -880,7 +885,7 @@ impl<T> [T] {
880885
core_slice::SliceExt::rsplitn_mut(self, n, pred)
881886
}
882887

883-
/// Returns true if the slice contains an element with the given value.
888+
/// Returns `true` if the slice contains an element with the given value.
884889
///
885890
/// # Examples
886891
///
@@ -896,7 +901,7 @@ impl<T> [T] {
896901
core_slice::SliceExt::contains(self, x)
897902
}
898903

899-
/// Returns true if `needle` is a prefix of the slice.
904+
/// Returns `true` if `needle` is a prefix of the slice.
900905
///
901906
/// # Examples
902907
///
@@ -907,14 +912,23 @@ impl<T> [T] {
907912
/// assert!(!v.starts_with(&[50]));
908913
/// assert!(!v.starts_with(&[10, 50]));
909914
/// ```
915+
///
916+
/// Always returns `true` if `needle` is an empty slice:
917+
///
918+
/// ```
919+
/// let v = &[10, 40, 30];
920+
/// assert!(v.starts_with(&[]));
921+
/// let v: &[u8] = &[];
922+
/// assert!(v.starts_with(&[]));
923+
/// ```
910924
#[stable(feature = "rust1", since = "1.0.0")]
911925
pub fn starts_with(&self, needle: &[T]) -> bool
912926
where T: PartialEq
913927
{
914928
core_slice::SliceExt::starts_with(self, needle)
915929
}
916930

917-
/// Returns true if `needle` is a suffix of the slice.
931+
/// Returns `true` if `needle` is a suffix of the slice.
918932
///
919933
/// # Examples
920934
///
@@ -925,6 +939,15 @@ impl<T> [T] {
925939
/// assert!(!v.ends_with(&[50]));
926940
/// assert!(!v.ends_with(&[50, 30]));
927941
/// ```
942+
///
943+
/// Always returns `true` if `needle` is an empty slice:
944+
///
945+
/// ```
946+
/// let v = &[10, 40, 30];
947+
/// assert!(v.ends_with(&[]));
948+
/// let v: &[u8] = &[];
949+
/// assert!(v.ends_with(&[]));
950+
/// ```
928951
#[stable(feature = "rust1", since = "1.0.0")]
929952
pub fn ends_with(&self, needle: &[T]) -> bool
930953
where T: PartialEq

src/librustc/dep_graph/thread.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub struct DepGraphThreadData {
5656
// current buffer, where we accumulate messages
5757
messages: VecCell<DepMessage>,
5858

59-
// whence to receive new buffer when full
59+
// where to receive new buffer when full
6060
swap_in: Receiver<Vec<DepMessage>>,
6161

6262
// where to send buffer when full

src/librustc/diagnostics.rs

+34-1
Original file line numberDiff line numberDiff line change
@@ -1454,6 +1454,40 @@ struct Prince<'kiss, 'SnowWhite: 'kiss> { // You say here that 'kiss must live
14541454
```
14551455
"##,
14561456

1457+
E0491: r##"
1458+
A reference has a longer lifetime than the data it references.
1459+
1460+
Erroneous code example:
1461+
1462+
```compile_fail,E0491
1463+
// struct containing a reference requires a lifetime parameter,
1464+
// because the data the reference points to must outlive the struct (see E0106)
1465+
struct Struct<'a> {
1466+
ref_i32: &'a i32,
1467+
}
1468+
1469+
// However, a nested struct like this, the signature itself does not tell
1470+
// whether 'a outlives 'b or the other way around.
1471+
// So it could be possible that 'b of reference outlives 'a of the data.
1472+
struct Nested<'a, 'b> {
1473+
ref_struct: &'b Struct<'a>, // compile error E0491
1474+
}
1475+
```
1476+
1477+
To fix this issue, you can specify a bound to the lifetime like below:
1478+
1479+
```
1480+
struct Struct<'a> {
1481+
ref_i32: &'a i32,
1482+
}
1483+
1484+
// 'a: 'b means 'a outlives 'b
1485+
struct Nested<'a: 'b, 'b> {
1486+
ref_struct: &'b Struct<'a>,
1487+
}
1488+
```
1489+
"##,
1490+
14571491
E0496: r##"
14581492
A lifetime name is shadowing another lifetime name. Erroneous code example:
14591493
@@ -1697,7 +1731,6 @@ register_diagnostics! {
16971731
E0488, // lifetime of variable does not enclose its declaration
16981732
E0489, // type/lifetime parameter not in scope here
16991733
E0490, // a value of type `..` is borrowed for too long
1700-
E0491, // in type `..`, reference has a longer lifetime than the data it...
17011734
E0495, // cannot infer an appropriate lifetime due to conflicting requirements
17021735
E0566 // conflicting representation hints
17031736
}

src/librustc/ty/inhabitedness/mod.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,13 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
190190
ty.uninhabited_from(visited, tcx)
191191
}
192192
}
193-
TyRef(_, ref tm) => tm.ty.uninhabited_from(visited, tcx),
193+
TyRef(_, ref tm) => {
194+
if tcx.sess.features.borrow().never_type {
195+
tm.ty.uninhabited_from(visited, tcx)
196+
} else {
197+
DefIdForest::empty()
198+
}
199+
}
194200

195201
_ => DefIdForest::empty(),
196202
}

src/librustc_typeck/collect.rs

+10
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,16 @@ fn ensure_no_ty_param_bounds(ccx: &CrateCtxt,
716716
}
717717
}
718718

719+
for predicate in generics.where_clause.predicates.iter() {
720+
match *predicate {
721+
hir::WherePredicate::BoundPredicate(..) => {
722+
warn = true;
723+
}
724+
hir::WherePredicate::RegionPredicate(..) => { }
725+
hir::WherePredicate::EqPredicate(..) => { }
726+
}
727+
}
728+
719729
if warn {
720730
// According to accepted RFC #XXX, we should
721731
// eventually accept these, but it will not be

src/libstd/fs.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ use time::SystemTime;
8181
/// # }
8282
/// ```
8383
///
84-
/// [`BufReader`]: ../io/struct.BufReader.html
84+
/// [`Read`]: ../io/trait.Read.html
85+
/// [`BufReader<R>`]: ../io/struct.BufReader.html
8586
#[stable(feature = "rust1", since = "1.0.0")]
8687
pub struct File {
8788
inner: fs_imp::File,

src/libstd/macros.rs

+20-5
Original file line numberDiff line numberDiff line change
@@ -458,23 +458,38 @@ pub mod builtin {
458458

459459
/// Parse a file as an expression or an item according to the context.
460460
///
461-
/// The file is located relative to the current file. (similarly to how
462-
/// modules are found)
461+
/// The file is located relative to the current file (similarly to how
462+
/// modules are found).
463463
///
464464
/// Using this macro is often a bad idea, because if the file is
465465
/// parsed as an expression, it is going to be placed in the
466-
/// surrounding code unhygenically. This could result in variables
466+
/// surrounding code unhygienically. This could result in variables
467467
/// or functions being different from what the file expected if
468468
/// there are variables or functions that have the same name in
469469
/// the current file.
470470
///
471471
/// # Examples
472472
///
473+
/// Assume there are two files in the same directory with the following
474+
/// contents:
475+
///
476+
/// File 'my_str.in':
477+
///
473478
/// ```ignore
474-
/// fn foo() {
475-
/// include!("/path/to/a/file")
479+
/// "Hello World!"
480+
/// ```
481+
///
482+
/// File 'main.rs':
483+
///
484+
/// ```ignore
485+
/// fn main() {
486+
/// let my_str = include!("my_str.in");
487+
/// println!("{}", my_str);
476488
/// }
477489
/// ```
490+
///
491+
/// Compiling 'main.rs' and running the resulting binary will print "Hello
492+
/// World!".
478493
#[stable(feature = "rust1", since = "1.0.0")]
479494
#[macro_export]
480495
macro_rules! include { ($file:expr) => ({ /* compiler built-in */ }) }

src/libsyntax/feature_gate.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -689,10 +689,10 @@ pub const BUILTIN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeG
689689
cfg_fn!(omit_gdb_pretty_printer_section))),
690690
("unsafe_destructor_blind_to_params",
691691
Normal,
692-
Gated(Stability::Unstable,
692+
Gated(Stability::Deprecated("https://github.com/rust-lang/rust/issues/34761"),
693693
"dropck_parametricity",
694-
"unsafe_destructor_blind_to_params has unstable semantics \
695-
and may be removed in the future",
694+
"unsafe_destructor_blind_to_params has been replaced by \
695+
may_dangle and will be removed in the future",
696696
cfg_fn!(dropck_parametricity))),
697697
("may_dangle",
698698
Normal,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![deny(deprecated)]
12+
#![feature(dropck_parametricity)]
13+
14+
struct Foo;
15+
16+
impl Drop for Foo {
17+
#[unsafe_destructor_blind_to_params]
18+
//~^ ERROR use of deprecated attribute `dropck_parametricity`
19+
fn drop(&mut self) {}
20+
}
21+
22+
fn main() {}

src/test/compile-fail/feature-gate-dropck-ugeh.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct Foo<T> { data: Vec<T> }
2727

2828
impl<T> Drop for Foo<T> {
2929
#[unsafe_destructor_blind_to_params] // This is the UGEH attribute
30-
//~^ ERROR unsafe_destructor_blind_to_params has unstable semantics
30+
//~^ ERROR unsafe_destructor_blind_to_params has been replaced
3131
fn drop(&mut self) { }
3232
}
3333

src/test/compile-fail/issue-17994.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
// except according to those terms.
1010

1111
trait Tr {}
12-
type Huh<T> where T: Tr = isize; //~ ERROR type parameter `T` is unused
12+
type Huh<T> where T: Tr = isize; //~ ERROR type parameter `T` is unused
13+
//~| WARNING E0122
1314
fn main() {}

src/test/compile-fail/issue-39122.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
type Foo<T: std::ops::Add> = T; //~ WARNING E0122
12+
13+
type Bar<T> where T: std::ops::Add = T; //~ WARNING E0122

src/test/compile-fail/private-in-public-warn.rs

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ mod traits_where {
8989
pub type Alias<T> where T: PrivTr = T;
9090
//~^ ERROR private trait `traits_where::PrivTr` in public interface
9191
//~| WARNING hard error
92+
//~| WARNING E0122
9293
pub trait Tr2<T> where T: PrivTr {}
9394
//~^ ERROR private trait `traits_where::PrivTr` in public interface
9495
//~| WARNING hard error
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
enum Void {}
12+
13+
fn main() {
14+
let x: Result<u32, &'static Void> = Ok(23);
15+
let _ = match x { //~ ERROR non-exhaustive
16+
Ok(n) => n,
17+
};
18+
}
19+

0 commit comments

Comments
 (0)