Skip to content

Commit 5d8d282

Browse files
committed
---
yaml --- r: 235233 b: refs/heads/stable c: f29b565 h: refs/heads/master i: 235231: 169a667 v: v3
1 parent bba39ed commit 5d8d282

File tree

9 files changed

+52
-138
lines changed

9 files changed

+52
-138
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ refs/heads/tmp: afae2ff723393b3ab4ccffef6ac7c6d1809e2da0
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: f859507de8c410b648d934d8f5ec1c52daac971d
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: c69663caf6001e7681336cd0fe7f50c5211e8016
32+
refs/heads/stable: f29b565e2d73cd0d5e732d6b04bcbb19ce4363b4
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375
3434
refs/tags/1.1.0: bc3c16f09287e5545c1d3f76b7abd54f2eca868b
3535
refs/tags/1.2.0: f557861f822c34f07270347b94b5280de20a597e

branches/stable/src/doc/trpl/lifetimes.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ the lifetime `'a` has snuck in between the `&` and the `mut i32`. We read `&mut
101101
i32` as ‘a mutable reference to an i32’ and `&'a mut i32` as ‘a mutable
102102
reference to an `i32` with the lifetime `'a`’.
103103

104+
# In `struct`s
105+
104106
You’ll also need explicit lifetimes when working with [`struct`][structs]s:
105107

106108
```rust
@@ -137,6 +139,33 @@ x: &'a i32,
137139
uses it. So why do we need a lifetime here? We need to ensure that any reference
138140
to a `Foo` cannot outlive the reference to an `i32` it contains.
139141

142+
## `impl` blocks
143+
144+
Let’s implement a method on `Foo`:
145+
146+
```rust
147+
struct Foo<'a> {
148+
x: &'a i32,
149+
}
150+
151+
impl<'a> Foo<'a> {
152+
fn x(&self) -> &'a i32 { self.x }
153+
}
154+
155+
fn main() {
156+
let y = &5; // this is the same as `let _y = 5; let y = &_y;`
157+
let f = Foo { x: y };
158+
159+
println!("x is: {}", f.x());
160+
}
161+
```
162+
163+
As you can see, we need to declare a lifetime for `Foo` in the `impl` line. We repeat
164+
`'a` twice, just like on functions: `impl<'a>` defines a lifetime `'a`, and `Foo<'a>`
165+
uses it.
166+
167+
## Multiple lifetimes
168+
140169
If you have multiple references, you can use the same lifetime multiple times:
141170

142171
```rust

branches/stable/src/librustc_driver/driver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ pub fn phase_2_configure_and_expand(sess: &Session,
547547
sess.diagnostic()));
548548

549549
krate = time(time_passes, "prelude injection", krate, |krate|
550-
syntax::std_inject::maybe_inject_prelude(&sess.parse_sess, krate));
550+
syntax::std_inject::maybe_inject_prelude(krate));
551551

552552
time(time_passes, "checking that all macro invocations are gone", &krate, |krate|
553553
syntax::ext::expand::check_for_macros(&sess.parse_sess, krate));

branches/stable/src/librustc_typeck/diagnostics.rs

Lines changed: 3 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,62 +1368,6 @@ struct Foo {
13681368
```
13691369
"##,
13701370

1371-
E0128: r##"
1372-
Type parameter defaults can only use parameters that occur before them.
1373-
Erroneous code example:
1374-
1375-
```
1376-
pub struct Foo<T=U, U=()> {
1377-
field1: T,
1378-
filed2: U,
1379-
}
1380-
// error: type parameters with a default cannot use forward declared
1381-
// identifiers
1382-
```
1383-
1384-
Since type parameters are evaluated in-order, you may be able to fix this issue
1385-
by doing:
1386-
1387-
```
1388-
pub struct Foo<U=(), T=U> {
1389-
field1: T,
1390-
filed2: U,
1391-
}
1392-
```
1393-
1394-
Please also verify that this wasn't because of a name-clash and rename the type
1395-
parameter if so.
1396-
"##,
1397-
1398-
E0130: r##"
1399-
You declared a pattern as an argument in a foreign function declaration.
1400-
Erroneous code example:
1401-
1402-
```
1403-
extern {
1404-
fn foo((a, b): (u32, u32)); // error: patterns aren't allowed in foreign
1405-
// function declarations
1406-
}
1407-
```
1408-
1409-
Please replace the pattern argument with a regular one. Example:
1410-
1411-
```
1412-
struct SomeStruct {
1413-
a: u32,
1414-
b: u32,
1415-
}
1416-
1417-
extern {
1418-
fn foo(s: SomeStruct); // ok!
1419-
}
1420-
// or
1421-
extern {
1422-
fn foo(a: (u32, u32)); // ok!
1423-
}
1424-
```
1425-
"##,
1426-
14271371
E0131: r##"
14281372
It is not possible to define `main` with type parameters, or even with function
14291373
parameters. When `main` is present, it must take no arguments and return `()`.
@@ -1438,30 +1382,6 @@ fn(isize, *const *const u8) -> isize
14381382
```
14391383
"##,
14401384

1441-
E0159: r##"
1442-
You tried to use a trait as a struct constructor. Erroneous code example:
1443-
1444-
```
1445-
trait TraitNotAStruct {}
1446-
1447-
TraitNotAStruct{ value: 0 }; // error: use of trait `TraitNotAStruct` as a
1448-
// struct constructor
1449-
```
1450-
1451-
Please verify you used the correct type name or please implement the trait
1452-
on a struct and use this struct constructor. Example:
1453-
1454-
```
1455-
trait TraitNotAStruct {}
1456-
1457-
struct Foo {
1458-
value: i32
1459-
}
1460-
1461-
Foo{ value: 0 }; // ok!
1462-
```
1463-
"##,
1464-
14651385
E0166: r##"
14661386
This error means that the compiler found a return expression in a function
14671387
marked as diverging. A function diverges if it has `!` in the place of the
@@ -2058,8 +1978,11 @@ register_diagnostics! {
20581978
E0122,
20591979
E0123,
20601980
E0127,
1981+
E0128,
20611982
E0129,
1983+
E0130,
20621984
E0141,
1985+
E0159,
20631986
E0163,
20641987
E0164,
20651988
E0167,

branches/stable/src/libsyntax/feature_gate.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,6 @@ const KNOWN_FEATURES: &'static [(&'static str, &'static str, Status)] = &[
155155

156156
// Allows the definition of `const fn` functions.
157157
("const_fn", "1.2.0", Active),
158-
159-
// Allows using #[prelude_import] on glob `use` items.
160-
("prelude_import", "1.2.0", Active),
161158
];
162159
// (changing above list without updating src/doc/reference.md makes @cmr sad)
163160

@@ -268,8 +265,7 @@ pub const KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[
268265
and may be removed in the future")),
269266

270267
// used in resolve
271-
("prelude_import", Gated("prelude_import",
272-
"`#[prelude_import]` is for use by rustc only")),
268+
("prelude_import", Whitelisted),
273269

274270
// FIXME: #14407 these are only looked at on-demand so we can't
275271
// guarantee they'll have already been checked

branches/stable/src/libsyntax/print/pprust.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,11 @@ pub fn print_crate<'a>(cm: &'a CodeMap,
120120
// of the feature gate, so we fake them up here.
121121

122122
let no_std_meta = attr::mk_word_item(InternedString::new("no_std"));
123-
let prelude_import_meta = attr::mk_word_item(InternedString::new("prelude_import"));
124123

125124
// #![feature(no_std)]
126125
let fake_attr = attr::mk_attr_inner(attr::mk_attr_id(),
127126
attr::mk_list_item(InternedString::new("feature"),
128-
vec![no_std_meta.clone(),
129-
prelude_import_meta]));
127+
vec![no_std_meta.clone()]));
130128
try!(s.print_attribute(&fake_attr));
131129

132130
// #![no_std]

branches/stable/src/libsyntax/std_inject.rs

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,16 @@
1010

1111
use ast;
1212
use attr;
13-
use codemap::{DUMMY_SP, Span, ExpnInfo, NameAndSpan, MacroAttribute};
13+
use codemap::DUMMY_SP;
1414
use codemap;
1515
use fold::Folder;
1616
use fold;
1717
use parse::token::InternedString;
1818
use parse::token::special_idents;
19-
use parse::{token, ParseSess};
19+
use parse::token;
2020
use ptr::P;
2121
use util::small_vector::SmallVector;
2222

23-
/// Craft a span that will be ignored by the stability lint's
24-
/// call to codemap's is_internal check.
25-
/// The expanded code uses the unstable `#[prelude_import]` attribute.
26-
fn ignored_span(sess: &ParseSess, sp: Span) -> Span {
27-
let info = ExpnInfo {
28-
call_site: DUMMY_SP,
29-
callee: NameAndSpan {
30-
name: "std_inject".to_string(),
31-
format: MacroAttribute,
32-
span: None,
33-
allow_internal_unstable: true,
34-
}
35-
};
36-
let expn_id = sess.codemap().record_expansion(info);
37-
let mut sp = sp;
38-
sp.expn_id = expn_id;
39-
return sp;
40-
}
41-
4223
pub fn maybe_inject_crates_ref(krate: ast::Crate, alt_std_name: Option<String>)
4324
-> ast::Crate {
4425
if use_std(&krate) {
@@ -48,12 +29,9 @@ pub fn maybe_inject_crates_ref(krate: ast::Crate, alt_std_name: Option<String>)
4829
}
4930
}
5031

51-
pub fn maybe_inject_prelude(sess: &ParseSess, krate: ast::Crate) -> ast::Crate {
32+
pub fn maybe_inject_prelude(krate: ast::Crate) -> ast::Crate {
5233
if use_std(&krate) {
53-
let mut fold = PreludeInjector {
54-
span: ignored_span(sess, DUMMY_SP)
55-
};
56-
fold.fold_crate(krate)
34+
inject_prelude(krate)
5735
} else {
5836
krate
5937
}
@@ -102,9 +80,8 @@ fn inject_crates_ref(krate: ast::Crate, alt_std_name: Option<String>) -> ast::Cr
10280
fold.fold_crate(krate)
10381
}
10482

105-
struct PreludeInjector {
106-
span: Span
107-
}
83+
struct PreludeInjector;
84+
10885

10986
impl fold::Folder for PreludeInjector {
11087
fn fold_crate(&mut self, mut krate: ast::Crate) -> ast::Crate {
@@ -130,7 +107,7 @@ impl fold::Folder for PreludeInjector {
130107

131108
fn fold_mod(&mut self, mut mod_: ast::Mod) -> ast::Mod {
132109
let prelude_path = ast::Path {
133-
span: self.span,
110+
span: DUMMY_SP,
134111
global: false,
135112
segments: vec![
136113
ast::PathSegment {
@@ -154,22 +131,27 @@ impl fold::Folder for PreludeInjector {
154131
ident: special_idents::invalid,
155132
node: ast::ItemUse(vp),
156133
attrs: vec![ast::Attribute {
157-
span: self.span,
134+
span: DUMMY_SP,
158135
node: ast::Attribute_ {
159136
id: attr::mk_attr_id(),
160137
style: ast::AttrOuter,
161138
value: P(ast::MetaItem {
162-
span: self.span,
139+
span: DUMMY_SP,
163140
node: ast::MetaWord(token::get_name(
164141
special_idents::prelude_import.name)),
165142
}),
166143
is_sugared_doc: false,
167144
},
168145
}],
169146
vis: ast::Inherited,
170-
span: self.span,
147+
span: DUMMY_SP,
171148
}));
172149

173150
fold::noop_fold_mod(mod_, self)
174151
}
175152
}
153+
154+
fn inject_prelude(krate: ast::Crate) -> ast::Crate {
155+
let mut fold = PreludeInjector;
156+
fold.fold_crate(krate)
157+
}

branches/stable/src/test/compile-fail/feature-gate-prelude_import.rs

Lines changed: 0 additions & 14 deletions
This file was deleted.

branches/stable/src/test/pretty/issue-4264.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(no_std, prelude_import)]
1+
#![feature(no_std)]
22
#![no_std]
33
#[prelude_import]
44
use std::prelude::v1::*;

0 commit comments

Comments
 (0)