Skip to content

Commit

Permalink
Auto merge of #72286 - Dylan-DPC:rollup-n3rk6df, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 4 pull requests

Successful merges:

 - #72233 (Fix {:#?} representation of proc_macro::Literal)
 - #72277 (emphasize that ManuallyDrop is safe-to-access and unsafe-to-drop)
 - #72281 (Fix whitespace in `?Sized` structured suggestion)
 - #72282 (Fix issue number typo in note)

Failed merges:

r? @ghost
  • Loading branch information
bors committed May 17, 2020
2 parents 0ec4b06 + 1d09a7b commit 09739c2
Show file tree
Hide file tree
Showing 13 changed files with 251 additions and 15 deletions.
6 changes: 5 additions & 1 deletion src/libcore/mem/manually_drop.rs
Expand Up @@ -2,7 +2,6 @@ use crate::ops::{Deref, DerefMut};
use crate::ptr;

/// A wrapper to inhibit compiler from automatically calling `T`’s destructor.
///
/// This wrapper is 0-cost.
///
/// `ManuallyDrop<T>` is subject to the same layout optimizations as `T`.
Expand All @@ -11,6 +10,11 @@ use crate::ptr;
/// with [`mem::zeroed`] is undefined behavior.
/// If you need to handle uninitialized data, use [`MaybeUninit<T>`] instead.
///
/// Note that accessing the value inside a `ManuallyDrop<T>` is safe.
/// This means that a `ManuallyDrop<T>` whose content has been dropped must not
/// be exposed through a public safe API.
/// Correspondingly, `ManuallyDrop::drop` is unsafe.
///
/// # Examples
///
/// This wrapper can be used to enforce a particular drop order on fields, regardless
Expand Down
10 changes: 8 additions & 2 deletions src/libproc_macro/bridge/client.rs
Expand Up @@ -202,10 +202,16 @@ impl Clone for Literal {
}
}

// FIXME(eddyb) `Literal` should not expose internal `Debug` impls.
impl fmt::Debug for Literal {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.debug())
f.debug_struct("Literal")
// format the kind without quotes, as in `kind: Float`
.field("kind", &format_args!("{}", &self.debug_kind()))
.field("symbol", &self.symbol())
// format `Some("...")` on one line even in {:#?} mode
.field("suffix", &format_args!("{:?}", &self.suffix()))
.field("span", &self.span())
.finish()
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/libproc_macro/bridge/mod.rs
Expand Up @@ -103,8 +103,9 @@ macro_rules! with_api {
Literal {
fn drop($self: $S::Literal);
fn clone($self: &$S::Literal) -> $S::Literal;
// FIXME(eddyb) `Literal` should not expose internal `Debug` impls.
fn debug($self: &$S::Literal) -> String;
fn debug_kind($self: &$S::Literal) -> String;
fn symbol($self: &$S::Literal) -> String;
fn suffix($self: &$S::Literal) -> Option<String>;
fn integer(n: &str) -> $S::Literal;
fn typed_integer(n: &str, kind: &str) -> $S::Literal;
fn float(n: &str) -> $S::Literal;
Expand Down
1 change: 0 additions & 1 deletion src/libproc_macro/lib.rs
Expand Up @@ -1141,7 +1141,6 @@ impl fmt::Display for Literal {
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
impl fmt::Debug for Literal {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// FIXME(eddyb) `Literal` should not expose internal `Debug` impls.
self.0.fmt(f)
}
}
11 changes: 8 additions & 3 deletions src/librustc_expand/proc_macro_server.rs
Expand Up @@ -507,9 +507,14 @@ impl server::Ident for Rustc<'_> {
}

impl server::Literal for Rustc<'_> {
// FIXME(eddyb) `Literal` should not expose internal `Debug` impls.
fn debug(&mut self, literal: &Self::Literal) -> String {
format!("{:?}", literal)
fn debug_kind(&mut self, literal: &Self::Literal) -> String {
format!("{:?}", literal.lit.kind)
}
fn symbol(&mut self, literal: &Self::Literal) -> String {
literal.lit.symbol.to_string()
}
fn suffix(&mut self, literal: &Self::Literal) -> Option<String> {
literal.lit.suffix.as_ref().map(Symbol::to_string)
}
fn integer(&mut self, n: &str) -> Self::Literal {
self.lit(token::Integer, Symbol::intern(n), None)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trait_selection/traits/error_reporting/mod.rs
Expand Up @@ -1655,7 +1655,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
{
let (span, separator) = match param.bounds {
[] => (span.shrink_to_hi(), ":"),
[.., bound] => (bound.span().shrink_to_hi(), " + "),
[.., bound] => (bound.span().shrink_to_hi(), " +"),
};
err.span_suggestion_verbose(
span,
Expand Down
Expand Up @@ -1685,7 +1685,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
if suggest_const_in_array_repeat_expressions {
err.note(
"this array initializer can be evaluated at compile-time, see issue \
#48147 <https://github.com/rust-lang/rust/issues/49147> \
#49147 <https://github.com/rust-lang/rust/issues/49147> \
for more information",
);
if tcx.sess.opts.unstable_features.is_nightly_build() {
Expand Down
Expand Up @@ -7,7 +7,7 @@ LL | let arr: [Option<String>; 2] = [None::<String>; 2];
= help: the following implementations were found:
<std::option::Option<T> as std::marker::Copy>
= note: the `Copy` trait is required because the repeated element will be copied
= note: this array initializer can be evaluated at compile-time, see issue #48147 <https://github.com/rust-lang/rust/issues/49147> for more information
= note: this array initializer can be evaluated at compile-time, see issue #49147 <https://github.com/rust-lang/rust/issues/49147> for more information
= help: add `#![feature(const_in_array_repeat_expressions)]` to the crate attributes to enable

error[E0277]: the trait bound `std::option::Option<std::string::String>: std::marker::Copy` is not satisfied
Expand Down
@@ -1,4 +1,4 @@
TokenStream [Ident { ident: "fn", span: #0 bytes(198..200) }, Ident { ident: "span_preservation", span: #0 bytes(201..218) }, Group { delimiter: Parenthesis, stream: TokenStream [], span: #0 bytes(218..220) }, Group { delimiter: Brace, stream: TokenStream [Ident { ident: "let", span: #0 bytes(228..231) }, Ident { ident: "tst", span: #0 bytes(232..235) }, Punct { ch: '=', spacing: Alone, span: #0 bytes(236..237) }, Literal { lit: Lit { kind: Integer, symbol: "123", suffix: None }, span: Span { lo: BytePos(238), hi: BytePos(241), ctxt: #0 } }, Punct { ch: ';', spacing: Joint, span: #0 bytes(241..242) }, Punct { ch: ';', spacing: Alone, span: #0 bytes(242..243) }, Ident { ident: "match", span: #0 bytes(289..294) }, Ident { ident: "tst", span: #0 bytes(295..298) }, Group { delimiter: Brace, stream: TokenStream [Literal { lit: Lit { kind: Integer, symbol: "123", suffix: None }, span: Span { lo: BytePos(483), hi: BytePos(486), ctxt: #0 } }, Punct { ch: '=', spacing: Joint, span: #0 bytes(487..489) }, Punct { ch: '>', spacing: Alone, span: #0 bytes(487..489) }, Group { delimiter: Parenthesis, stream: TokenStream [], span: #0 bytes(490..492) }, Punct { ch: ',', spacing: Alone, span: #0 bytes(492..493) }, Ident { ident: "_", span: #0 bytes(502..503) }, Punct { ch: '=', spacing: Joint, span: #0 bytes(504..506) }, Punct { ch: '>', spacing: Alone, span: #0 bytes(504..506) }, Group { delimiter: Parenthesis, stream: TokenStream [], span: #0 bytes(507..509) }], span: #0 bytes(299..515) }, Punct { ch: ';', spacing: Joint, span: #0 bytes(515..516) }, Punct { ch: ';', spacing: Joint, span: #0 bytes(516..517) }, Punct { ch: ';', spacing: Alone, span: #0 bytes(517..518) }], span: #0 bytes(222..562) }]
TokenStream [Ident { ident: "fn", span: #0 bytes(198..200) }, Ident { ident: "span_preservation", span: #0 bytes(201..218) }, Group { delimiter: Parenthesis, stream: TokenStream [], span: #0 bytes(218..220) }, Group { delimiter: Brace, stream: TokenStream [Ident { ident: "let", span: #0 bytes(228..231) }, Ident { ident: "tst", span: #0 bytes(232..235) }, Punct { ch: '=', spacing: Alone, span: #0 bytes(236..237) }, Literal { kind: Integer, symbol: "123", suffix: None, span: #0 bytes(238..241) }, Punct { ch: ';', spacing: Joint, span: #0 bytes(241..242) }, Punct { ch: ';', spacing: Alone, span: #0 bytes(242..243) }, Ident { ident: "match", span: #0 bytes(289..294) }, Ident { ident: "tst", span: #0 bytes(295..298) }, Group { delimiter: Brace, stream: TokenStream [Literal { kind: Integer, symbol: "123", suffix: None, span: #0 bytes(483..486) }, Punct { ch: '=', spacing: Joint, span: #0 bytes(487..489) }, Punct { ch: '>', spacing: Alone, span: #0 bytes(487..489) }, Group { delimiter: Parenthesis, stream: TokenStream [], span: #0 bytes(490..492) }, Punct { ch: ',', spacing: Alone, span: #0 bytes(492..493) }, Ident { ident: "_", span: #0 bytes(502..503) }, Punct { ch: '=', spacing: Joint, span: #0 bytes(504..506) }, Punct { ch: '>', spacing: Alone, span: #0 bytes(504..506) }, Group { delimiter: Parenthesis, stream: TokenStream [], span: #0 bytes(507..509) }], span: #0 bytes(299..515) }, Punct { ch: ';', spacing: Joint, span: #0 bytes(515..516) }, Punct { ch: ';', spacing: Joint, span: #0 bytes(516..517) }, Punct { ch: ';', spacing: Alone, span: #0 bytes(517..518) }], span: #0 bytes(222..562) }]
error: unnecessary trailing semicolon
--> $DIR/redundant-semi-proc-macro.rs:9:19
|
Expand Down
15 changes: 15 additions & 0 deletions src/test/ui/proc-macro/debug/auxiliary/macro-dump-debug.rs
@@ -0,0 +1,15 @@
// force-host
// no-prefer-dynamic

#![crate_type = "proc-macro"]
#![crate_name = "macro_dump_debug"]

extern crate proc_macro;
use proc_macro::TokenStream;

#[proc_macro]
pub fn dump_debug(tokens: TokenStream) -> TokenStream {
eprintln!("{:?}", tokens);
eprintln!("{:#?}", tokens);
TokenStream::new()
}
40 changes: 40 additions & 0 deletions src/test/ui/proc-macro/debug/dump-debug.rs
@@ -0,0 +1,40 @@
// run-pass
// aux-build:macro-dump-debug.rs

extern crate macro_dump_debug;
use macro_dump_debug::dump_debug;

dump_debug! {
ident // ident
r#ident // raw ident
, // alone punct
==> // joint punct
() // empty group
[_] // nonempty group

// unsuffixed literals
0
1.0
"S"
b"B"
r"R"
r##"R"##
br"BR"
br##"BR"##
'C'
b'B'

// suffixed literals
0q
1.0q
"S"q
b"B"q
r"R"q
r##"R"##q
br"BR"q
br##"BR"##q
'C'q
b'B'q
}

fn main() {}
166 changes: 166 additions & 0 deletions src/test/ui/proc-macro/debug/dump-debug.stderr
@@ -0,0 +1,166 @@
TokenStream [Ident { ident: "ident", span: #0 bytes(130..135) }, Ident { ident: "r#ident", span: #0 bytes(151..158) }, Punct { ch: ',', spacing: Alone, span: #0 bytes(176..177) }, Punct { ch: '=', spacing: Joint, span: #0 bytes(203..205) }, Punct { ch: '=', spacing: Joint, span: #0 bytes(203..205) }, Punct { ch: '>', spacing: Alone, span: #0 bytes(205..206) }, Group { delimiter: Parenthesis, stream: TokenStream [], span: #0 bytes(230..232) }, Group { delimiter: Bracket, stream: TokenStream [Ident { ident: "_", span: #0 bytes(258..259) }], span: #0 bytes(257..260) }, Literal { kind: Integer, symbol: "0", suffix: None, span: #0 bytes(315..316) }, Literal { kind: Float, symbol: "1.0", suffix: None, span: #0 bytes(321..324) }, Literal { kind: Str, symbol: "S", suffix: None, span: #0 bytes(329..332) }, Literal { kind: ByteStr, symbol: "B", suffix: None, span: #0 bytes(337..341) }, Literal { kind: StrRaw(0), symbol: "R", suffix: None, span: #0 bytes(346..350) }, Literal { kind: StrRaw(2), symbol: "R", suffix: None, span: #0 bytes(355..363) }, Literal { kind: ByteStrRaw(0), symbol: "BR", suffix: None, span: #0 bytes(368..374) }, Literal { kind: ByteStrRaw(2), symbol: "BR", suffix: None, span: #0 bytes(379..389) }, Literal { kind: Char, symbol: "C", suffix: None, span: #0 bytes(394..397) }, Literal { kind: Byte, symbol: "B", suffix: None, span: #0 bytes(402..406) }, Literal { kind: Integer, symbol: "0", suffix: Some("q"), span: #0 bytes(437..439) }, Literal { kind: Float, symbol: "1.0", suffix: Some("q"), span: #0 bytes(444..448) }, Literal { kind: Str, symbol: "S", suffix: Some("q"), span: #0 bytes(453..457) }, Literal { kind: ByteStr, symbol: "B", suffix: Some("q"), span: #0 bytes(462..467) }, Literal { kind: StrRaw(0), symbol: "R", suffix: Some("q"), span: #0 bytes(472..477) }, Literal { kind: StrRaw(2), symbol: "R", suffix: Some("q"), span: #0 bytes(482..491) }, Literal { kind: ByteStrRaw(0), symbol: "BR", suffix: Some("q"), span: #0 bytes(496..503) }, Literal { kind: ByteStrRaw(2), symbol: "BR", suffix: Some("q"), span: #0 bytes(508..519) }, Literal { kind: Char, symbol: "C", suffix: Some("q"), span: #0 bytes(524..528) }, Literal { kind: Byte, symbol: "B", suffix: Some("q"), span: #0 bytes(533..538) }]
TokenStream [
Ident {
ident: "ident",
span: #0 bytes(130..135),
},
Ident {
ident: "r#ident",
span: #0 bytes(151..158),
},
Punct {
ch: ',',
spacing: Alone,
span: #0 bytes(176..177),
},
Punct {
ch: '=',
spacing: Joint,
span: #0 bytes(203..205),
},
Punct {
ch: '=',
spacing: Joint,
span: #0 bytes(203..205),
},
Punct {
ch: '>',
spacing: Alone,
span: #0 bytes(205..206),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [],
span: #0 bytes(230..232),
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
ident: "_",
span: #0 bytes(258..259),
},
],
span: #0 bytes(257..260),
},
Literal {
kind: Integer,
symbol: "0",
suffix: None,
span: #0 bytes(315..316),
},
Literal {
kind: Float,
symbol: "1.0",
suffix: None,
span: #0 bytes(321..324),
},
Literal {
kind: Str,
symbol: "S",
suffix: None,
span: #0 bytes(329..332),
},
Literal {
kind: ByteStr,
symbol: "B",
suffix: None,
span: #0 bytes(337..341),
},
Literal {
kind: StrRaw(0),
symbol: "R",
suffix: None,
span: #0 bytes(346..350),
},
Literal {
kind: StrRaw(2),
symbol: "R",
suffix: None,
span: #0 bytes(355..363),
},
Literal {
kind: ByteStrRaw(0),
symbol: "BR",
suffix: None,
span: #0 bytes(368..374),
},
Literal {
kind: ByteStrRaw(2),
symbol: "BR",
suffix: None,
span: #0 bytes(379..389),
},
Literal {
kind: Char,
symbol: "C",
suffix: None,
span: #0 bytes(394..397),
},
Literal {
kind: Byte,
symbol: "B",
suffix: None,
span: #0 bytes(402..406),
},
Literal {
kind: Integer,
symbol: "0",
suffix: Some("q"),
span: #0 bytes(437..439),
},
Literal {
kind: Float,
symbol: "1.0",
suffix: Some("q"),
span: #0 bytes(444..448),
},
Literal {
kind: Str,
symbol: "S",
suffix: Some("q"),
span: #0 bytes(453..457),
},
Literal {
kind: ByteStr,
symbol: "B",
suffix: Some("q"),
span: #0 bytes(462..467),
},
Literal {
kind: StrRaw(0),
symbol: "R",
suffix: Some("q"),
span: #0 bytes(472..477),
},
Literal {
kind: StrRaw(2),
symbol: "R",
suffix: Some("q"),
span: #0 bytes(482..491),
},
Literal {
kind: ByteStrRaw(0),
symbol: "BR",
suffix: Some("q"),
span: #0 bytes(496..503),
},
Literal {
kind: ByteStrRaw(2),
symbol: "BR",
suffix: Some("q"),
span: #0 bytes(508..519),
},
Literal {
kind: Char,
symbol: "C",
suffix: Some("q"),
span: #0 bytes(524..528),
},
Literal {
kind: Byte,
symbol: "B",
suffix: Some("q"),
span: #0 bytes(533..538),
},
]
4 changes: 2 additions & 2 deletions src/test/ui/unsized3.stderr
Expand Up @@ -31,8 +31,8 @@ LL | fn f4<X: T>(x: &X) {
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
help: consider relaxing the implicit `Sized` restriction
|
LL | fn f4<X: T + ?Sized>(x: &X) {
| ^^^^^^^^^
LL | fn f4<X: T + ?Sized>(x: &X) {
| ^^^^^^^^

error[E0277]: the size for values of type `X` cannot be known at compilation time
--> $DIR/unsized3.rs:33:8
Expand Down

0 comments on commit 09739c2

Please sign in to comment.