expand: Micro-optimize prelude injection

Use `splice` to avoid shifting the other items twice.
Put `extern crate std;` first so it's already resolved when we resolve `::std::prelude::rust_20XX`.
This commit is contained in:
Vadim Petrochenkov
2025-07-28 17:24:28 +03:00
parent 65b6cdb6a6
commit c56f49dc34
53 changed files with 105 additions and 107 deletions

View File

@@ -47,8 +47,6 @@ pub fn inject(
ast::ItemKind::ExternCrate(None, Ident::new(name, ident_span)),
);
krate.items.insert(0, item);
let root = (edition == Edition2015).then_some(kw::PathRoot);
let import_path = root
@@ -75,6 +73,6 @@ pub fn inject(
}),
);
krate.items.insert(0, use_item);
krate.items.splice(0..0, [item, use_item]);
krate.items.len() - orig_num_items
}