Skip to content

Rollup of 5 pull requests #62006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jun 20, 2019
2 changes: 1 addition & 1 deletion src/doc/unstable-book/src/language-features/generators.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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`.