Skip to content

Commit e843d86

Browse files
committed
rustc_metadata: Crate loader is immutable
1 parent 2805553 commit e843d86

File tree

3 files changed

+22
-32
lines changed

3 files changed

+22
-32
lines changed

src/librustc_interface/passes.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,15 @@ pub fn configure_and_expand(
130130
let crate_name = crate_name.to_string();
131131
let (result, resolver) = BoxedResolver::new(static move || {
132132
let sess = &*sess;
133-
let mut crate_loader = CrateLoader::new(sess, &*cstore, &crate_name);
133+
let crate_loader = CrateLoader::new(sess, &*cstore, &crate_name);
134134
let resolver_arenas = Resolver::arenas();
135135
let res = configure_and_expand_inner(
136136
sess,
137137
&*cstore,
138138
krate,
139139
&crate_name,
140140
&resolver_arenas,
141-
&mut crate_loader,
141+
&crate_loader,
142142
plugin_info,
143143
);
144144
let mut resolver = match res {
@@ -319,7 +319,7 @@ fn configure_and_expand_inner<'a>(
319319
mut krate: ast::Crate,
320320
crate_name: &str,
321321
resolver_arenas: &'a ResolverArenas<'a>,
322-
crate_loader: &'a mut CrateLoader<'a>,
322+
crate_loader: &'a CrateLoader<'a>,
323323
plugin_info: PluginInfo,
324324
) -> Result<(ast::Crate, Resolver<'a>)> {
325325
time(sess, "pre-AST-expansion lint checks", || {

src/librustc_metadata/creader.rs

+17-27
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl<'a> CrateLoader<'a> {
187187
}
188188

189189
fn register_crate(
190-
&mut self,
190+
&self,
191191
host_lib: Option<Library>,
192192
root: Option<&CratePaths>,
193193
span: Span,
@@ -272,7 +272,7 @@ impl<'a> CrateLoader<'a> {
272272
}
273273

274274
fn load_proc_macro<'b>(
275-
&mut self,
275+
&self,
276276
locate_ctxt: &mut locator::Context<'b>,
277277
path_kind: PathKind,
278278
) -> Option<(LoadResult, Option<Library>)>
@@ -327,7 +327,7 @@ impl<'a> CrateLoader<'a> {
327327
}
328328

329329
fn resolve_crate<'b>(
330-
&'b mut self,
330+
&'b self,
331331
name: Symbol,
332332
span: Span,
333333
dep_kind: DepKind,
@@ -337,7 +337,7 @@ impl<'a> CrateLoader<'a> {
337337
}
338338

339339
fn maybe_resolve_crate<'b>(
340-
&'b mut self,
340+
&'b self,
341341
name: Symbol,
342342
span: Span,
343343
mut dep_kind: DepKind,
@@ -397,7 +397,7 @@ impl<'a> CrateLoader<'a> {
397397
}
398398
}
399399

400-
fn load(&mut self, locate_ctxt: &mut locator::Context<'_>) -> Option<LoadResult> {
400+
fn load(&self, locate_ctxt: &mut locator::Context<'_>) -> Option<LoadResult> {
401401
let library = locate_ctxt.maybe_load_library_crate()?;
402402

403403
// In the case that we're loading a crate, but not matching
@@ -424,7 +424,7 @@ impl<'a> CrateLoader<'a> {
424424
}
425425
}
426426

427-
fn update_extern_crate(&mut self,
427+
fn update_extern_crate(&self,
428428
cnum: CrateNum,
429429
mut extern_crate: ExternCrate,
430430
visited: &mut FxHashSet<(CrateNum, bool)>)
@@ -466,7 +466,7 @@ impl<'a> CrateLoader<'a> {
466466
}
467467

468468
// Go through the crate metadata and load any crates that it references
469-
fn resolve_crate_deps(&mut self,
469+
fn resolve_crate_deps(&self,
470470
root: &CratePaths,
471471
crate_root: &CrateRoot<'_>,
472472
metadata: &MetadataBlob,
@@ -496,7 +496,7 @@ impl<'a> CrateLoader<'a> {
496496
})).collect()
497497
}
498498

499-
fn read_extension_crate(&mut self, name: Symbol, span: Span) -> ExtensionCrate {
499+
fn read_extension_crate(&self, name: Symbol, span: Span) -> ExtensionCrate {
500500
info!("read extension crate `{}`", name);
501501
let target_triple = self.sess.opts.target_triple.clone();
502502
let host_triple = TargetTriple::from_triple(config::host_triple());
@@ -592,7 +592,7 @@ impl<'a> CrateLoader<'a> {
592592

593593
/// Look for a plugin registrar. Returns library path, crate
594594
/// SVH and DefIndex of the registrar function.
595-
pub fn find_plugin_registrar(&mut self,
595+
pub fn find_plugin_registrar(&self,
596596
span: Span,
597597
name: Symbol)
598598
-> Option<(PathBuf, CrateDisambiguator)> {
@@ -625,7 +625,7 @@ impl<'a> CrateLoader<'a> {
625625
}
626626
}
627627

628-
fn inject_panic_runtime(&mut self, krate: &ast::Crate) {
628+
fn inject_panic_runtime(&self, krate: &ast::Crate) {
629629
// If we're only compiling an rlib, then there's no need to select a
630630
// panic runtime, so we just skip this section entirely.
631631
let any_non_rlib = self.sess.crate_types.borrow().iter().any(|ct| {
@@ -706,7 +706,7 @@ impl<'a> CrateLoader<'a> {
706706
&|data| data.root.needs_panic_runtime);
707707
}
708708

709-
fn inject_sanitizer_runtime(&mut self) {
709+
fn inject_sanitizer_runtime(&self) {
710710
if let Some(ref sanitizer) = self.sess.opts.debugging_opts.sanitizer {
711711
// Sanitizers can only be used on some tested platforms with
712712
// executables linked to `std`
@@ -804,7 +804,7 @@ impl<'a> CrateLoader<'a> {
804804
}
805805
}
806806

807-
fn inject_profiler_runtime(&mut self) {
807+
fn inject_profiler_runtime(&self) {
808808
if self.sess.opts.debugging_opts.profile ||
809809
self.sess.opts.cg.profile_generate.enabled()
810810
{
@@ -821,7 +821,7 @@ impl<'a> CrateLoader<'a> {
821821
}
822822
}
823823

824-
fn inject_allocator_crate(&mut self, krate: &ast::Crate) {
824+
fn inject_allocator_crate(&self, krate: &ast::Crate) {
825825
let has_global_allocator = match &*global_allocator_spans(krate) {
826826
[span1, span2, ..] => {
827827
self.sess.struct_span_err(*span2, "cannot define multiple global allocators")
@@ -960,7 +960,7 @@ impl<'a> CrateLoader<'a> {
960960
}
961961

962962
impl<'a> CrateLoader<'a> {
963-
pub fn postprocess(&mut self, krate: &ast::Crate) {
963+
pub fn postprocess(&self, krate: &ast::Crate) {
964964
self.inject_sanitizer_runtime();
965965
self.inject_profiler_runtime();
966966
self.inject_allocator_crate(krate);
@@ -971,9 +971,7 @@ impl<'a> CrateLoader<'a> {
971971
}
972972
}
973973

974-
pub fn process_extern_crate(
975-
&mut self, item: &ast::Item, definitions: &Definitions,
976-
) -> CrateNum {
974+
pub fn process_extern_crate(&self, item: &ast::Item, definitions: &Definitions) -> CrateNum {
977975
match item.kind {
978976
ast::ItemKind::ExternCrate(orig_name) => {
979977
debug!("resolving extern crate stmt. ident: {} orig_name: {:?}",
@@ -1013,11 +1011,7 @@ impl<'a> CrateLoader<'a> {
10131011
}
10141012
}
10151013

1016-
pub fn process_path_extern(
1017-
&mut self,
1018-
name: Symbol,
1019-
span: Span,
1020-
) -> CrateNum {
1014+
pub fn process_path_extern(&self, name: Symbol, span: Span) -> CrateNum {
10211015
let cnum = self.resolve_crate(name, span, DepKind::Explicit, None).0;
10221016

10231017
self.update_extern_crate(
@@ -1035,11 +1029,7 @@ impl<'a> CrateLoader<'a> {
10351029
cnum
10361030
}
10371031

1038-
pub fn maybe_process_path_extern(
1039-
&mut self,
1040-
name: Symbol,
1041-
span: Span,
1042-
) -> Option<CrateNum> {
1032+
pub fn maybe_process_path_extern(&self, name: Symbol, span: Span) -> Option<CrateNum> {
10431033
let cnum = self.maybe_resolve_crate(name, span, DepKind::Explicit, None).ok()?.0;
10441034

10451035
self.update_extern_crate(

src/librustc_resolve/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ pub struct Resolver<'a> {
900900
arenas: &'a ResolverArenas<'a>,
901901
dummy_binding: &'a NameBinding<'a>,
902902

903-
crate_loader: &'a mut CrateLoader<'a>,
903+
crate_loader: &'a CrateLoader<'a>,
904904
macro_names: FxHashSet<Ident>,
905905
builtin_macros: FxHashMap<Name, SyntaxExtension>,
906906
macro_use_prelude: FxHashMap<Name, &'a NameBinding<'a>>,
@@ -1070,7 +1070,7 @@ impl<'a> Resolver<'a> {
10701070
cstore: &'a CStore,
10711071
krate: &Crate,
10721072
crate_name: &str,
1073-
crate_loader: &'a mut CrateLoader<'a>,
1073+
crate_loader: &'a CrateLoader<'a>,
10741074
arenas: &'a ResolverArenas<'a>)
10751075
-> Resolver<'a> {
10761076
let root_def_id = DefId::local(CRATE_DEF_INDEX);

0 commit comments

Comments
 (0)