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