Skip to content

Commit 4450779

Browse files
committed
Auto merge of #42780 - frewsxcv:rollup, r=frewsxcv
Rollup of 6 pull requests - Successful merges: #42271, #42717, #42728, #42749, #42756, #42772 - Failed merges:
2 parents 29bce6e + 58425ef commit 4450779

File tree

13 files changed

+278
-18
lines changed

13 files changed

+278
-18
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# `char_error_internals`
2+
3+
This feature is internal to the Rust compiler and is not intended for general use.
4+
5+
------------------------

src/liballoc/vec.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -2124,10 +2124,12 @@ impl<T> From<Box<[T]>> for Vec<T> {
21242124
}
21252125
}
21262126

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

src/libcore/char.rs

+58-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use char_private::is_printable;
1919
use convert::TryFrom;
2020
use fmt::{self, Write};
2121
use slice;
22-
use str::from_utf8_unchecked_mut;
22+
use str::{from_utf8_unchecked_mut, FromStr};
2323
use iter::FusedIterator;
2424
use mem::transmute;
2525

@@ -208,6 +208,63 @@ impl From<u8> for char {
208208
}
209209
}
210210

211+
212+
/// An error which can be returned when parsing a char.
213+
#[stable(feature = "char_from_str", since = "1.19.0")]
214+
#[derive(Clone, Debug)]
215+
pub struct ParseCharError {
216+
kind: CharErrorKind,
217+
}
218+
219+
impl ParseCharError {
220+
#[unstable(feature = "char_error_internals",
221+
reason = "this method should not be available publicly",
222+
issue = "0")]
223+
#[doc(hidden)]
224+
pub fn __description(&self) -> &str {
225+
match self.kind {
226+
CharErrorKind::EmptyString => {
227+
"cannot parse char from empty string"
228+
},
229+
CharErrorKind::TooManyChars => "too many characters in string"
230+
}
231+
}
232+
}
233+
234+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
235+
enum CharErrorKind {
236+
EmptyString,
237+
TooManyChars,
238+
}
239+
240+
#[stable(feature = "char_from_str", since = "1.19.0")]
241+
impl fmt::Display for ParseCharError {
242+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
243+
self.__description().fmt(f)
244+
}
245+
}
246+
247+
248+
#[stable(feature = "char_from_str", since = "1.19.0")]
249+
impl FromStr for char {
250+
type Err = ParseCharError;
251+
252+
#[inline]
253+
fn from_str(s: &str) -> Result<Self, Self::Err> {
254+
let mut chars = s.chars();
255+
match (chars.next(), chars.next()) {
256+
(None, _) => {
257+
Err(ParseCharError { kind: CharErrorKind::EmptyString })
258+
},
259+
(Some(c), None) => Ok(c),
260+
_ => {
261+
Err(ParseCharError { kind: CharErrorKind::TooManyChars })
262+
}
263+
}
264+
}
265+
}
266+
267+
211268
#[unstable(feature = "try_from", issue = "33417")]
212269
impl TryFrom<u32> for char {
213270
type Error = CharTryFromError;

src/libcore/tests/char.rs

+11
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use std::{char,str};
1212
use std::convert::TryFrom;
13+
use std::str::FromStr;
1314

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

32+
#[test]
33+
fn test_from_str() {
34+
assert_eq!(char::from_str("a").unwrap(), 'a');
35+
assert_eq!(char::try_from("a").unwrap(), 'a');
36+
assert_eq!(char::from_str("\0").unwrap(), '\0');
37+
assert_eq!(char::from_str("\u{D7FF}").unwrap(), '\u{d7FF}');
38+
assert!(char::from_str("").is_err());
39+
assert!(char::from_str("abc").is_err());
40+
}
41+
3142
#[test]
3243
fn test_is_lowercase() {
3344
assert!('a'.is_lowercase());

src/librustc_lint/unused.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use rustc::hir::def_id::DefId;
1112
use rustc::ty;
1213
use rustc::ty::adjustment;
1314
use util::nodemap::FxHashMap;
@@ -144,20 +145,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
144145
ty::TyTuple(ref tys, _) if tys.is_empty() => return,
145146
ty::TyNever => return,
146147
ty::TyBool => return,
147-
ty::TyAdt(def, _) => {
148-
let attrs = cx.tcx.get_attrs(def.did);
149-
check_must_use(cx, &attrs, s.span)
150-
}
148+
ty::TyAdt(def, _) => check_must_use(cx, def.did, s.span),
151149
_ => false,
152150
};
153151
if !warned {
154152
cx.span_lint(UNUSED_RESULTS, s.span, "unused result");
155153
}
156154

157-
fn check_must_use(cx: &LateContext, attrs: &[ast::Attribute], sp: Span) -> bool {
158-
for attr in attrs {
155+
fn check_must_use(cx: &LateContext, def_id: DefId, sp: Span) -> bool {
156+
for attr in cx.tcx.get_attrs(def_id).iter() {
159157
if attr.check_name("must_use") {
160-
let mut msg = "unused result which must be used".to_string();
158+
let mut msg = format!("unused `{}` which must be used",
159+
cx.tcx.item_path_str(def_id));
161160
// check for #[must_use="..."]
162161
if let Some(s) = attr.value_str() {
163162
msg.push_str(": ");

src/librustc_resolve/build_reduced_graph.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,10 @@ impl<'a> Resolver<'a> {
523523
};
524524

525525
let kind = ModuleKind::Def(Def::Mod(def_id), name);
526-
self.arenas.alloc_module(ModuleData::new(parent, kind, def_id, Mark::root(), DUMMY_SP))
526+
let module =
527+
self.arenas.alloc_module(ModuleData::new(parent, kind, def_id, Mark::root(), DUMMY_SP));
528+
self.extern_module_map.insert((def_id, macros_only), module);
529+
module
527530
}
528531

529532
pub fn macro_def_scope(&mut self, expansion: Mark) -> Module<'a> {

src/libstd/env.rs

+29
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,35 @@ pub struct JoinPathsError {
438438
///
439439
/// # Examples
440440
///
441+
/// Joining paths on a Unix-like platform:
442+
///
443+
/// ```
444+
/// # if cfg!(unix) {
445+
/// use std::env;
446+
/// use std::ffi::OsString;
447+
/// use std::path::Path;
448+
///
449+
/// let paths = [Path::new("/bin"), Path::new("/usr/bin")];
450+
/// let path_os_string = env::join_paths(paths.iter()).unwrap();
451+
/// assert_eq!(path_os_string, OsString::from("/bin:/usr/bin"));
452+
/// # }
453+
/// ```
454+
///
455+
/// Joining a path containing a colon on a Unix-like platform results in an error:
456+
///
457+
/// ```
458+
/// # if cfg!(unix) {
459+
/// use std::env;
460+
/// use std::path::Path;
461+
///
462+
/// let paths = [Path::new("/bin"), Path::new("/usr/bi:n")];
463+
/// assert!(env::join_paths(paths.iter()).is_err());
464+
/// # }
465+
/// ```
466+
///
467+
/// Using `env::join_paths` with `env::spit_paths` to append an item to the `PATH` environment
468+
/// variable:
469+
///
441470
/// ```
442471
/// use std::env;
443472
/// use std::path::PathBuf;

src/libstd/error.rs

+8
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,14 @@ impl Error for char::CharTryFromError {
340340
}
341341
}
342342

343+
#[stable(feature = "char_from_str", since = "1.19.0")]
344+
impl Error for char::ParseCharError {
345+
fn description(&self) -> &str {
346+
self.__description()
347+
}
348+
}
349+
350+
343351
// copied from any.rs
344352
impl Error + 'static {
345353
/// Returns true if the boxed type is the same as `T`

0 commit comments

Comments
 (0)