diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index da56b21cf0c05..966144233894c 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -479,18 +479,45 @@ impl Vec { } } - /// Shorten a vector to be `len` elements long, dropping excess elements. + /// Shortens the vector, keeping the first `len` elements and dropping + /// the rest. /// /// If `len` is greater than the vector's current length, this has no /// effect. /// + /// The [`drain`] method can emulate `truncate`, but causes the excess + /// elements to be returned instead of dropped. + /// /// # Examples /// + /// Truncating a five element vector to two elements: + /// /// ``` /// let mut vec = vec![1, 2, 3, 4, 5]; /// vec.truncate(2); /// assert_eq!(vec, [1, 2]); /// ``` + /// + /// No truncation occurs when `len` is greater than the vector's current + /// length: + /// + /// ``` + /// let mut vec = vec![1, 2, 3]; + /// vec.truncate(8); + /// assert_eq!(vec, [1, 2, 3]); + /// ``` + /// + /// Truncating when `len == 0` is equivalent to calling the [`clear`] + /// method. + /// + /// ``` + /// let mut vec = vec![1, 2, 3]; + /// vec.truncate(0); + /// assert_eq!(vec, []); + /// ``` + /// + /// [`clear`]: #method.clear + /// [`drain`]: #method.drain #[stable(feature = "rust1", since = "1.0.0")] pub fn truncate(&mut self, len: usize) { unsafe { diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index 3f5c9a6d3bd83..409cec282bce9 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -687,32 +687,6 @@ fn each_child_of_item_or_crate(cdata: Cmd, } } - // As a special case, iterate over all static methods of - // associated implementations too. This is a bit of a botch. - // --pcwalton - for inherent_impl_def_id_doc in reader::tagged_docs(item_doc, - tag_items_data_item_inherent_impl) { - let inherent_impl_def_id = item_def_id(inherent_impl_def_id_doc, cdata); - if let Some(inherent_impl_doc) = cdata.get_item(inherent_impl_def_id.index) { - for impl_item_def_id_doc in reader::tagged_docs(inherent_impl_doc, - tag_item_impl_item) { - let impl_item_def_id = item_def_id(impl_item_def_id_doc, - cdata); - if let Some(impl_method_doc) = cdata.get_item(impl_item_def_id.index) { - if let StaticMethod = item_family(impl_method_doc) { - // Hand off the static method to the callback. - let static_method_name = item_name(impl_method_doc); - let static_method_def_like = item_to_def_like(cdata, impl_method_doc, - impl_item_def_id); - callback(static_method_def_like, - static_method_name, - item_visibility(impl_method_doc)); - } - } - } - } - } - for reexport_doc in reexports(item_doc) { let def_id_doc = reader::get_doc(reexport_doc, tag_items_data_item_reexport_def_id); diff --git a/src/librustc_mir/pretty.rs b/src/librustc_mir/pretty.rs index 515620d425389..c9ca1a963a42a 100644 --- a/src/librustc_mir/pretty.rs +++ b/src/librustc_mir/pretty.rs @@ -195,7 +195,7 @@ fn write_basic_block(tcx: TyCtxt, ALIGN, comment(tcx, data.terminator().source_info))?; - writeln!(w, "{}}}\n", INDENT) + writeln!(w, "{}}}", INDENT) } fn comment(tcx: TyCtxt, SourceInfo { span, scope }: SourceInfo) -> String { diff --git a/src/libstd/panicking.rs b/src/libstd/panicking.rs index d73e9542d2125..a7de9d3a0c5d6 100644 --- a/src/libstd/panicking.rs +++ b/src/libstd/panicking.rs @@ -232,10 +232,9 @@ fn default_hook(info: &PanicInfo) { pub unsafe fn try R>(f: F) -> Result> { let mut slot = None; let mut f = Some(f); - let ret = PANIC_COUNT.with(|s| { - let prev = s.get(); - s.set(0); + let ret; + { let mut to_run = || { slot = Some(f.take().unwrap()()); }; @@ -248,18 +247,21 @@ pub unsafe fn try R>(f: F) -> Result> { dataptr, &mut any_data, &mut any_vtable); - s.set(prev); - if r == 0 { - Ok(()) + ret = Ok(()); } else { - Err(mem::transmute(raw::TraitObject { + PANIC_COUNT.with(|s| { + let prev = s.get(); + s.set(prev - 1); + }); + ret = Err(mem::transmute(raw::TraitObject { data: any_data as *mut _, vtable: any_vtable as *mut _, - })) + })); } - }); + } + debug_assert!(PANIC_COUNT.with(|c| c.get() == 0)); return ret.map(|()| { slot.take().unwrap() }); diff --git a/src/test/compile-fail/use-from-trait-xc.rs b/src/test/compile-fail/use-from-trait-xc.rs index e6c9b1b41c048..687cdba1542bd 100644 --- a/src/test/compile-fail/use-from-trait-xc.rs +++ b/src/test/compile-fail/use-from-trait-xc.rs @@ -31,6 +31,6 @@ use use_from_trait_xc::Bar::new as bnew; //~^ ERROR unresolved import `use_from_trait_xc::Bar::new` use use_from_trait_xc::Baz::new as baznew; -//~^ ERROR `baznew` is not directly importable +//~^ ERROR unresolved import `use_from_trait_xc::Baz::new` fn main() {}