Skip to content

Commit 5a6fb8e

Browse files
committed
Merge remote-tracking branch 'rust-lang/master'
Conflicts: src/librustc/lint/builtin.rs src/librustc/lint/context.rs
2 parents d179ba3 + 16286f5 commit 5a6fb8e

Some content is hidden

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

89 files changed

+841
-841
lines changed

src/doc/reference.md

-4
Original file line numberDiff line numberDiff line change
@@ -2418,10 +2418,6 @@ The currently implemented features of the reference compiler are:
24182418
for now until the specification of identifiers is fully
24192419
fleshed out.
24202420

2421-
* `once_fns` - Onceness guarantees a closure is only executed once. Defining a
2422-
closure as `once` is unlikely to be supported going forward. So
2423-
they are hidden behind this feature until they are to be removed.
2424-
24252421
* `plugin` - Usage of [compiler plugins][plugin] for custom lints or syntax extensions.
24262422
These depend on compiler internals and are subject to change.
24272423

src/libcollections/string.rs

+16
Original file line numberDiff line numberDiff line change
@@ -1417,4 +1417,20 @@ mod tests {
14171417
let _ = String::from_utf8_lossy(s.as_slice());
14181418
});
14191419
}
1420+
1421+
#[bench]
1422+
fn bench_exact_size_shrink_to_fit(b: &mut Bencher) {
1423+
let s = "Hello there, the quick brown fox jumped over the lazy dog! \
1424+
Lorem ipsum dolor sit amet, consectetur. ";
1425+
// ensure our operation produces an exact-size string before we benchmark it
1426+
let mut r = String::with_capacity(s.len());
1427+
r.push_str(s);
1428+
assert_eq!(r.len(), r.capacity());
1429+
b.iter(|| {
1430+
let mut r = String::with_capacity(s.len());
1431+
r.push_str(s);
1432+
r.shrink_to_fit();
1433+
r
1434+
});
1435+
}
14201436
}

src/libcollections/vec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ impl<T> Vec<T> {
357357
}
358358
self.cap = 0;
359359
}
360-
} else {
360+
} else if self.cap != self.len {
361361
unsafe {
362362
// Overflow check is unnecessary as the vector is already at
363363
// least this large.

src/libcore/fmt/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ pub trait Show {
255255
reason = "I/O and core have yet to be reconciled")]
256256
#[rustc_on_unimplemented = "`{Self}` cannot be formatted using `:?`; if it is defined in your \
257257
crate, add `#[derive(Debug)]` or manually implement it"]
258+
#[lang = "debug_trait"]
258259
pub trait Debug {
259260
/// Formats the value using the given formatter.
260261
fn fmt(&self, &mut Formatter) -> Result;

src/librustc/lint/builtin.rs

+64-1
Original file line numberDiff line numberDiff line change
@@ -1624,6 +1624,69 @@ impl LintPass for MissingCopyImplementations {
16241624
}
16251625
}
16261626

1627+
declare_lint! {
1628+
MISSING_DEBUG_IMPLEMENTATIONS,
1629+
Allow,
1630+
"detects missing implementations of fmt::Debug"
1631+
}
1632+
1633+
pub struct MissingDebugImplementations {
1634+
impling_types: Option<NodeSet>,
1635+
}
1636+
1637+
impl MissingDebugImplementations {
1638+
pub fn new() -> MissingDebugImplementations {
1639+
MissingDebugImplementations {
1640+
impling_types: None,
1641+
}
1642+
}
1643+
}
1644+
1645+
impl LintPass for MissingDebugImplementations {
1646+
fn get_lints(&self) -> LintArray {
1647+
lint_array!(MISSING_DEBUG_IMPLEMENTATIONS)
1648+
}
1649+
1650+
fn check_item(&mut self, cx: &Context, item: &ast::Item) {
1651+
if !cx.exported_items.contains(&item.id) {
1652+
return;
1653+
}
1654+
1655+
match item.node {
1656+
ast::ItemStruct(..) | ast::ItemEnum(..) => {},
1657+
_ => return,
1658+
}
1659+
1660+
let debug = match cx.tcx.lang_items.debug_trait() {
1661+
Some(debug) => debug,
1662+
None => return,
1663+
};
1664+
1665+
if self.impling_types.is_none() {
1666+
let impls = cx.tcx.trait_impls.borrow();
1667+
let impls = match impls.get(&debug) {
1668+
Some(impls) => {
1669+
impls.borrow().iter()
1670+
.filter(|d| d.krate == ast::LOCAL_CRATE)
1671+
.filter_map(|d| ty::ty_to_def_id(ty::node_id_to_type(cx.tcx, d.node)))
1672+
.map(|d| d.node)
1673+
.collect()
1674+
}
1675+
None => NodeSet(),
1676+
};
1677+
self.impling_types = Some(impls);
1678+
debug!("{:?}", self.impling_types);
1679+
}
1680+
1681+
if !self.impling_types.as_ref().unwrap().contains(&item.id) {
1682+
cx.span_lint(MISSING_DEBUG_IMPLEMENTATIONS,
1683+
item.span,
1684+
"type does not implement `fmt::Debug`; consider adding #[derive(Debug)] \
1685+
or a manual implementation")
1686+
}
1687+
}
1688+
}
1689+
16271690
declare_lint! {
16281691
DEPRECATED,
16291692
Warn,
@@ -1826,7 +1889,7 @@ impl LintPass for UnconditionalRecursion {
18261889
ty::MethodTraitObject(_) => return false,
18271890

18281891
// This `did` refers directly to the method definition.
1829-
ty::MethodStatic(did) | ty::MethodStaticUnboxedClosure(did) => did,
1892+
ty::MethodStatic(did) | ty::MethodStaticClosure(did) => did,
18301893

18311894
// MethodTypeParam are methods from traits:
18321895

src/librustc/lint/context.rs

+1
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ impl LintStore {
219219
TypeLimits,
220220
RawPointerDerive,
221221
MissingDoc,
222+
MissingDebugImplementations,
222223
);
223224

224225
add_lint_group!(sess, "bad_style",

src/librustc/metadata/common.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ pub enum astencode_tag { // Reserves 0x40 -- 0x5f
139139
tag_table_adjustments = 0x51,
140140
tag_table_moves_map = 0x52,
141141
tag_table_capture_map = 0x53,
142-
tag_table_unboxed_closures = 0x54,
142+
tag_table_closures = 0x54,
143143
tag_table_upvar_borrow_map = 0x55,
144144
tag_table_capture_modes = 0x56,
145145
tag_table_object_cast_map = 0x57,
@@ -225,10 +225,10 @@ pub struct LinkMeta {
225225
pub crate_hash: Svh,
226226
}
227227

228-
pub const tag_unboxed_closures: uint = 0x95;
229-
pub const tag_unboxed_closure: uint = 0x96;
230-
pub const tag_unboxed_closure_type: uint = 0x97;
231-
pub const tag_unboxed_closure_kind: uint = 0x98;
228+
pub const tag_closures: uint = 0x95;
229+
pub const tag_closure: uint = 0x96;
230+
pub const tag_closure_type: uint = 0x97;
231+
pub const tag_closure_kind: uint = 0x98;
232232

233233
pub const tag_struct_fields: uint = 0x99;
234234
pub const tag_struct_field: uint = 0x9a;

src/librustc/metadata/encoder.rs

+20-26
Original file line numberDiff line numberDiff line change
@@ -618,13 +618,12 @@ fn encode_visibility(rbml_w: &mut Encoder, visibility: ast::Visibility) {
618618
rbml_w.end_tag();
619619
}
620620

621-
fn encode_unboxed_closure_kind(rbml_w: &mut Encoder,
622-
kind: ty::UnboxedClosureKind) {
623-
rbml_w.start_tag(tag_unboxed_closure_kind);
621+
fn encode_closure_kind(rbml_w: &mut Encoder, kind: ty::ClosureKind) {
622+
rbml_w.start_tag(tag_closure_kind);
624623
let ch = match kind {
625-
ty::FnUnboxedClosureKind => 'f',
626-
ty::FnMutUnboxedClosureKind => 'm',
627-
ty::FnOnceUnboxedClosureKind => 'o',
624+
ty::FnClosureKind => 'f',
625+
ty::FnMutClosureKind => 'm',
626+
ty::FnOnceClosureKind => 'o',
628627
};
629628
rbml_w.wr_str(&ch.to_string()[]);
630629
rbml_w.end_tag();
@@ -1838,24 +1837,19 @@ fn encode_macro_defs(rbml_w: &mut Encoder,
18381837
rbml_w.end_tag();
18391838
}
18401839

1841-
fn encode_unboxed_closures<'a>(
1842-
ecx: &'a EncodeContext,
1843-
rbml_w: &'a mut Encoder) {
1844-
rbml_w.start_tag(tag_unboxed_closures);
1845-
for (unboxed_closure_id, unboxed_closure) in ecx.tcx
1846-
.unboxed_closures
1847-
.borrow()
1848-
.iter() {
1849-
if unboxed_closure_id.krate != ast::LOCAL_CRATE {
1840+
fn encode_closures<'a>(ecx: &'a EncodeContext, rbml_w: &'a mut Encoder) {
1841+
rbml_w.start_tag(tag_closures);
1842+
for (closure_id, closure) in ecx.tcx.closures.borrow().iter() {
1843+
if closure_id.krate != ast::LOCAL_CRATE {
18501844
continue
18511845
}
18521846

1853-
rbml_w.start_tag(tag_unboxed_closure);
1854-
encode_def_id(rbml_w, *unboxed_closure_id);
1855-
rbml_w.start_tag(tag_unboxed_closure_type);
1856-
write_closure_type(ecx, rbml_w, &unboxed_closure.closure_type);
1847+
rbml_w.start_tag(tag_closure);
1848+
encode_def_id(rbml_w, *closure_id);
1849+
rbml_w.start_tag(tag_closure_type);
1850+
write_closure_type(ecx, rbml_w, &closure.closure_type);
18571851
rbml_w.end_tag();
1858-
encode_unboxed_closure_kind(rbml_w, unboxed_closure.kind);
1852+
encode_closure_kind(rbml_w, closure.kind);
18591853
rbml_w.end_tag();
18601854
}
18611855
rbml_w.end_tag();
@@ -2069,7 +2063,7 @@ fn encode_metadata_inner(wr: &mut SeekableMemWriter,
20692063
native_lib_bytes: u64,
20702064
plugin_registrar_fn_bytes: u64,
20712065
macro_defs_bytes: u64,
2072-
unboxed_closure_bytes: u64,
2066+
closure_bytes: u64,
20732067
impl_bytes: u64,
20742068
misc_bytes: u64,
20752069
item_bytes: u64,
@@ -2084,7 +2078,7 @@ fn encode_metadata_inner(wr: &mut SeekableMemWriter,
20842078
native_lib_bytes: 0,
20852079
plugin_registrar_fn_bytes: 0,
20862080
macro_defs_bytes: 0,
2087-
unboxed_closure_bytes: 0,
2081+
closure_bytes: 0,
20882082
impl_bytes: 0,
20892083
misc_bytes: 0,
20902084
item_bytes: 0,
@@ -2154,10 +2148,10 @@ fn encode_metadata_inner(wr: &mut SeekableMemWriter,
21542148
encode_macro_defs(&mut rbml_w, krate);
21552149
stats.macro_defs_bytes = rbml_w.writer.tell().unwrap() - i;
21562150

2157-
// Encode the types of all unboxed closures in this crate.
2151+
// Encode the types of all closures in this crate.
21582152
i = rbml_w.writer.tell().unwrap();
2159-
encode_unboxed_closures(&ecx, &mut rbml_w);
2160-
stats.unboxed_closure_bytes = rbml_w.writer.tell().unwrap() - i;
2153+
encode_closures(&ecx, &mut rbml_w);
2154+
stats.closure_bytes = rbml_w.writer.tell().unwrap() - i;
21612155

21622156
// Encode the def IDs of impls, for coherence checking.
21632157
i = rbml_w.writer.tell().unwrap();
@@ -2199,7 +2193,7 @@ fn encode_metadata_inner(wr: &mut SeekableMemWriter,
21992193
println!(" native bytes: {}", stats.native_lib_bytes);
22002194
println!("plugin registrar bytes: {}", stats.plugin_registrar_fn_bytes);
22012195
println!(" macro def bytes: {}", stats.macro_defs_bytes);
2202-
println!(" unboxed closure bytes: {}", stats.unboxed_closure_bytes);
2196+
println!(" closure bytes: {}", stats.closure_bytes);
22032197
println!(" impl bytes: {}", stats.impl_bytes);
22042198
println!(" misc bytes: {}", stats.misc_bytes);
22052199
println!(" item bytes: {}", stats.item_bytes);

src/librustc/metadata/tydecode.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ pub enum DefIdSource {
5757
// Identifies a region parameter (`fn foo<'X>() { ... }`).
5858
RegionParameter,
5959

60-
// Identifies an unboxed closure
61-
UnboxedClosureSource
60+
// Identifies a closure
61+
ClosureSource
6262
}
6363

6464
// type conv_did = impl FnMut(DefIdSource, ast::DefId) -> ast::DefId;
@@ -537,11 +537,11 @@ fn parse_ty_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F) -> Ty<'tcx> w
537537
}
538538
'k' => {
539539
assert_eq!(next(st), '[');
540-
let did = parse_def_(st, UnboxedClosureSource, conv);
540+
let did = parse_def_(st, ClosureSource, conv);
541541
let region = parse_region_(st, conv);
542542
let substs = parse_substs_(st, conv);
543543
assert_eq!(next(st), ']');
544-
return ty::mk_unboxed_closure(st.tcx, did,
544+
return ty::mk_closure(st.tcx, did,
545545
st.tcx.mk_region(region), st.tcx.mk_substs(substs));
546546
}
547547
'P' => {

src/librustc/metadata/tyencode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ pub fn enc_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>, t: Ty<'t
139139
enc_substs(w, cx, substs);
140140
mywrite!(w, "]");
141141
}
142-
ty::ty_unboxed_closure(def, region, substs) => {
142+
ty::ty_closure(def, region, substs) => {
143143
mywrite!(w, "k[{}|", (cx.ds)(def));
144144
enc_region(w, cx, *region);
145145
enc_substs(w, cx, substs);

0 commit comments

Comments
 (0)