Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 6 pull requests #42780

Merged
merged 23 commits into from
Jun 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
222a328
Convert `Into<Box<[T]>> for Vec<T>` into `From<Vec<T>> for Box<[T]>`
ollie27 Jun 17, 2017
3c1af32
resolve: fix perf bug.
jseyfried Jun 17, 2017
05540bf
Show type name for unused_must_use lint
sanxiyn Jun 19, 2017
fd9d7aa
added `FromStr` Impl for `char`
tinaun May 27, 2017
174a7fc
Update libc to 0.2.24
MaloJaffre Jun 20, 2017
0fad2e0
Add doc example for `CStr::to_bytes`.
frewsxcv Jun 18, 2017
7f687f8
Add doc example for `CStr::to_bytes_with_nul`.
frewsxcv Jun 18, 2017
5d71e8c
Add error scenario doc examples for `CStr::from_bytes_with_nul`.
frewsxcv Jun 18, 2017
82ba871
Add doc example for `CStr::to_string_lossy`.
frewsxcv Jun 18, 2017
db97145
Add doc example for `CString::into_boxed_c_str`.
frewsxcv Jun 18, 2017
65793b3
Add doc example for `Box<CStr>::into_c_string`.
frewsxcv Jun 18, 2017
0962394
Add doc example for `CString::as_c_str`.
frewsxcv Jun 18, 2017
e52d2f2
Add doc example for `CStr::to_str`.
frewsxcv Jun 18, 2017
4797d84
Add doc example for `NulError`.
frewsxcv Jun 19, 2017
d3c26fe
Add doc example for `FromBytesWithNulError`.
frewsxcv Jun 19, 2017
93abc2f
Add doc example for `CString::from_raw`.
frewsxcv Jun 19, 2017
58bbe1d
Add a couple doc additional examples for `env::join_paths`.
frewsxcv Jun 19, 2017
4c43bc3
Rollup merge of #42271 - tinaun:charfromstr, r=alexcrichton
frewsxcv Jun 20, 2017
dbe16e0
Rollup merge of #42717 - ollie27:into_to_from2, r=sfackler
frewsxcv Jun 20, 2017
d92edac
Rollup merge of #42728 - jseyfried:fix_resolve_perf, r=nrc
frewsxcv Jun 20, 2017
d3e116a
Rollup merge of #42749 - frewsxcv:frewsxcxv/doc-examples, r=QuietMisd…
frewsxcv Jun 20, 2017
f9edbcc
Rollup merge of #42756 - sanxiyn:name-for-must-use, r=estebank
frewsxcv Jun 20, 2017
58425ef
Rollup merge of #42772 - MaloJaffre:libc, r=alexcrichton
frewsxcv Jun 20, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# `char_error_internals`

This feature is internal to the Rust compiler and is not intended for general use.

------------------------
10 changes: 6 additions & 4 deletions src/liballoc/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2124,10 +2124,12 @@ impl<T> From<Box<[T]>> for Vec<T> {
}
}

#[stable(feature = "box_from_vec", since = "1.18.0")]
impl<T> Into<Box<[T]>> for Vec<T> {
fn into(self) -> Box<[T]> {
self.into_boxed_slice()
// note: test pulls in libstd, which causes errors here
#[cfg(not(test))]
#[stable(feature = "box_from_vec", since = "1.20.0")]
impl<T> From<Vec<T>> for Box<[T]> {
fn from(v: Vec<T>) -> Box<[T]> {
v.into_boxed_slice()
}
}

Expand Down
59 changes: 58 additions & 1 deletion src/libcore/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use char_private::is_printable;
use convert::TryFrom;
use fmt::{self, Write};
use slice;
use str::from_utf8_unchecked_mut;
use str::{from_utf8_unchecked_mut, FromStr};
use iter::FusedIterator;
use mem::transmute;

Expand Down Expand Up @@ -208,6 +208,63 @@ impl From<u8> for char {
}
}


/// An error which can be returned when parsing a char.
#[stable(feature = "char_from_str", since = "1.19.0")]
#[derive(Clone, Debug)]
pub struct ParseCharError {
kind: CharErrorKind,
}

impl ParseCharError {
#[unstable(feature = "char_error_internals",
reason = "this method should not be available publicly",
issue = "0")]
#[doc(hidden)]
pub fn __description(&self) -> &str {
match self.kind {
CharErrorKind::EmptyString => {
"cannot parse char from empty string"
},
CharErrorKind::TooManyChars => "too many characters in string"
}
}
}

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
enum CharErrorKind {
EmptyString,
TooManyChars,
}

#[stable(feature = "char_from_str", since = "1.19.0")]
impl fmt::Display for ParseCharError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.__description().fmt(f)
}
}


#[stable(feature = "char_from_str", since = "1.19.0")]
impl FromStr for char {
type Err = ParseCharError;

#[inline]
fn from_str(s: &str) -> Result<Self, Self::Err> {
let mut chars = s.chars();
match (chars.next(), chars.next()) {
(None, _) => {
Err(ParseCharError { kind: CharErrorKind::EmptyString })
},
(Some(c), None) => Ok(c),
_ => {
Err(ParseCharError { kind: CharErrorKind::TooManyChars })
}
}
}
}


#[unstable(feature = "try_from", issue = "33417")]
impl TryFrom<u32> for char {
type Error = CharTryFromError;
Expand Down
11 changes: 11 additions & 0 deletions src/libcore/tests/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use std::{char,str};
use std::convert::TryFrom;
use std::str::FromStr;

#[test]
fn test_convert() {
Expand All @@ -28,6 +29,16 @@ fn test_convert() {
assert!(char::try_from(0xFFFF_FFFF_u32).is_err());
}

#[test]
fn test_from_str() {
assert_eq!(char::from_str("a").unwrap(), 'a');
assert_eq!(char::try_from("a").unwrap(), 'a');
assert_eq!(char::from_str("\0").unwrap(), '\0');
assert_eq!(char::from_str("\u{D7FF}").unwrap(), '\u{d7FF}');
assert!(char::from_str("").is_err());
assert!(char::from_str("abc").is_err());
}

#[test]
fn test_is_lowercase() {
assert!('a'.is_lowercase());
Expand Down
13 changes: 6 additions & 7 deletions src/librustc_lint/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use rustc::hir::def_id::DefId;
use rustc::ty;
use rustc::ty::adjustment;
use util::nodemap::FxHashMap;
Expand Down Expand Up @@ -144,20 +145,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
ty::TyTuple(ref tys, _) if tys.is_empty() => return,
ty::TyNever => return,
ty::TyBool => return,
ty::TyAdt(def, _) => {
let attrs = cx.tcx.get_attrs(def.did);
check_must_use(cx, &attrs, s.span)
}
ty::TyAdt(def, _) => check_must_use(cx, def.did, s.span),
_ => false,
};
if !warned {
cx.span_lint(UNUSED_RESULTS, s.span, "unused result");
}

fn check_must_use(cx: &LateContext, attrs: &[ast::Attribute], sp: Span) -> bool {
for attr in attrs {
fn check_must_use(cx: &LateContext, def_id: DefId, sp: Span) -> bool {
for attr in cx.tcx.get_attrs(def_id).iter() {
if attr.check_name("must_use") {
let mut msg = "unused result which must be used".to_string();
let mut msg = format!("unused `{}` which must be used",
cx.tcx.item_path_str(def_id));
// check for #[must_use="..."]
if let Some(s) = attr.value_str() {
msg.push_str(": ");
Expand Down
5 changes: 4 additions & 1 deletion src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,10 @@ impl<'a> Resolver<'a> {
};

let kind = ModuleKind::Def(Def::Mod(def_id), name);
self.arenas.alloc_module(ModuleData::new(parent, kind, def_id, Mark::root(), DUMMY_SP))
let module =
self.arenas.alloc_module(ModuleData::new(parent, kind, def_id, Mark::root(), DUMMY_SP));
self.extern_module_map.insert((def_id, macros_only), module);
module
}

pub fn macro_def_scope(&mut self, expansion: Mark) -> Module<'a> {
Expand Down
29 changes: 29 additions & 0 deletions src/libstd/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,35 @@ pub struct JoinPathsError {
///
/// # Examples
///
/// Joining paths on a Unix-like platform:
///
/// ```
/// # if cfg!(unix) {
/// use std::env;
/// use std::ffi::OsString;
/// use std::path::Path;
///
/// let paths = [Path::new("/bin"), Path::new("/usr/bin")];
/// let path_os_string = env::join_paths(paths.iter()).unwrap();
/// assert_eq!(path_os_string, OsString::from("/bin:/usr/bin"));
/// # }
/// ```
///
/// Joining a path containing a colon on a Unix-like platform results in an error:
///
/// ```
/// # if cfg!(unix) {
/// use std::env;
/// use std::path::Path;
///
/// let paths = [Path::new("/bin"), Path::new("/usr/bi:n")];
/// assert!(env::join_paths(paths.iter()).is_err());
/// # }
/// ```
///
/// Using `env::join_paths` with `env::spit_paths` to append an item to the `PATH` environment
/// variable:
///
/// ```
/// use std::env;
/// use std::path::PathBuf;
Expand Down
8 changes: 8 additions & 0 deletions src/libstd/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,14 @@ impl Error for char::CharTryFromError {
}
}

#[stable(feature = "char_from_str", since = "1.19.0")]
impl Error for char::ParseCharError {
fn description(&self) -> &str {
self.__description()
}
}


// copied from any.rs
impl Error + 'static {
/// Returns true if the boxed type is the same as `T`
Expand Down
Loading