about summary refs log tree commit diff
path: root/compiler/rustc_span/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-07-11 08:46:43 +0000
committerbors <bors@rust-lang.org>2021-07-11 08:46:43 +0000
commit4581c4ef6ff388dd624bdceb484fb03c33d7bae4 (patch)
tree734a1f1bf766994dac153ee2c5c0ed2ddba6c16e /compiler/rustc_span/src
parent0d76b7374589c45e3e9290309781a1ed9a461951 (diff)
parent4ba91a063d2c22587bca2c89740214ac7f4ab8d9 (diff)
downloadrust-4581c4ef6ff388dd624bdceb484fb03c33d7bae4.tar.gz
rust-4581c4ef6ff388dd624bdceb484fb03c33d7bae4.zip
Auto merge of #87042 - petrochenkov:cleanquotspan, r=Aaron1011
Cleanup span quoting

I finally got to reviewing https://github.com/rust-lang/rust/pull/84278.
See the individual commit messages.
r? `@Aaron1011`
Diffstat (limited to 'compiler/rustc_span/src')
-rw-r--r--compiler/rustc_span/src/hygiene.rs66
-rw-r--r--compiler/rustc_span/src/lib.rs5
2 files changed, 29 insertions, 42 deletions
diff --git a/compiler/rustc_span/src/hygiene.rs b/compiler/rustc_span/src/hygiene.rs
index b2da51f8f38..78b181aa330 100644
--- a/compiler/rustc_span/src/hygiene.rs
+++ b/compiler/rustc_span/src/hygiene.rs
@@ -144,10 +144,7 @@ impl ExpnId {
             let expn_data = self.expn_data();
             // Stop going up the backtrace once include! is encountered
             if expn_data.is_root()
-                || matches!(
-                    expn_data.kind,
-                    ExpnKind::Macro { kind: MacroKind::Bang, name: sym::include, proc_macro: _ }
-                )
+                || expn_data.kind == ExpnKind::Macro(MacroKind::Bang, sym::include)
             {
                 break;
             }
@@ -712,31 +709,6 @@ pub struct ExpnData {
     /// call_site span would have its own ExpnData, with the call_site
     /// pointing to the `foo!` invocation.
     pub call_site: Span,
-
-    // --- The part specific to the macro/desugaring definition.
-    // --- It may be reasonable to share this part between expansions with the same definition,
-    // --- but such sharing is known to bring some minor inconveniences without also bringing
-    // --- noticeable perf improvements (PR #62898).
-    /// The span of the macro definition (possibly dummy).
-    /// This span serves only informational purpose and is not used for resolution.
-    pub def_site: Span,
-    /// List of `#[unstable]`/feature-gated features that the macro is allowed to use
-    /// internally without forcing the whole crate to opt-in
-    /// to them.
-    pub allow_internal_unstable: Option<Lrc<[Symbol]>>,
-    /// Whether the macro is allowed to use `unsafe` internally
-    /// even if the user crate has `#![forbid(unsafe_code)]`.
-    pub allow_internal_unsafe: bool,
-    /// Enables the macro helper hack (`ident!(...)` -> `$crate::ident!(...)`)
-    /// for a given macro.
-    pub local_inner_macros: bool,
-    /// Edition of the crate in which the macro is defined.
-    pub edition: Edition,
-    /// The `DefId` of the macro being invoked,
-    /// if this `ExpnData` corresponds to a macro invocation
-    pub macro_def_id: Option<DefId>,
-    /// The normal module (`mod`) in which the expanded macro was defined.
-    pub parent_module: Option<DefId>,
     /// The crate that originally created this `ExpnData`. During
     /// metadata serialization, we only encode `ExpnData`s that were
     /// created locally - when our serialized metadata is decoded,
@@ -751,7 +723,6 @@ pub struct ExpnData {
     // be considered equivalent.
     #[stable_hasher(ignore)]
     orig_id: Option<u32>,
-
     /// Used to force two `ExpnData`s to have different `Fingerprint`s.
     /// Due to macro expansion, it's possible to end up with two `ExpnId`s
     /// that have identical `ExpnData`s. This violates the contract of `HashStable`
@@ -763,6 +734,31 @@ pub struct ExpnData {
     /// `ExpnId`s would end up with the same `Fingerprint`. Since `ExpnData` includes
     /// a `krate` field, this value only needs to be unique within a single crate.
     disambiguator: u32,
+
+    // --- The part specific to the macro/desugaring definition.
+    // --- It may be reasonable to share this part between expansions with the same definition,
+    // --- but such sharing is known to bring some minor inconveniences without also bringing
+    // --- noticeable perf improvements (PR #62898).
+    /// The span of the macro definition (possibly dummy).
+    /// This span serves only informational purpose and is not used for resolution.
+    pub def_site: Span,
+    /// List of `#[unstable]`/feature-gated features that the macro is allowed to use
+    /// internally without forcing the whole crate to opt-in
+    /// to them.
+    pub allow_internal_unstable: Option<Lrc<[Symbol]>>,
+    /// Whether the macro is allowed to use `unsafe` internally
+    /// even if the user crate has `#![forbid(unsafe_code)]`.
+    pub allow_internal_unsafe: bool,
+    /// Enables the macro helper hack (`ident!(...)` -> `$crate::ident!(...)`)
+    /// for a given macro.
+    pub local_inner_macros: bool,
+    /// Edition of the crate in which the macro is defined.
+    pub edition: Edition,
+    /// The `DefId` of the macro being invoked,
+    /// if this `ExpnData` corresponds to a macro invocation
+    pub macro_def_id: Option<DefId>,
+    /// The normal module (`mod`) in which the expanded macro was defined.
+    pub parent_module: Option<DefId>,
 }
 
 // These would require special handling of `orig_id`.
@@ -850,13 +846,7 @@ pub enum ExpnKind {
     /// No expansion, aka root expansion. Only `ExpnId::root()` has this kind.
     Root,
     /// Expansion produced by a macro.
-    Macro {
-        kind: MacroKind,
-        name: Symbol,
-        /// If `true`, this macro is a procedural macro. This
-        /// flag is only used for diagnostic purposes
-        proc_macro: bool,
-    },
+    Macro(MacroKind, Symbol),
     /// Transform done by the compiler on the AST.
     AstPass(AstPass),
     /// Desugaring done by the compiler during HIR lowering.
@@ -869,7 +859,7 @@ impl ExpnKind {
     pub fn descr(&self) -> String {
         match *self {
             ExpnKind::Root => kw::PathRoot.to_string(),
-            ExpnKind::Macro { kind, name, proc_macro: _ } => match kind {
+            ExpnKind::Macro(macro_kind, name) => match macro_kind {
                 MacroKind::Bang => format!("{}!", name),
                 MacroKind::Attr => format!("#[{}]", name),
                 MacroKind::Derive => format!("#[derive({})]", name),
diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs
index 6265470e625..84bef4b113c 100644
--- a/compiler/rustc_span/src/lib.rs
+++ b/compiler/rustc_span/src/lib.rs
@@ -520,10 +520,7 @@ impl Span {
 
     /// Returns `true` if `span` originates in a derive-macro's expansion.
     pub fn in_derive_expansion(self) -> bool {
-        matches!(
-            self.ctxt().outer_expn_data().kind,
-            ExpnKind::Macro { kind: MacroKind::Derive, name: _, proc_macro: _ }
-        )
+        matches!(self.ctxt().outer_expn_data().kind, ExpnKind::Macro(MacroKind::Derive, _))
     }
 
     #[inline]