Skip to content

Commit 09739c2

Browse files
committed
Auto merge of #72286 - Dylan-DPC:rollup-n3rk6df, r=Dylan-DPC
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
2 parents 0ec4b06 + 1d09a7b commit 09739c2

File tree

13 files changed

+251
-15
lines changed

13 files changed

+251
-15
lines changed

src/libcore/mem/manually_drop.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::ops::{Deref, DerefMut};
22
use crate::ptr;
33

44
/// A wrapper to inhibit compiler from automatically calling `T`’s destructor.
5-
///
65
/// This wrapper is 0-cost.
76
///
87
/// `ManuallyDrop<T>` is subject to the same layout optimizations as `T`.
@@ -11,6 +10,11 @@ use crate::ptr;
1110
/// with [`mem::zeroed`] is undefined behavior.
1211
/// If you need to handle uninitialized data, use [`MaybeUninit<T>`] instead.
1312
///
13+
/// Note that accessing the value inside a `ManuallyDrop<T>` is safe.
14+
/// This means that a `ManuallyDrop<T>` whose content has been dropped must not
15+
/// be exposed through a public safe API.
16+
/// Correspondingly, `ManuallyDrop::drop` is unsafe.
17+
///
1418
/// # Examples
1519
///
1620
/// This wrapper can be used to enforce a particular drop order on fields, regardless

src/libproc_macro/bridge/client.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,16 @@ impl Clone for Literal {
202202
}
203203
}
204204

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

src/libproc_macro/bridge/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@ macro_rules! with_api {
103103
Literal {
104104
fn drop($self: $S::Literal);
105105
fn clone($self: &$S::Literal) -> $S::Literal;
106-
// FIXME(eddyb) `Literal` should not expose internal `Debug` impls.
107-
fn debug($self: &$S::Literal) -> String;
106+
fn debug_kind($self: &$S::Literal) -> String;
107+
fn symbol($self: &$S::Literal) -> String;
108+
fn suffix($self: &$S::Literal) -> Option<String>;
108109
fn integer(n: &str) -> $S::Literal;
109110
fn typed_integer(n: &str, kind: &str) -> $S::Literal;
110111
fn float(n: &str) -> $S::Literal;

src/libproc_macro/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,6 @@ impl fmt::Display for Literal {
11411141
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
11421142
impl fmt::Debug for Literal {
11431143
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1144-
// FIXME(eddyb) `Literal` should not expose internal `Debug` impls.
11451144
self.0.fmt(f)
11461145
}
11471146
}

src/librustc_expand/proc_macro_server.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,9 +507,14 @@ impl server::Ident for Rustc<'_> {
507507
}
508508

509509
impl server::Literal for Rustc<'_> {
510-
// FIXME(eddyb) `Literal` should not expose internal `Debug` impls.
511-
fn debug(&mut self, literal: &Self::Literal) -> String {
512-
format!("{:?}", literal)
510+
fn debug_kind(&mut self, literal: &Self::Literal) -> String {
511+
format!("{:?}", literal.lit.kind)
512+
}
513+
fn symbol(&mut self, literal: &Self::Literal) -> String {
514+
literal.lit.symbol.to_string()
515+
}
516+
fn suffix(&mut self, literal: &Self::Literal) -> Option<String> {
517+
literal.lit.suffix.as_ref().map(Symbol::to_string)
513518
}
514519
fn integer(&mut self, n: &str) -> Self::Literal {
515520
self.lit(token::Integer, Symbol::intern(n), None)

src/librustc_trait_selection/traits/error_reporting/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1655,7 +1655,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
16551655
{
16561656
let (span, separator) = match param.bounds {
16571657
[] => (span.shrink_to_hi(), ":"),
1658-
[.., bound] => (bound.span().shrink_to_hi(), " + "),
1658+
[.., bound] => (bound.span().shrink_to_hi(), " +"),
16591659
};
16601660
err.span_suggestion_verbose(
16611661
span,

src/librustc_trait_selection/traits/error_reporting/suggestions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1685,7 +1685,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
16851685
if suggest_const_in_array_repeat_expressions {
16861686
err.note(
16871687
"this array initializer can be evaluated at compile-time, see issue \
1688-
#48147 <https://github.com/rust-lang/rust/issues/49147> \
1688+
#49147 <https://github.com/rust-lang/rust/issues/49147> \
16891689
for more information",
16901690
);
16911691
if tcx.sess.opts.unstable_features.is_nightly_build() {

src/test/ui/feature-gates/feature-gate-const_in_array_repeat_expressions.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | let arr: [Option<String>; 2] = [None::<String>; 2];
77
= help: the following implementations were found:
88
<std::option::Option<T> as std::marker::Copy>
99
= note: the `Copy` trait is required because the repeated element will be copied
10-
= note: this array initializer can be evaluated at compile-time, see issue #48147 <https://github.com/rust-lang/rust/issues/49147> for more information
10+
= note: this array initializer can be evaluated at compile-time, see issue #49147 <https://github.com/rust-lang/rust/issues/49147> for more information
1111
= help: add `#![feature(const_in_array_repeat_expressions)]` to the crate attributes to enable
1212

1313
error[E0277]: the trait bound `std::option::Option<std::string::String>: std::marker::Copy` is not satisfied

src/test/ui/lint/redundant-semicolon/redundant-semi-proc-macro.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
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) }]
1+
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) }]
22
error: unnecessary trailing semicolon
33
--> $DIR/redundant-semi-proc-macro.rs:9:19
44
|
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// force-host
2+
// no-prefer-dynamic
3+
4+
#![crate_type = "proc-macro"]
5+
#![crate_name = "macro_dump_debug"]
6+
7+
extern crate proc_macro;
8+
use proc_macro::TokenStream;
9+
10+
#[proc_macro]
11+
pub fn dump_debug(tokens: TokenStream) -> TokenStream {
12+
eprintln!("{:?}", tokens);
13+
eprintln!("{:#?}", tokens);
14+
TokenStream::new()
15+
}

0 commit comments

Comments
 (0)