]> git.lizzy.rs Git - rust.git/blob - src/libsyntax_ext/lib.rs
Omit 'missing IndexMut impl' suggestion when IndexMut is implemented.
[rust.git] / src / libsyntax_ext / lib.rs
1 // Copyright 2015 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 //! Syntax extensions in the Rust compiler.
12
13 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
14        html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
15        html_root_url = "https://doc.rust-lang.org/nightly/")]
16
17 #![feature(proc_macro_internals)]
18 #![feature(decl_macro)]
19 #![cfg_attr(not(stage0), feature(nll))]
20 #![cfg_attr(not(stage0), feature(infer_outlives_requirements))]
21 #![feature(str_escape)]
22
23 #![feature(rustc_diagnostic_macros)]
24
25 extern crate fmt_macros;
26 #[macro_use]
27 extern crate syntax;
28 extern crate syntax_pos;
29 extern crate proc_macro;
30 extern crate rustc_data_structures;
31 extern crate rustc_errors as errors;
32 extern crate rustc_target;
33 #[macro_use]
34 extern crate smallvec;
35
36 mod diagnostics;
37
38 #[macro_use]
39 // for custom_derive
40 pub mod deriving;
41
42 mod asm;
43 mod assert;
44 mod cfg;
45 mod compile_error;
46 mod concat;
47 mod concat_idents;
48 mod env;
49 mod format;
50 mod format_foreign;
51 mod global_asm;
52 mod log_syntax;
53 mod trace_macros;
54
55 pub mod proc_macro_registrar;
56
57
58 pub mod proc_macro_impl;
59
60 use rustc_data_structures::sync::Lrc;
61 use syntax::ast;
62 use syntax::ext::base::{MacroExpanderFn, NormalTT, NamedSyntaxExtension};
63 use syntax::ext::hygiene;
64 use syntax::symbol::Symbol;
65
66 pub fn register_builtins(resolver: &mut dyn syntax::ext::base::Resolver,
67                          user_exts: Vec<NamedSyntaxExtension>,
68                          enable_quotes: bool) {
69     deriving::register_builtin_derives(resolver);
70
71     let mut register = |name, ext| {
72         resolver.add_builtin(ast::Ident::with_empty_ctxt(name), Lrc::new(ext));
73     };
74
75     macro_rules! register {
76         ($( $name:ident: $f:expr, )*) => { $(
77             register(Symbol::intern(stringify!($name)),
78                      NormalTT {
79                         expander: Box::new($f as MacroExpanderFn),
80                         def_info: None,
81                         allow_internal_unstable: false,
82                         allow_internal_unsafe: false,
83                         local_inner_macros: false,
84                         unstable_feature: None,
85                         edition: hygiene::default_edition(),
86                     });
87         )* }
88     }
89
90     if enable_quotes {
91         use syntax::ext::quote::*;
92         register! {
93             quote_tokens: expand_quote_tokens,
94             quote_expr: expand_quote_expr,
95             quote_ty: expand_quote_ty,
96             quote_item: expand_quote_item,
97             quote_pat: expand_quote_pat,
98             quote_arm: expand_quote_arm,
99             quote_stmt: expand_quote_stmt,
100             quote_attr: expand_quote_attr,
101             quote_arg: expand_quote_arg,
102             quote_block: expand_quote_block,
103             quote_meta_item: expand_quote_meta_item,
104             quote_path: expand_quote_path,
105         }
106     }
107
108     use syntax::ext::source_util::*;
109     register! {
110         line: expand_line,
111         __rust_unstable_column: expand_column_gated,
112         column: expand_column,
113         file: expand_file,
114         stringify: expand_stringify,
115         include: expand_include,
116         include_str: expand_include_str,
117         include_bytes: expand_include_bytes,
118         module_path: expand_mod,
119
120         asm: asm::expand_asm,
121         global_asm: global_asm::expand_global_asm,
122         cfg: cfg::expand_cfg,
123         concat: concat::expand_syntax_ext,
124         concat_idents: concat_idents::expand_syntax_ext,
125         env: env::expand_env,
126         option_env: env::expand_option_env,
127         log_syntax: log_syntax::expand_syntax_ext,
128         trace_macros: trace_macros::expand_trace_macros,
129         compile_error: compile_error::expand_compile_error,
130         assert: assert::expand_assert,
131     }
132
133     // format_args uses `unstable` things internally.
134     register(Symbol::intern("format_args"),
135              NormalTT {
136                 expander: Box::new(format::expand_format_args),
137                 def_info: None,
138                 allow_internal_unstable: true,
139                 allow_internal_unsafe: false,
140                 local_inner_macros: false,
141                 unstable_feature: None,
142                 edition: hygiene::default_edition(),
143             });
144     register(Symbol::intern("format_args_nl"),
145              NormalTT {
146                  expander: Box::new(format::expand_format_args_nl),
147                  def_info: None,
148                  allow_internal_unstable: true,
149                  allow_internal_unsafe: false,
150                  local_inner_macros: false,
151                  unstable_feature: None,
152                  edition: hygiene::default_edition(),
153              });
154
155     for (name, ext) in user_exts {
156         register(name, ext);
157     }
158 }