Skip to content

Commit e76132e

Browse files
authored
Rollup merge of rust-lang#65545 - nnethercote:more-symbol-cleanups, r=petrochenkov
More symbol cleanups Some minor improvements, mostly aimed at reducing unimportant differences between `Symbol` and `InternedString`. Helps a little with rust-lang#60869. r? @petrochenkov
2 parents e74345a + d343ee8 commit e76132e

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

src/librustc/hir/map/definitions.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pub struct Definitions {
111111
/// A unique identifier that we can use to lookup a definition
112112
/// precisely. It combines the index of the definition's parent (if
113113
/// any) with a `DisambiguatedDefPathData`.
114-
#[derive(Clone, PartialEq, Debug, Hash, RustcEncodable, RustcDecodable)]
114+
#[derive(Clone, PartialEq, Debug, RustcEncodable, RustcDecodable)]
115115
pub struct DefKey {
116116
/// The parent path.
117117
pub parent: Option<DefIndex>,
@@ -162,13 +162,13 @@ impl DefKey {
162162
/// between them. This introduces some artificial ordering dependency
163163
/// but means that if you have, e.g., two impls for the same type in
164164
/// the same module, they do get distinct `DefId`s.
165-
#[derive(Clone, PartialEq, Debug, Hash, RustcEncodable, RustcDecodable)]
165+
#[derive(Clone, PartialEq, Debug, RustcEncodable, RustcDecodable)]
166166
pub struct DisambiguatedDefPathData {
167167
pub data: DefPathData,
168168
pub disambiguator: u32
169169
}
170170

171-
#[derive(Clone, Debug, Hash, RustcEncodable, RustcDecodable)]
171+
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
172172
pub struct DefPath {
173173
/// The path leading from the crate root to the item.
174174
pub data: Vec<DisambiguatedDefPathData>,

src/libsyntax_pos/symbol.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -934,19 +934,19 @@ impl Symbol {
934934

935935
impl fmt::Debug for Symbol {
936936
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
937-
fmt::Display::fmt(self, f)
937+
self.with(|str| fmt::Debug::fmt(&str, f))
938938
}
939939
}
940940

941941
impl fmt::Display for Symbol {
942942
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
943-
fmt::Display::fmt(&self.as_str(), f)
943+
self.with(|str| fmt::Display::fmt(&str, f))
944944
}
945945
}
946946

947947
impl Encodable for Symbol {
948948
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
949-
s.emit_str(&self.as_str())
949+
self.with(|string| s.emit_str(string))
950950
}
951951
}
952952

@@ -1106,8 +1106,8 @@ fn with_interner<T, F: FnOnce(&mut Interner) -> T>(f: F) -> T {
11061106
}
11071107

11081108
/// An alternative to `Symbol` and `InternedString`, useful when the chars
1109-
/// within the symbol need to be accessed. It is best used for temporary
1110-
/// values.
1109+
/// within the symbol need to be accessed. It deliberately has limited
1110+
/// functionality and should only be used for temporary values.
11111111
///
11121112
/// Because the interner outlives any thread which uses this type, we can
11131113
/// safely treat `string` which points to interner data, as an immortal string,
@@ -1116,7 +1116,7 @@ fn with_interner<T, F: FnOnce(&mut Interner) -> T>(f: F) -> T {
11161116
// FIXME: ensure that the interner outlives any thread which uses
11171117
// `LocalInternedString`, by creating a new thread right after constructing the
11181118
// interner.
1119-
#[derive(Clone, Copy, Eq, PartialOrd, Ord)]
1119+
#[derive(Eq, PartialOrd, Ord)]
11201120
pub struct LocalInternedString {
11211121
string: &'static str,
11221122
}

src/test/ui/hygiene/unpretty-debug.stdout

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn y /* 0#0 */() { }
1717
/*
1818
Expansions:
1919
0: parent: ExpnId(0), call_site_ctxt: #0, kind: Root
20-
1: parent: ExpnId(0), call_site_ctxt: #0, kind: Macro(Bang, foo)
20+
1: parent: ExpnId(0), call_site_ctxt: #0, kind: Macro(Bang, "foo")
2121

2222
SyntaxContexts:
2323
#0: parent: #0, outer_mark: (ExpnId(0), Opaque)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
TokenStream [Ident { ident: "fn", span: #0 bytes(197..199) }, Ident { ident: "span_preservation", span: #0 bytes(200..217) }, Group { delimiter: Parenthesis, stream: TokenStream [], span: #0 bytes(217..219) }, Group { delimiter: Brace, stream: TokenStream [Ident { ident: "let", span: #0 bytes(227..230) }, Ident { ident: "tst", span: #0 bytes(231..234) }, Punct { ch: '=', spacing: Alone, span: #0 bytes(235..236) }, Literal { lit: Lit { kind: Integer, symbol: 123, suffix: None }, span: Span { lo: BytePos(237), hi: BytePos(240), ctxt: #0 } }, Punct { ch: ';', spacing: Joint, span: #0 bytes(240..241) }, Punct { ch: ';', spacing: Alone, span: #0 bytes(241..242) }, Ident { ident: "match", span: #0 bytes(288..293) }, Ident { ident: "tst", span: #0 bytes(294..297) }, Group { delimiter: Brace, stream: TokenStream [Literal { lit: Lit { kind: Integer, symbol: 123, suffix: None }, span: Span { lo: BytePos(482), hi: BytePos(485), ctxt: #0 } }, Punct { ch: '=', spacing: Joint, span: #0 bytes(486..488) }, Punct { ch: '>', spacing: Alone, span: #0 bytes(486..488) }, Group { delimiter: Parenthesis, stream: TokenStream [], span: #0 bytes(489..491) }, Punct { ch: ',', spacing: Alone, span: #0 bytes(491..492) }, Ident { ident: "_", span: #0 bytes(501..502) }, Punct { ch: '=', spacing: Joint, span: #0 bytes(503..505) }, Punct { ch: '>', spacing: Alone, span: #0 bytes(503..505) }, Group { delimiter: Parenthesis, stream: TokenStream [], span: #0 bytes(506..508) }], span: #0 bytes(298..514) }, Punct { ch: ';', spacing: Joint, span: #0 bytes(514..515) }, Punct { ch: ';', spacing: Joint, span: #0 bytes(515..516) }, Punct { ch: ';', spacing: Alone, span: #0 bytes(516..517) }], span: #0 bytes(221..561) }]
1+
TokenStream [Ident { ident: "fn", span: #0 bytes(197..199) }, Ident { ident: "span_preservation", span: #0 bytes(200..217) }, Group { delimiter: Parenthesis, stream: TokenStream [], span: #0 bytes(217..219) }, Group { delimiter: Brace, stream: TokenStream [Ident { ident: "let", span: #0 bytes(227..230) }, Ident { ident: "tst", span: #0 bytes(231..234) }, Punct { ch: '=', spacing: Alone, span: #0 bytes(235..236) }, Literal { lit: Lit { kind: Integer, symbol: "123", suffix: None }, span: Span { lo: BytePos(237), hi: BytePos(240), ctxt: #0 } }, Punct { ch: ';', spacing: Joint, span: #0 bytes(240..241) }, Punct { ch: ';', spacing: Alone, span: #0 bytes(241..242) }, Ident { ident: "match", span: #0 bytes(288..293) }, Ident { ident: "tst", span: #0 bytes(294..297) }, Group { delimiter: Brace, stream: TokenStream [Literal { lit: Lit { kind: Integer, symbol: "123", suffix: None }, span: Span { lo: BytePos(482), hi: BytePos(485), ctxt: #0 } }, Punct { ch: '=', spacing: Joint, span: #0 bytes(486..488) }, Punct { ch: '>', spacing: Alone, span: #0 bytes(486..488) }, Group { delimiter: Parenthesis, stream: TokenStream [], span: #0 bytes(489..491) }, Punct { ch: ',', spacing: Alone, span: #0 bytes(491..492) }, Ident { ident: "_", span: #0 bytes(501..502) }, Punct { ch: '=', spacing: Joint, span: #0 bytes(503..505) }, Punct { ch: '>', spacing: Alone, span: #0 bytes(503..505) }, Group { delimiter: Parenthesis, stream: TokenStream [], span: #0 bytes(506..508) }], span: #0 bytes(298..514) }, Punct { ch: ';', spacing: Joint, span: #0 bytes(514..515) }, Punct { ch: ';', spacing: Joint, span: #0 bytes(515..516) }, Punct { ch: ';', spacing: Alone, span: #0 bytes(516..517) }], span: #0 bytes(221..561) }]
22
error: unnecessary trailing semicolon
33
--> $DIR/redundant-semi-proc-macro.rs:9:19
44
|

0 commit comments

Comments
 (0)