Skip to content

Commit

Permalink
Auto merge of #42780 - frewsxcv:rollup, r=frewsxcv
Browse files Browse the repository at this point in the history
Rollup of 6 pull requests

- Successful merges: #42271, #42717, #42728, #42749, #42756, #42772
- Failed merges:
  • Loading branch information
bors committed Jun 20, 2017
2 parents 29bce6e + 58425ef commit 4450779
Show file tree
Hide file tree
Showing 13 changed files with 278 additions and 18 deletions.
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

0 comments on commit 4450779

Please sign in to comment.