mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
Restrict access to crate_name.
Also remove original_crate_name, which had the exact same implementation
This commit is contained in:
parent
5d9f96ab27
commit
10fb4b2fe5
@ -524,7 +524,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
}
|
||||
|
||||
fn path_crate(self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
|
||||
Ok(vec![self.tcx.original_crate_name(cnum).to_string()])
|
||||
Ok(vec![self.tcx.crate_name(cnum).to_string()])
|
||||
}
|
||||
fn path_qualified(
|
||||
self,
|
||||
|
@ -922,7 +922,7 @@ impl<'tcx> LateContext<'tcx> {
|
||||
}
|
||||
|
||||
fn path_crate(self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
|
||||
Ok(vec![self.tcx.original_crate_name(cnum)])
|
||||
Ok(vec![self.tcx.crate_name(cnum)])
|
||||
}
|
||||
|
||||
fn path_qualified(
|
||||
|
@ -187,7 +187,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
|
||||
foreign_modules => { cdata.get_foreign_modules(tcx) }
|
||||
crate_hash => { cdata.root.hash }
|
||||
crate_host_hash => { cdata.host_hash }
|
||||
original_crate_name => { cdata.root.name }
|
||||
crate_name => { cdata.root.name }
|
||||
|
||||
extra_filename => { cdata.root.extra_filename.clone() }
|
||||
|
||||
@ -204,7 +204,6 @@ provide! { <'tcx> tcx, def_id, other, cdata,
|
||||
let r = *cdata.dep_kind.lock();
|
||||
r
|
||||
}
|
||||
crate_name => { cdata.root.name }
|
||||
item_children => {
|
||||
let mut result = SmallVec::<[_; 8]>::new();
|
||||
cdata.each_child_of_item(def_id.index, |child| result.push(child), tcx.sess);
|
||||
|
@ -1673,7 +1673,7 @@ impl EncodeContext<'a, 'tcx> {
|
||||
.iter()
|
||||
.map(|&cnum| {
|
||||
let dep = CrateDep {
|
||||
name: self.tcx.original_crate_name(cnum),
|
||||
name: self.tcx.crate_name(cnum),
|
||||
hash: self.tcx.crate_hash(cnum),
|
||||
host_hash: self.tcx.crate_host_hash(cnum),
|
||||
kind: self.tcx.dep_kind(cnum),
|
||||
|
@ -285,7 +285,7 @@ pub type DepNode = rustc_query_system::dep_graph::DepNode<DepKind>;
|
||||
// required that their size stay the same, but we don't want to change
|
||||
// it inadvertently. This assert just ensures we're aware of any change.
|
||||
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
||||
static_assert_size!(DepNode, 18);
|
||||
static_assert_size!(DepNode, 17);
|
||||
|
||||
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
|
||||
static_assert_size!(DepNode, 24);
|
||||
|
@ -49,7 +49,7 @@ impl<'tcx> ExportedSymbol<'tcx> {
|
||||
pub fn metadata_symbol_name(tcx: TyCtxt<'_>) -> String {
|
||||
format!(
|
||||
"rust_metadata_{}_{:08x}",
|
||||
tcx.original_crate_name(LOCAL_CRATE),
|
||||
tcx.crate_name(LOCAL_CRATE),
|
||||
tcx.sess.local_stable_crate_id().to_u64(),
|
||||
)
|
||||
}
|
||||
|
@ -1252,10 +1252,6 @@ rustc_queries! {
|
||||
eval_always
|
||||
desc { "looking up the hash of a host version of a crate" }
|
||||
}
|
||||
query original_crate_name(_: CrateNum) -> Symbol {
|
||||
eval_always
|
||||
desc { "looking up the original name a crate" }
|
||||
}
|
||||
query extra_filename(_: CrateNum) -> String {
|
||||
eval_always
|
||||
desc { "looking up the extra filename for a crate" }
|
||||
|
@ -985,7 +985,7 @@ pub struct GlobalCtxt<'tcx> {
|
||||
|
||||
/// The definite name of the current crate after taking into account
|
||||
/// attributes, commandline parameters, etc.
|
||||
pub crate_name: Symbol,
|
||||
crate_name: Symbol,
|
||||
|
||||
/// Data layout specification for the current target.
|
||||
pub data_layout: TargetDataLayout,
|
||||
|
@ -1619,7 +1619,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
|
||||
fn item_name_from_def_id(self, def_id: DefId) -> Option<Symbol> {
|
||||
if def_id.index == CRATE_DEF_INDEX {
|
||||
Some(self.original_crate_name(def_id.krate))
|
||||
Some(self.crate_name(def_id.krate))
|
||||
} else {
|
||||
let def_key = self.def_key(def_id);
|
||||
match def_key.disambiguated_data.data {
|
||||
|
@ -452,7 +452,7 @@ pub trait PrettyPrinter<'tcx>:
|
||||
}
|
||||
// Re-exported `extern crate` (#43189).
|
||||
DefPathData::CrateRoot => {
|
||||
data = DefPathData::TypeNs(self.tcx().original_crate_name(def_id.krate));
|
||||
data = DefPathData::TypeNs(self.tcx().crate_name(def_id.krate));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
|
||||
}
|
||||
|
||||
fn path_crate(mut self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
|
||||
self.path.push_str(&self.tcx.original_crate_name(cnum).as_str());
|
||||
self.path.push_str(&self.tcx.crate_name(cnum).as_str());
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
|
||||
|
||||
match def_key.disambiguated_data.data {
|
||||
DefPathData::CrateRoot => {
|
||||
crate_name = self.tcx.original_crate_name(def_id.krate).as_str();
|
||||
crate_name = self.tcx.crate_name(def_id.krate).as_str();
|
||||
name = &*crate_name;
|
||||
dis = "";
|
||||
end_index = 3;
|
||||
|
@ -254,7 +254,7 @@ impl Printer<'tcx> for SymbolPrinter<'tcx> {
|
||||
}
|
||||
|
||||
fn path_crate(mut self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
|
||||
self.write_str(&self.tcx.original_crate_name(cnum).as_str())?;
|
||||
self.write_str(&self.tcx.crate_name(cnum).as_str())?;
|
||||
Ok(self)
|
||||
}
|
||||
fn path_qualified(
|
||||
|
@ -594,7 +594,7 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
|
||||
self.push("C");
|
||||
let stable_crate_id = self.tcx.def_path_hash(cnum.as_def_id()).stable_crate_id();
|
||||
self.push_disambiguator(stable_crate_id.to_u64());
|
||||
let name = self.tcx.original_crate_name(cnum).as_str();
|
||||
let name = self.tcx.crate_name(cnum).as_str();
|
||||
self.push_ident(&name);
|
||||
Ok(self)
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ use rustc_infer::infer::InferCtxt;
|
||||
use rustc_middle::ty::{self, TraitRef, Ty, TyCtxt, WithConstness};
|
||||
use rustc_middle::ty::{ToPredicate, TypeFoldable};
|
||||
use rustc_session::DiagnosticMessageId;
|
||||
use rustc_span::def_id::LOCAL_CRATE;
|
||||
use rustc_span::Span;
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
@ -231,7 +232,8 @@ pub fn report_autoderef_recursion_limit_error<'tcx>(tcx: TyCtxt<'tcx>, span: Spa
|
||||
.span_label(span, "deref recursion limit reached")
|
||||
.help(&format!(
|
||||
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate (`{}`)",
|
||||
suggested_limit, tcx.crate_name,
|
||||
suggested_limit,
|
||||
tcx.crate_name(LOCAL_CRATE),
|
||||
))
|
||||
.emit();
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ use rustc_middle::ty::{
|
||||
Infer, InferTy, ToPredicate, Ty, TyCtxt, TypeFoldable, WithConstness,
|
||||
};
|
||||
use rustc_middle::ty::{TypeAndMut, TypeckResults};
|
||||
use rustc_span::def_id::LOCAL_CRATE;
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
use rustc_span::{BytePos, MultiSpan, Span, DUMMY_SP};
|
||||
use rustc_target::spec::abi;
|
||||
@ -2313,7 +2314,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
let suggested_limit = current_limit * 2;
|
||||
err.help(&format!(
|
||||
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate (`{}`)",
|
||||
suggested_limit, self.tcx.crate_name,
|
||||
suggested_limit,
|
||||
self.tcx.crate_name(LOCAL_CRATE),
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,11 @@
|
||||
use rustc_data_structures::fx::FxIndexSet;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_middle::hir::map as hir_map;
|
||||
use rustc_middle::ty::subst::Subst;
|
||||
use rustc_middle::ty::{
|
||||
self, Binder, Predicate, PredicateKind, ToPredicate, Ty, TyCtxt, WithConstness,
|
||||
};
|
||||
use rustc_span::symbol::Symbol;
|
||||
use rustc_span::Span;
|
||||
use rustc_trait_selection::traits;
|
||||
|
||||
@ -388,11 +387,6 @@ fn param_env_reveal_all_normalized(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamE
|
||||
tcx.param_env(def_id).with_reveal_all_normalized(tcx)
|
||||
}
|
||||
|
||||
fn original_crate_name(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Symbol {
|
||||
assert_eq!(crate_num, LOCAL_CRATE);
|
||||
tcx.crate_name
|
||||
}
|
||||
|
||||
fn instance_def_size_estimate<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
instance_def: ty::InstanceDef<'tcx>,
|
||||
@ -538,7 +532,6 @@ pub fn provide(providers: &mut ty::query::Providers) {
|
||||
param_env,
|
||||
param_env_reveal_all_normalized,
|
||||
trait_of_item,
|
||||
original_crate_name,
|
||||
instance_def_size_estimate,
|
||||
issue33140_self_ty,
|
||||
impl_defaultness,
|
||||
|
@ -527,7 +527,7 @@ fn build_static(cx: &mut DocContext<'_>, did: DefId, mutable: bool) -> clean::St
|
||||
}
|
||||
|
||||
fn build_macro(cx: &mut DocContext<'_>, did: DefId, name: Symbol) -> clean::ItemKind {
|
||||
let imported_from = cx.tcx.original_crate_name(did.krate);
|
||||
let imported_from = cx.tcx.crate_name(did.krate);
|
||||
match cx.enter_resolver(|r| r.cstore().load_macro_untracked(did, cx.sess())) {
|
||||
LoadedMacro::MacroDef(def, _) => {
|
||||
let matchers: Vec<Span> = if let ast::ItemKind::MacroDef(ref def) = def.kind {
|
||||
|
@ -9,6 +9,7 @@ use rustc_hir::Node;
|
||||
use rustc_middle::middle::privacy::AccessLevel;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_span;
|
||||
use rustc_span::def_id::LOCAL_CRATE;
|
||||
use rustc_span::source_map::Spanned;
|
||||
use rustc_span::symbol::{kw, sym, Symbol};
|
||||
|
||||
@ -76,7 +77,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||
&Spanned { span, node: hir::VisibilityKind::Public },
|
||||
hir::CRATE_HIR_ID,
|
||||
&krate.item,
|
||||
self.cx.tcx.crate_name,
|
||||
self.cx.tcx.crate_name(LOCAL_CRATE),
|
||||
);
|
||||
// Attach the crate's exported macros to the top-level module.
|
||||
// In the case of macros 2.0 (`pub macro`), and for built-in `derive`s or attributes as
|
||||
|
Loading…
Reference in New Issue
Block a user