Skip to content

Commit 046d660

Browse files
committed
---
yaml --- r: 218183 b: refs/heads/tmp c: a97687e h: refs/heads/master i: 218181: b5b2dd3 218179: 9e027b2 218175: 54e5645 v: v3
1 parent 938f474 commit 046d660

File tree

8 files changed

+138
-23
lines changed

8 files changed

+138
-23
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
2626
refs/heads/beta: 18adf6230e2e229d4d73391cebff060afc5e5aaa
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
28-
refs/heads/tmp: f29b565e2d73cd0d5e732d6b04bcbb19ce4363b4
28+
refs/heads/tmp: a97687e521eeb4ba8b9f26b21b34c7a98a71c1a4
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: e6596d0052e79e6393bbee3538bb122930d89887
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828

branches/tmp/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(krate));
550+
syntax::std_inject::maybe_inject_prelude(&sess.parse_sess, 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/tmp/src/librustc_typeck/diagnostics.rs

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,6 +1368,62 @@ 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+
13711427
E0131: r##"
13721428
It is not possible to define `main` with type parameters, or even with function
13731429
parameters. When `main` is present, it must take no arguments and return `()`.
@@ -1382,6 +1438,30 @@ fn(isize, *const *const u8) -> isize
13821438
```
13831439
"##,
13841440

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+
13851465
E0166: r##"
13861466
This error means that the compiler found a return expression in a function
13871467
marked as diverging. A function diverges if it has `!` in the place of the
@@ -1978,11 +2058,8 @@ register_diagnostics! {
19782058
E0122,
19792059
E0123,
19802060
E0127,
1981-
E0128,
19822061
E0129,
1983-
E0130,
19842062
E0141,
1985-
E0159,
19862063
E0163,
19872064
E0164,
19882065
E0167,

branches/tmp/src/libsyntax/feature_gate.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ 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),
158161
];
159162
// (changing above list without updating src/doc/reference.md makes @cmr sad)
160163

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

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

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

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,13 @@ 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"));
123124

124125
// #![feature(no_std)]
125126
let fake_attr = attr::mk_attr_inner(attr::mk_attr_id(),
126127
attr::mk_list_item(InternedString::new("feature"),
127-
vec![no_std_meta.clone()]));
128+
vec![no_std_meta.clone(),
129+
prelude_import_meta]));
128130
try!(s.print_attribute(&fake_attr));
129131

130132
// #![no_std]

branches/tmp/src/libsyntax/std_inject.rs

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

1111
use ast;
1212
use attr;
13-
use codemap::DUMMY_SP;
13+
use codemap::{DUMMY_SP, Span, ExpnInfo, NameAndSpan, MacroAttribute};
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;
19+
use parse::{token, ParseSess};
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+
2342
pub fn maybe_inject_crates_ref(krate: ast::Crate, alt_std_name: Option<String>)
2443
-> ast::Crate {
2544
if use_std(&krate) {
@@ -29,9 +48,12 @@ pub fn maybe_inject_crates_ref(krate: ast::Crate, alt_std_name: Option<String>)
2948
}
3049
}
3150

32-
pub fn maybe_inject_prelude(krate: ast::Crate) -> ast::Crate {
51+
pub fn maybe_inject_prelude(sess: &ParseSess, krate: ast::Crate) -> ast::Crate {
3352
if use_std(&krate) {
34-
inject_prelude(krate)
53+
let mut fold = PreludeInjector {
54+
span: ignored_span(sess, DUMMY_SP)
55+
};
56+
fold.fold_crate(krate)
3557
} else {
3658
krate
3759
}
@@ -80,8 +102,9 @@ fn inject_crates_ref(krate: ast::Crate, alt_std_name: Option<String>) -> ast::Cr
80102
fold.fold_crate(krate)
81103
}
82104

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

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

108131
fn fold_mod(&mut self, mut mod_: ast::Mod) -> ast::Mod {
109132
let prelude_path = ast::Path {
110-
span: DUMMY_SP,
133+
span: self.span,
111134
global: false,
112135
segments: vec![
113136
ast::PathSegment {
@@ -131,27 +154,22 @@ impl fold::Folder for PreludeInjector {
131154
ident: special_idents::invalid,
132155
node: ast::ItemUse(vp),
133156
attrs: vec![ast::Attribute {
134-
span: DUMMY_SP,
157+
span: self.span,
135158
node: ast::Attribute_ {
136159
id: attr::mk_attr_id(),
137160
style: ast::AttrOuter,
138161
value: P(ast::MetaItem {
139-
span: DUMMY_SP,
162+
span: self.span,
140163
node: ast::MetaWord(token::get_name(
141164
special_idents::prelude_import.name)),
142165
}),
143166
is_sugared_doc: false,
144167
},
145168
}],
146169
vis: ast::Inherited,
147-
span: DUMMY_SP,
170+
span: self.span,
148171
}));
149172

150173
fold::noop_fold_mod(mod_, self)
151174
}
152175
}
153-
154-
fn inject_prelude(krate: ast::Crate) -> ast::Crate {
155-
let mut fold = PreludeInjector;
156-
fold.fold_crate(krate)
157-
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2015 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+
#[prelude_import] //~ ERROR `#[prelude_import]` is for use by rustc only
12+
use std::prelude::v1::*;
13+
14+
fn main() {}

branches/tmp/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)]
1+
#![feature(no_std, prelude_import)]
22
#![no_std]
33
#[prelude_import]
44
use std::prelude::v1::*;

0 commit comments

Comments
 (0)