Auto merge of #62006 - Centril:rollup-4my59er, r=Centril

Rollup of 5 pull requests

Successful merges:

 - #61900 (implement Error::source for Box<T: Error>)
 - #61979 (Implement Debug for PlaceBase)
 - #61981 (Closures implement Copy and Clone, generators don't)
 - #61996 (Add unit tests for unescaping raw (byte) strings)
 - #62000 (Add test for issue-54189)

Failed merges:

r? @ghost
This commit is contained in:
bors 2019-06-20 20:55:02 +00:00
commit 1d9981f04e
6 changed files with 75 additions and 24 deletions

View File

@ -146,7 +146,7 @@ closure-like semantics. Namely:
generators also depend on variables live across suspension points. This means
that although the ambient environment may be `Send` or `Sync`, the generator
itself may not be due to internal variables live across `yield` points being
not-`Send` or not-`Sync`. Note that generators, like closures, do
not-`Send` or not-`Sync`. Note that generators do
not implement traits like `Copy` or `Clone` automatically.
* Whenever a generator is dropped it will drop all captured environment

View File

@ -2184,29 +2184,7 @@ fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
});
self.iterate(|place_base, place_projections| {
match place_base {
PlaceBase::Local(id) => {
write!(fmt, "{:?}", id)?;
}
PlaceBase::Static(box self::Static { ty, kind: StaticKind::Static(def_id) }) => {
write!(
fmt,
"({}: {:?})",
ty::tls::with(|tcx| tcx.def_path_str(*def_id)),
ty
)?;
},
PlaceBase::Static(
box self::Static { ty, kind: StaticKind::Promoted(promoted) }
) => {
write!(
fmt,
"({:?}: {:?})",
promoted,
ty
)?;
},
}
write!(fmt, "{:?}", place_base)?;
for projection in place_projections {
match projection.elem {
@ -2256,6 +2234,30 @@ fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
}
}
impl Debug for PlaceBase<'_> {
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
match *self {
PlaceBase::Local(id) => write!(fmt, "{:?}", id),
PlaceBase::Static(box self::Static { ty, kind: StaticKind::Static(def_id) }) => {
write!(
fmt,
"({}: {:?})",
ty::tls::with(|tcx| tcx.def_path_str(def_id)),
ty
)
},
PlaceBase::Static(box self::Static { ty, kind: StaticKind::Promoted(promoted) }) => {
write!(
fmt,
"({:?}: {:?})",
promoted,
ty
)
},
}
}
}
///////////////////////////////////////////////////////////////////////////
// Scopes

View File

@ -560,6 +560,10 @@ fn description(&self) -> &str {
fn cause(&self) -> Option<&dyn Error> {
Error::cause(&**self)
}
fn source(&self) -> Option<&(dyn Error + 'static)> {
Error::source(&**self)
}
}
#[stable(feature = "fmt_error", since = "1.11.0")]

View File

@ -569,4 +569,34 @@ fn check(literal_text: &str, expected: &[u8]) {
check("hello \\\r\n world", b"hello world");
check("thread's", b"thread's")
}
#[test]
fn test_unescape_raw_str() {
fn check(literal: &str, expected: &[(Range<usize>, Result<char, EscapeError>)]) {
let mut unescaped = Vec::with_capacity(literal.len());
unescape_raw_str(literal, &mut |range, res| unescaped.push((range, res)));
assert_eq!(unescaped, expected);
}
check("\r\n", &[(0..2, Ok('\n'))]);
check("\r", &[(0..1, Err(EscapeError::BareCarriageReturnInRawString))]);
check("\rx", &[(0..1, Err(EscapeError::BareCarriageReturnInRawString)), (1..2, Ok('x'))]);
}
#[test]
fn test_unescape_raw_byte_str() {
fn check(literal: &str, expected: &[(Range<usize>, Result<u8, EscapeError>)]) {
let mut unescaped = Vec::with_capacity(literal.len());
unescape_raw_byte_str(literal, &mut |range, res| unescaped.push((range, res)));
assert_eq!(unescaped, expected);
}
check("\r\n", &[(0..2, Ok(byte_from_char('\n')))]);
check("\r", &[(0..1, Err(EscapeError::BareCarriageReturnInRawString))]);
check("🦀", &[(0..4, Err(EscapeError::NonAsciiCharInByteString))]);
check(
"🦀a",
&[(0..4, Err(EscapeError::NonAsciiCharInByteString)), (4..5, Ok(byte_from_char('a')))],
);
}
}

View File

@ -0,0 +1,6 @@
fn bug() -> impl for <'r> Fn() -> &'r () { || { &() } }
//~^ ERROR binding for associated type `Output` references lifetime `'r`
fn main() {
let f = bug();
}

View File

@ -0,0 +1,9 @@
error[E0582]: binding for associated type `Output` references lifetime `'r`, which does not appear in the trait input types
--> $DIR/issue-54189.rs:1:35
|
LL | fn bug() -> impl for <'r> Fn() -> &'r () { || { &() } }
| ^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0582`.