Eliminate `CrateMetadataRef`. There are a number of things I dislike about `CrateMetadataRef`. - It contains two fields `cstore` and `cdata`. The latter points to data within the former. It's like having an `Elem` type that has a reference to a vec element and also a reference to the vec itself. Weird. - The `cdata` field gets a lot of use, and the `Deref` impl just derefs that field. The `cstore` field is rarely used. - `CrateMetadataRef` is not a good name. - Variables named `cdata` sometimes refer to values of this type and sometimes to values of type `CrateMetadata`, which is confusing. The good news is that `CrateMetadataRef` is not necessary and can be replaced with `&CrateMetadata`. Why? Everywhere that `CrateMetadataRef` is used, a `TyCtxt` is also present, and the `CStore` is accessible from the `TyCtxt` with `CStore::from_tcx`. So this commit removes `CrateMetadataRef` and replaces all its uses with `&CrateMetadata`. Notes: - This requires adding only two uses of `CStore::from_tcx`, which shows how rarely the `cstore` field was used. - `get_crate_data` now matches `get_crate_data_mut` more closely. - A few variables are renamed for consistency, e.g. `data`/`cmeta` -> `cdata`. - An unnecessary local variable (`local_cdata`) in `decode_expn_id` is removed. - All the `CrateMetadataRef` methods become `CrateMetadata` methods, and their receiver changes from `self` to `&self`. - `RawDefId::decode_from_cdata` is inlined and removed, because it has a single call site.
Website | Getting started | Learn | Documentation | Contributing
This is the main source code repository for Rust. It contains the compiler, standard library, and documentation.
Performance: Fast and memory-efficient, suitable for critical services, embedded devices, and easily integrated with other languages.
Reliability: Our rich type system and ownership model ensure memory and thread safety, reducing bugs at compile-time.
Productivity: Comprehensive documentation, a compiler committed to providing great diagnostics, and advanced tooling including package manager and build tool (Cargo), auto-formatter (rustfmt), linter (Clippy) and editor support (rust-analyzer).
Read “Installation” from The Book.
If you really want to install from source (though this is not recommended), see INSTALL.md.
See https://www.rust-lang.org/community for a list of chat platforms and forums.
See CONTRIBUTING.md.
For a detailed explanation of the compiler's architecture and how to begin contributing, see the rustc-dev-guide.
Rust is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0), with portions covered by various BSD-like licenses.
See LICENSE-APACHE, LICENSE-MIT, and COPYRIGHT for details.
The Rust Foundation owns and protects the Rust and Cargo trademarks and logos (the “Rust Trademarks”).
If you want to use these names or brands, please read the Rust language trademark policy.
Third-party logos may be subject to third-party copyrights and trademarks. See Licenses for details.