diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2018-05-03 13:51:34 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-03 13:51:34 -0400 |
commit | 9b8ddae646f942df3d82e6e68f335c0ce106b0e9 (patch) | |
tree | f43a726b3e0820fcf2aea04b354a6cdfec2eb11d /src/codegen/mod.rs | |
parent | af54e58a8c2e513ba8c3cc00c22aa958de091a53 (diff) | |
parent | 786ed31d471ba01a30343efdc6b341959801b939 (diff) |
Auto merge of #1308 - emilio:per-module-lines, r=fitzgen
Add an option to add lines per module.
Fixes #1307
Diffstat (limited to 'src/codegen/mod.rs')
-rw-r--r-- | src/codegen/mod.rs | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 04e28db2..fd48ff2b 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -422,6 +422,18 @@ impl CodeGenerator for Module { let mut found_any = false; let inner_items = result.inner(|result| { result.push(root_import(ctx, item)); + + let path = item.namespace_aware_canonical_path(ctx).join("::"); + if let Some(raw_lines) = ctx.options().module_lines.get(&path) { + for raw_line in raw_lines { + found_any = true; + // FIXME(emilio): The use of `Term` is an abuse, but we abuse it + // in a bunch more places. + let line = Term::new(raw_line, Span::call_site()); + result.push(quote! { #line }); + } + } + codegen_self(result, &mut found_any); }); @@ -431,16 +443,15 @@ impl CodeGenerator for Module { } let name = item.canonical_name(ctx); - - result.push(if name == "root" { + let ident = ctx.rust_ident(name); + result.push(if item.id() == ctx.root_module() { quote! { #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] - pub mod root { + pub mod #ident { #( #inner_items )* } } } else { - let ident = ctx.rust_ident(name); quote! { pub mod #ident { #( #inner_items )* |