Skip to content

Commit 1fd89b6

Browse files
committed
Auto merge of #24156 - Manishearth:rollup, r=Manishearth
2 parents b41f2df + ae64d8e commit 1fd89b6

File tree

11 files changed

+73
-38
lines changed

11 files changed

+73
-38
lines changed

src/doc/trpl/benchmark-tests.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub fn add_two(a: i32) -> i32 {
1313
}
1414
1515
#[cfg(test)]
16-
mod tests {
16+
mod test {
1717
use super::*;
1818
use test::Bencher;
1919

src/doc/trpl/hello-cargo.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
% Hello, Cargo!
22

33
[Cargo](http://crates.io) is a tool that Rustaceans use to help manage their
4-
Rust projects. Cargo is currently in an alpha state, just like Rust, and so it
4+
Rust projects. Cargo is currently in a pre-1.0 state, just like Rust, and so it
55
is still a work in progress. However, it is already good enough to use for many
66
Rust projects, and so it is assumed that Rust projects will use Cargo from the
77
beginning.

src/doc/trpl/testing.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ pub fn add_two(a: i32) -> i32 {
382382
}
383383
384384
#[cfg(test)]
385-
mod tests {
385+
mod test {
386386
use super::*;
387387
388388
#[test]

src/doc/trpl/traits.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,6 @@ everything is fine:
229229

230230
```{rust}
231231
# #![feature(core)]
232-
use shapes::HasArea;
233-
234232
mod shapes {
235233
use std::f64::consts;
236234
@@ -251,6 +249,7 @@ mod shapes {
251249
}
252250
}
253251
252+
use shapes::HasArea;
254253
255254
fn main() {
256255
let c = shapes::Circle {

src/libcore/any.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,12 @@ use marker::{Reflect, Sized};
8383
// Any trait
8484
///////////////////////////////////////////////////////////////////////////////
8585

86-
/// A type to emulate dynamic typing. See the [module-level documentation][mod] for more details.
86+
/// A type to emulate dynamic typing.
8787
///
8888
/// Every type with no non-`'static` references implements `Any`.
89+
/// See the [module-level documentation][mod] for more details.
8990
///
90-
/// [mod]: ../index.html
91+
/// [mod]: index.html
9192
#[stable(feature = "rust1", since = "1.0.0")]
9293
pub trait Any: Reflect + 'static {
9394
/// Get the `TypeId` of `self`

src/libcore/marker.rs

+58-9
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,49 @@ impl<A:?Sized,R:?Sized,T:?Sized> PhantomFn<A,R> for T { }
316316
///
317317
/// # Examples
318318
///
319-
/// When handling external resources over a foreign function interface, `PhantomData<T>` can
320-
/// prevent mismatches by enforcing types in the method implementations:
319+
/// ## Unused lifetime parameter
320+
///
321+
/// Perhaps the most common time that `PhantomData` is required is
322+
/// with a struct that has an unused lifetime parameter, typically as
323+
/// part of some unsafe code. For example, here is a struct `Slice`
324+
/// that has two pointers of type `*const T`, presumably pointing into
325+
/// an array somewhere:
326+
///
327+
/// ```ignore
328+
/// struct Slice<'a, T> {
329+
/// start: *const T,
330+
/// end: *const T,
331+
/// }
332+
/// ```
333+
///
334+
/// The intention is that the underlying data is only valid for the
335+
/// lifetime `'a`, so `Slice` should not outlive `'a`. However, this
336+
/// intent is not expressed in the code, since there are no uses of
337+
/// the lifetime `'a` and hence it is not clear what data it applies
338+
/// to. We can correct this by telling the compiler to act *as if* the
339+
/// `Slice` struct contained a borrowed reference `&'a T`:
340+
///
341+
/// ```
342+
/// use std::marker::PhantomData;
343+
///
344+
/// struct Slice<'a, T:'a> {
345+
/// start: *const T,
346+
/// end: *const T,
347+
/// phantom: PhantomData<&'a T>
348+
/// }
349+
/// ```
350+
///
351+
/// This also in turn requires that we annotate `T:'a`, indicating
352+
/// that `T` is a type that can be borrowed for the lifetime `'a`.
353+
///
354+
/// ## Unused type parameters
355+
///
356+
/// It sometimes happens that there are unused type parameters that
357+
/// indicate what type of data a struct is "tied" to, even though that
358+
/// data is not actually found in the struct itself. Here is an
359+
/// example where this arises when handling external resources over a
360+
/// foreign function interface. `PhantomData<T>` can prevent
361+
/// mismatches by enforcing types in the method implementations:
321362
///
322363
/// ```
323364
/// # trait ResType { fn foo(&self); };
@@ -351,13 +392,21 @@ impl<A:?Sized,R:?Sized,T:?Sized> PhantomFn<A,R> for T { }
351392
/// }
352393
/// ```
353394
///
354-
/// Another example: embedding a `PhantomData<T>` will inform the compiler
355-
/// that one or more instances of the type `T` could be dropped when
356-
/// instances of the type itself is dropped, though that may not be
357-
/// apparent from the other structure of the type itself. This is
358-
/// commonly necessary if the structure is using an unsafe pointer
359-
/// like `*mut T` whose referent may be dropped when the type is
360-
/// dropped, as a `*mut T` is otherwise not treated as owned.
395+
/// ## Indicating ownership
396+
///
397+
/// Adding a field of type `PhantomData<T>` also indicates that your
398+
/// struct owns data of type `T`. This in turn implies that when your
399+
/// struct is dropped, it may in turn drop one or more instances of
400+
/// the type `T`, though that may not be apparent from the other
401+
/// structure of the type itself. This is commonly necessary if the
402+
/// structure is using an unsafe pointer like `*mut T` whose referent
403+
/// may be dropped when the type is dropped, as a `*mut T` is
404+
/// otherwise not treated as owned.
405+
///
406+
/// If your struct does not in fact *own* the data of type `T`, it is
407+
/// better to use a reference type, like `PhantomData<&'a T>`
408+
/// (ideally) or `PhantomData<*const T>` (if no lifetime applies), so
409+
/// as not to indicate ownership.
361410
#[lang="phantom_data"]
362411
#[stable(feature = "rust1", since = "1.0.0")]
363412
pub struct PhantomData<T:?Sized>;

src/libcore/ops.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,13 @@ macro_rules! forward_ref_binop {
172172
/// type Output = Foo;
173173
///
174174
/// fn add(self, _rhs: Foo) -> Foo {
175-
/// println!("Adding!");
176-
/// self
177-
/// }
175+
/// println!("Adding!");
176+
/// self
177+
/// }
178178
/// }
179179
///
180180
/// fn main() {
181-
/// Foo + Foo;
181+
/// Foo + Foo;
182182
/// }
183183
/// ```
184184
#[lang="add"]

src/librustc/middle/resolve_lifetime.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ impl<'a> LifetimeContext<'a> {
507507
EarlyScope(_, lifetimes, s) |
508508
LateScope(lifetimes, s) => {
509509
if let Some((_, lifetime_def)) = search_lifetimes(lifetimes, lifetime) {
510-
self.sess.span_warn(
510+
self.sess.span_err(
511511
lifetime.span,
512512
&format!("lifetime name `{}` shadows another \
513513
lifetime name that is already in scope",
@@ -516,10 +516,6 @@ impl<'a> LifetimeContext<'a> {
516516
lifetime_def.span,
517517
&format!("shadowed lifetime `{}` declared here",
518518
token::get_name(lifetime.name)));
519-
self.sess.span_note(
520-
lifetime.span,
521-
"shadowed lifetimes are deprecated \
522-
and will become a hard error before 1.0");
523519
return;
524520
}
525521

src/libstd/io/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -618,9 +618,6 @@ pub trait BufRead: Read {
618618
/// The iterator returned from this function will yield instances of
619619
/// `io::Result<String>`. Each string returned will *not* have a newline
620620
/// byte (the 0xA byte) at the end.
621-
///
622-
/// This function will yield errors whenever `read_string` would have also
623-
/// yielded an error.
624621
#[stable(feature = "rust1", since = "1.0.0")]
625622
fn lines(self) -> Lines<Self> where Self: Sized {
626623
Lines { buf: self }

src/test/compile-fail/shadowed-lifetime.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,14 @@ struct Foo<'a>(&'a isize);
1515
impl<'a> Foo<'a> {
1616
//~^ NOTE shadowed lifetime `'a` declared here
1717
fn shadow_in_method<'a>(&'a self) -> &'a isize {
18-
//~^ WARNING lifetime name `'a` shadows another lifetime name that is already in scope
19-
//~| NOTE deprecated
18+
//~^ ERROR lifetime name `'a` shadows another lifetime name that is already in scope
2019
self.0
2120
}
2221

2322
fn shadow_in_type<'b>(&'b self) -> &'b isize {
2423
//~^ NOTE shadowed lifetime `'b` declared here
2524
let x: for<'b> fn(&'b isize) = panic!();
26-
//~^ WARNING lifetime name `'b` shadows another lifetime name that is already in scope
27-
//~| NOTE deprecated
25+
//~^ ERROR lifetime name `'b` shadows another lifetime name that is already in scope
2826
self.0
2927
}
3028

@@ -35,9 +33,4 @@ impl<'a> Foo<'a> {
3533
}
3634

3735
fn main() {
38-
// intentional error that occurs after `resolve_lifetime` runs,
39-
// just to ensure that this test fails to compile; when shadowed
40-
// lifetimes become either an error or a proper lint, this will
41-
// not be needed.
42-
let x: isize = 3_usize; //~ ERROR mismatched types
4336
}

src/test/run-pass/overloaded-index-assoc-list.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl<K,V> AssociationList<K,V> {
3535
impl<'a, K: PartialEq + std::fmt::Debug, V:Clone> Index<&'a K> for AssociationList<K,V> {
3636
type Output = V;
3737

38-
fn index<'a>(&'a self, index: &K) -> &'a V {
38+
fn index(&self, index: &K) -> &V {
3939
for pair in &self.pairs {
4040
if pair.key == *index {
4141
return &pair.value

0 commit comments

Comments
 (0)