Skip to content

Commit

Permalink
Auto merge of #62006 - Centril:rollup-4my59er, r=Centril
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Jun 20, 2019
2 parents f693d33 + 9e5ace6 commit 1d9981f
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/doc/unstable-book/src/language-features/generators.md
Expand Up @@ -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
Expand Down
48 changes: 25 additions & 23 deletions src/librustc/mir/mod.rs
Expand Up @@ -2184,29 +2184,7 @@ impl<'tcx> Debug for Place<'tcx> {
});

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 {
Expand Down Expand Up @@ -2256,6 +2234,30 @@ impl<'tcx> Debug for Place<'tcx> {
}
}

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

Expand Down
4 changes: 4 additions & 0 deletions src/libstd/error.rs
Expand Up @@ -560,6 +560,10 @@ impl<T: Error> Error for Box<T> {
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")]
Expand Down
30 changes: 30 additions & 0 deletions src/libsyntax/parse/unescape.rs
Expand Up @@ -569,4 +569,34 @@ mod tests {
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')))],
);
}
}
6 changes: 6 additions & 0 deletions src/test/ui/issues/issue-54189.rs
@@ -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();
}
9 changes: 9 additions & 0 deletions src/test/ui/issues/issue-54189.stderr
@@ -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`.

0 comments on commit 1d9981f

Please sign in to comment.