Skip to content

Commit 1d9981f

Browse files
committed
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
2 parents f693d33 + 9e5ace6 commit 1d9981f

File tree

6 files changed

+75
-24
lines changed

6 files changed

+75
-24
lines changed

src/doc/unstable-book/src/language-features/generators.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ closure-like semantics. Namely:
146146
generators also depend on variables live across suspension points. This means
147147
that although the ambient environment may be `Send` or `Sync`, the generator
148148
itself may not be due to internal variables live across `yield` points being
149-
not-`Send` or not-`Sync`. Note that generators, like closures, do
149+
not-`Send` or not-`Sync`. Note that generators do
150150
not implement traits like `Copy` or `Clone` automatically.
151151

152152
* Whenever a generator is dropped it will drop all captured environment

src/librustc/mir/mod.rs

+25-23
Original file line numberDiff line numberDiff line change
@@ -2184,29 +2184,7 @@ impl<'tcx> Debug for Place<'tcx> {
21842184
});
21852185

21862186
self.iterate(|place_base, place_projections| {
2187-
match place_base {
2188-
PlaceBase::Local(id) => {
2189-
write!(fmt, "{:?}", id)?;
2190-
}
2191-
PlaceBase::Static(box self::Static { ty, kind: StaticKind::Static(def_id) }) => {
2192-
write!(
2193-
fmt,
2194-
"({}: {:?})",
2195-
ty::tls::with(|tcx| tcx.def_path_str(*def_id)),
2196-
ty
2197-
)?;
2198-
},
2199-
PlaceBase::Static(
2200-
box self::Static { ty, kind: StaticKind::Promoted(promoted) }
2201-
) => {
2202-
write!(
2203-
fmt,
2204-
"({:?}: {:?})",
2205-
promoted,
2206-
ty
2207-
)?;
2208-
},
2209-
}
2187+
write!(fmt, "{:?}", place_base)?;
22102188

22112189
for projection in place_projections {
22122190
match projection.elem {
@@ -2256,6 +2234,30 @@ impl<'tcx> Debug for Place<'tcx> {
22562234
}
22572235
}
22582236

2237+
impl Debug for PlaceBase<'_> {
2238+
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
2239+
match *self {
2240+
PlaceBase::Local(id) => write!(fmt, "{:?}", id),
2241+
PlaceBase::Static(box self::Static { ty, kind: StaticKind::Static(def_id) }) => {
2242+
write!(
2243+
fmt,
2244+
"({}: {:?})",
2245+
ty::tls::with(|tcx| tcx.def_path_str(def_id)),
2246+
ty
2247+
)
2248+
},
2249+
PlaceBase::Static(box self::Static { ty, kind: StaticKind::Promoted(promoted) }) => {
2250+
write!(
2251+
fmt,
2252+
"({:?}: {:?})",
2253+
promoted,
2254+
ty
2255+
)
2256+
},
2257+
}
2258+
}
2259+
}
2260+
22592261
///////////////////////////////////////////////////////////////////////////
22602262
// Scopes
22612263

src/libstd/error.rs

+4
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,10 @@ impl<T: Error> Error for Box<T> {
560560
fn cause(&self) -> Option<&dyn Error> {
561561
Error::cause(&**self)
562562
}
563+
564+
fn source(&self) -> Option<&(dyn Error + 'static)> {
565+
Error::source(&**self)
566+
}
563567
}
564568

565569
#[stable(feature = "fmt_error", since = "1.11.0")]

src/libsyntax/parse/unescape.rs

+30
Original file line numberDiff line numberDiff line change
@@ -569,4 +569,34 @@ mod tests {
569569
check("hello \\\r\n world", b"hello world");
570570
check("thread's", b"thread's")
571571
}
572+
573+
#[test]
574+
fn test_unescape_raw_str() {
575+
fn check(literal: &str, expected: &[(Range<usize>, Result<char, EscapeError>)]) {
576+
let mut unescaped = Vec::with_capacity(literal.len());
577+
unescape_raw_str(literal, &mut |range, res| unescaped.push((range, res)));
578+
assert_eq!(unescaped, expected);
579+
}
580+
581+
check("\r\n", &[(0..2, Ok('\n'))]);
582+
check("\r", &[(0..1, Err(EscapeError::BareCarriageReturnInRawString))]);
583+
check("\rx", &[(0..1, Err(EscapeError::BareCarriageReturnInRawString)), (1..2, Ok('x'))]);
584+
}
585+
586+
#[test]
587+
fn test_unescape_raw_byte_str() {
588+
fn check(literal: &str, expected: &[(Range<usize>, Result<u8, EscapeError>)]) {
589+
let mut unescaped = Vec::with_capacity(literal.len());
590+
unescape_raw_byte_str(literal, &mut |range, res| unescaped.push((range, res)));
591+
assert_eq!(unescaped, expected);
592+
}
593+
594+
check("\r\n", &[(0..2, Ok(byte_from_char('\n')))]);
595+
check("\r", &[(0..1, Err(EscapeError::BareCarriageReturnInRawString))]);
596+
check("🦀", &[(0..4, Err(EscapeError::NonAsciiCharInByteString))]);
597+
check(
598+
"🦀a",
599+
&[(0..4, Err(EscapeError::NonAsciiCharInByteString)), (4..5, Ok(byte_from_char('a')))],
600+
);
601+
}
572602
}

src/test/ui/issues/issue-54189.rs

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

src/test/ui/issues/issue-54189.stderr

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

0 commit comments

Comments
 (0)