Skip to content

Commit dbe459d

Browse files
committed
Auto merge of #85904 - cjgillot:one-name, r=petrochenkov
Restrict access to crate_name. Also remove original_crate_name, which had the exact same implementation. Part of #85153
2 parents 2f601ef + 0e71283 commit dbe459d

File tree

19 files changed

+23
-30
lines changed

19 files changed

+23
-30
lines changed

Diff for: compiler/rustc_infer/src/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
524524
}
525525

526526
fn path_crate(self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
527-
Ok(vec![self.tcx.original_crate_name(cnum).to_string()])
527+
Ok(vec![self.tcx.crate_name(cnum).to_string()])
528528
}
529529
fn path_qualified(
530530
self,

Diff for: compiler/rustc_lint/src/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ impl<'tcx> LateContext<'tcx> {
922922
}
923923

924924
fn path_crate(self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
925-
Ok(vec![self.tcx.original_crate_name(cnum)])
925+
Ok(vec![self.tcx.crate_name(cnum)])
926926
}
927927

928928
fn path_qualified(

Diff for: compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
188188
foreign_modules => { cdata.get_foreign_modules(tcx) }
189189
crate_hash => { cdata.root.hash }
190190
crate_host_hash => { cdata.host_hash }
191-
original_crate_name => { cdata.root.name }
191+
crate_name => { cdata.root.name }
192192

193193
extra_filename => { cdata.root.extra_filename.clone() }
194194

@@ -205,7 +205,6 @@ provide! { <'tcx> tcx, def_id, other, cdata,
205205
let r = *cdata.dep_kind.lock();
206206
r
207207
}
208-
crate_name => { cdata.root.name }
209208
item_children => {
210209
let mut result = SmallVec::<[_; 8]>::new();
211210
cdata.each_child_of_item(def_id.index, |child| result.push(child), tcx.sess);

Diff for: compiler/rustc_metadata/src/rmeta/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1673,7 +1673,7 @@ impl EncodeContext<'a, 'tcx> {
16731673
.iter()
16741674
.map(|&cnum| {
16751675
let dep = CrateDep {
1676-
name: self.tcx.original_crate_name(cnum),
1676+
name: self.tcx.crate_name(cnum),
16771677
hash: self.tcx.crate_hash(cnum),
16781678
host_hash: self.tcx.crate_host_hash(cnum),
16791679
kind: self.tcx.dep_kind(cnum),

Diff for: compiler/rustc_middle/src/dep_graph/dep_node.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ pub type DepNode = rustc_query_system::dep_graph::DepNode<DepKind>;
285285
// required that their size stay the same, but we don't want to change
286286
// it inadvertently. This assert just ensures we're aware of any change.
287287
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
288-
static_assert_size!(DepNode, 18);
288+
static_assert_size!(DepNode, 17);
289289

290290
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
291291
static_assert_size!(DepNode, 24);

Diff for: compiler/rustc_middle/src/middle/exported_symbols.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl<'tcx> ExportedSymbol<'tcx> {
4949
pub fn metadata_symbol_name(tcx: TyCtxt<'_>) -> String {
5050
format!(
5151
"rust_metadata_{}_{:08x}",
52-
tcx.original_crate_name(LOCAL_CRATE),
52+
tcx.crate_name(LOCAL_CRATE),
5353
tcx.sess.local_stable_crate_id().to_u64(),
5454
)
5555
}

Diff for: compiler/rustc_middle/src/query/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1247,10 +1247,6 @@ rustc_queries! {
12471247
eval_always
12481248
desc { "looking up the hash of a host version of a crate" }
12491249
}
1250-
query original_crate_name(_: CrateNum) -> Symbol {
1251-
eval_always
1252-
desc { "looking up the original name a crate" }
1253-
}
12541250
query extra_filename(_: CrateNum) -> String {
12551251
eval_always
12561252
desc { "looking up the extra filename for a crate" }

Diff for: compiler/rustc_middle/src/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ pub struct GlobalCtxt<'tcx> {
10051005

10061006
/// The definite name of the current crate after taking into account
10071007
/// attributes, commandline parameters, etc.
1008-
pub crate_name: Symbol,
1008+
crate_name: Symbol,
10091009

10101010
/// Data layout specification for the current target.
10111011
pub data_layout: TargetDataLayout,

Diff for: compiler/rustc_middle/src/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1621,7 +1621,7 @@ impl<'tcx> TyCtxt<'tcx> {
16211621

16221622
fn item_name_from_def_id(self, def_id: DefId) -> Option<Symbol> {
16231623
if def_id.index == CRATE_DEF_INDEX {
1624-
Some(self.original_crate_name(def_id.krate))
1624+
Some(self.crate_name(def_id.krate))
16251625
} else {
16261626
let def_key = self.def_key(def_id);
16271627
match def_key.disambiguated_data.data {

Diff for: compiler/rustc_middle/src/ty/print/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ pub trait PrettyPrinter<'tcx>:
452452
}
453453
// Re-exported `extern crate` (#43189).
454454
DefPathData::CrateRoot => {
455-
data = DefPathData::TypeNs(self.tcx().original_crate_name(def_id.krate));
455+
data = DefPathData::TypeNs(self.tcx().crate_name(def_id.krate));
456456
}
457457
_ => {}
458458
}

Diff for: compiler/rustc_mir/src/interpret/intrinsics/type_name.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
8888
}
8989

9090
fn path_crate(mut self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
91-
self.path.push_str(&self.tcx.original_crate_name(cnum).as_str());
91+
self.path.push_str(&self.tcx.crate_name(cnum).as_str());
9292
Ok(self)
9393
}
9494

Diff for: compiler/rustc_query_impl/src/profiling_support.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
6161

6262
match def_key.disambiguated_data.data {
6363
DefPathData::CrateRoot => {
64-
crate_name = self.tcx.original_crate_name(def_id.krate).as_str();
64+
crate_name = self.tcx.crate_name(def_id.krate).as_str();
6565
name = &*crate_name;
6666
dis = "";
6767
end_index = 3;

Diff for: compiler/rustc_symbol_mangling/src/legacy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ impl Printer<'tcx> for SymbolPrinter<'tcx> {
254254
}
255255

256256
fn path_crate(mut self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
257-
self.write_str(&self.tcx.original_crate_name(cnum).as_str())?;
257+
self.write_str(&self.tcx.crate_name(cnum).as_str())?;
258258
Ok(self)
259259
}
260260
fn path_qualified(

Diff for: compiler/rustc_symbol_mangling/src/v0.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
594594
self.push("C");
595595
let stable_crate_id = self.tcx.def_path_hash(cnum.as_def_id()).stable_crate_id();
596596
self.push_disambiguator(stable_crate_id.to_u64());
597-
let name = self.tcx.original_crate_name(cnum).as_str();
597+
let name = self.tcx.crate_name(cnum).as_str();
598598
self.push_ident(&name);
599599
Ok(self)
600600
}

Diff for: compiler/rustc_trait_selection/src/autoderef.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc_infer::infer::InferCtxt;
66
use rustc_middle::ty::{self, TraitRef, Ty, TyCtxt, WithConstness};
77
use rustc_middle::ty::{ToPredicate, TypeFoldable};
88
use rustc_session::DiagnosticMessageId;
9+
use rustc_span::def_id::LOCAL_CRATE;
910
use rustc_span::Span;
1011

1112
#[derive(Copy, Clone, Debug)]
@@ -231,7 +232,8 @@ pub fn report_autoderef_recursion_limit_error<'tcx>(tcx: TyCtxt<'tcx>, span: Spa
231232
.span_label(span, "deref recursion limit reached")
232233
.help(&format!(
233234
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate (`{}`)",
234-
suggested_limit, tcx.crate_name,
235+
suggested_limit,
236+
tcx.crate_name(LOCAL_CRATE),
235237
))
236238
.emit();
237239
}

Diff for: compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use rustc_middle::ty::{
2121
Infer, InferTy, ToPredicate, Ty, TyCtxt, TypeFoldable, WithConstness,
2222
};
2323
use rustc_middle::ty::{TypeAndMut, TypeckResults};
24+
use rustc_span::def_id::LOCAL_CRATE;
2425
use rustc_span::symbol::{kw, sym, Ident, Symbol};
2526
use rustc_span::{BytePos, MultiSpan, Span, DUMMY_SP};
2627
use rustc_target::spec::abi;
@@ -2313,7 +2314,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
23132314
let suggested_limit = current_limit * 2;
23142315
err.help(&format!(
23152316
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate (`{}`)",
2316-
suggested_limit, self.tcx.crate_name,
2317+
suggested_limit,
2318+
self.tcx.crate_name(LOCAL_CRATE),
23172319
));
23182320
}
23192321

Diff for: compiler/rustc_ty_utils/src/ty.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use rustc_data_structures::fx::FxIndexSet;
22
use rustc_hir as hir;
3-
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
3+
use rustc_hir::def_id::{DefId, LocalDefId};
44
use rustc_middle::hir::map as hir_map;
55
use rustc_middle::ty::subst::Subst;
66
use rustc_middle::ty::{
77
self, Binder, Predicate, PredicateKind, ToPredicate, Ty, TyCtxt, WithConstness,
88
};
9-
use rustc_span::symbol::Symbol;
109
use rustc_span::Span;
1110
use rustc_trait_selection::traits;
1211

@@ -388,11 +387,6 @@ fn param_env_reveal_all_normalized(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamE
388387
tcx.param_env(def_id).with_reveal_all_normalized(tcx)
389388
}
390389

391-
fn original_crate_name(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Symbol {
392-
assert_eq!(crate_num, LOCAL_CRATE);
393-
tcx.crate_name
394-
}
395-
396390
fn instance_def_size_estimate<'tcx>(
397391
tcx: TyCtxt<'tcx>,
398392
instance_def: ty::InstanceDef<'tcx>,
@@ -538,7 +532,6 @@ pub fn provide(providers: &mut ty::query::Providers) {
538532
param_env,
539533
param_env_reveal_all_normalized,
540534
trait_of_item,
541-
original_crate_name,
542535
instance_def_size_estimate,
543536
issue33140_self_ty,
544537
impl_defaultness,

Diff for: src/librustdoc/clean/inline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ fn build_static(cx: &mut DocContext<'_>, did: DefId, mutable: bool) -> clean::St
527527
}
528528

529529
fn build_macro(cx: &mut DocContext<'_>, did: DefId, name: Symbol) -> clean::ItemKind {
530-
let imported_from = cx.tcx.original_crate_name(did.krate);
530+
let imported_from = cx.tcx.crate_name(did.krate);
531531
match cx.enter_resolver(|r| r.cstore().load_macro_untracked(did, cx.sess())) {
532532
LoadedMacro::MacroDef(def, _) => {
533533
let matchers: Vec<Span> = if let ast::ItemKind::MacroDef(ref def) = def.kind {

Diff for: src/librustdoc/visit_ast.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_hir::Node;
99
use rustc_middle::middle::privacy::AccessLevel;
1010
use rustc_middle::ty::TyCtxt;
1111
use rustc_span;
12+
use rustc_span::def_id::LOCAL_CRATE;
1213
use rustc_span::source_map::Spanned;
1314
use rustc_span::symbol::{kw, sym, Symbol};
1415

@@ -76,7 +77,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
7677
&Spanned { span, node: hir::VisibilityKind::Public },
7778
hir::CRATE_HIR_ID,
7879
&krate.item,
79-
self.cx.tcx.crate_name,
80+
self.cx.tcx.crate_name(LOCAL_CRATE),
8081
);
8182
// Attach the crate's exported macros to the top-level module.
8283
// In the case of macros 2.0 (`pub macro`), and for built-in `derive`s or attributes as

0 commit comments

Comments
 (0)