From 8951cb5c40e4f577511ce7a10eca59f779c88933 Mon Sep 17 00:00:00 2001 From: s3bk <48330868+s3bk@users.noreply.github.com> Date: Sun, 16 Jun 2019 22:59:12 +0300 Subject: [PATCH 1/5] implement Error::source for Box fixes https://github.com/rust-lang/rust/issues/61899 --- src/libstd/error.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libstd/error.rs b/src/libstd/error.rs index 5cc7dcdae1fcd..5b1e78a113917 100644 --- a/src/libstd/error.rs +++ b/src/libstd/error.rs @@ -560,6 +560,10 @@ impl Error for Box { 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")] From b0dd7fc9f54f85f5844e62a9aeeeb4381f18000e Mon Sep 17 00:00:00 2001 From: Jake Goulding Date: Wed, 19 Jun 2019 23:03:33 -0400 Subject: [PATCH 2/5] Closures implement Copy and Clone, generators don't --- src/doc/unstable-book/src/language-features/generators.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/unstable-book/src/language-features/generators.md b/src/doc/unstable-book/src/language-features/generators.md index 426fc01a6b051..97cf58e57e605 100644 --- a/src/doc/unstable-book/src/language-features/generators.md +++ b/src/doc/unstable-book/src/language-features/generators.md @@ -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 From 047421e69efa88f1a5f65c39b1562063ab859436 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Thu, 20 Jun 2019 09:37:20 +0200 Subject: [PATCH 3/5] Add unit tests for unescaping raw (byte) strings --- src/libsyntax/parse/unescape.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/libsyntax/parse/unescape.rs b/src/libsyntax/parse/unescape.rs index 22cce67b5eeb7..87cc9c1c9e323 100644 --- a/src/libsyntax/parse/unescape.rs +++ b/src/libsyntax/parse/unescape.rs @@ -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, Result)]) { + 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, Result)]) { + 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')))], + ); + } } From f0d9d55138fd08f7f4af1c6c311694452369c111 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 20 Jun 2019 03:02:53 +0200 Subject: [PATCH 4/5] Implement Debug for PlaceBase --- src/librustc/mir/mod.rs | 48 +++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 9dfd8d959a3c4..6e09cc0452828 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -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 { @@ -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 From 127edbac343433b89e3574d5e61b4b23ed05b165 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Fri, 21 Jun 2019 00:19:11 +0900 Subject: [PATCH 5/5] Add test for issue-54189 --- src/test/ui/issues/issue-54189.rs | 6 ++++++ src/test/ui/issues/issue-54189.stderr | 9 +++++++++ 2 files changed, 15 insertions(+) create mode 100644 src/test/ui/issues/issue-54189.rs create mode 100644 src/test/ui/issues/issue-54189.stderr diff --git a/src/test/ui/issues/issue-54189.rs b/src/test/ui/issues/issue-54189.rs new file mode 100644 index 0000000000000..70aecc384effe --- /dev/null +++ b/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(); +} diff --git a/src/test/ui/issues/issue-54189.stderr b/src/test/ui/issues/issue-54189.stderr new file mode 100644 index 0000000000000..4787abd49d178 --- /dev/null +++ b/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`.