]> git.lizzy.rs Git - rust.git/blob - src/libsyntax_pos/hygiene.rs
Rollup merge of #60487 - GuillaumeGomez:fix-search-sidebar-width-colors, r=Dylan-DPC
[rust.git] / src / libsyntax_pos / hygiene.rs
1 //! Machinery for hygienic macros, inspired by the `MTWT[1]` paper.
2 //!
3 //! `[1]` Matthew Flatt, Ryan Culpepper, David Darais, and Robert Bruce Findler. 2012.
4 //! *Macros that work together: Compile-time bindings, partial expansion,
5 //! and definition contexts*. J. Funct. Program. 22, 2 (March 2012), 181-216.
6 //! DOI=10.1017/S0956796812000093 <https://doi.org/10.1017/S0956796812000093>
7
8 use crate::GLOBALS;
9 use crate::Span;
10 use crate::edition::{Edition, DEFAULT_EDITION};
11 use crate::symbol::{keywords, Symbol};
12
13 use serialize::{Encodable, Decodable, Encoder, Decoder};
14 use rustc_data_structures::fx::{FxHashMap, FxHashSet};
15 use rustc_data_structures::sync::Lrc;
16 use std::{fmt, mem};
17
18 /// A SyntaxContext represents a chain of macro expansions (represented by marks).
19 #[derive(Clone, Copy, PartialEq, Eq, Default, PartialOrd, Ord, Hash)]
20 pub struct SyntaxContext(u32);
21
22 #[derive(Copy, Clone, Debug)]
23 struct SyntaxContextData {
24     outer_mark: Mark,
25     transparency: Transparency,
26     prev_ctxt: SyntaxContext,
27     /// This context, but with all transparent and semi-transparent marks filtered away.
28     opaque: SyntaxContext,
29     /// This context, but with all transparent marks filtered away.
30     opaque_and_semitransparent: SyntaxContext,
31     /// Name of the crate to which `$crate` with this context would resolve.
32     dollar_crate_name: Symbol,
33 }
34
35 /// A mark is a unique ID associated with a macro expansion.
36 #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)]
37 pub struct Mark(u32);
38
39 #[derive(Clone, Debug)]
40 struct MarkData {
41     parent: Mark,
42     default_transparency: Transparency,
43     expn_info: Option<ExpnInfo>,
44 }
45
46 /// A property of a macro expansion that determines how identifiers
47 /// produced by that expansion are resolved.
48 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Hash, Debug)]
49 pub enum Transparency {
50     /// Identifier produced by a transparent expansion is always resolved at call-site.
51     /// Call-site spans in procedural macros, hygiene opt-out in `macro` should use this.
52     Transparent,
53     /// Identifier produced by a semi-transparent expansion may be resolved
54     /// either at call-site or at definition-site.
55     /// If it's a local variable, label or `$crate` then it's resolved at def-site.
56     /// Otherwise it's resolved at call-site.
57     /// `macro_rules` macros behave like this, built-in macros currently behave like this too,
58     /// but that's an implementation detail.
59     SemiTransparent,
60     /// Identifier produced by an opaque expansion is always resolved at definition-site.
61     /// Def-site spans in procedural macros, identifiers from `macro` by default use this.
62     Opaque,
63 }
64
65 impl Mark {
66     pub fn fresh(parent: Mark) -> Self {
67         HygieneData::with(|data| {
68             data.marks.push(MarkData {
69                 parent,
70                 // By default expansions behave like `macro_rules`.
71                 default_transparency: Transparency::SemiTransparent,
72                 expn_info: None,
73             });
74             Mark(data.marks.len() as u32 - 1)
75         })
76     }
77
78     /// The mark of the theoretical expansion that generates freshly parsed, unexpanded AST.
79     #[inline]
80     pub fn root() -> Self {
81         Mark(0)
82     }
83
84     #[inline]
85     pub fn as_u32(self) -> u32 {
86         self.0
87     }
88
89     #[inline]
90     pub fn from_u32(raw: u32) -> Mark {
91         Mark(raw)
92     }
93
94     #[inline]
95     pub fn parent(self) -> Mark {
96         HygieneData::with(|data| data.marks[self.0 as usize].parent)
97     }
98
99     #[inline]
100     pub fn expn_info(self) -> Option<ExpnInfo> {
101         HygieneData::with(|data| data.marks[self.0 as usize].expn_info.clone())
102     }
103
104     #[inline]
105     pub fn set_expn_info(self, info: ExpnInfo) {
106         HygieneData::with(|data| data.marks[self.0 as usize].expn_info = Some(info))
107     }
108
109     #[inline]
110     pub fn set_default_transparency(self, transparency: Transparency) {
111         assert_ne!(self, Mark::root());
112         HygieneData::with(|data| data.marks[self.0 as usize].default_transparency = transparency)
113     }
114
115     pub fn is_descendant_of(mut self, ancestor: Mark) -> bool {
116         HygieneData::with(|data| {
117             while self != ancestor {
118                 if self == Mark::root() {
119                     return false;
120                 }
121                 self = data.marks[self.0 as usize].parent;
122             }
123             true
124         })
125     }
126
127     /// Computes a mark such that both input marks are descendants of (or equal to) the returned
128     /// mark. That is, the following holds:
129     ///
130     /// ```rust
131     /// let la = least_ancestor(a, b);
132     /// assert!(a.is_descendant_of(la))
133     /// assert!(b.is_descendant_of(la))
134     /// ```
135     pub fn least_ancestor(mut a: Mark, mut b: Mark) -> Mark {
136         HygieneData::with(|data| {
137             // Compute the path from a to the root
138             let mut a_path = FxHashSet::<Mark>::default();
139             while a != Mark::root() {
140                 a_path.insert(a);
141                 a = data.marks[a.0 as usize].parent;
142             }
143
144             // While the path from b to the root hasn't intersected, move up the tree
145             while !a_path.contains(&b) {
146                 b = data.marks[b.0 as usize].parent;
147             }
148
149             b
150         })
151     }
152
153     // Used for enabling some compatibility fallback in resolve.
154     #[inline]
155     pub fn looks_like_proc_macro_derive(self) -> bool {
156         HygieneData::with(|data| {
157             let mark_data = &data.marks[self.0 as usize];
158             if mark_data.default_transparency == Transparency::Opaque {
159                 if let Some(expn_info) = &mark_data.expn_info {
160                     if let ExpnFormat::MacroAttribute(name) = expn_info.format {
161                         if name.as_str().starts_with("derive(") {
162                             return true;
163                         }
164                     }
165                 }
166             }
167             false
168         })
169     }
170 }
171
172 #[derive(Debug)]
173 crate struct HygieneData {
174     marks: Vec<MarkData>,
175     syntax_contexts: Vec<SyntaxContextData>,
176     markings: FxHashMap<(SyntaxContext, Mark, Transparency), SyntaxContext>,
177     default_edition: Edition,
178 }
179
180 impl HygieneData {
181     crate fn new() -> Self {
182         HygieneData {
183             marks: vec![MarkData {
184                 parent: Mark::root(),
185                 // If the root is opaque, then loops searching for an opaque mark
186                 // will automatically stop after reaching it.
187                 default_transparency: Transparency::Opaque,
188                 expn_info: None,
189             }],
190             syntax_contexts: vec![SyntaxContextData {
191                 outer_mark: Mark::root(),
192                 transparency: Transparency::Opaque,
193                 prev_ctxt: SyntaxContext(0),
194                 opaque: SyntaxContext(0),
195                 opaque_and_semitransparent: SyntaxContext(0),
196                 dollar_crate_name: keywords::DollarCrate.name(),
197             }],
198             markings: FxHashMap::default(),
199             default_edition: DEFAULT_EDITION,
200         }
201     }
202
203     fn with<T, F: FnOnce(&mut HygieneData) -> T>(f: F) -> T {
204         GLOBALS.with(|globals| f(&mut *globals.hygiene_data.borrow_mut()))
205     }
206 }
207
208 pub fn default_edition() -> Edition {
209     HygieneData::with(|data| data.default_edition)
210 }
211
212 pub fn set_default_edition(edition: Edition) {
213     HygieneData::with(|data| data.default_edition = edition);
214 }
215
216 pub fn clear_markings() {
217     HygieneData::with(|data| data.markings = FxHashMap::default());
218 }
219
220 impl SyntaxContext {
221     #[inline]
222     pub const fn empty() -> Self {
223         SyntaxContext(0)
224     }
225
226     #[inline]
227     crate fn as_u32(self) -> u32 {
228         self.0
229     }
230
231     #[inline]
232     crate fn from_u32(raw: u32) -> SyntaxContext {
233         SyntaxContext(raw)
234     }
235
236     // Allocate a new SyntaxContext with the given ExpnInfo. This is used when
237     // deserializing Spans from the incr. comp. cache.
238     // FIXME(mw): This method does not restore MarkData::parent or
239     // SyntaxContextData::prev_ctxt or SyntaxContextData::opaque. These things
240     // don't seem to be used after HIR lowering, so everything should be fine
241     // as long as incremental compilation does not kick in before that.
242     pub fn allocate_directly(expansion_info: ExpnInfo) -> Self {
243         HygieneData::with(|data| {
244             data.marks.push(MarkData {
245                 parent: Mark::root(),
246                 default_transparency: Transparency::SemiTransparent,
247                 expn_info: Some(expansion_info),
248             });
249
250             let mark = Mark(data.marks.len() as u32 - 1);
251
252             data.syntax_contexts.push(SyntaxContextData {
253                 outer_mark: mark,
254                 transparency: Transparency::SemiTransparent,
255                 prev_ctxt: SyntaxContext::empty(),
256                 opaque: SyntaxContext::empty(),
257                 opaque_and_semitransparent: SyntaxContext::empty(),
258                 dollar_crate_name: keywords::DollarCrate.name(),
259             });
260             SyntaxContext(data.syntax_contexts.len() as u32 - 1)
261         })
262     }
263
264     /// Extend a syntax context with a given mark and default transparency for that mark.
265     pub fn apply_mark(self, mark: Mark) -> SyntaxContext {
266         assert_ne!(mark, Mark::root());
267         self.apply_mark_with_transparency(
268             mark, HygieneData::with(|data| data.marks[mark.0 as usize].default_transparency)
269         )
270     }
271
272     /// Extend a syntax context with a given mark and transparency
273     pub fn apply_mark_with_transparency(self, mark: Mark, transparency: Transparency)
274                                         -> SyntaxContext {
275         assert_ne!(mark, Mark::root());
276         if transparency == Transparency::Opaque {
277             return self.apply_mark_internal(mark, transparency);
278         }
279
280         let call_site_ctxt =
281             mark.expn_info().map_or(SyntaxContext::empty(), |info| info.call_site.ctxt());
282         let call_site_ctxt = if transparency == Transparency::SemiTransparent {
283             call_site_ctxt.modern()
284         } else {
285             call_site_ctxt.modern_and_legacy()
286         };
287
288         if call_site_ctxt == SyntaxContext::empty() {
289             return self.apply_mark_internal(mark, transparency);
290         }
291
292         // Otherwise, `mark` is a macros 1.0 definition and the call site is in a
293         // macros 2.0 expansion, i.e., a macros 1.0 invocation is in a macros 2.0 definition.
294         //
295         // In this case, the tokens from the macros 1.0 definition inherit the hygiene
296         // at their invocation. That is, we pretend that the macros 1.0 definition
297         // was defined at its invocation (i.e., inside the macros 2.0 definition)
298         // so that the macros 2.0 definition remains hygienic.
299         //
300         // See the example at `test/run-pass/hygiene/legacy_interaction.rs`.
301         let mut ctxt = call_site_ctxt;
302         for (mark, transparency) in self.marks() {
303             ctxt = ctxt.apply_mark_internal(mark, transparency);
304         }
305         ctxt.apply_mark_internal(mark, transparency)
306     }
307
308     fn apply_mark_internal(self, mark: Mark, transparency: Transparency) -> SyntaxContext {
309         HygieneData::with(|data| {
310             let syntax_contexts = &mut data.syntax_contexts;
311             let mut opaque = syntax_contexts[self.0 as usize].opaque;
312             let mut opaque_and_semitransparent =
313                 syntax_contexts[self.0 as usize].opaque_and_semitransparent;
314
315             if transparency >= Transparency::Opaque {
316                 let prev_ctxt = opaque;
317                 opaque = *data.markings.entry((prev_ctxt, mark, transparency)).or_insert_with(|| {
318                     let new_opaque = SyntaxContext(syntax_contexts.len() as u32);
319                     syntax_contexts.push(SyntaxContextData {
320                         outer_mark: mark,
321                         transparency,
322                         prev_ctxt,
323                         opaque: new_opaque,
324                         opaque_and_semitransparent: new_opaque,
325                         dollar_crate_name: keywords::DollarCrate.name(),
326                     });
327                     new_opaque
328                 });
329             }
330
331             if transparency >= Transparency::SemiTransparent {
332                 let prev_ctxt = opaque_and_semitransparent;
333                 opaque_and_semitransparent =
334                         *data.markings.entry((prev_ctxt, mark, transparency)).or_insert_with(|| {
335                     let new_opaque_and_semitransparent =
336                         SyntaxContext(syntax_contexts.len() as u32);
337                     syntax_contexts.push(SyntaxContextData {
338                         outer_mark: mark,
339                         transparency,
340                         prev_ctxt,
341                         opaque,
342                         opaque_and_semitransparent: new_opaque_and_semitransparent,
343                         dollar_crate_name: keywords::DollarCrate.name(),
344                     });
345                     new_opaque_and_semitransparent
346                 });
347             }
348
349             let prev_ctxt = self;
350             *data.markings.entry((prev_ctxt, mark, transparency)).or_insert_with(|| {
351                 let new_opaque_and_semitransparent_and_transparent =
352                     SyntaxContext(syntax_contexts.len() as u32);
353                 syntax_contexts.push(SyntaxContextData {
354                     outer_mark: mark,
355                     transparency,
356                     prev_ctxt,
357                     opaque,
358                     opaque_and_semitransparent,
359                     dollar_crate_name: keywords::DollarCrate.name(),
360                 });
361                 new_opaque_and_semitransparent_and_transparent
362             })
363         })
364     }
365
366     /// Pulls a single mark off of the syntax context. This effectively moves the
367     /// context up one macro definition level. That is, if we have a nested macro
368     /// definition as follows:
369     ///
370     /// ```rust
371     /// macro_rules! f {
372     ///    macro_rules! g {
373     ///        ...
374     ///    }
375     /// }
376     /// ```
377     ///
378     /// and we have a SyntaxContext that is referring to something declared by an invocation
379     /// of g (call it g1), calling remove_mark will result in the SyntaxContext for the
380     /// invocation of f that created g1.
381     /// Returns the mark that was removed.
382     pub fn remove_mark(&mut self) -> Mark {
383         HygieneData::with(|data| {
384             let outer_mark = data.syntax_contexts[self.0 as usize].outer_mark;
385             *self = data.syntax_contexts[self.0 as usize].prev_ctxt;
386             outer_mark
387         })
388     }
389
390     pub fn marks(mut self) -> Vec<(Mark, Transparency)> {
391         HygieneData::with(|data| {
392             let mut marks = Vec::new();
393             while self != SyntaxContext::empty() {
394                 let ctxt_data = &data.syntax_contexts[self.0 as usize];
395                 marks.push((ctxt_data.outer_mark, ctxt_data.transparency));
396                 self = ctxt_data.prev_ctxt;
397             }
398             marks.reverse();
399             marks
400         })
401     }
402
403     /// Adjust this context for resolution in a scope created by the given expansion.
404     /// For example, consider the following three resolutions of `f`:
405     ///
406     /// ```rust
407     /// mod foo { pub fn f() {} } // `f`'s `SyntaxContext` is empty.
408     /// m!(f);
409     /// macro m($f:ident) {
410     ///     mod bar {
411     ///         pub fn f() {} // `f`'s `SyntaxContext` has a single `Mark` from `m`.
412     ///         pub fn $f() {} // `$f`'s `SyntaxContext` is empty.
413     ///     }
414     ///     foo::f(); // `f`'s `SyntaxContext` has a single `Mark` from `m`
415     ///     //^ Since `mod foo` is outside this expansion, `adjust` removes the mark from `f`,
416     ///     //| and it resolves to `::foo::f`.
417     ///     bar::f(); // `f`'s `SyntaxContext` has a single `Mark` from `m`
418     ///     //^ Since `mod bar` not outside this expansion, `adjust` does not change `f`,
419     ///     //| and it resolves to `::bar::f`.
420     ///     bar::$f(); // `f`'s `SyntaxContext` is empty.
421     ///     //^ Since `mod bar` is not outside this expansion, `adjust` does not change `$f`,
422     ///     //| and it resolves to `::bar::$f`.
423     /// }
424     /// ```
425     /// This returns the expansion whose definition scope we use to privacy check the resolution,
426     /// or `None` if we privacy check as usual (i.e., not w.r.t. a macro definition scope).
427     pub fn adjust(&mut self, expansion: Mark) -> Option<Mark> {
428         let mut scope = None;
429         while !expansion.is_descendant_of(self.outer()) {
430             scope = Some(self.remove_mark());
431         }
432         scope
433     }
434
435     /// Adjust this context for resolution in a scope created by the given expansion
436     /// via a glob import with the given `SyntaxContext`.
437     /// For example:
438     ///
439     /// ```rust
440     /// m!(f);
441     /// macro m($i:ident) {
442     ///     mod foo {
443     ///         pub fn f() {} // `f`'s `SyntaxContext` has a single `Mark` from `m`.
444     ///         pub fn $i() {} // `$i`'s `SyntaxContext` is empty.
445     ///     }
446     ///     n(f);
447     ///     macro n($j:ident) {
448     ///         use foo::*;
449     ///         f(); // `f`'s `SyntaxContext` has a mark from `m` and a mark from `n`
450     ///         //^ `glob_adjust` removes the mark from `n`, so this resolves to `foo::f`.
451     ///         $i(); // `$i`'s `SyntaxContext` has a mark from `n`
452     ///         //^ `glob_adjust` removes the mark from `n`, so this resolves to `foo::$i`.
453     ///         $j(); // `$j`'s `SyntaxContext` has a mark from `m`
454     ///         //^ This cannot be glob-adjusted, so this is a resolution error.
455     ///     }
456     /// }
457     /// ```
458     /// This returns `None` if the context cannot be glob-adjusted.
459     /// Otherwise, it returns the scope to use when privacy checking (see `adjust` for details).
460     pub fn glob_adjust(&mut self, expansion: Mark, mut glob_ctxt: SyntaxContext)
461                        -> Option<Option<Mark>> {
462         let mut scope = None;
463         while !expansion.is_descendant_of(glob_ctxt.outer()) {
464             scope = Some(glob_ctxt.remove_mark());
465             if self.remove_mark() != scope.unwrap() {
466                 return None;
467             }
468         }
469         if self.adjust(expansion).is_some() {
470             return None;
471         }
472         Some(scope)
473     }
474
475     /// Undo `glob_adjust` if possible:
476     ///
477     /// ```rust
478     /// if let Some(privacy_checking_scope) = self.reverse_glob_adjust(expansion, glob_ctxt) {
479     ///     assert!(self.glob_adjust(expansion, glob_ctxt) == Some(privacy_checking_scope));
480     /// }
481     /// ```
482     pub fn reverse_glob_adjust(&mut self, expansion: Mark, mut glob_ctxt: SyntaxContext)
483                                -> Option<Option<Mark>> {
484         if self.adjust(expansion).is_some() {
485             return None;
486         }
487
488         let mut marks = Vec::new();
489         while !expansion.is_descendant_of(glob_ctxt.outer()) {
490             marks.push(glob_ctxt.remove_mark());
491         }
492
493         let scope = marks.last().cloned();
494         while let Some(mark) = marks.pop() {
495             *self = self.apply_mark(mark);
496         }
497         Some(scope)
498     }
499
500     #[inline]
501     pub fn modern(self) -> SyntaxContext {
502         HygieneData::with(|data| data.syntax_contexts[self.0 as usize].opaque)
503     }
504
505     #[inline]
506     pub fn modern_and_legacy(self) -> SyntaxContext {
507         HygieneData::with(|data| data.syntax_contexts[self.0 as usize].opaque_and_semitransparent)
508     }
509
510     #[inline]
511     pub fn outer(self) -> Mark {
512         HygieneData::with(|data| data.syntax_contexts[self.0 as usize].outer_mark)
513     }
514
515     pub fn dollar_crate_name(self) -> Symbol {
516         HygieneData::with(|data| data.syntax_contexts[self.0 as usize].dollar_crate_name)
517     }
518
519     pub fn set_dollar_crate_name(self, dollar_crate_name: Symbol) {
520         HygieneData::with(|data| {
521             let prev_dollar_crate_name = mem::replace(
522                 &mut data.syntax_contexts[self.0 as usize].dollar_crate_name, dollar_crate_name
523             );
524             assert!(dollar_crate_name == prev_dollar_crate_name ||
525                     prev_dollar_crate_name == keywords::DollarCrate.name(),
526                     "$crate name is reset for a syntax context");
527         })
528     }
529 }
530
531 impl fmt::Debug for SyntaxContext {
532     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
533         write!(f, "#{}", self.0)
534     }
535 }
536
537 /// Extra information for tracking spans of macro and syntax sugar expansion
538 #[derive(Clone, Hash, Debug, RustcEncodable, RustcDecodable)]
539 pub struct ExpnInfo {
540     /// The location of the actual macro invocation or syntax sugar , e.g.
541     /// `let x = foo!();` or `if let Some(y) = x {}`
542     ///
543     /// This may recursively refer to other macro invocations, e.g., if
544     /// `foo!()` invoked `bar!()` internally, and there was an
545     /// expression inside `bar!`; the call_site of the expression in
546     /// the expansion would point to the `bar!` invocation; that
547     /// call_site span would have its own ExpnInfo, with the call_site
548     /// pointing to the `foo!` invocation.
549     pub call_site: Span,
550     /// The span of the macro definition itself. The macro may not
551     /// have a sensible definition span (e.g., something defined
552     /// completely inside libsyntax) in which case this is None.
553     /// This span serves only informational purpose and is not used for resolution.
554     pub def_site: Option<Span>,
555     /// The format with which the macro was invoked.
556     pub format: ExpnFormat,
557     /// List of #[unstable]/feature-gated features that the macro is allowed to use
558     /// internally without forcing the whole crate to opt-in
559     /// to them.
560     pub allow_internal_unstable: Option<Lrc<[Symbol]>>,
561     /// Whether the macro is allowed to use `unsafe` internally
562     /// even if the user crate has `#![forbid(unsafe_code)]`.
563     pub allow_internal_unsafe: bool,
564     /// Enables the macro helper hack (`ident!(...)` -> `$crate::ident!(...)`)
565     /// for a given macro.
566     pub local_inner_macros: bool,
567     /// Edition of the crate in which the macro is defined.
568     pub edition: Edition,
569 }
570
571 /// The source of expansion.
572 #[derive(Clone, Hash, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable)]
573 pub enum ExpnFormat {
574     /// e.g., #[derive(...)] <item>
575     MacroAttribute(Symbol),
576     /// e.g., `format!()`
577     MacroBang(Symbol),
578     /// Desugaring done by the compiler during HIR lowering.
579     CompilerDesugaring(CompilerDesugaringKind)
580 }
581
582 impl ExpnFormat {
583     pub fn name(&self) -> Symbol {
584         match *self {
585             ExpnFormat::MacroBang(name) | ExpnFormat::MacroAttribute(name) => name,
586             ExpnFormat::CompilerDesugaring(kind) => kind.name(),
587         }
588     }
589 }
590
591 /// The kind of compiler desugaring.
592 #[derive(Clone, Copy, Hash, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable)]
593 pub enum CompilerDesugaringKind {
594     /// We desugar `if c { i } else { e }` to `match $ExprKind::Use(c) { true => i, _ => e }`.
595     /// However, we do not want to blame `c` for unreachability but rather say that `i`
596     /// is unreachable. This desugaring kind allows us to avoid blaming `c`.
597     IfTemporary,
598     QuestionMark,
599     TryBlock,
600     /// Desugaring of an `impl Trait` in return type position
601     /// to an `existential type Foo: Trait;` and replacing the
602     /// `impl Trait` with `Foo`.
603     ExistentialReturnType,
604     Async,
605     Await,
606     ForLoop,
607 }
608
609 impl CompilerDesugaringKind {
610     pub fn name(self) -> Symbol {
611         Symbol::intern(match self {
612             CompilerDesugaringKind::IfTemporary => "if",
613             CompilerDesugaringKind::Async => "async",
614             CompilerDesugaringKind::Await => "await",
615             CompilerDesugaringKind::QuestionMark => "?",
616             CompilerDesugaringKind::TryBlock => "try block",
617             CompilerDesugaringKind::ExistentialReturnType => "existential type",
618             CompilerDesugaringKind::ForLoop => "for loop",
619         })
620     }
621 }
622
623 impl Encodable for SyntaxContext {
624     fn encode<E: Encoder>(&self, _: &mut E) -> Result<(), E::Error> {
625         Ok(()) // FIXME(jseyfried) intercrate hygiene
626     }
627 }
628
629 impl Decodable for SyntaxContext {
630     fn decode<D: Decoder>(_: &mut D) -> Result<SyntaxContext, D::Error> {
631         Ok(SyntaxContext::empty()) // FIXME(jseyfried) intercrate hygiene
632     }
633 }