Skip to content

Commit c57393e

Browse files
committed
Auto merge of #114852 - GuillaumeGomez:rollup-vjagxjr, r=GuillaumeGomez
Rollup of 10 pull requests Successful merges: - #114711 (Infer `Lld::No` linker hint when the linker stem is a generic compiler driver) - #114772 (Add `{Local}ModDefId` to more strongly type DefIds`) - #114800 (std: add some missing repr(transparent)) - #114820 (Add test for unknown_lints from another file.) - #114825 (Upgrade std to gimli 0.28.0) - #114827 (Only consider object candidates for object-safe dyn types in new solver) - #114828 (Probe when assembling upcast candidates so they don't step on eachother's toes in new solver) - #114829 (Separate `consider_unsize_to_dyn_candidate` from other unsize candidates) - #114830 (Clean up some bad UI testing annotations) - #114831 (Check projection args before substitution in new solver) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4f4dae0 + 31a4131 commit c57393e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+574
-228
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+2-17
Original file line numberDiff line numberDiff line change
@@ -2991,25 +2991,10 @@ fn add_lld_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
29912991
return;
29922992
}
29932993

2994-
let self_contained_linker = sess.opts.cg.link_self_contained.linker();
2995-
2996-
// FIXME: some targets default to using `lld`, but users can only override the linker on the CLI
2997-
// and cannot yet select the precise linker flavor to opt out of that. See for example issue
2998-
// #113597 for the `thumbv6m-none-eabi` target: a driver is used, and its default linker
2999-
// conflicts with the target's flavor, causing unexpected arguments being passed.
3000-
//
3001-
// Until the new `LinkerFlavor`-like CLI options are stabilized, we only adopt MCP510's behavior
3002-
// if its dedicated unstable CLI flags are used, to keep the current sub-optimal stable
3003-
// behavior.
3004-
let using_mcp510 =
3005-
self_contained_linker || sess.opts.cg.linker_flavor.is_some_and(|f| f.is_unstable());
3006-
if !using_mcp510 && !unstable_use_lld {
3007-
return;
3008-
}
3009-
30102994
// 1. Implement the "self-contained" part of this feature by adding rustc distribution
30112995
// directories to the tool's search path.
3012-
if self_contained_linker || unstable_use_lld {
2996+
let self_contained_linker = sess.opts.cg.link_self_contained.linker() || unstable_use_lld;
2997+
if self_contained_linker {
30132998
for path in sess.get_tools_search_paths(false) {
30142999
cmd.arg({
30153000
let mut arg = OsString::from("-B");

compiler/rustc_hir_analysis/src/check/check.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_attr as attr;
88
use rustc_errors::{Applicability, ErrorGuaranteed, MultiSpan};
99
use rustc_hir as hir;
1010
use rustc_hir::def::{CtorKind, DefKind, Res};
11-
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
11+
use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId};
1212
use rustc_hir::intravisit::Visitor;
1313
use rustc_hir::{ItemKind, Node, PathSegment};
1414
use rustc_infer::infer::opaque_types::ConstrainOpaqueTypeRegionVisitor;
@@ -1443,12 +1443,12 @@ pub(super) fn check_type_params_are_used<'tcx>(
14431443
}
14441444
}
14451445

1446-
pub(super) fn check_mod_item_types(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
1446+
pub(super) fn check_mod_item_types(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
14471447
let module = tcx.hir_module_items(module_def_id);
14481448
for id in module.items() {
14491449
check_item_type(tcx, id);
14501450
}
1451-
if module_def_id == CRATE_DEF_ID {
1451+
if module_def_id == LocalModDefId::CRATE_DEF_ID {
14521452
super::entry::check_for_entry_fn(tcx);
14531453
}
14541454
}

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_ast as ast;
55
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
66
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed};
77
use rustc_hir as hir;
8-
use rustc_hir::def_id::{DefId, LocalDefId};
8+
use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId};
99
use rustc_hir::lang_items::LangItem;
1010
use rustc_hir::ItemKind;
1111
use rustc_infer::infer::outlives::env::{OutlivesEnvironment, RegionBoundPairs};
@@ -1854,7 +1854,7 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
18541854
}
18551855
}
18561856

1857-
fn check_mod_type_wf(tcx: TyCtxt<'_>, module: LocalDefId) {
1857+
fn check_mod_type_wf(tcx: TyCtxt<'_>, module: LocalModDefId) {
18581858
let items = tcx.hir_module_items(module);
18591859
items.par_items(|item| tcx.ensure().check_well_formed(item.owner_id));
18601860
items.par_impl_items(|item| tcx.ensure().check_well_formed(item.owner_id));

compiler/rustc_hir_analysis/src/collect.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc_data_structures::captures::Captures;
2222
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
2323
use rustc_errors::{Applicability, DiagnosticBuilder, ErrorGuaranteed, StashKey};
2424
use rustc_hir as hir;
25-
use rustc_hir::def_id::{DefId, LocalDefId};
25+
use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId};
2626
use rustc_hir::intravisit::{self, Visitor};
2727
use rustc_hir::{GenericParamKind, Node};
2828
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
@@ -48,7 +48,7 @@ mod type_of;
4848
///////////////////////////////////////////////////////////////////////////
4949
// Main entry point
5050

51-
fn collect_mod_item_types(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
51+
fn collect_mod_item_types(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
5252
tcx.hir().visit_item_likes_in_module(module_def_id, &mut CollectItemTypesVisitor { tcx });
5353
}
5454

compiler/rustc_hir_analysis/src/impl_wf_check.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use min_specialization::check_min_specialization;
1414
use rustc_data_structures::fx::FxHashSet;
1515
use rustc_errors::struct_span_err;
1616
use rustc_hir::def::DefKind;
17-
use rustc_hir::def_id::LocalDefId;
17+
use rustc_hir::def_id::{LocalDefId, LocalModDefId};
1818
use rustc_middle::query::Providers;
1919
use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt};
2020
use rustc_span::{Span, Symbol};
@@ -51,7 +51,7 @@ mod min_specialization;
5151
/// impl<'a> Trait<Foo> for Bar { type X = &'a i32; }
5252
/// // ^ 'a is unused and appears in assoc type, error
5353
/// ```
54-
fn check_mod_impl_wf(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
54+
fn check_mod_impl_wf(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
5555
let min_specialization = tcx.features().min_specialization;
5656
let module = tcx.hir_module_items(module_def_id);
5757
for id in module.items() {

compiler/rustc_lint/src/late.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_ast as ast;
1919
use rustc_data_structures::stack::ensure_sufficient_stack;
2020
use rustc_data_structures::sync::join;
2121
use rustc_hir as hir;
22-
use rustc_hir::def_id::LocalDefId;
22+
use rustc_hir::def_id::{LocalDefId, LocalModDefId};
2323
use rustc_hir::intravisit as hir_visit;
2424
use rustc_hir::intravisit::Visitor;
2525
use rustc_middle::hir::nested_filter;
@@ -338,7 +338,7 @@ crate::late_lint_methods!(impl_late_lint_pass, []);
338338

339339
pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
340340
tcx: TyCtxt<'tcx>,
341-
module_def_id: LocalDefId,
341+
module_def_id: LocalModDefId,
342342
builtin_lints: T,
343343
) {
344344
let context = LateContext {
@@ -369,7 +369,7 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
369369

370370
fn late_lint_mod_inner<'tcx, T: LateLintPass<'tcx>>(
371371
tcx: TyCtxt<'tcx>,
372-
module_def_id: LocalDefId,
372+
module_def_id: LocalModDefId,
373373
context: LateContext<'tcx>,
374374
pass: T,
375375
) {

compiler/rustc_lint/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ use rustc_ast as ast;
9090
use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage};
9191
use rustc_fluent_macro::fluent_messages;
9292
use rustc_hir as hir;
93-
use rustc_hir::def_id::LocalDefId;
93+
use rustc_hir::def_id::{LocalDefId, LocalModDefId};
9494
use rustc_middle::query::Providers;
9595
use rustc_middle::ty::TyCtxt;
9696
use rustc_session::lint::builtin::{
@@ -145,7 +145,7 @@ pub fn provide(providers: &mut Providers) {
145145
*providers = Providers { lint_mod, ..*providers };
146146
}
147147

148-
fn lint_mod(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
148+
fn lint_mod(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
149149
late_lint_mod(tcx, module_def_id, BuiltinCombinedModuleLateLintPass::new());
150150
}
151151

compiler/rustc_middle/src/dep_graph/dep_node.rs

+51-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ use crate::mir::mono::MonoItem;
6060
use crate::ty::TyCtxt;
6161

6262
use rustc_data_structures::fingerprint::Fingerprint;
63-
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
63+
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LocalModDefId, ModDefId, LOCAL_CRATE};
6464
use rustc_hir::definitions::DefPathHash;
6565
use rustc_hir::{HirId, ItemLocalId, OwnerId};
6666
use rustc_query_system::dep_graph::FingerprintStyle;
@@ -387,3 +387,53 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for HirId {
387387
}
388388
}
389389
}
390+
391+
macro_rules! impl_for_typed_def_id {
392+
($Name:ident, $LocalName:ident) => {
393+
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for $Name {
394+
#[inline(always)]
395+
fn fingerprint_style() -> FingerprintStyle {
396+
FingerprintStyle::DefPathHash
397+
}
398+
399+
#[inline(always)]
400+
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
401+
self.to_def_id().to_fingerprint(tcx)
402+
}
403+
404+
#[inline(always)]
405+
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
406+
self.to_def_id().to_debug_str(tcx)
407+
}
408+
409+
#[inline(always)]
410+
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
411+
DefId::recover(tcx, dep_node).map($Name::new_unchecked)
412+
}
413+
}
414+
415+
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for $LocalName {
416+
#[inline(always)]
417+
fn fingerprint_style() -> FingerprintStyle {
418+
FingerprintStyle::DefPathHash
419+
}
420+
421+
#[inline(always)]
422+
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
423+
self.to_def_id().to_fingerprint(tcx)
424+
}
425+
426+
#[inline(always)]
427+
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
428+
self.to_def_id().to_debug_str(tcx)
429+
}
430+
431+
#[inline(always)]
432+
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
433+
LocalDefId::recover(tcx, dep_node).map($LocalName::new_unchecked)
434+
}
435+
}
436+
};
437+
}
438+
439+
impl_for_typed_def_id! { ModDefId, LocalModDefId }

compiler/rustc_middle/src/hir/map/mod.rs

+15-13
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
88
use rustc_data_structures::svh::Svh;
99
use rustc_data_structures::sync::{par_for_each_in, DynSend, DynSync};
1010
use rustc_hir::def::{DefKind, Res};
11-
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID, LOCAL_CRATE};
11+
use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId, LOCAL_CRATE};
1212
use rustc_hir::definitions::{DefKey, DefPath, DefPathData, DefPathHash};
1313
use rustc_hir::intravisit::{self, Visitor};
1414
use rustc_hir::*;
@@ -148,7 +148,7 @@ impl<'hir> Map<'hir> {
148148
}
149149

150150
#[inline]
151-
pub fn module_items(self, module: LocalDefId) -> impl Iterator<Item = ItemId> + 'hir {
151+
pub fn module_items(self, module: LocalModDefId) -> impl Iterator<Item = ItemId> + 'hir {
152152
self.tcx.hir_module_items(module).items()
153153
}
154154

@@ -169,8 +169,8 @@ impl<'hir> Map<'hir> {
169169
}
170170

171171
#[inline]
172-
pub fn local_def_id_to_hir_id(self, def_id: LocalDefId) -> HirId {
173-
self.tcx.local_def_id_to_hir_id(def_id)
172+
pub fn local_def_id_to_hir_id(self, def_id: impl Into<LocalDefId>) -> HirId {
173+
self.tcx.local_def_id_to_hir_id(def_id.into())
174174
}
175175

176176
/// Do not call this function directly. The query should be called.
@@ -529,8 +529,8 @@ impl<'hir> Map<'hir> {
529529
self.krate_attrs().iter().any(|attr| attr.has_name(sym::rustc_coherence_is_core))
530530
}
531531

532-
pub fn get_module(self, module: LocalDefId) -> (&'hir Mod<'hir>, Span, HirId) {
533-
let hir_id = HirId::make_owner(module);
532+
pub fn get_module(self, module: LocalModDefId) -> (&'hir Mod<'hir>, Span, HirId) {
533+
let hir_id = HirId::make_owner(module.to_local_def_id());
534534
match self.tcx.hir_owner(hir_id.owner).map(|o| o.node) {
535535
Some(OwnerNode::Item(&Item { span, kind: ItemKind::Mod(ref m), .. })) => {
536536
(m, span, hir_id)
@@ -542,7 +542,7 @@ impl<'hir> Map<'hir> {
542542

543543
/// Walks the contents of the local crate. See also `visit_all_item_likes_in_crate`.
544544
pub fn walk_toplevel_module(self, visitor: &mut impl Visitor<'hir>) {
545-
let (top_mod, span, hir_id) = self.get_module(CRATE_DEF_ID);
545+
let (top_mod, span, hir_id) = self.get_module(LocalModDefId::CRATE_DEF_ID);
546546
visitor.visit_mod(top_mod, span, hir_id);
547547
}
548548

@@ -595,7 +595,7 @@ impl<'hir> Map<'hir> {
595595

596596
/// This method is the equivalent of `visit_all_item_likes_in_crate` but restricted to
597597
/// item-likes in a single module.
598-
pub fn visit_item_likes_in_module<V>(self, module: LocalDefId, visitor: &mut V)
598+
pub fn visit_item_likes_in_module<V>(self, module: LocalModDefId, visitor: &mut V)
599599
where
600600
V: Visitor<'hir>,
601601
{
@@ -618,17 +618,19 @@ impl<'hir> Map<'hir> {
618618
}
619619
}
620620

621-
pub fn for_each_module(self, mut f: impl FnMut(LocalDefId)) {
621+
pub fn for_each_module(self, mut f: impl FnMut(LocalModDefId)) {
622622
let crate_items = self.tcx.hir_crate_items(());
623623
for module in crate_items.submodules.iter() {
624-
f(module.def_id)
624+
f(LocalModDefId::new_unchecked(module.def_id))
625625
}
626626
}
627627

628628
#[inline]
629-
pub fn par_for_each_module(self, f: impl Fn(LocalDefId) + DynSend + DynSync) {
629+
pub fn par_for_each_module(self, f: impl Fn(LocalModDefId) + DynSend + DynSync) {
630630
let crate_items = self.tcx.hir_crate_items(());
631-
par_for_each_in(&crate_items.submodules[..], |module| f(module.def_id))
631+
par_for_each_in(&crate_items.submodules[..], |module| {
632+
f(LocalModDefId::new_unchecked(module.def_id))
633+
})
632634
}
633635

634636
/// Returns an iterator for the nodes in the ancestor tree of the `current_id`
@@ -1324,7 +1326,7 @@ fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
13241326
}
13251327
}
13261328

1327-
pub(super) fn hir_module_items(tcx: TyCtxt<'_>, module_id: LocalDefId) -> ModuleItems {
1329+
pub(super) fn hir_module_items(tcx: TyCtxt<'_>, module_id: LocalModDefId) -> ModuleItems {
13281330
let mut collector = ItemCollector::new(tcx, false);
13291331

13301332
let (hir_mod, span, hir_id) = tcx.hir().get_module(module_id);

compiler/rustc_middle/src/hir/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::ty::{EarlyBinder, ImplSubject, TyCtxt};
1111
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1212
use rustc_data_structures::sync::{par_for_each_in, DynSend, DynSync};
1313
use rustc_hir::def::DefKind;
14-
use rustc_hir::def_id::{DefId, LocalDefId};
14+
use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId};
1515
use rustc_hir::*;
1616
use rustc_query_system::ich::StableHashingContext;
1717
use rustc_span::{ExpnId, DUMMY_SP};
@@ -101,22 +101,22 @@ impl<'tcx> TyCtxt<'tcx> {
101101
map::Map { tcx: self }
102102
}
103103

104-
pub fn parent_module(self, id: HirId) -> LocalDefId {
104+
pub fn parent_module(self, id: HirId) -> LocalModDefId {
105105
if !id.is_owner() && self.def_kind(id.owner) == DefKind::Mod {
106-
id.owner.def_id
106+
LocalModDefId::new_unchecked(id.owner.def_id)
107107
} else {
108108
self.parent_module_from_def_id(id.owner.def_id)
109109
}
110110
}
111111

112-
pub fn parent_module_from_def_id(self, mut id: LocalDefId) -> LocalDefId {
112+
pub fn parent_module_from_def_id(self, mut id: LocalDefId) -> LocalModDefId {
113113
while let Some(parent) = self.opt_local_parent(id) {
114114
id = parent;
115115
if self.def_kind(id) == DefKind::Mod {
116116
break;
117117
}
118118
}
119-
id
119+
LocalModDefId::new_unchecked(id)
120120
}
121121

122122
pub fn impl_subject(self, def_id: DefId) -> EarlyBinder<ImplSubject<'tcx>> {

compiler/rustc_middle/src/query/erase.rs

+1
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ trivial! {
235235
rustc_hir::def_id::DefId,
236236
rustc_hir::def_id::DefIndex,
237237
rustc_hir::def_id::LocalDefId,
238+
rustc_hir::def_id::LocalModDefId,
238239
rustc_hir::def::DefKind,
239240
rustc_hir::Defaultness,
240241
rustc_hir::definitions::DefKey,

compiler/rustc_middle/src/query/keys.rs

+36-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::ty::fast_reject::SimplifiedType;
88
use crate::ty::layout::{TyAndLayout, ValidityRequirement};
99
use crate::ty::{self, Ty, TyCtxt};
1010
use crate::ty::{GenericArg, GenericArgsRef};
11-
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
11+
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LocalModDefId, ModDefId, LOCAL_CRATE};
1212
use rustc_hir::hir_id::{HirId, OwnerId};
1313
use rustc_query_system::query::{DefaultCacheSelector, SingleCacheSelector, VecCacheSelector};
1414
use rustc_span::symbol::{Ident, Symbol};
@@ -175,6 +175,41 @@ impl AsLocalKey for DefId {
175175
}
176176
}
177177

178+
impl Key for LocalModDefId {
179+
type CacheSelector = DefaultCacheSelector<Self>;
180+
181+
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
182+
tcx.def_span(*self)
183+
}
184+
185+
#[inline(always)]
186+
fn key_as_def_id(&self) -> Option<DefId> {
187+
Some(self.to_def_id())
188+
}
189+
}
190+
191+
impl Key for ModDefId {
192+
type CacheSelector = DefaultCacheSelector<Self>;
193+
194+
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
195+
tcx.def_span(*self)
196+
}
197+
198+
#[inline(always)]
199+
fn key_as_def_id(&self) -> Option<DefId> {
200+
Some(self.to_def_id())
201+
}
202+
}
203+
204+
impl AsLocalKey for ModDefId {
205+
type LocalKey = LocalModDefId;
206+
207+
#[inline(always)]
208+
fn as_local_key(&self) -> Option<Self::LocalKey> {
209+
self.as_local()
210+
}
211+
}
212+
178213
impl Key for SimplifiedType {
179214
type CacheSelector = DefaultCacheSelector<Self>;
180215

0 commit comments

Comments
 (0)