Skip to content

Commit c209aef

Browse files
committed
codegen: Actually honor the new option for module_lines.
Only when modules are enabled of course.
1 parent 7129d89 commit c209aef

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/codegen/mod.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,18 @@ impl CodeGenerator for Module {
422422
let mut found_any = false;
423423
let inner_items = result.inner(|result| {
424424
result.push(root_import(ctx, item));
425+
426+
let path = item.namespace_aware_canonical_path(ctx).join("::");
427+
if let Some(raw_lines) = ctx.options().module_lines.get(&path) {
428+
for raw_line in raw_lines {
429+
found_any = true;
430+
// FIXME(emilio): The use of `Term` is an abuse, but we abuse it
431+
// in a bunch more places.
432+
let line = Term::new(raw_line, Span::call_site());
433+
result.push(quote! { #line });
434+
}
435+
}
436+
425437
codegen_self(result, &mut found_any);
426438
});
427439

@@ -431,16 +443,15 @@ impl CodeGenerator for Module {
431443
}
432444

433445
let name = item.canonical_name(ctx);
434-
435-
result.push(if name == "root" {
446+
let ident = ctx.rust_ident(name);
447+
result.push(if item.id() == ctx.root_module() {
436448
quote! {
437449
#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)]
438-
pub mod root {
450+
pub mod #ident {
439451
#( #inner_items )*
440452
}
441453
}
442454
} else {
443-
let ident = ctx.rust_ident(name);
444455
quote! {
445456
pub mod #ident {
446457
#( #inner_items )*

0 commit comments

Comments
 (0)