Skip to content

Commit 692401a

Browse files
committed
---
yaml --- r: 213487 b: refs/heads/try c: 115121d h: refs/heads/master i: 213485: 5a4e20f 213483: c393654 213479: eacfdd9 213471: cbeb1e6 v: v3
1 parent 961f199 commit 692401a

File tree

33 files changed

+159
-127
lines changed

33 files changed

+159
-127
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 2f5683913c9815d9f12494784747f79b0f3b3066
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: ba0e1cd8147d452c356aacb29fb87568ca26f111
5-
refs/heads/try: e36e97ba51f512de2fd05e3250db4a7b72caae04
5+
refs/heads/try: 115121de3d4669a798e99aa69dfdbc7012b4181c
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try/src/liballoc/boxed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ use core::raw::{TraitObject};
8181
#[lang = "exchange_heap"]
8282
#[unstable(feature = "alloc",
8383
reason = "may be renamed; uncertain about custom allocator design")]
84-
pub static HEAP: () = ();
84+
pub const HEAP: () = ();
8585

8686
/// A pointer type for heap allocation.
8787
///

branches/try/src/libcollections/bit.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ fn match_words <'a,'b>(a: &'a BitVec, b: &'b BitVec) -> (MatchWords<'a>, MatchWo
125125
}
126126
}
127127

128-
static TRUE: bool = true;
129-
static FALSE: bool = false;
128+
const TRUE: &'static bool = &true;
129+
const FALSE: &'static bool = &false;
130130

131131
/// The bitvector type.
132132
///
@@ -172,9 +172,9 @@ impl Index<usize> for BitVec {
172172
#[inline]
173173
fn index(&self, i: usize) -> &bool {
174174
if self.get(i).expect("index out of bounds") {
175-
&TRUE
175+
TRUE
176176
} else {
177-
&FALSE
177+
FALSE
178178
}
179179
}
180180
}

branches/try/src/libcollections/vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ use borrow::{Cow, IntoCow};
8383
use super::range::RangeArgument;
8484

8585
// FIXME- fix places which assume the max vector allowed has memory usize::MAX.
86-
static MAX_MEMORY_SIZE: usize = isize::MAX as usize;
86+
const MAX_MEMORY_SIZE: usize = isize::MAX as usize;
8787

8888
/// A growable list type, written `Vec<T>` but pronounced 'vector.'
8989
///

branches/try/src/libcore/num/flt2dec/strategy/dragon.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use num::flt2dec::estimator::estimate_scaling_factor;
2424
use num::flt2dec::bignum::Digit32 as Digit;
2525
use num::flt2dec::bignum::Big32x36 as Big;
2626

27-
// FIXME(#22540) const ref to static array seems to ICE
2827
static POW10: [Digit; 10] = [1, 10, 100, 1000, 10000, 100000,
2928
1000000, 10000000, 100000000, 1000000000];
3029
static TWOPOW10: [Digit; 10] = [2, 20, 200, 2000, 20000, 200000,
@@ -328,4 +327,3 @@ pub fn format_exact(d: &Decoded, buf: &mut [u8], limit: i16) -> (/*#digits*/ usi
328327

329328
(len, k)
330329
}
331-

branches/try/src/libcore/num/flt2dec/strategy/grisu.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ for i in xrange(-308, 333, 8):
8787
f = ((f << 64 >> (l-1)) + 1) >> 1; e += l - 64
8888
print ' (%#018x, %5d, %4d),' % (f, e, i)
8989
*/
90-
// FIXME(#22540) const ref to static array seems to ICE
90+
9191
#[doc(hidden)]
9292
pub static CACHED_POW10: [(u64, i16, i16); 81] = [ // (f, e, k)
9393
(0xe61acf033d1a45df, -1087, -308),
@@ -746,4 +746,3 @@ pub fn format_exact(d: &Decoded, buf: &mut [u8], limit: i16) -> (/*#digits*/ usi
746746
None => fallback(d, buf, limit),
747747
}
748748
}
749-

branches/try/src/liblog/directive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub struct LogDirective {
1717
pub level: u32,
1818
}
1919

20-
pub static LOG_LEVEL_NAMES: [&'static str; 4] = ["ERROR", "WARN", "INFO",
20+
pub const LOG_LEVEL_NAMES: [&'static str; 4] = ["ERROR", "WARN", "INFO",
2121
"DEBUG"];
2222

2323
/// Parse an individual log level that is either a number or a symbolic log level

branches/try/src/librand/distributions/ziggurat_tables.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// algorithm. Autogenerated by `ziggurat_tables.py`.
1313

1414
pub type ZigTable = &'static [f64; 257];
15-
pub static ZIG_NORM_R: f64 = 3.654152885361008796;
15+
pub const ZIG_NORM_R: f64 = 3.654152885361008796;
1616
pub static ZIG_NORM_X: [f64; 257] =
1717
[3.910757959537090045, 3.654152885361008796, 3.449278298560964462, 3.320244733839166074,
1818
3.224575052047029100, 3.147889289517149969, 3.083526132001233044, 3.027837791768635434,
@@ -145,7 +145,7 @@ pub static ZIG_NORM_F: [f64; 257] =
145145
0.887984660763399880, 0.898095921906304051, 0.908726440060562912, 0.919991505048360247,
146146
0.932060075968990209, 0.945198953453078028, 0.959879091812415930, 0.977101701282731328,
147147
1.000000000000000000];
148-
pub static ZIG_EXP_R: f64 = 7.697117470131050077;
148+
pub const ZIG_EXP_R: f64 = 7.697117470131050077;
149149
pub static ZIG_EXP_X: [f64; 257] =
150150
[8.697117470131052741, 7.697117470131050077, 6.941033629377212577, 6.478378493832569696,
151151
6.144164665772472667, 5.882144315795399869, 5.666410167454033697, 5.482890627526062488,

branches/try/src/librustc/diagnostics.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,25 @@ const Y: i32 = A;
227227
```
228228
"##,
229229

230+
E0014: r##"
231+
Constants can only be initialized by a constant value or, in a future
232+
version of Rust, a call to a const function. This error indicates the use
233+
of a path (like a::b, or x) denoting something other than one of these
234+
allowed items. Example:
235+
236+
```
237+
const FOO: i32 = { let x = 0; x }; // 'x' isn't a constant nor a function!
238+
```
239+
240+
To avoid it, you have to replace the non-constant value:
241+
242+
```
243+
const FOO: i32 = { const X : i32 = 0; X };
244+
// or even:
245+
const FOO: i32 = { 0 }; // but brackets are useless here
246+
```
247+
"##,
248+
230249
E0015: r##"
231250
The only functions that can be called in static or constant expressions are
232251
`const` functions. Rust currently does not support more general compile-time
@@ -931,7 +950,6 @@ static mut BAR: Option<Vec<i32>> = None;
931950

932951

933952
register_diagnostics! {
934-
E0014,
935953
E0016,
936954
E0017,
937955
E0019,

branches/try/src/librustc/lint/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,8 @@ macro_rules! declare_lint {
101101
#[macro_export]
102102
macro_rules! lint_array { ($( $lint:expr ),*) => (
103103
{
104-
#[allow(non_upper_case_globals)]
105-
static array: LintArray = &[ $( &$lint ),* ];
106-
array
104+
static ARRAY: LintArray = &[ $( &$lint ),* ];
105+
ARRAY
107106
}
108107
) }
109108

branches/try/src/librustc/metadata/tydecode.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ pub enum DefIdSource {
5050
// Identifies a type alias (`type X = ...`).
5151
TypeWithId,
5252

53-
// Identifies a type parameter (`fn foo<X>() { ... }`).
54-
TypeParameter,
55-
5653
// Identifies a region parameter (`fn foo<'X>() { ... }`).
5754
RegionParameter,
5855

@@ -193,7 +190,7 @@ pub fn parse_substs_data<'tcx, F>(data: &[u8], crate_num: ast::CrateNum, pos: us
193190
tcx: &ty::ctxt<'tcx>, conv: F) -> subst::Substs<'tcx> where
194191
F: FnMut(DefIdSource, ast::DefId) -> ast::DefId,
195192
{
196-
debug!("parse_substs_data {}", data_log_string(data, pos));
193+
debug!("parse_substs_data{}", data_log_string(data, pos));
197194
let mut st = parse_state_from_data(data, crate_num, pos, tcx);
198195
parse_substs(&mut st, conv)
199196
}
@@ -542,7 +539,14 @@ fn parse_ty_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F) -> Ty<'tcx> w
542539
len: len };
543540

544541
match tcx.rcache.borrow().get(&key).cloned() {
545-
Some(tt) => return tt,
542+
Some(tt) => {
543+
// If there is a closure buried in the type some where, then we
544+
// need to re-convert any def ids (see case 'k', below). That means
545+
// we can't reuse the cached version.
546+
if !ty::type_has_ty_closure(tt) {
547+
return tt;
548+
}
549+
}
546550
None => {}
547551
}
548552
let mut ps = PState {

branches/try/src/librustc/middle/astencode.rs

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use middle::def;
2020
use metadata::encoder as e;
2121
use middle::region;
2222
use metadata::tydecode;
23-
use metadata::tydecode::{DefIdSource, NominalType, TypeWithId, TypeParameter};
23+
use metadata::tydecode::{DefIdSource, NominalType, TypeWithId};
2424
use metadata::tydecode::{RegionParameter, ClosureSource};
2525
use metadata::tyencode;
2626
use middle::cast;
@@ -346,13 +346,6 @@ impl<D:serialize::Decoder> def_id_decoder_helpers for D
346346
// ______________________________________________________________________
347347
// Encoding and decoding the AST itself
348348
//
349-
// The hard work is done by an autogenerated module astencode_gen. To
350-
// regenerate astencode_gen, run src/etc/gen-astencode. It will
351-
// replace astencode_gen with a dummy file and regenerate its
352-
// contents. If you get compile errors, the dummy file
353-
// remains---resolve the errors and then rerun astencode_gen.
354-
// Annoying, I know, but hopefully only temporary.
355-
//
356349
// When decoding, we have to renumber the AST so that the node ids that
357350
// appear within are disjoint from the node ids in our existing ASTs.
358351
// We also have to adjust the spans: for now we just insert a dummy span,
@@ -656,35 +649,6 @@ impl<'a, 'tcx> read_method_callee_helper<'tcx> for reader::Decoder<'a> {
656649
}
657650
}
658651

659-
impl<'tcx> tr for MethodOrigin<'tcx> {
660-
fn tr(&self, dcx: &DecodeContext) -> MethodOrigin<'tcx> {
661-
match *self {
662-
ty::MethodStatic(did) => ty::MethodStatic(did.tr(dcx)),
663-
ty::MethodStaticClosure(did) => {
664-
ty::MethodStaticClosure(did.tr(dcx))
665-
}
666-
ty::MethodTypeParam(ref mp) => {
667-
ty::MethodTypeParam(
668-
ty::MethodParam {
669-
// def-id is already translated when we read it out
670-
trait_ref: mp.trait_ref.clone(),
671-
method_num: mp.method_num,
672-
impl_def_id: mp.impl_def_id.tr(dcx),
673-
}
674-
)
675-
}
676-
ty::MethodTraitObject(ref mo) => {
677-
ty::MethodTraitObject(
678-
ty::MethodObject {
679-
trait_ref: mo.trait_ref.clone(),
680-
.. *mo
681-
}
682-
)
683-
}
684-
}
685-
}
686-
}
687-
688652
pub fn encode_closure_kind(ebml_w: &mut Encoder, kind: ty::ClosureKind) {
689653
kind.encode(ebml_w).unwrap();
690654
}
@@ -1473,10 +1437,10 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
14731437
-> subst::Substs<'tcx> {
14741438
self.read_opaque(|this, doc| {
14751439
Ok(tydecode::parse_substs_data(doc.data,
1476-
dcx.cdata.cnum,
1477-
doc.start,
1478-
dcx.tcx,
1479-
|s, a| this.convert_def_id(dcx, s, a)))
1440+
dcx.cdata.cnum,
1441+
doc.start,
1442+
dcx.tcx,
1443+
|s, a| this.convert_def_id(dcx, s, a)))
14801444
}).unwrap()
14811445
}
14821446

@@ -1617,7 +1581,7 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
16171581
-> ast::DefId {
16181582
let r = match source {
16191583
NominalType | TypeWithId | RegionParameter => dcx.tr_def_id(did),
1620-
TypeParameter | ClosureSource => dcx.tr_intern_def_id(did)
1584+
ClosureSource => dcx.tr_intern_def_id(did)
16211585
};
16221586
debug!("convert_def_id(source={:?}, did={:?})={:?}", source, did, r);
16231587
return r;

branches/try/src/librustc/middle/ty.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,7 @@ bitflags! {
814814
const HAS_REGIONS = 1 << 5,
815815
const HAS_TY_ERR = 1 << 6,
816816
const HAS_PROJECTION = 1 << 7,
817+
const HAS_TY_CLOSURE = 1 << 8,
817818
const NEEDS_SUBST = TypeFlags::HAS_PARAMS.bits |
818819
TypeFlags::HAS_SELF.bits |
819820
TypeFlags::HAS_REGIONS.bits,
@@ -985,6 +986,9 @@ pub fn type_needs_infer(ty: Ty) -> bool {
985986
pub fn type_has_projection(ty: Ty) -> bool {
986987
ty.flags.get().intersects(TypeFlags::HAS_PROJECTION)
987988
}
989+
pub fn type_has_ty_closure(ty: Ty) -> bool {
990+
ty.flags.get().intersects(TypeFlags::HAS_TY_CLOSURE)
991+
}
988992

989993
pub fn type_has_late_bound_regions(ty: Ty) -> bool {
990994
ty.flags.get().intersects(TypeFlags::HAS_RE_LATE_BOUND)
@@ -2960,6 +2964,7 @@ impl FlagComputation {
29602964
}
29612965

29622966
&ty_closure(_, substs) => {
2967+
self.add_flags(TypeFlags::HAS_TY_CLOSURE);
29632968
self.add_substs(substs);
29642969
}
29652970

branches/try/src/librustc/util/ppaux.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,18 @@ pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String {
304304
s
305305
}
306306

307-
fn closure_to_string<'tcx>(cx: &ctxt<'tcx>, cty: &ty::ClosureTy<'tcx>) -> String {
307+
fn closure_to_string<'tcx>(cx: &ctxt<'tcx>,
308+
cty: &ty::ClosureTy<'tcx>,
309+
did: &ast::DefId)
310+
-> String {
308311
let mut s = String::new();
309312
s.push_str("[closure");
310313
push_sig_to_string(cx, &mut s, '(', ')', &cty.sig);
311-
s.push(']');
314+
if cx.sess.verbose() {
315+
s.push_str(&format!(" id={:?}]", did));
316+
} else {
317+
s.push(']');
318+
}
312319
s
313320
}
314321

@@ -407,13 +414,20 @@ pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String {
407414
ty_closure(ref did, substs) => {
408415
let closure_tys = cx.closure_tys.borrow();
409416
closure_tys.get(did).map(|closure_type| {
410-
closure_to_string(cx, &closure_type.subst(cx, substs))
417+
closure_to_string(cx, &closure_type.subst(cx, substs), did)
411418
}).unwrap_or_else(|| {
419+
let id_str = if cx.sess.verbose() {
420+
format!(" id={:?}", did)
421+
} else {
422+
"".to_owned()
423+
};
424+
425+
412426
if did.krate == ast::LOCAL_CRATE {
413427
let span = cx.map.span(did.node);
414-
format!("[closure {}]", span.repr(cx))
428+
format!("[closure {}{}]", span.repr(cx), id_str)
415429
} else {
416-
format!("[closure]")
430+
format!("[closure{}]", id_str)
417431
}
418432
})
419433
}

branches/try/src/librustc_resolve/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3206,14 +3206,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
32063206
NoSuggestion
32073207
}
32083208

3209-
fn find_best_match_for_name(&mut self, name: &str, max_distance: usize)
3210-
-> Option<String> {
3211-
let this = &mut *self;
3212-
3209+
fn find_best_match_for_name(&mut self, name: &str) -> Option<String> {
32133210
let mut maybes: Vec<token::InternedString> = Vec::new();
32143211
let mut values: Vec<usize> = Vec::new();
32153212

3216-
for rib in this.value_ribs.iter().rev() {
3213+
for rib in self.value_ribs.iter().rev() {
32173214
for (&k, _) in &rib.bindings {
32183215
maybes.push(token::get_name(k));
32193216
values.push(usize::MAX);
@@ -3229,9 +3226,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
32293226
}
32303227
}
32313228

3229+
// As a loose rule to avoid obviously incorrect suggestions, clamp the
3230+
// maximum edit distance we will accept for a suggestion to one third of
3231+
// the typo'd name's length.
3232+
let max_distance = std::cmp::max(name.len(), 3) / 3;
3233+
32323234
if !values.is_empty() &&
3233-
values[smallest] != usize::MAX &&
3234-
values[smallest] < name.len() + 2 &&
32353235
values[smallest] <= max_distance &&
32363236
name != &maybes[smallest][..] {
32373237

@@ -3357,7 +3357,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
33573357
NoSuggestion => {
33583358
// limit search to 5 to reduce the number
33593359
// of stupid suggestions
3360-
self.find_best_match_for_name(&path_name, 5)
3360+
self.find_best_match_for_name(&path_name)
33613361
.map_or("".to_string(),
33623362
|x| format!("`{}`", x))
33633363
}

0 commit comments

Comments
 (0)