Skip to content

Commit f1e0fd1

Browse files
committed
---
yaml --- r: 271475 b: refs/heads/auto c: 40deb27 h: refs/heads/master i: 271473: e0565c4 271471: 4910c7d
1 parent 2cd699f commit f1e0fd1

File tree

48 files changed

+382
-394
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+382
-394
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
88
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
99
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1010
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
11-
refs/heads/auto: a21c5f267a722b6c80790a559bf272942b946cd4
11+
refs/heads/auto: 40deb279a87e640f799140e9f19b3e64623c30da
1212
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1313
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336
1414
refs/tags/0.2: 1754d02027f2924bed83b0160ee340c7f41d5ea1

branches/auto/src/doc/book/drop.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ BOOM times 100!!!
5555
BOOM times 1!!!
5656
```
5757

58-
The TNT goes off before the firecracker does, because it was declared
58+
The `tnt` goes off before the `firecracker` does, because it was declared
5959
afterwards. Last in, first out.
6060

6161
So what is `Drop` good for? Generally, `Drop` is used to clean up any resources

branches/auto/src/libcore/clone.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,29 @@
1818
//! them cheap and safe to copy. For other types copies must be made
1919
//! explicitly, by convention implementing the `Clone` trait and calling
2020
//! the `clone` method.
21+
//!
22+
//! Basic usage example:
23+
//!
24+
//! ```
25+
//! let s = String::new(); // String type implements Clone
26+
//! let copy = s.clone(); // so we can clone it
27+
//! ```
28+
//!
29+
//! To easily implement the Clone trait, you can also use
30+
//! `#[derive(Clone)]`. Example:
31+
//!
32+
//! ```
33+
//! #[derive(Clone)] // we add the Clone trait to Morpheus struct
34+
//! struct Morpheus {
35+
//! blue_pill: f32,
36+
//! red_pill: i64,
37+
//! }
38+
//!
39+
//! fn main() {
40+
//! let f = Morpheus { blue_pill: 0.0, red_pill: 0 };
41+
//! let copy = f.clone(); // and now we can clone it!
42+
//! }
43+
//! ```
2144
2245
#![stable(feature = "rust1", since = "1.0.0")]
2346

branches/auto/src/libcore/option.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,12 @@
9393
//! let msg = Some("howdy");
9494
//!
9595
//! // Take a reference to the contained string
96-
//! match msg {
97-
//! Some(ref m) => println!("{}", *m),
98-
//! None => (),
96+
//! if let Some(ref m) = msg {
97+
//! println!("{}", *m);
9998
//! }
10099
//!
101100
//! // Remove the contained string, destroying the Option
102-
//! let unwrapped_msg = match msg {
103-
//! Some(m) => m,
104-
//! None => "default message",
105-
//! };
101+
//! let unwrapped_msg = msg.unwrap_or("default message");
106102
//! ```
107103
//!
108104
//! Initialize a result to `None` before a loop:

branches/auto/src/librustc/lint/builtin.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ declare_lint! {
160160
"two overlapping inherent impls define an item with the same name were erroneously allowed"
161161
}
162162

163+
declare_lint! {
164+
pub RENAMED_AND_REMOVED_LINTS,
165+
Warn,
166+
"lints that have been renamed or removed"
167+
}
168+
163169
/// Does nothing as a lint pass, but registers some `Lint`s
164170
/// which are used by other parts of the compiler.
165171
#[derive(Copy, Clone)]
@@ -191,7 +197,8 @@ impl LintPass for HardwiredLints {
191197
CONST_ERR,
192198
RAW_POINTER_DERIVE,
193199
TRANSMUTE_FROM_FN_ITEM_TYPES,
194-
OVERLAPPING_INHERENT_IMPLS
200+
OVERLAPPING_INHERENT_IMPLS,
201+
RENAMED_AND_REMOVED_LINTS
195202
)
196203
}
197204
}

branches/auto/src/librustc/lint/context.rs

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,13 +1144,13 @@ impl LateLintPass for GatherNodeLevels {
11441144
}
11451145
}
11461146

1147-
enum CheckLintNameResult<'a> {
1147+
enum CheckLintNameResult {
11481148
Ok,
11491149
// Lint doesn't exist
11501150
NoLint,
1151-
// The lint is either renamed or removed and a warning was
1152-
// generated in the DiagnosticBuilder
1153-
Mentioned(DiagnosticBuilder<'a>)
1151+
// The lint is either renamed or removed. This is the warning
1152+
// message.
1153+
Warning(String)
11541154
}
11551155

11561156
/// Checks the name of a lint for its existence, and whether it was
@@ -1160,27 +1160,18 @@ enum CheckLintNameResult<'a> {
11601160
/// it emits non-fatal warnings and there are *two* lint passes that
11611161
/// inspect attributes, this is only run from the late pass to avoid
11621162
/// printing duplicate warnings.
1163-
fn check_lint_name<'a>(sess: &'a Session,
1164-
lint_cx: &LintStore,
1165-
lint_name: &str,
1166-
span: Option<Span>) -> CheckLintNameResult<'a> {
1163+
fn check_lint_name(lint_cx: &LintStore,
1164+
lint_name: &str) -> CheckLintNameResult {
11671165
match lint_cx.by_name.get(lint_name) {
11681166
Some(&Renamed(ref new_name, _)) => {
1169-
let warning = format!("lint {} has been renamed to {}",
1170-
lint_name, new_name);
1171-
let db = match span {
1172-
Some(span) => sess.struct_span_warn(span, &warning[..]),
1173-
None => sess.struct_warn(&warning[..]),
1174-
};
1175-
CheckLintNameResult::Mentioned(db)
1167+
CheckLintNameResult::Warning(
1168+
format!("lint {} has been renamed to {}", lint_name, new_name)
1169+
)
11761170
},
11771171
Some(&Removed(ref reason)) => {
1178-
let warning = format!("lint {} has been removed: {}", lint_name, reason);
1179-
let db = match span {
1180-
Some(span) => sess.struct_span_warn(span, &warning[..]),
1181-
None => sess.struct_warn(&warning[..])
1182-
};
1183-
CheckLintNameResult::Mentioned(db)
1172+
CheckLintNameResult::Warning(
1173+
format!("lint {} has been removed: {}", lint_name, reason)
1174+
)
11841175
},
11851176
None => {
11861177
match lint_cx.lint_groups.get(lint_name) {
@@ -1209,10 +1200,12 @@ fn check_lint_name_attribute(cx: &LateContext, attr: &ast::Attribute) {
12091200
continue;
12101201
}
12111202
Ok((lint_name, _, span)) => {
1212-
match check_lint_name(&cx.tcx.sess, &cx.lints, &lint_name[..], Some(span)) {
1203+
match check_lint_name(&cx.lints,
1204+
&lint_name[..]) {
12131205
CheckLintNameResult::Ok => (),
1214-
CheckLintNameResult::Mentioned(mut db) => {
1215-
db.emit();
1206+
CheckLintNameResult::Warning(ref msg) => {
1207+
cx.span_lint(builtin::RENAMED_AND_REMOVED_LINTS,
1208+
span, msg);
12161209
}
12171210
CheckLintNameResult::NoLint => {
12181211
cx.span_lint(builtin::UNKNOWN_LINTS, span,
@@ -1228,9 +1221,11 @@ fn check_lint_name_attribute(cx: &LateContext, attr: &ast::Attribute) {
12281221
// Checks the validity of lint names derived from the command line
12291222
fn check_lint_name_cmdline(sess: &Session, lint_cx: &LintStore,
12301223
lint_name: &str, level: Level) {
1231-
let db = match check_lint_name(sess, lint_cx, lint_name, None) {
1224+
let db = match check_lint_name(lint_cx, lint_name) {
12321225
CheckLintNameResult::Ok => None,
1233-
CheckLintNameResult::Mentioned(db) => Some(db),
1226+
CheckLintNameResult::Warning(ref msg) => {
1227+
Some(sess.struct_warn(msg))
1228+
},
12341229
CheckLintNameResult::NoLint => {
12351230
Some(sess.struct_err(&format!("unknown lint: `{}`", lint_name)))
12361231
}

branches/auto/src/librustc/middle/subst.rs

Lines changed: 28 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
// Type substitutions.
1212

1313
pub use self::ParamSpace::*;
14-
pub use self::RegionSubsts::*;
1514

1615
use middle::cstore;
1716
use middle::def_id::DefId;
@@ -34,24 +33,15 @@ use syntax::codemap::{Span, DUMMY_SP};
3433
#[derive(Clone, PartialEq, Eq, Hash)]
3534
pub struct Substs<'tcx> {
3635
pub types: VecPerParamSpace<Ty<'tcx>>,
37-
pub regions: RegionSubsts,
38-
}
39-
40-
/// Represents the values to use when substituting lifetime parameters.
41-
/// If the value is `ErasedRegions`, then this subst is occurring during
42-
/// trans, and all region parameters will be replaced with `ty::ReStatic`.
43-
#[derive(Clone, PartialEq, Eq, Hash)]
44-
pub enum RegionSubsts {
45-
ErasedRegions,
46-
NonerasedRegions(VecPerParamSpace<ty::Region>)
36+
pub regions: VecPerParamSpace<ty::Region>,
4737
}
4838

4939
impl<'tcx> Substs<'tcx> {
5040
pub fn new(t: VecPerParamSpace<Ty<'tcx>>,
5141
r: VecPerParamSpace<ty::Region>)
5242
-> Substs<'tcx>
5343
{
54-
Substs { types: t, regions: NonerasedRegions(r) }
44+
Substs { types: t, regions: r }
5545
}
5646

5747
pub fn new_type(t: Vec<Ty<'tcx>>,
@@ -71,32 +61,15 @@ impl<'tcx> Substs<'tcx> {
7161
VecPerParamSpace::new(r, Vec::new(), Vec::new()))
7262
}
7363

74-
pub fn erased(t: VecPerParamSpace<Ty<'tcx>>) -> Substs<'tcx>
75-
{
76-
Substs { types: t, regions: ErasedRegions }
77-
}
78-
7964
pub fn empty() -> Substs<'tcx> {
8065
Substs {
8166
types: VecPerParamSpace::empty(),
82-
regions: NonerasedRegions(VecPerParamSpace::empty()),
83-
}
84-
}
85-
86-
pub fn trans_empty() -> Substs<'tcx> {
87-
Substs {
88-
types: VecPerParamSpace::empty(),
89-
regions: ErasedRegions
67+
regions: VecPerParamSpace::empty(),
9068
}
9169
}
9270

9371
pub fn is_noop(&self) -> bool {
94-
let regions_is_noop = match self.regions {
95-
ErasedRegions => false, // may be used to canonicalize
96-
NonerasedRegions(ref regions) => regions.is_empty(),
97-
};
98-
99-
regions_is_noop && self.types.is_empty()
72+
self.regions.is_empty() && self.types.is_empty()
10073
}
10174

10275
pub fn type_for_def(&self, ty_param_def: &ty::TypeParameterDef) -> Ty<'tcx> {
@@ -115,26 +88,9 @@ impl<'tcx> Substs<'tcx> {
11588
}
11689

11790
pub fn erase_regions(self) -> Substs<'tcx> {
118-
let Substs { types, regions: _ } = self;
119-
Substs { types: types, regions: ErasedRegions }
120-
}
121-
122-
/// Since ErasedRegions are only to be used in trans, most of the compiler can use this method
123-
/// to easily access the set of region substitutions.
124-
pub fn regions<'a>(&'a self) -> &'a VecPerParamSpace<ty::Region> {
125-
match self.regions {
126-
ErasedRegions => panic!("Erased regions only expected in trans"),
127-
NonerasedRegions(ref r) => r
128-
}
129-
}
130-
131-
/// Since ErasedRegions are only to be used in trans, most of the compiler can use this method
132-
/// to easily access the set of region substitutions.
133-
pub fn mut_regions<'a>(&'a mut self) -> &'a mut VecPerParamSpace<ty::Region> {
134-
match self.regions {
135-
ErasedRegions => panic!("Erased regions only expected in trans"),
136-
NonerasedRegions(ref mut r) => r
137-
}
91+
let Substs { types, regions } = self;
92+
let regions = regions.map(|_| ty::ReStatic);
93+
Substs { types: types, regions: regions }
13894
}
13995

14096
pub fn with_method(self,
@@ -144,7 +100,7 @@ impl<'tcx> Substs<'tcx> {
144100
{
145101
let Substs { types, regions } = self;
146102
let types = types.with_slice(FnSpace, &m_types);
147-
let regions = regions.map(|r| r.with_slice(FnSpace, &m_regions));
103+
let regions = regions.with_slice(FnSpace, &m_regions);
148104
Substs { types: types, regions: regions }
149105
}
150106

@@ -154,27 +110,23 @@ impl<'tcx> Substs<'tcx> {
154110
{
155111
let Substs { types, regions } = self.clone();
156112
let types = types.with_slice(FnSpace, meth_substs.types.get_slice(FnSpace));
157-
let regions = regions.map(|r| {
158-
r.with_slice(FnSpace, meth_substs.regions().get_slice(FnSpace))
159-
});
113+
let regions = regions.with_slice(FnSpace, meth_substs.regions.get_slice(FnSpace));
160114
Substs { types: types, regions: regions }
161115
}
162116

163117
pub fn with_method_from_subst(self, other: &Substs<'tcx>) -> Substs<'tcx> {
164118
let Substs { types, regions } = self;
165119
let types = types.with_slice(FnSpace, other.types.get_slice(FnSpace));
166-
let regions = regions.map(|r| {
167-
r.with_slice(FnSpace, other.regions().get_slice(FnSpace))
168-
});
120+
let regions = regions.with_slice(FnSpace, other.regions.get_slice(FnSpace));
169121
Substs { types: types, regions: regions }
170122
}
171123

172124
/// Creates a trait-ref out of this substs, ignoring the FnSpace substs
173125
pub fn to_trait_ref(&self, tcx: &TyCtxt<'tcx>, trait_id: DefId)
174126
-> ty::TraitRef<'tcx> {
175-
let Substs { mut types, regions } = self.clone();
127+
let Substs { mut types, mut regions } = self.clone();
176128
types.truncate(FnSpace, 0);
177-
let regions = regions.map(|mut r| { r.truncate(FnSpace, 0); r });
129+
regions.truncate(FnSpace, 0);
178130

179131
ty::TraitRef {
180132
def_id: trait_id,
@@ -212,24 +164,6 @@ impl<'tcx> Decodable for &'tcx Substs<'tcx> {
212164
}
213165
}
214166

215-
impl RegionSubsts {
216-
pub fn map<F>(self, op: F) -> RegionSubsts where
217-
F: FnOnce(VecPerParamSpace<ty::Region>) -> VecPerParamSpace<ty::Region>,
218-
{
219-
match self {
220-
ErasedRegions => ErasedRegions,
221-
NonerasedRegions(r) => NonerasedRegions(op(r))
222-
}
223-
}
224-
225-
pub fn is_erased(&self) -> bool {
226-
match *self {
227-
ErasedRegions => true,
228-
NonerasedRegions(_) => false,
229-
}
230-
}
231-
}
232-
233167
///////////////////////////////////////////////////////////////////////////
234168
// ParamSpace
235169

@@ -664,26 +598,22 @@ impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> {
664598
// the specialized routine `ty::replace_late_regions()`.
665599
match r {
666600
ty::ReEarlyBound(data) => {
667-
match self.substs.regions {
668-
ErasedRegions => ty::ReStatic,
669-
NonerasedRegions(ref regions) =>
670-
match regions.opt_get(data.space, data.index as usize) {
671-
Some(&r) => {
672-
self.shift_region_through_binders(r)
673-
}
674-
None => {
675-
let span = self.span.unwrap_or(DUMMY_SP);
676-
self.tcx().sess.span_bug(
677-
span,
678-
&format!("Type parameter out of range \
679-
when substituting in region {} (root type={:?}) \
680-
(space={:?}, index={})",
681-
data.name,
682-
self.root_ty,
683-
data.space,
684-
data.index));
685-
}
686-
}
601+
match self.substs.regions.opt_get(data.space, data.index as usize) {
602+
Some(&r) => {
603+
self.shift_region_through_binders(r)
604+
}
605+
None => {
606+
let span = self.span.unwrap_or(DUMMY_SP);
607+
self.tcx().sess.span_bug(
608+
span,
609+
&format!("Region parameter out of range \
610+
when substituting in region {} (root type={:?}) \
611+
(space={:?}, index={})",
612+
data.name,
613+
self.root_ty,
614+
data.space,
615+
data.index));
616+
}
687617
}
688618
}
689619
_ => r

branches/auto/src/librustc/middle/traits/specialize/mod.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,6 @@ pub fn translate_substs<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
102102
specialization_graph::Node::Trait(..) => source_trait_ref.substs.clone(),
103103
};
104104

105-
// retain erasure mode
106-
// NB: this must happen before inheriting method generics below
107-
let target_substs = if source_substs.regions.is_erased() {
108-
target_substs.erase_regions()
109-
} else {
110-
target_substs
111-
};
112-
113105
// directly inherent the method generics, since those do not vary across impls
114106
infcx.tcx.mk_substs(target_substs.with_method_from_subst(source_substs))
115107
}

0 commit comments

Comments
 (0)