// Standard trait implementations for slices
////////////////////////////////////////////////////////////////////////////////
-#[unstable(feature = "collections", reason = "trait is unstable")]
-impl<T> BorrowFrom<Vec<T>> for [T] {
- fn borrow_from(owned: &Vec<T>) -> &[T] { &owned[..] }
+#[stable(feature = "rust1", since = "1.0.0")]
+impl<T> Borrow<[T]> for Vec<T> {
- fn borrow(&self) -> &[T] { &self[] }
++ fn borrow(&self) -> &[T] { &self[..] }
}
-#[unstable(feature = "collections", reason = "trait is unstable")]
-impl<T> BorrowFromMut<Vec<T>> for [T] {
- fn borrow_from_mut(owned: &mut Vec<T>) -> &mut [T] { &mut owned[..] }
+#[stable(feature = "rust1", since = "1.0.0")]
+impl<T> BorrowMut<[T]> for Vec<T> {
- fn borrow_mut(&mut self) -> &mut [T] { &mut self[] }
++ fn borrow_mut(&mut self) -> &mut [T] { &mut self[..] }
}
-#[unstable(feature = "collections", reason = "trait is unstable")]
-impl<T: Clone> ToOwned<Vec<T>> for [T] {
+#[stable(feature = "rust1", since = "1.0.0")]
+impl<T: Clone> ToOwned for [T] {
+ type Owned = Vec<T>;
fn to_owned(&self) -> Vec<T> { self.to_vec() }
}
($ch:expr, $byte:expr) => (($ch << 6) | ($byte & 63u8) as u32)
}
-#[unstable(feature = "collections", reason = "trait is unstable")]
-impl BorrowFrom<String> for str {
- fn borrow_from(owned: &String) -> &str { &owned[..] }
+#[stable(feature = "rust1", since = "1.0.0")]
+impl Borrow<str> for String {
- fn borrow(&self) -> &str { &self[] }
++ fn borrow(&self) -> &str { &self[..] }
}
-#[unstable(feature = "collections", reason = "trait is unstable")]
-impl ToOwned<String> for str {
+#[stable(feature = "rust1", since = "1.0.0")]
+impl ToOwned for str {
+ type Owned = String;
fn to_owned(&self) -> String {
unsafe {
String::from_utf8_unchecked(self.as_bytes().to_owned())
}
}
- impl<S: hash::Writer + Hasher, T: Hash<S>> Hash<S> for [T; $N] {
+ #[cfg(stage0)]
+ impl<S: hash::Writer + hash::Hasher, T: Hash<S>> Hash<S> for [T; $N] {
fn hash(&self, state: &mut S) {
- Hash::hash(&self[], state)
+ Hash::hash(&self[..], state)
}
}
+ #[cfg(not(stage0))]
+ #[stable(feature = "rust1", since = "1.0.0")]
+ impl<T: Hash> Hash for [T; $N] {
+ fn hash<H: hash::Hasher>(&self, state: &mut H) {
+ Hash::hash(&self[], state)
+ }
+ }
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: fmt::Debug> fmt::Debug for [T; $N] {
impl<'a, 'v> Visitor<'v> for LanguageItemCollector<'a> {
fn visit_item(&mut self, item: &ast::Item) {
- match extract(&item.attrs) {
- Some(value) => {
- let item_index = self.item_refs.get(&value[..]).map(|x| *x);
-
- match item_index {
- Some(item_index) => {
- self.collect_item(item_index, local_def(item.id), item.span)
- }
- None => {}
- }
+ if let Some(value) = extract(&item.attrs) {
- let item_index = self.item_refs.get(&value[]).cloned();
++ let item_index = self.item_refs.get(&value[..]).cloned();
+
+ if let Some(item_index) = item_index {
+ self.collect_item(item_index, local_def(item.id), item.span)
}
- None => {}
}
visit::walk_item(self, item);
debug!("preparing the RPATH!");
let libs = config.used_crates.clone();
- let libs = libs.into_iter().filter_map(|(_, l)| {
- l.map(|p| p.clone())
- }).collect::<Vec<_>>();
-
+ let libs = libs.into_iter().filter_map(|(_, l)| l).collect::<Vec<_>>();
- let rpaths = get_rpaths(config, &libs[]);
- flags.push_all(&rpaths_to_flags(&rpaths[])[]);
+ let rpaths = get_rpaths(config, &libs[..]);
- flags.push_all(&rpaths_to_flags(&rpaths[..])[]);
++ flags.push_all(&rpaths_to_flags(&rpaths[..]));
flags
}
unsafe {
let cstr = llvm::LLVMRustGetLastError();
if cstr == ptr::null() {
- handler.fatal(&msg[]);
+ handler.fatal(&msg[..]);
} else {
- let err = ffi::c_str_to_bytes(&cstr);
+ let err = CStr::from_ptr(cstr).to_bytes();
let err = String::from_utf8_lossy(err).to_string();
libc::free(cstr as *mut _);
handler.fatal(&format!("{}: {}",
let namespace_node = namespace_for_item(cx, ast_util::local_def(node_id));
let var_name = token::get_ident(ident).to_string();
let linkage_name =
- namespace_node.mangled_name_of_contained_item(&var_name[]);
+ namespace_node.mangled_name_of_contained_item(&var_name[..]);
let var_scope = namespace_node.scope;
- let var_name = CString::from_slice(var_name.as_bytes());
- let linkage_name = CString::from_slice(linkage_name.as_bytes());
+ let var_name = CString::new(var_name).unwrap();
+ let linkage_name = CString::new(linkage_name).unwrap();
unsafe {
llvm::LLVMDIBuilderCreateStaticVariable(DIB(cx),
var_scope,
};
let len = self.region_bound_pairs.len();
- self.relate_free_regions(&fn_sig[..], body.id);
- link_fn_args(self, CodeExtent::from_node_id(body.id), &fn_decl.inputs[]);
+ let old_body_id = self.set_body_id(body.id);
- self.relate_free_regions(&fn_sig[], body.id, span);
- link_fn_args(self, CodeExtent::from_node_id(body.id), &fn_decl.inputs[]);
++ self.relate_free_regions(&fn_sig[..], body.id, span);
++ link_fn_args(self, CodeExtent::from_node_id(body.id), &fn_decl.inputs[..]);
self.visit_block(body);
self.visit_region_obligations(body.id);
self.region_bound_pairs.truncate(len);
}
}
-impl BorrowFrom<OsString> for OsStr {
- fn borrow_from(owned: &OsString) -> &OsStr { &owned[..] }
+impl Borrow<OsStr> for OsString {
- fn borrow(&self) -> &OsStr { &self[] }
++ fn borrow(&self) -> &OsStr { &self[..] }
}
-impl ToOwned<OsString> for OsStr {
+impl ToOwned for OsStr {
+ type Owned = OsString;
fn to_owned(&self) -> OsString { self.to_os_string() }
}
cm: &codemap::CodeMap,
sp: Span)
-> old_io::IoResult<()> {
- let cs = try!(cm.with_expn_info(sp.expn_id, |expn_info| match expn_info {
- Some(ei) => {
- let ss = ei.callee.span.map_or(String::new(), |span| cm.span_to_string(span));
- let (pre, post) = match ei.callee.format {
- codemap::MacroAttribute => ("#[", "]"),
- codemap::MacroBang => ("", "!")
- };
- try!(print_diagnostic(w, &ss[..], Note,
- &format!("in expansion of {}{}{}", pre,
- ei.callee.name,
- post)[], None));
- let ss = cm.span_to_string(ei.call_site);
- try!(print_diagnostic(w, &ss[..], Note, "expansion site", None));
- Ok(Some(ei.call_site))
- }
- None => Ok(None)
+ let cs = try!(cm.with_expn_info(sp.expn_id, |expn_info| -> old_io::IoResult<_> {
+ match expn_info {
+ Some(ei) => {
+ let ss = ei.callee.span.map_or(String::new(),
+ |span| cm.span_to_string(span));
+ let (pre, post) = match ei.callee.format {
+ codemap::MacroAttribute => ("#[", "]"),
+ codemap::MacroBang => ("", "!")
+ };
- try!(print_diagnostic(w, &ss[], Note,
++ try!(print_diagnostic(w, &ss, Note,
+ &format!("in expansion of {}{}{}", pre,
+ ei.callee.name,
- post)[], None));
++ post), None));
+ let ss = cm.span_to_string(ei.call_site);
- try!(print_diagnostic(w, &ss[], Note, "expansion site", None));
++ try!(print_diagnostic(w, &ss, Note, "expansion site", None));
+ Ok(Some(ei.call_site))
+ }
+ None => Ok(None)
+ }
}));
cs.map_or(Ok(()), |call_site| print_macro_backtrace(w, cm, call_site))
}
debug!("commit_expr {:?}", e);
if let ExprPath(..) = e.node {
// might be unit-struct construction; check for recoverableinput error.
- let mut expected = edible.iter().map(|x| x.clone()).collect::<Vec<_>>();
+ let mut expected = edible.iter().cloned().collect::<Vec<_>>();
expected.push_all(inedible);
- self.check_for_erroneous_unit_struct_expecting(&expected[]);
+ self.check_for_erroneous_unit_struct_expecting(&expected[..]);
}
self.expect_one_of(edible, inedible)
}
if self.last_token
.as_ref()
.map_or(false, |t| t.is_ident() || t.is_path()) {
- let mut expected = edible.iter().map(|x| x.clone()).collect::<Vec<_>>();
- expected.push_all(&inedible[..]);
- self.check_for_erroneous_unit_struct_expecting(
- &expected[..]);
+ let mut expected = edible.iter().cloned().collect::<Vec<_>>();
- expected.push_all(&inedible[]);
- self.check_for_erroneous_unit_struct_expecting(
- &expected[]);
++ expected.push_all(&inedible);
++ self.check_for_erroneous_unit_struct_expecting(&expected);
}
self.expect_one_of(edible, inedible)
}
try!(self.word_space("for ?"));
try!(self.print_trait_ref(&ptr.trait_ref));
} else {
- real_bounds.push(b);
+ real_bounds.push(b.clone());
}
}
- try!(self.print_bounds(":", &real_bounds[]));
+ try!(self.print_bounds(":", &real_bounds[..]));
try!(self.print_where_clause(generics));
try!(word(&mut self.s, " "));
try!(self.bopen());
}
}
-impl BorrowFrom<RcStr> for str {
- fn borrow_from(owned: &RcStr) -> &str {
- &owned.string[..]
+impl Borrow<str> for RcStr {
+ fn borrow(&self) -> &str {
- &self.string[]
++ &self.string[..]
}
}
// This version does not yet work (associated type issues)...
#[cfg(cannot_use_this_yet)]
fn foo<'a>(map: RefCell<HashMap<&'static str, &'a [u8]>>) {
- let one = [1u];
+ let one = [1_usize];
- assert_eq!(map.borrow().get("one"), Some(&one[]));
+ assert_eq!(map.borrow().get("one"), Some(&one[..]));
}
#[cfg(cannot_use_this_yet_either)]