From 082bfde412176249dc7328e771a2a15d202824cf Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 10 Dec 2014 19:46:38 -0800 Subject: Fallout of std::str stabilization --- src/libstd/path/mod.rs | 19 +++--- src/libstd/path/posix.rs | 5 +- src/libstd/path/windows.rs | 144 ++++++++++++++++++++++----------------------- 3 files changed, 84 insertions(+), 84 deletions(-) (limited to 'src/libstd/path') diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index ed4bb6ee081..30f3f56bc1c 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -69,7 +69,7 @@ use iter::IteratorExt; use option::Option; use option::Option::{None, Some}; use str; -use str::{CowString, MaybeOwned, Str, StrPrelude}; +use str::{CowString, MaybeOwned, Str, StrExt}; use string::String; use slice::{AsSlice, CloneSliceExt}; use slice::{PartialEqSliceExt, SliceExt}; @@ -197,7 +197,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// ``` #[inline] fn as_str<'a>(&'a self) -> Option<&'a str> { - str::from_utf8(self.as_vec()) + str::from_utf8(self.as_vec()).ok() } /// Returns the path as a byte vector @@ -293,7 +293,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// ``` #[inline] fn dirname_str<'a>(&'a self) -> Option<&'a str> { - str::from_utf8(self.dirname()) + str::from_utf8(self.dirname()).ok() } /// Returns the file component of `self`, as a byte vector. @@ -327,7 +327,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// ``` #[inline] fn filename_str<'a>(&'a self) -> Option<&'a str> { - self.filename().and_then(str::from_utf8) + self.filename().and_then(|s| str::from_utf8(s).ok()) } /// Returns the stem of the filename of `self`, as a byte vector. @@ -373,7 +373,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// ``` #[inline] fn filestem_str<'a>(&'a self) -> Option<&'a str> { - self.filestem().and_then(str::from_utf8) + self.filestem().and_then(|s| str::from_utf8(s).ok()) } /// Returns the extension of the filename of `self`, as an optional byte vector. @@ -420,7 +420,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// ``` #[inline] fn extension_str<'a>(&'a self) -> Option<&'a str> { - self.extension().and_then(str::from_utf8) + self.extension().and_then(|s| str::from_utf8(s).ok()) } /// Replaces the filename portion of the path with the given byte vector or string. @@ -793,7 +793,7 @@ pub trait BytesContainer for Sized? { /// Returns the receiver interpreted as a utf-8 string, if possible #[inline] fn container_as_str<'a>(&'a self) -> Option<&'a str> { - str::from_utf8(self.container_as_bytes()) + str::from_utf8(self.container_as_bytes()).ok() } /// Returns whether .container_as_str() is guaranteed to not fail // FIXME (#8888): Remove unused arg once :: works @@ -870,7 +870,7 @@ impl BytesContainer for String { } #[inline] fn container_as_str(&self) -> Option<&str> { - Some(self.as_slice()) + Some(self[]) } #[inline] fn is_str(_: Option<&String>) -> bool { true } @@ -886,7 +886,7 @@ impl BytesContainer for [u8] { impl BytesContainer for Vec { #[inline] fn container_as_bytes(&self) -> &[u8] { - self.as_slice() + self[] } } @@ -897,6 +897,7 @@ impl BytesContainer for CString { } } +#[allow(deprecated)] impl<'a> BytesContainer for str::MaybeOwned<'a> { #[inline] fn container_as_bytes<'b>(&'b self) -> &'b [u8] { diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index 88907951673..a514837492a 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -401,7 +401,10 @@ impl Path { /// Returns an iterator that yields each component of the path as Option<&str>. /// See components() for details. pub fn str_components<'a>(&'a self) -> StrComponents<'a> { - self.components().map(str::from_utf8) + fn from_utf8(s: &[u8]) -> Option<&str> { + str::from_utf8(s).ok() + } + self.components().map(from_utf8) } } diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index c2c17103554..277c675c22d 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -25,9 +25,9 @@ use iter::{Iterator, IteratorExt, Map}; use mem; use option::Option; use option::Option::{Some, None}; -use slice::{AsSlice, SliceExt}; -use str::{CharSplits, FromStr, Str, StrAllocating, StrVector, StrPrelude}; -use string::String; +use slice::SliceExt; +use str::{CharSplits, FromStr, StrVector, StrExt}; +use string::{String, ToString}; use unicode::char::UnicodeChar; use vec::Vec; @@ -187,30 +187,30 @@ impl GenericPathUnsafe for Path { s.push_str(".."); s.push(SEP); s.push_str(filename); - self.update_normalized(s); + self.update_normalized(s[]); } None => { self.update_normalized(filename); } - Some((_,idxa,end)) if self.repr.slice(idxa,end) == ".." => { + Some((_,idxa,end)) if self.repr[idxa..end] == ".." => { let mut s = String::with_capacity(end + 1 + filename.len()); - s.push_str(self.repr.slice_to(end)); + s.push_str(self.repr[0..end]); s.push(SEP); s.push_str(filename); - self.update_normalized(s); + self.update_normalized(s[]); } Some((idxb,idxa,_)) if self.prefix == Some(DiskPrefix) && idxa == self.prefix_len() => { let mut s = String::with_capacity(idxb + filename.len()); - s.push_str(self.repr.slice_to(idxb)); + s.push_str(self.repr[0..idxb]); s.push_str(filename); - self.update_normalized(s); + self.update_normalized(s[]); } Some((idxb,_,_)) => { let mut s = String::with_capacity(idxb + 1 + filename.len()); - s.push_str(self.repr.slice_to(idxb)); + s.push_str(self.repr[0..idxb]); s.push(SEP); s.push_str(filename); - self.update_normalized(s); + self.update_normalized(s[]); } } } @@ -229,12 +229,12 @@ impl GenericPathUnsafe for Path { let path = path.container_as_str().unwrap(); fn is_vol_abs(path: &str, prefix: Option) -> bool { // assume prefix is Some(DiskPrefix) - let rest = path.slice_from(prefix_len(prefix)); + let rest = path[prefix_len(prefix)..]; !rest.is_empty() && rest.as_bytes()[0].is_ascii() && is_sep(rest.as_bytes()[0] as char) } fn shares_volume(me: &Path, path: &str) -> bool { // path is assumed to have a prefix of Some(DiskPrefix) - let repr = me.repr.as_slice(); + let repr = me.repr[]; match me.prefix { Some(DiskPrefix) => { repr.as_bytes()[0] == path.as_bytes()[0].to_ascii().to_uppercase().as_byte() @@ -266,7 +266,7 @@ impl GenericPathUnsafe for Path { else { None }; let pathlen = path_.as_ref().map_or(path.len(), |p| p.len()); let mut s = String::with_capacity(me.repr.len() + 1 + pathlen); - s.push_str(me.repr.as_slice()); + s.push_str(me.repr[]); let plen = me.prefix_len(); // if me is "C:" we don't want to add a path separator match me.prefix { @@ -278,9 +278,9 @@ impl GenericPathUnsafe for Path { } match path_ { None => s.push_str(path), - Some(p) => s.push_str(p.as_slice()) + Some(p) => s.push_str(p[]), }; - me.update_normalized(s) + me.update_normalized(s[]) } if !path.is_empty() { @@ -288,7 +288,7 @@ impl GenericPathUnsafe for Path { match prefix { Some(DiskPrefix) if !is_vol_abs(path, prefix) && shares_volume(self, path) => { // cwd-relative path, self is on the same volume - append_path(self, path.slice_from(prefix_len(prefix))); + append_path(self, path[prefix_len(prefix)..]); } Some(_) => { // absolute path, or cwd-relative and self is not same volume @@ -334,7 +334,7 @@ impl GenericPath for Path { /// Always returns a `Some` value. #[inline] fn as_str<'a>(&'a self) -> Option<&'a str> { - Some(self.repr.as_slice()) + Some(self.repr[]) } #[inline] @@ -356,21 +356,17 @@ impl GenericPath for Path { /// Always returns a `Some` value. fn dirname_str<'a>(&'a self) -> Option<&'a str> { Some(match self.sepidx_or_prefix_len() { - None if ".." == self.repr => self.repr.as_slice(), + None if ".." == self.repr => self.repr[], None => ".", - Some((_,idxa,end)) if self.repr.slice(idxa, end) == ".." => { - self.repr.as_slice() - } - Some((idxb,_,end)) if self.repr.slice(idxb, end) == "\\" => { - self.repr.as_slice() - } - Some((0,idxa,_)) => self.repr.slice_to(idxa), + Some((_,idxa,end)) if self.repr[idxa..end] == ".." => self.repr[], + Some((idxb,_,end)) if self.repr[idxb..end] == "\\" => self.repr[], + Some((0,idxa,_)) => self.repr[0..idxa], Some((idxb,idxa,_)) => { match self.prefix { Some(DiskPrefix) | Some(VerbatimDiskPrefix) if idxb == self.prefix_len() => { - self.repr.slice_to(idxa) + self.repr[0..idxa] } - _ => self.repr.slice_to(idxb) + _ => self.repr[0..idxb] } } }) @@ -384,13 +380,13 @@ impl GenericPath for Path { /// See `GenericPath::filename_str` for info. /// Always returns a `Some` value if `filename` returns a `Some` value. fn filename_str<'a>(&'a self) -> Option<&'a str> { - let repr = self.repr.as_slice(); + let repr = self.repr[]; match self.sepidx_or_prefix_len() { None if "." == repr || ".." == repr => None, None => Some(repr), - Some((_,idxa,end)) if repr.slice(idxa, end) == ".." => None, + Some((_,idxa,end)) if repr[idxa..end] == ".." => None, Some((_,idxa,end)) if idxa == end => None, - Some((_,idxa,end)) => Some(repr.slice(idxa, end)) + Some((_,idxa,end)) => Some(repr[idxa..end]) } } @@ -422,7 +418,7 @@ impl GenericPath for Path { true } Some((idxb,idxa,end)) if idxb == idxa && idxb == end => false, - Some((idxb,_,end)) if self.repr.slice(idxb, end) == "\\" => false, + Some((idxb,_,end)) if self.repr[idxb..end] == "\\" => false, Some((idxb,idxa,_)) => { let trunc = match self.prefix { Some(DiskPrefix) | Some(VerbatimDiskPrefix) | None => { @@ -442,15 +438,15 @@ impl GenericPath for Path { if self.prefix.is_some() { Some(Path::new(match self.prefix { Some(DiskPrefix) if self.is_absolute() => { - self.repr.slice_to(self.prefix_len()+1) + self.repr[0..self.prefix_len()+1] } Some(VerbatimDiskPrefix) => { - self.repr.slice_to(self.prefix_len()+1) + self.repr[0..self.prefix_len()+1] } - _ => self.repr.slice_to(self.prefix_len()) + _ => self.repr[0..self.prefix_len()] })) } else if is_vol_relative(self) { - Some(Path::new(self.repr.slice_to(1))) + Some(Path::new(self.repr[0..1])) } else { None } @@ -469,7 +465,7 @@ impl GenericPath for Path { fn is_absolute(&self) -> bool { match self.prefix { Some(DiskPrefix) => { - let rest = self.repr.slice_from(self.prefix_len()); + let rest = self.repr[self.prefix_len()..]; rest.len() > 0 && rest.as_bytes()[0] == SEP_BYTE } Some(_) => true, @@ -644,15 +640,15 @@ impl Path { /// Does not distinguish between absolute and cwd-relative paths, e.g. /// C:\foo and C:foo. pub fn str_components<'a>(&'a self) -> StrComponents<'a> { - let repr = self.repr.as_slice(); + let repr = self.repr[]; let s = match self.prefix { Some(_) => { let plen = self.prefix_len(); if repr.len() > plen && repr.as_bytes()[plen] == SEP_BYTE { - repr.slice_from(plen+1) - } else { repr.slice_from(plen) } + repr[plen+1..] + } else { repr[plen..] } } - None if repr.as_bytes()[0] == SEP_BYTE => repr.slice_from(1), + None if repr.as_bytes()[0] == SEP_BYTE => repr[1..], None => repr }; let ret = s.split_terminator(SEP).map(Some); @@ -670,8 +666,8 @@ impl Path { } fn equiv_prefix(&self, other: &Path) -> bool { - let s_repr = self.repr.as_slice(); - let o_repr = other.repr.as_slice(); + let s_repr = self.repr[]; + let o_repr = other.repr[]; match (self.prefix, other.prefix) { (Some(DiskPrefix), Some(VerbatimDiskPrefix)) => { self.is_absolute() && @@ -688,28 +684,28 @@ impl Path { o_repr.as_bytes()[4].to_ascii().to_lowercase() } (Some(UNCPrefix(_,_)), Some(VerbatimUNCPrefix(_,_))) => { - s_repr.slice(2, self.prefix_len()) == o_repr.slice(8, other.prefix_len()) + s_repr[2..self.prefix_len()] == o_repr[8..other.prefix_len()] } (Some(VerbatimUNCPrefix(_,_)), Some(UNCPrefix(_,_))) => { - s_repr.slice(8, self.prefix_len()) == o_repr.slice(2, other.prefix_len()) + s_repr[8..self.prefix_len()] == o_repr[2..other.prefix_len()] } (None, None) => true, (a, b) if a == b => { - s_repr.slice_to(self.prefix_len()) == o_repr.slice_to(other.prefix_len()) + s_repr[0..self.prefix_len()] == o_repr[0..other.prefix_len()] } _ => false } } - fn normalize_(s: S) -> (Option, String) { + fn normalize_(s: &str) -> (Option, String) { // make borrowck happy let (prefix, val) = { - let prefix = parse_prefix(s.as_slice()); - let path = Path::normalize__(s.as_slice(), prefix); + let prefix = parse_prefix(s); + let path = Path::normalize__(s, prefix); (prefix, path) }; (prefix, match val { - None => s.into_string(), + None => s.to_string(), Some(val) => val }) } @@ -749,7 +745,7 @@ impl Path { match prefix.unwrap() { DiskPrefix => { let len = prefix_len(prefix) + is_abs as uint; - let mut s = String::from_str(s.slice_to(len)); + let mut s = String::from_str(s[0..len]); unsafe { let v = s.as_mut_vec(); v[0] = (*v)[0].to_ascii().to_uppercase().as_byte(); @@ -764,7 +760,7 @@ impl Path { } VerbatimDiskPrefix => { let len = prefix_len(prefix) + is_abs as uint; - let mut s = String::from_str(s.slice_to(len)); + let mut s = String::from_str(s[0..len]); unsafe { let v = s.as_mut_vec(); v[4] = (*v)[4].to_ascii().to_uppercase().as_byte(); @@ -774,14 +770,14 @@ impl Path { _ => { let plen = prefix_len(prefix); if s.len() > plen { - Some(String::from_str(s.slice_to(plen))) + Some(String::from_str(s[0..plen])) } else { None } } } } else if is_abs && comps.is_empty() { Some(String::from_char(1, SEP)) } else { - let prefix_ = s.slice_to(prefix_len(prefix)); + let prefix_ = s[0..prefix_len(prefix)]; let n = prefix_.len() + if is_abs { comps.len() } else { comps.len() - 1} + comps.iter().map(|v| v.len()).sum(); @@ -793,16 +789,16 @@ impl Path { s.push(':'); } Some(VerbatimDiskPrefix) => { - s.push_str(prefix_.slice_to(4)); + s.push_str(prefix_[0..4]); s.push(prefix_.as_bytes()[4].to_ascii() .to_uppercase().as_char()); - s.push_str(prefix_.slice_from(5)); + s.push_str(prefix_[5..]); } Some(UNCPrefix(a,b)) => { s.push_str("\\\\"); - s.push_str(prefix_.slice(2, a+2)); + s.push_str(prefix_[2..a+2]); s.push(SEP); - s.push_str(prefix_.slice(3+a, 3+a+b)); + s.push_str(prefix_[3+a..3+a+b]); } Some(_) => s.push_str(prefix_), None => () @@ -827,8 +823,8 @@ impl Path { fn update_sepidx(&mut self) { let s = if self.has_nonsemantic_trailing_slash() { - self.repr.slice_to(self.repr.len()-1) - } else { self.repr.as_slice() }; + self.repr[0..self.repr.len()-1] + } else { self.repr[] }; let idx = s.rfind(if !prefix_is_verbatim(self.prefix) { is_sep } else { is_sep_verbatim }); let prefixlen = self.prefix_len(); @@ -860,8 +856,8 @@ impl Path { self.repr.as_bytes()[self.repr.len()-1] == SEP_BYTE } - fn update_normalized(&mut self, s: S) { - let (prefix, path) = Path::normalize_(s.as_slice()); + fn update_normalized(&mut self, s: &str) { + let (prefix, path) = Path::normalize_(s); self.repr = path; self.prefix = prefix; self.update_sepidx(); @@ -903,17 +899,17 @@ pub fn is_verbatim(path: &Path) -> bool { /// non-verbatim, the non-verbatim version is returned. /// Otherwise, None is returned. pub fn make_non_verbatim(path: &Path) -> Option { - let repr = path.repr.as_slice(); + let repr = path.repr[]; let new_path = match path.prefix { Some(VerbatimPrefix(_)) | Some(DeviceNSPrefix(_)) => return None, Some(UNCPrefix(_,_)) | Some(DiskPrefix) | None => return Some(path.clone()), Some(VerbatimDiskPrefix) => { // \\?\D:\ - Path::new(repr.slice_from(4)) + Path::new(repr[4..]) } Some(VerbatimUNCPrefix(_,_)) => { // \\?\UNC\server\share - Path::new(format!(r"\{}", repr.slice_from(7))) + Path::new(format!(r"\{}", repr[7..])) } }; if new_path.prefix.is_none() { @@ -922,8 +918,8 @@ pub fn make_non_verbatim(path: &Path) -> Option { return None; } // now ensure normalization didn't change anything - if repr.slice_from(path.prefix_len()) == - new_path.repr.slice_from(new_path.prefix_len()) { + if repr[path.prefix_len()..] == + new_path.repr[new_path.prefix_len()..] { Some(new_path) } else { None @@ -988,13 +984,13 @@ pub enum PathPrefix { fn parse_prefix<'a>(mut path: &'a str) -> Option { if path.starts_with("\\\\") { // \\ - path = path.slice_from(2); + path = path[2..]; if path.starts_with("?\\") { // \\?\ - path = path.slice_from(2); + path = path[2..]; if path.starts_with("UNC\\") { // \\?\UNC\server\share - path = path.slice_from(4); + path = path[4..]; let (idx_a, idx_b) = match parse_two_comps(path, is_sep_verbatim) { Some(x) => x, None => (path.len(), 0) @@ -1015,7 +1011,7 @@ fn parse_prefix<'a>(mut path: &'a str) -> Option { } } else if path.starts_with(".\\") { // \\.\path - path = path.slice_from(2); + path = path[2..]; let idx = path.find('\\').unwrap_or(path.len()); return Some(DeviceNSPrefix(idx)); } @@ -1040,7 +1036,7 @@ fn parse_prefix<'a>(mut path: &'a str) -> Option { None => return None, Some(x) => x }; - path = path.slice_from(idx_a+1); + path = path[idx_a+1..]; let idx_b = path.find(f).unwrap_or(path.len()); Some((idx_a, idx_b)) } @@ -1050,8 +1046,8 @@ fn parse_prefix<'a>(mut path: &'a str) -> Option { fn normalize_helper<'a>(s: &'a str, prefix: Option) -> (bool, Option>) { let f = if !prefix_is_verbatim(prefix) { is_sep } else { is_sep_verbatim }; let is_abs = s.len() > prefix_len(prefix) && f(s.char_at(prefix_len(prefix))); - let s_ = s.slice_from(prefix_len(prefix)); - let s_ = if is_abs { s_.slice_from(1) } else { s_ }; + let s_ = s[prefix_len(prefix)..]; + let s_ = if is_abs { s_[1..] } else { s_ }; if is_abs && s_.is_empty() { return (is_abs, match prefix { -- cgit 1.4.1-3-g733a5 From 7f6177e64627110e5b9776bd5304d65806081390 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 26 Nov 2014 05:52:16 -0500 Subject: Fix fallout from changes. In cases where stage0 compiler is needed, we cannot use an `as` expression to coerce, so I used a one-off function instead (this is a no-op in stage0, but in stage1+ it triggers coercion from the fn pointer to the fn item type). --- src/libcore/str.rs | 1 + src/librustdoc/html/markdown.rs | 20 +++++++------ src/libstd/path/windows.rs | 14 +++++++-- src/libstd/thread_local/mod.rs | 24 +++++++++++++++- src/libsyntax/ext/base.rs | 28 ++++++++++++------ src/test/compile-fail/borrowck-autoref-3261.rs | 2 +- src/test/compile-fail/cast-to-bare-fn.rs | 2 +- .../coerce-bare-fn-to-closure-and-proc.rs | 15 ++++++++-- src/test/compile-fail/issue-10764.rs | 2 +- src/test/compile-fail/issue-9575.rs | 2 +- .../compile-fail/regions-lifetime-bounds-on-fns.rs | 2 +- src/test/compile-fail/regions-nested-fns.rs | 4 +-- src/test/compile-fail/static-reference-to-fn-1.rs | 2 +- src/test/compile-fail/static-reference-to-fn-2.rs | 12 ++++---- src/test/pretty/issue-4264.pp | 33 +++++++++++----------- src/test/run-pass/const-extern-function.rs | 2 +- .../run-pass/extern-compare-with-return-type.rs | 12 ++++---- src/test/run-pass/issue-10767.rs | 2 +- src/test/run-pass/issue-15444.rs | 1 + 19 files changed, 120 insertions(+), 60 deletions(-) (limited to 'src/libstd/path') diff --git a/src/libcore/str.rs b/src/libcore/str.rs index a89a7970ae9..1cd58aee061 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -30,6 +30,7 @@ use iter::range; use kinds::Sized; use mem; use num::Int; +use ops::FnMut; use option::Option; use option::Option::{None, Some}; use ops::{Fn, FnMut}; diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 8b2f644dfe3..009079bd214 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -65,17 +65,21 @@ const HOEDOWN_EXTENSIONS: libc::c_uint = type hoedown_document = libc::c_void; // this is opaque to us +type blockcodefn = extern "C" fn(*mut hoedown_buffer, *const hoedown_buffer, + *const hoedown_buffer, *mut libc::c_void); + +type headerfn = extern "C" fn(*mut hoedown_buffer, *const hoedown_buffer, + libc::c_int, *mut libc::c_void); + #[repr(C)] struct hoedown_renderer { opaque: *mut hoedown_html_renderer_state, - blockcode: Option, + blockcode: Option, blockquote: Option, blockhtml: Option, - header: Option, + header: Option, other: [libc::size_t, ..28], } @@ -281,8 +285,8 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result { toc_builder: if print_toc {Some(TocBuilder::new())} else {None} }; (*(*renderer).opaque).opaque = &mut opaque as *mut _ as *mut libc::c_void; - (*renderer).blockcode = Some(block); - (*renderer).header = Some(header); + (*renderer).blockcode = Some(block as blockcodefn); + (*renderer).header = Some(header as headerfn); let document = hoedown_document_new(renderer, HOEDOWN_EXTENSIONS, 16); hoedown_document_render(document, ob, s.as_ptr(), @@ -354,8 +358,8 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) { unsafe { let ob = hoedown_buffer_new(DEF_OUNIT); let renderer = hoedown_html_renderer_new(0, 0); - (*renderer).blockcode = Some(block); - (*renderer).header = Some(header); + (*renderer).blockcode = Some(block as blockcodefn); + (*renderer).header = Some(header as headerfn); (*(*renderer).opaque).opaque = tests as *mut _ as *mut libc::c_void; let document = hoedown_document_new(renderer, HOEDOWN_EXTENSIONS, 16); diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index c2c17103554..9e4a66e0e5e 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -829,8 +829,12 @@ impl Path { let s = if self.has_nonsemantic_trailing_slash() { self.repr.slice_to(self.repr.len()-1) } else { self.repr.as_slice() }; - let idx = s.rfind(if !prefix_is_verbatim(self.prefix) { is_sep } - else { is_sep_verbatim }); + let sep_test: fn(char) -> bool = if !prefix_is_verbatim(self.prefix) { + is_sep + } else { + is_sep_verbatim + }; + let idx = s.rfind(sep_test); let prefixlen = self.prefix_len(); self.sepidx = idx.and_then(|x| if x < prefixlen { None } else { Some(x) }); } @@ -1048,7 +1052,11 @@ fn parse_prefix<'a>(mut path: &'a str) -> Option { // None result means the string didn't need normalizing fn normalize_helper<'a>(s: &'a str, prefix: Option) -> (bool, Option>) { - let f = if !prefix_is_verbatim(prefix) { is_sep } else { is_sep_verbatim }; + let f: fn(char) -> bool = if !prefix_is_verbatim(prefix) { + is_sep + } else { + is_sep_verbatim + }; let is_abs = s.len() > prefix_len(prefix) && f(s.char_at(prefix_len(prefix))); let s_ = s.slice_from(prefix_len(prefix)); let s_ = if is_abs { s_.slice_from(1) } else { s_ }; diff --git a/src/libstd/thread_local/mod.rs b/src/libstd/thread_local/mod.rs index 4c33d1c418d..04718dcc6ae 100644 --- a/src/libstd/thread_local/mod.rs +++ b/src/libstd/thread_local/mod.rs @@ -189,11 +189,12 @@ macro_rules! __thread_local_inner { } }; - #[cfg(not(any(target_os = "macos", target_os = "linux")))] + #[cfg(all(stage0, not(any(target_os = "macos", target_os = "linux"))))] const INIT: ::std::thread_local::KeyInner<$t> = { unsafe extern fn __destroy(ptr: *mut u8) { ::std::thread_local::destroy_value::<$t>(ptr); } + ::std::thread_local::KeyInner { inner: ::std::cell::UnsafeCell { value: $init }, os: ::std::thread_local::OsStaticKey { @@ -203,6 +204,21 @@ macro_rules! __thread_local_inner { } }; + #[cfg(all(not(stage0), not(any(target_os = "macos", target_os = "linux"))))] + const INIT: ::std::thread_local::KeyInner<$t> = { + unsafe extern fn __destroy(ptr: *mut u8) { + ::std::thread_local::destroy_value::<$t>(ptr); + } + + ::std::thread_local::KeyInner { + inner: ::std::cell::UnsafeCell { value: $init }, + os: ::std::thread_local::OsStaticKey { + inner: ::std::thread_local::OS_INIT_INNER, + dtor: ::std::option::Option::Some(__destroy as unsafe extern fn(*mut u8)), + }, + } + }; + INIT }); } @@ -323,6 +339,12 @@ mod imp { // *should* be the case that this loop always terminates because we // provide the guarantee that a TLS key cannot be set after it is // flagged for destruction. + #[cfg(not(stage0))] + static DTORS: os::StaticKey = os::StaticKey { + inner: os::INIT_INNER, + dtor: Some(run_dtors as unsafe extern "C" fn(*mut u8)), + }; + #[cfg(stage0)] static DTORS: os::StaticKey = os::StaticKey { inner: os::INIT_INNER, dtor: Some(run_dtors), diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index aefbb2a1fea..f76c350902d 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -50,14 +50,16 @@ pub trait ItemDecorator { push: |P|); } -impl ItemDecorator for fn(&mut ExtCtxt, Span, &ast::MetaItem, &ast::Item, |P|) { +impl ItemDecorator for F + where F : Fn(&mut ExtCtxt, Span, &ast::MetaItem, &ast::Item, |P|) +{ fn expand(&self, ecx: &mut ExtCtxt, sp: Span, meta_item: &ast::MetaItem, item: &ast::Item, push: |P|) { - self.clone()(ecx, sp, meta_item, item, push) + (*self)(ecx, sp, meta_item, item, push) } } @@ -70,14 +72,16 @@ pub trait ItemModifier { -> P; } -impl ItemModifier for fn(&mut ExtCtxt, Span, &ast::MetaItem, P) -> P { +impl ItemModifier for F + where F : Fn(&mut ExtCtxt, Span, &ast::MetaItem, P) -> P +{ fn expand(&self, ecx: &mut ExtCtxt, span: Span, meta_item: &ast::MetaItem, item: P) -> P { - self.clone()(ecx, span, meta_item, item) + (*self)(ecx, span, meta_item, item) } } @@ -93,13 +97,15 @@ pub trait TTMacroExpander { pub type MacroExpanderFn = for<'cx> fn(&'cx mut ExtCtxt, Span, &[ast::TokenTree]) -> Box; -impl TTMacroExpander for MacroExpanderFn { +impl TTMacroExpander for F + where F : for<'cx> Fn(&'cx mut ExtCtxt, Span, &[ast::TokenTree]) -> Box +{ fn expand<'cx>(&self, ecx: &'cx mut ExtCtxt, span: Span, token_tree: &[ast::TokenTree]) -> Box { - self.clone()(ecx, span, token_tree) + (*self)(ecx, span, token_tree) } } @@ -115,14 +121,18 @@ pub trait IdentMacroExpander { pub type IdentMacroExpanderFn = for<'cx> fn(&'cx mut ExtCtxt, Span, ast::Ident, Vec) -> Box; -impl IdentMacroExpander for IdentMacroExpanderFn { +impl IdentMacroExpander for F + where F : for<'cx> Fn(&'cx mut ExtCtxt, Span, ast::Ident, + Vec) -> Box +{ fn expand<'cx>(&self, cx: &'cx mut ExtCtxt, sp: Span, ident: ast::Ident, token_tree: Vec ) - -> Box { - self.clone()(cx, sp, ident, token_tree) + -> Box + { + (*self)(cx, sp, ident, token_tree) } } diff --git a/src/test/compile-fail/borrowck-autoref-3261.rs b/src/test/compile-fail/borrowck-autoref-3261.rs index 8c6e76e7746..1b4e5891f94 100644 --- a/src/test/compile-fail/borrowck-autoref-3261.rs +++ b/src/test/compile-fail/borrowck-autoref-3261.rs @@ -20,7 +20,7 @@ impl X { } fn main() { - let mut x = X(Either::Right(main)); + let mut x = X(Either::Right(main as fn())); (&mut x).with( |opt| { //~ ERROR cannot borrow `x` as mutable more than once at a time match opt { diff --git a/src/test/compile-fail/cast-to-bare-fn.rs b/src/test/compile-fail/cast-to-bare-fn.rs index 10a829fd794..1db813292b0 100644 --- a/src/test/compile-fail/cast-to-bare-fn.rs +++ b/src/test/compile-fail/cast-to-bare-fn.rs @@ -13,7 +13,7 @@ fn foo(_x: int) { } fn main() { let v: u64 = 5; let x = foo as extern "C" fn() -> int; - //~^ ERROR non-scalar cast + //~^ ERROR mismatched types let y = v as extern "Rust" fn(int) -> (int, int); //~^ ERROR non-scalar cast y(x()); diff --git a/src/test/compile-fail/coerce-bare-fn-to-closure-and-proc.rs b/src/test/compile-fail/coerce-bare-fn-to-closure-and-proc.rs index 27e339180a6..52f4c4749e2 100644 --- a/src/test/compile-fail/coerce-bare-fn-to-closure-and-proc.rs +++ b/src/test/compile-fail/coerce-bare-fn-to-closure-and-proc.rs @@ -8,12 +8,21 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// Test that coercions from fn item types are ok, but not fn pointer +// types to closures/procs are not allowed. + fn foo() {} -fn main() { +fn fn_item_type() { let f = foo; let f_closure: || = f; - //~^ ERROR: cannot coerce non-statically resolved bare fn to closure - //~^^ HELP: consider embedding the function in a closure } + +fn fn_pointer_type() { + let f = foo as fn(); + let f_closure: || = f; + //~^ ERROR: mismatched types +} + +fn main() { } diff --git a/src/test/compile-fail/issue-10764.rs b/src/test/compile-fail/issue-10764.rs index 0733744b652..cd4ec495556 100644 --- a/src/test/compile-fail/issue-10764.rs +++ b/src/test/compile-fail/issue-10764.rs @@ -12,4 +12,4 @@ fn f(_: extern "Rust" fn()) {} extern fn bar() {} fn main() { f(bar) } -//~^ ERROR: expected `fn()`, found `extern "C" fn()` +//~^ ERROR mismatched types diff --git a/src/test/compile-fail/issue-9575.rs b/src/test/compile-fail/issue-9575.rs index aa3d9d9fef0..6e8f7ffb68d 100644 --- a/src/test/compile-fail/issue-9575.rs +++ b/src/test/compile-fail/issue-9575.rs @@ -10,6 +10,6 @@ #[start] fn start(argc: int, argv: *const *const u8, crate_map: *const u8) -> int { - //~^ ERROR start function expects type: `fn(int, *const *const u8) -> int` + //~^ ERROR incorrect number of function parameters 0 } diff --git a/src/test/compile-fail/regions-lifetime-bounds-on-fns.rs b/src/test/compile-fail/regions-lifetime-bounds-on-fns.rs index 773d6e2c703..4a42728da6f 100644 --- a/src/test/compile-fail/regions-lifetime-bounds-on-fns.rs +++ b/src/test/compile-fail/regions-lifetime-bounds-on-fns.rs @@ -15,7 +15,7 @@ fn a<'a, 'b:'a>(x: &mut &'a int, y: &mut &'b int) { fn b<'a, 'b>(x: &mut &'a int, y: &mut &'b int) { // Illegal now because there is no `'b:'a` declaration. - *x = *y; //~ ERROR mismatched types + *x = *y; //~ ERROR cannot infer } fn c<'a,'b>(x: &mut &'a int, y: &mut &'b int) { diff --git a/src/test/compile-fail/regions-nested-fns.rs b/src/test/compile-fail/regions-nested-fns.rs index cf0b615bb01..f4654367970 100644 --- a/src/test/compile-fail/regions-nested-fns.rs +++ b/src/test/compile-fail/regions-nested-fns.rs @@ -12,10 +12,10 @@ fn ignore(t: T) {} fn nested<'x>(x: &'x int) { let y = 3; - let mut ay = &y; //~ ERROR cannot infer + let mut ay = &y; ignore::< for<'z>|&'z int|>(|z| { - ay = x; + ay = x; //~ ERROR cannot infer ay = &y; ay = z; }); diff --git a/src/test/compile-fail/static-reference-to-fn-1.rs b/src/test/compile-fail/static-reference-to-fn-1.rs index c0d430908a1..bce397c4793 100644 --- a/src/test/compile-fail/static-reference-to-fn-1.rs +++ b/src/test/compile-fail/static-reference-to-fn-1.rs @@ -24,7 +24,7 @@ fn foo() -> Option { fn create() -> A<'static> { A { - func: &foo, //~ ERROR borrowed value does not live long enough + func: &foo, //~ ERROR mismatched types } } diff --git a/src/test/compile-fail/static-reference-to-fn-2.rs b/src/test/compile-fail/static-reference-to-fn-2.rs index 3a0f0a193cf..d7255c3ba06 100644 --- a/src/test/compile-fail/static-reference-to-fn-2.rs +++ b/src/test/compile-fail/static-reference-to-fn-2.rs @@ -9,9 +9,11 @@ // except according to those terms. struct StateMachineIter<'a> { - statefn: &'a fn(&mut StateMachineIter<'a>) -> Option<&'static str> + statefn: &'a StateMachineFunc<'a> } +type StateMachineFunc<'a> = fn(&mut StateMachineIter<'a>) -> Option<&'static str>; + impl<'a> Iterator<&'static str> for StateMachineIter<'a> { fn next(&mut self) -> Option<&'static str> { return (*self.statefn)(self); @@ -19,19 +21,19 @@ impl<'a> Iterator<&'static str> for StateMachineIter<'a> { } fn state1(self_: &mut StateMachineIter) -> Option<&'static str> { - self_.statefn = &state2; + self_.statefn = &(state2 as StateMachineFunc); //~^ ERROR borrowed value does not live long enough return Some("state1"); } fn state2(self_: &mut StateMachineIter) -> Option<(&'static str)> { - self_.statefn = &state3; + self_.statefn = &(state3 as StateMachineFunc); //~^ ERROR borrowed value does not live long enough return Some("state2"); } fn state3(self_: &mut StateMachineIter) -> Option<(&'static str)> { - self_.statefn = &finished; + self_.statefn = &(finished as StateMachineFunc); //~^ ERROR borrowed value does not live long enough return Some("state3"); } @@ -42,7 +44,7 @@ fn finished(_: &mut StateMachineIter) -> Option<(&'static str)> { fn state_iter() -> StateMachineIter<'static> { StateMachineIter { - statefn: &state1 //~ ERROR borrowed value does not live long enough + statefn: &(state1 as StateMachineFunc) //~ ERROR borrowed value does not live long enough } } diff --git a/src/test/pretty/issue-4264.pp b/src/test/pretty/issue-4264.pp index 974af1e6f3e..e4389cd69dd 100644 --- a/src/test/pretty/issue-4264.pp +++ b/src/test/pretty/issue-4264.pp @@ -50,20 +50,20 @@ pub fn bar() { ((::std::fmt::format as - fn(&core::fmt::Arguments<'_>) -> collections::string::String)((&((::std::fmt::Arguments::new - as - fn(&[&str], &[core::fmt::Argument<'_>]) -> core::fmt::Arguments<'_>)((__STATIC_FMTSTR - as - &'static [&'static str]), - (&([] - as - [core::fmt::Argument<'_>; 0]) - as - &[core::fmt::Argument<'_>; 0])) - as - core::fmt::Arguments<'_>) - as - &core::fmt::Arguments<'_>)) + fn(&core::fmt::Arguments<'_>) -> collections::string::String {std::fmt::format})((&((::std::fmt::Arguments::new + as + fn(&[&str], &[core::fmt::Argument<'_>]) -> core::fmt::Arguments<'_> {core::fmt::Arguments<'a>::new})((__STATIC_FMTSTR + as + &'static [&'static str]), + (&([] + as + [core::fmt::Argument<'_>; 0]) + as + &[core::fmt::Argument<'_>; 0])) + as + core::fmt::Arguments<'_>) + as + &core::fmt::Arguments<'_>)) as collections::string::String) } } as collections::string::String); @@ -78,7 +78,8 @@ pub fn id(x: T) -> T { (x as T) } pub fn use_id() { let _ = ((id::<[int; (3u as uint)]> as - fn([int; 3]) -> [int; 3])(([(1 as int), (2 as int), (3 as int)] - as [int; 3])) as [int; 3]); + fn([int; 3]) -> [int; 3] {id})(([(1 as int), (2 as int), + (3 as int)] as [int; 3])) as + [int; 3]); } fn main() { } diff --git a/src/test/run-pass/const-extern-function.rs b/src/test/run-pass/const-extern-function.rs index be7c47dafc0..069ca6ecf49 100644 --- a/src/test/run-pass/const-extern-function.rs +++ b/src/test/run-pass/const-extern-function.rs @@ -18,6 +18,6 @@ struct S { } pub fn main() { - assert!(foopy == f); + assert!(foopy as extern "C" fn() == f); assert!(f == s.f); } diff --git a/src/test/run-pass/extern-compare-with-return-type.rs b/src/test/run-pass/extern-compare-with-return-type.rs index 057394b2624..3febff18704 100644 --- a/src/test/run-pass/extern-compare-with-return-type.rs +++ b/src/test/run-pass/extern-compare-with-return-type.rs @@ -18,15 +18,17 @@ extern fn uintret() -> uint { 22 } extern fn uintvoidret(_x: uint) {} extern fn uintuintuintuintret(x: uint, y: uint, z: uint) -> uint { x+y+z } +type uintuintuintuintret = extern fn(uint,uint,uint) -> uint; pub fn main() { - assert!(voidret1 == voidret1); - assert!(voidret1 != voidret2); + assert!(voidret1 as extern fn() == voidret1 as extern fn()); + assert!(voidret1 as extern fn() != voidret2 as extern fn()); - assert!(uintret == uintret); + assert!(uintret as extern fn() -> uint == uintret as extern fn() -> uint); - assert!(uintvoidret == uintvoidret); + assert!(uintvoidret as extern fn(uint) == uintvoidret as extern fn(uint)); - assert!(uintuintuintuintret == uintuintuintuintret); + assert!(uintuintuintuintret as uintuintuintuintret == + uintuintuintuintret as uintuintuintuintret); } diff --git a/src/test/run-pass/issue-10767.rs b/src/test/run-pass/issue-10767.rs index a30eb8120ea..d2895024187 100644 --- a/src/test/run-pass/issue-10767.rs +++ b/src/test/run-pass/issue-10767.rs @@ -12,5 +12,5 @@ pub fn main() { fn f() { }; - let _: Box = box f; + let _: Box = box() (f as fn()); } diff --git a/src/test/run-pass/issue-15444.rs b/src/test/run-pass/issue-15444.rs index f5618c2c7a3..0f4978d78dd 100644 --- a/src/test/run-pass/issue-15444.rs +++ b/src/test/run-pass/issue-15444.rs @@ -25,5 +25,6 @@ fn thing(a: int, b: int) -> int { } fn main() { + let thing: fn(int, int) -> int = thing; // coerce to fn type bar(&thing); } -- cgit 1.4.1-3-g733a5 From 8fe9e4dff6d9d0fdd940835ae377edcb3754f8c1 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 15 Dec 2014 15:41:30 -0500 Subject: Insert coercions to fn pointer types required for the new types post-unboxed-closure-conversion. This requires a fair amount of annoying coercions because all the `map` etc types are defined generically over the `F`, so the automatic coercions don't propagate; this is compounded by the need to use `let` and not `as` due to stage0. That said, this pattern is to a large extent temporary and unusual. --- src/libcollections/btree/map.rs | 2 ++ src/libcollections/btree/set.rs | 1 + src/libcollections/vec_map.rs | 3 +++ src/libcore/iter.rs | 3 +++ src/libcore/str.rs | 1 + src/librustc_trans/trans/basic_block.rs | 3 +++ src/libstd/collections/hash/map.rs | 8 ++++++-- src/libstd/collections/hash/set.rs | 3 +++ src/libstd/path/posix.rs | 4 +++- src/libstd/path/windows.rs | 4 +++- src/libunicode/u_str.rs | 3 +++ 11 files changed, 31 insertions(+), 4 deletions(-) (limited to 'src/libstd/path') diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs index 01096c1fd4e..778314f352c 100644 --- a/src/libcollections/btree/map.rs +++ b/src/libcollections/btree/map.rs @@ -1230,6 +1230,7 @@ impl BTreeMap { #[unstable = "matches collection reform specification, waiting for dust to settle"] pub fn keys<'a>(&'a self) -> Keys<'a, K, V> { fn first((a, _): (A, B)) -> A { a } + let first: fn((&'a K, &'a V)) -> &'a K = first; // coerce to fn pointer Keys { inner: self.iter().map(first) } } @@ -1251,6 +1252,7 @@ impl BTreeMap { #[unstable = "matches collection reform specification, waiting for dust to settle"] pub fn values<'a>(&'a self) -> Values<'a, K, V> { fn second((_, b): (A, B)) -> B { b } + let second: fn((&'a K, &'a V)) -> &'a V = second; // coerce to fn pointer Values { inner: self.iter().map(second) } } diff --git a/src/libcollections/btree/set.rs b/src/libcollections/btree/set.rs index e4328a3cb20..4ab9c7a4fcd 100644 --- a/src/libcollections/btree/set.rs +++ b/src/libcollections/btree/set.rs @@ -126,6 +126,7 @@ impl BTreeSet { #[unstable = "matches collection reform specification, waiting for dust to settle"] pub fn into_iter(self) -> MoveItems { fn first((a, _): (A, B)) -> A { a } + let first: fn((T, ())) -> T = first; // coerce to fn pointer MoveItems { iter: self.map.into_iter().map(first) } } diff --git a/src/libcollections/vec_map.rs b/src/libcollections/vec_map.rs index 1babde6066d..553eae4d896 100644 --- a/src/libcollections/vec_map.rs +++ b/src/libcollections/vec_map.rs @@ -144,6 +144,7 @@ impl VecMap { #[unstable = "matches collection reform specification, waiting for dust to settle"] pub fn keys<'r>(&'r self) -> Keys<'r, V> { fn first((a, _): (A, B)) -> A { a } + let first: fn((uint, &'r V)) -> uint = first; // coerce to fn pointer Keys { iter: self.iter().map(first) } } @@ -153,6 +154,7 @@ impl VecMap { #[unstable = "matches collection reform specification, waiting for dust to settle"] pub fn values<'r>(&'r self) -> Values<'r, V> { fn second((_, b): (A, B)) -> B { b } + let second: fn((uint, &'r V)) -> &'r V = second; // coerce to fn pointer Values { iter: self.iter().map(second) } } @@ -239,6 +241,7 @@ impl VecMap { fn filter((i, v): (uint, Option)) -> Option<(uint, A)> { v.map(|v| (i, v)) } + let filter: fn((uint, Option)) -> Option<(uint, V)> = filter; // coerce to fn ptr let values = replace(&mut self.v, vec!()); MoveItems { iter: values.into_iter().enumerate().filter_map(filter) } diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index b592d1db274..1cd4d7b89d6 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -2612,6 +2612,9 @@ pub fn iterate(seed: T, f: F) -> Iterate where val.clone() } + // coerce to a fn pointer + let next: fn(&mut IterateState) -> Option = next; + Unfold::new((f, Some(seed), true), next) } diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 1cd58aee061..1207c78fa37 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -2101,6 +2101,7 @@ impl StrPrelude for str { else { line } } + let f: fn(&str) -> &str = f; // coerce to fn pointer self.lines().map(f) } diff --git a/src/librustc_trans/trans/basic_block.rs b/src/librustc_trans/trans/basic_block.rs index 476f5e2d618..ab25343ff5f 100644 --- a/src/librustc_trans/trans/basic_block.rs +++ b/src/librustc_trans/trans/basic_block.rs @@ -37,7 +37,10 @@ impl BasicBlock { pub fn pred_iter(self) -> Preds { fn is_a_terminator_inst(user: &Value) -> bool { user.is_a_terminator_inst() } + let is_a_terminator_inst: fn(&Value) -> bool = is_a_terminator_inst; + fn get_parent(user: Value) -> BasicBlock { user.get_parent().unwrap() } + let get_parent: fn(Value) -> BasicBlock = get_parent; self.as_value().user_iter() .filter(is_a_terminator_inst) diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 8149864afd4..dc9fd289344 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -838,8 +838,9 @@ impl, V, S, H: Hasher> HashMap { /// } /// ``` #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn keys(&self) -> Keys { + pub fn keys<'a>(&'a self) -> Keys<'a, K, V> { fn first((a, _): (A, B)) -> A { a } + let first: fn((&'a K,&'a V)) -> &'a K = first; // coerce to fn ptr Keys { inner: self.iter().map(first) } } @@ -862,8 +863,9 @@ impl, V, S, H: Hasher> HashMap { /// } /// ``` #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn values(&self) -> Values { + pub fn values<'a>(&'a self) -> Values<'a, K, V> { fn second((_, b): (A, B)) -> B { b } + let second: fn((&'a K,&'a V)) -> &'a V = second; // coerce to fn ptr Values { inner: self.iter().map(second) } } @@ -938,6 +940,7 @@ impl, V, S, H: Hasher> HashMap { #[unstable = "matches collection reform specification, waiting for dust to settle"] pub fn into_iter(self) -> MoveEntries { fn last_two((_, b, c): (A, B, C)) -> (B, C) { (b, c) } + let last_two: fn((SafeHash, K, V)) -> (K, V) = last_two; MoveEntries { inner: self.table.into_iter().map(last_two) @@ -1007,6 +1010,7 @@ impl, V, S, H: Hasher> HashMap { #[unstable = "matches collection reform specification, waiting for dust to settle"] pub fn drain(&mut self) -> Drain { fn last_two((_, b, c): (A, B, C)) -> (B, C) { (b, c) } + let last_two: fn((SafeHash, K, V)) -> (K, V) = last_two; // coerce to fn pointer Drain { inner: self.table.drain().map(last_two), diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index f587669d3da..15ac3394d41 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -277,6 +277,7 @@ impl, S, H: Hasher> HashSet { #[unstable = "matches collection reform specification, waiting for dust to settle"] pub fn into_iter(self) -> IntoIter { fn first((a, _): (A, B)) -> A { a } + let first: fn((T, ())) -> T = first; IntoIter { iter: self.map.into_iter().map(first) } } @@ -419,6 +420,8 @@ impl, S, H: Hasher> HashSet { #[unstable = "matches collection reform specification, waiting for dust to settle"] pub fn drain(&mut self) -> Drain { fn first((a, _): (A, B)) -> A { a } + let first: fn((T, ())) -> T = first; // coerce to fn pointer + Drain { iter: self.map.drain().map(first) } } diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index 88907951673..0808b2a4f42 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -390,6 +390,7 @@ impl Path { let v = if self.repr[0] == SEP_BYTE { self.repr[1..] } else { self.repr.as_slice() }; + let is_sep_byte: fn(&u8) -> bool = is_sep_byte; // coerce to fn ptr let mut ret = v.split(is_sep_byte); if v.is_empty() { // consume the empty "" component @@ -401,7 +402,8 @@ impl Path { /// Returns an iterator that yields each component of the path as Option<&str>. /// See components() for details. pub fn str_components<'a>(&'a self) -> StrComponents<'a> { - self.components().map(str::from_utf8) + let from_utf8: fn(&[u8]) -> Option<&str> = str::from_utf8; // coerce to fn ptr + self.components().map(from_utf8) } } diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 9e4a66e0e5e..4b8fb7fad6a 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -655,7 +655,8 @@ impl Path { None if repr.as_bytes()[0] == SEP_BYTE => repr.slice_from(1), None => repr }; - let ret = s.split_terminator(SEP).map(Some); + let some: fn(&'a str) -> Option<&'a str> = Some; // coerce to fn ptr + let ret = s.split_terminator(SEP).map(some); ret } @@ -666,6 +667,7 @@ impl Path { #![inline] x.unwrap().as_bytes() } + let convert: for<'b> fn(Option<&'b str>) -> &'b [u8] = convert; // coerce to fn ptr self.str_components().map(convert) } diff --git a/src/libunicode/u_str.rs b/src/libunicode/u_str.rs index 5e98109c432..88d87717ff3 100644 --- a/src/libunicode/u_str.rs +++ b/src/libunicode/u_str.rs @@ -143,7 +143,10 @@ impl UnicodeStrPrelude for str { #[inline] fn words(&self) -> Words { fn is_not_empty(s: &&str) -> bool { !s.is_empty() } + let is_not_empty: fn(&&str) -> bool = is_not_empty; // coerce to fn pointer + fn is_whitespace(c: char) -> bool { c.is_whitespace() } + let is_whitespace: fn(char) -> bool = is_whitespace; // coerce to fn pointer self.split(is_whitespace).filter(is_not_empty) } -- cgit 1.4.1-3-g733a5 From 3583d613b9c81855feb067aeeebb525cf8a4184c Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 22 Dec 2014 12:56:18 -0800 Subject: Test fixes and rebase conflicts --- src/libcollections/bit.rs | 6 +++--- src/libcore/str.rs | 2 +- src/librustc/session/config.rs | 3 +-- src/librustc_trans/trans/closure.rs | 11 ----------- src/librustc_typeck/collect.rs | 3 ++- src/libstd/path/windows.rs | 8 ++++++-- src/libstd/sys/unix/os.rs | 2 +- src/libunicode/u_str.rs | 2 +- 8 files changed, 15 insertions(+), 22 deletions(-) (limited to 'src/libstd/path') diff --git a/src/libcollections/bit.rs b/src/libcollections/bit.rs index 3b9b1eb1fb3..430d7210bf6 100644 --- a/src/libcollections/bit.rs +++ b/src/libcollections/bit.rs @@ -88,14 +88,14 @@ use core::fmt; use core::iter::{Cloned, Chain, Enumerate, Repeat, Skip, Take}; use core::iter; use core::num::Int; -use core::slice::{Items, MutItems}; +use core::slice::{Iter, IterMut}; use core::{u8, u32, uint}; use core::hash; use Vec; -type Blocks<'a> = Cloned>; -type MutBlocks<'a> = MutItems<'a, u32>; +type Blocks<'a> = Cloned>; +type MutBlocks<'a> = IterMut<'a, u32>; type MatchWords<'a> = Chain>, Skip>>>>; fn reverse_bits(byte: u8) -> u8 { diff --git a/src/libcore/str.rs b/src/libcore/str.rs index de5b34ff0ca..204ffae6cbd 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -336,7 +336,7 @@ impl<'a> DoubleEndedIterator<(uint, char)> for CharIndices<'a> { #[stable] #[deriving(Clone)] pub struct Bytes<'a> { - inner: Map<&'a u8, u8, slice::Items<'a, u8>, BytesFn>, + inner: Map<&'a u8, u8, slice::Iter<'a, u8>, BytesFn>, } /// A temporary new type wrapper that ensures that the `Bytes` iterator diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 86f0655a3ad..6629f6620d4 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -743,13 +743,12 @@ pub fn rustc_short_optgroups() -> Vec { assumed.", "NAME[:KIND]"), opt::multi("", "crate-type", "Comma separated list of types of crates for the compiler to emit", - "[bin|lib|rlib|dylib|staticlib]"), + "[bin|lib|rlib|dylib|staticlib]"), opt::opt("", "crate-name", "Specify the name of the crate being built", "NAME"), opt::multi("", "emit", "Comma separated list of types of output for \ the compiler to emit", "[asm|llvm-bc|llvm-ir|obj|link|dep-info]"), - "[asm|llvm-bc|llvm-ir|obj|link]"), opt::multi("", "print", "Comma separated list of compiler information to \ print on stdout", "[crate-name|output-file-names|sysroot]"), diff --git a/src/librustc_trans/trans/closure.rs b/src/librustc_trans/trans/closure.rs index 28716f0a481..0ae9de8c891 100644 --- a/src/librustc_trans/trans/closure.rs +++ b/src/librustc_trans/trans/closure.rs @@ -606,17 +606,6 @@ pub fn get_wrapper_for_bare_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_ptr: ValueRef, is_local: bool) -> ValueRef { - let def_id = match def { - def::DefFn(did, _) | def::DefStaticMethod(did, _) | - def::DefVariant(_, did, _) | def::DefStruct(did) => did, - _ => { - ccx.sess().bug(format!("get_wrapper_for_bare_fn: \ - expected a statically resolved fn, got \ - {}", - def)[]); - } - }; - match ccx.closure_bare_wrapper_cache().borrow().get(&fn_ptr) { Some(&llval) => return llval, None => {} diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index c7c33db5746..8380ed349cb 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -219,7 +219,7 @@ pub fn get_enum_variant_types<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, ast::TupleVariantKind(ref args) if args.len() > 0 => { let rs = ExplicitRscope; let input_tys: Vec<_> = args.iter().map(|va| ccx.to_ty(&rs, &*va.ty)).collect(); - ty::mk_ctor_fn(tcx, input_tys[], enum_ty) + ty::mk_ctor_fn(tcx, variant_def_id, input_tys[], enum_ty) } ast::TupleVariantKind(_) => { @@ -1282,6 +1282,7 @@ pub fn convert_struct<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, |field| (*tcx.tcache.borrow())[ local_def(field.node.id)].ty).collect(); let ctor_fn_ty = ty::mk_ctor_fn(tcx, + local_def(ctor_id), inputs[], selfty); write_ty_to_tcx(tcx, ctor_id, ctor_fn_ty); diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index b24966241ff..7d10188c437 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -827,8 +827,12 @@ impl Path { let s = if self.has_nonsemantic_trailing_slash() { self.repr[0..self.repr.len()-1] } else { self.repr[] }; - let idx = s.rfind(if !prefix_is_verbatim(self.prefix) { is_sep } - else { is_sep_verbatim }); + let sep_test: fn(char) -> bool = if !prefix_is_verbatim(self.prefix) { + is_sep + } else { + is_sep_verbatim + }; + let idx = s.rfind(sep_test); let prefixlen = self.prefix_len(); self.sepidx = idx.and_then(|x| if x < prefixlen { None } else { Some(x) }); } diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index 6c909d7562d..316d97064ee 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -189,7 +189,7 @@ pub fn load_self() -> Option> { if sz == 0 { return None; } let mut v: Vec = Vec::with_capacity(sz as uint); let err = sysctl(mib.as_mut_ptr(), mib.len() as ::libc::c_uint, - v.as_mut_ptr() as *mut c_void, &mut sz, + v.as_mut_ptr() as *mut libc::c_void, &mut sz, ptr::null_mut(), 0u as libc::size_t); if err != 0 { return None; } if sz == 0 { return None; } diff --git a/src/libunicode/u_str.rs b/src/libunicode/u_str.rs index 65b8ad997f6..a3d4dd057d0 100644 --- a/src/libunicode/u_str.rs +++ b/src/libunicode/u_str.rs @@ -404,7 +404,7 @@ pub fn is_utf16(v: &[u16]) -> bool { /// of `u16`s. #[deriving(Clone)] pub struct Utf16Items<'a> { - iter: slice::Items<'a, u16> + iter: slice::Iter<'a, u16> } /// The possibilities for values decoded from a `u16` stream. #[deriving(PartialEq, Eq, Clone, Show)] -- cgit 1.4.1-3-g733a5