Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e02ab69

Browse files
authoredAug 23, 2024
Unrolled build for rust-lang#129386
Rollup merge of rust-lang#129386 - cjgillot:local-resolved-arg, r=compiler-errors Use a LocalDefId in ResolvedArg.
2 parents b5723af + c51f2d2 commit e02ab69

File tree

9 files changed

+58
-55
lines changed

9 files changed

+58
-55
lines changed
 

‎compiler/rustc_hir_analysis/src/check/check.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ fn check_opaque_precise_captures<'tcx>(tcx: TyCtxt<'tcx>, opaque_def_id: LocalDe
529529

530530
match tcx.named_bound_var(hir_id) {
531531
Some(ResolvedArg::EarlyBound(def_id)) => {
532-
expected_captures.insert(def_id);
532+
expected_captures.insert(def_id.to_def_id());
533533

534534
// Make sure we allow capturing these lifetimes through `Self` and
535535
// `T::Assoc` projection syntax, too. These will occur when we only
@@ -538,7 +538,7 @@ fn check_opaque_precise_captures<'tcx>(tcx: TyCtxt<'tcx>, opaque_def_id: LocalDe
538538
// feature -- see <https://github.com/rust-lang/rust/pull/115659>.
539539
if let DefKind::LifetimeParam = tcx.def_kind(def_id)
540540
&& let Some(def_id) = tcx
541-
.map_opaque_lifetime_to_parent_lifetime(def_id.expect_local())
541+
.map_opaque_lifetime_to_parent_lifetime(def_id)
542542
.opt_param_def_id(tcx, tcx.parent(opaque_def_id.to_def_id()))
543543
{
544544
shadowed_captures.insert(def_id);

‎compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+13-14
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use rustc_ast::visit::walk_list;
1313
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
1414
use rustc_hir as hir;
1515
use rustc_hir::def::{DefKind, Res};
16-
use rustc_hir::def_id::LocalDefId;
1716
use rustc_hir::intravisit::{self, Visitor};
1817
use rustc_hir::{GenericArg, GenericParam, GenericParamKind, HirId, HirIdMap, LifetimeName, Node};
1918
use rustc_macros::extension;
@@ -22,7 +21,7 @@ use rustc_middle::middle::resolve_bound_vars::*;
2221
use rustc_middle::query::Providers;
2322
use rustc_middle::ty::{self, TyCtxt, TypeSuperVisitable, TypeVisitor};
2423
use rustc_middle::{bug, span_bug};
25-
use rustc_span::def_id::DefId;
24+
use rustc_span::def_id::{DefId, LocalDefId};
2625
use rustc_span::symbol::{sym, Ident};
2726
use rustc_span::Span;
2827

@@ -32,7 +31,7 @@ use crate::errors;
3231
impl ResolvedArg {
3332
fn early(param: &GenericParam<'_>) -> (LocalDefId, ResolvedArg) {
3433
debug!("ResolvedArg::early: def_id={:?}", param.def_id);
35-
(param.def_id, ResolvedArg::EarlyBound(param.def_id.to_def_id()))
34+
(param.def_id, ResolvedArg::EarlyBound(param.def_id))
3635
}
3736

3837
fn late(idx: u32, param: &GenericParam<'_>) -> (LocalDefId, ResolvedArg) {
@@ -41,10 +40,10 @@ impl ResolvedArg {
4140
"ResolvedArg::late: idx={:?}, param={:?} depth={:?} def_id={:?}",
4241
idx, param, depth, param.def_id,
4342
);
44-
(param.def_id, ResolvedArg::LateBound(depth, idx, param.def_id.to_def_id()))
43+
(param.def_id, ResolvedArg::LateBound(depth, idx, param.def_id))
4544
}
4645

47-
fn id(&self) -> Option<DefId> {
46+
fn id(&self) -> Option<LocalDefId> {
4847
match *self {
4948
ResolvedArg::StaticLifetime | ResolvedArg::Error(_) => None,
5049

@@ -288,13 +287,14 @@ fn late_arg_as_bound_arg<'tcx>(
288287
) -> ty::BoundVariableKind {
289288
match arg {
290289
ResolvedArg::LateBound(_, _, def_id) => {
291-
let name = tcx.hir().name(tcx.local_def_id_to_hir_id(def_id.expect_local()));
290+
let def_id = def_id.to_def_id();
291+
let name = tcx.item_name(def_id);
292292
match param.kind {
293293
GenericParamKind::Lifetime { .. } => {
294-
ty::BoundVariableKind::Region(ty::BrNamed(*def_id, name))
294+
ty::BoundVariableKind::Region(ty::BrNamed(def_id, name))
295295
}
296296
GenericParamKind::Type { .. } => {
297-
ty::BoundVariableKind::Ty(ty::BoundTyKind::Param(*def_id, name))
297+
ty::BoundVariableKind::Ty(ty::BoundTyKind::Param(def_id, name))
298298
}
299299
GenericParamKind::Const { .. } => ty::BoundVariableKind::Const,
300300
}
@@ -717,7 +717,6 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
717717
// In the future, this should be fixed and this error should be removed.
718718
let def = self.map.defs.get(&lifetime.hir_id).copied();
719719
let Some(ResolvedArg::LateBound(_, _, lifetime_def_id)) = def else { continue };
720-
let Some(lifetime_def_id) = lifetime_def_id.as_local() else { continue };
721720
let lifetime_hir_id = self.tcx.local_def_id_to_hir_id(lifetime_def_id);
722721

723722
let bad_place = match self.tcx.hir_node(self.tcx.parent_hir_id(lifetime_hir_id))
@@ -1150,7 +1149,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
11501149
.param_def_id_to_index(self.tcx, region_def_id.to_def_id())
11511150
.is_some()
11521151
{
1153-
break Some(ResolvedArg::EarlyBound(region_def_id.to_def_id()));
1152+
break Some(ResolvedArg::EarlyBound(region_def_id));
11541153
}
11551154
break None;
11561155
}
@@ -1259,7 +1258,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
12591258
kind => span_bug!(
12601259
use_span,
12611260
"did not expect to resolve lifetime to {}",
1262-
kind.descr(param_def_id)
1261+
kind.descr(param_def_id.to_def_id())
12631262
),
12641263
};
12651264
def = ResolvedArg::Error(guar);
@@ -1277,10 +1276,10 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
12771276
kind: hir::ImplItemKind::Fn(..),
12781277
..
12791278
}) => {
1280-
def = ResolvedArg::Free(owner_id.to_def_id(), def.id().unwrap());
1279+
def = ResolvedArg::Free(owner_id.def_id, def.id().unwrap());
12811280
}
12821281
Node::Expr(hir::Expr { kind: hir::ExprKind::Closure(closure), .. }) => {
1283-
def = ResolvedArg::Free(closure.def_id.to_def_id(), def.id().unwrap());
1282+
def = ResolvedArg::Free(closure.def_id, def.id().unwrap());
12841283
}
12851284
_ => {}
12861285
}
@@ -1351,7 +1350,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
13511350
.param_def_id_to_index(self.tcx, param_def_id.to_def_id())
13521351
.is_some()
13531352
{
1354-
break Some(ResolvedArg::EarlyBound(param_def_id.to_def_id()));
1353+
break Some(ResolvedArg::EarlyBound(param_def_id));
13551354
}
13561355
break None;
13571356
}

‎compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

+16-13
Original file line numberDiff line numberDiff line change
@@ -296,25 +296,29 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
296296
Some(rbv::ResolvedArg::StaticLifetime) => tcx.lifetimes.re_static,
297297

298298
Some(rbv::ResolvedArg::LateBound(debruijn, index, def_id)) => {
299-
let name = lifetime_name(def_id.expect_local());
299+
let name = lifetime_name(def_id);
300300
let br = ty::BoundRegion {
301301
var: ty::BoundVar::from_u32(index),
302-
kind: ty::BrNamed(def_id, name),
302+
kind: ty::BrNamed(def_id.to_def_id(), name),
303303
};
304304
ty::Region::new_bound(tcx, debruijn, br)
305305
}
306306

307307
Some(rbv::ResolvedArg::EarlyBound(def_id)) => {
308-
let name = tcx.hir().ty_param_name(def_id.expect_local());
309-
let item_def_id = tcx.hir().ty_param_owner(def_id.expect_local());
308+
let name = tcx.hir().ty_param_name(def_id);
309+
let item_def_id = tcx.hir().ty_param_owner(def_id);
310310
let generics = tcx.generics_of(item_def_id);
311-
let index = generics.param_def_id_to_index[&def_id];
311+
let index = generics.param_def_id_to_index[&def_id.to_def_id()];
312312
ty::Region::new_early_param(tcx, ty::EarlyParamRegion { index, name })
313313
}
314314

315315
Some(rbv::ResolvedArg::Free(scope, id)) => {
316-
let name = lifetime_name(id.expect_local());
317-
ty::Region::new_late_param(tcx, scope, ty::BrNamed(id, name))
316+
let name = lifetime_name(id);
317+
ty::Region::new_late_param(
318+
tcx,
319+
scope.to_def_id(),
320+
ty::BrNamed(id.to_def_id(), name),
321+
)
318322

319323
// (*) -- not late-bound, won't change
320324
}
@@ -1953,15 +1957,14 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
19531957
let tcx = self.tcx();
19541958
match tcx.named_bound_var(hir_id) {
19551959
Some(rbv::ResolvedArg::LateBound(debruijn, index, def_id)) => {
1956-
let name = tcx.item_name(def_id);
1960+
let name = tcx.item_name(def_id.to_def_id());
19571961
let br = ty::BoundTy {
19581962
var: ty::BoundVar::from_u32(index),
1959-
kind: ty::BoundTyKind::Param(def_id, name),
1963+
kind: ty::BoundTyKind::Param(def_id.to_def_id(), name),
19601964
};
19611965
Ty::new_bound(tcx, debruijn, br)
19621966
}
19631967
Some(rbv::ResolvedArg::EarlyBound(def_id)) => {
1964-
let def_id = def_id.expect_local();
19651968
let item_def_id = tcx.hir().ty_param_owner(def_id);
19661969
let generics = tcx.generics_of(item_def_id);
19671970
let index = generics.param_def_id_to_index[&def_id.to_def_id()];
@@ -1982,10 +1985,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
19821985
Some(rbv::ResolvedArg::EarlyBound(def_id)) => {
19831986
// Find the name and index of the const parameter by indexing the generics of
19841987
// the parent item and construct a `ParamConst`.
1985-
let item_def_id = tcx.parent(def_id);
1988+
let item_def_id = tcx.local_parent(def_id);
19861989
let generics = tcx.generics_of(item_def_id);
1987-
let index = generics.param_def_id_to_index[&def_id];
1988-
let name = tcx.item_name(def_id);
1990+
let index = generics.param_def_id_to_index[&def_id.to_def_id()];
1991+
let name = tcx.item_name(def_id.to_def_id());
19891992
ty::Const::new_param(tcx, ty::ParamConst::new(index, name))
19901993
}
19911994
Some(rbv::ResolvedArg::LateBound(debruijn, index, _)) => {

‎compiler/rustc_lint/src/builtin.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1925,16 +1925,16 @@ impl ExplicitOutlivesRequirements {
19251925
fn lifetimes_outliving_lifetime<'tcx>(
19261926
tcx: TyCtxt<'tcx>,
19271927
inferred_outlives: impl Iterator<Item = &'tcx (ty::Clause<'tcx>, Span)>,
1928-
item: DefId,
1929-
lifetime: DefId,
1928+
item: LocalDefId,
1929+
lifetime: LocalDefId,
19301930
) -> Vec<ty::Region<'tcx>> {
19311931
let item_generics = tcx.generics_of(item);
19321932

19331933
inferred_outlives
19341934
.filter_map(|(clause, _)| match clause.kind().skip_binder() {
19351935
ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(a, b)) => match *a {
19361936
ty::ReEarlyParam(ebr)
1937-
if item_generics.region_param(ebr, tcx).def_id == lifetime =>
1937+
if item_generics.region_param(ebr, tcx).def_id == lifetime.to_def_id() =>
19381938
{
19391939
Some(b)
19401940
}
@@ -1982,7 +1982,7 @@ impl ExplicitOutlivesRequirements {
19821982
let is_inferred = match tcx.named_bound_var(lifetime.hir_id) {
19831983
Some(ResolvedArg::EarlyBound(def_id)) => inferred_outlives
19841984
.iter()
1985-
.any(|r| matches!(**r, ty::ReEarlyParam(ebr) if { item_generics.region_param(ebr, tcx).def_id == def_id })),
1985+
.any(|r| matches!(**r, ty::ReEarlyParam(ebr) if { item_generics.region_param(ebr, tcx).def_id == def_id.to_def_id() })),
19861986
_ => false,
19871987
};
19881988

@@ -2097,7 +2097,7 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
20972097
inferred_outlives
20982098
.iter()
20992099
.filter(|(_, span)| !predicate.span.contains(*span)),
2100-
item.owner_id.to_def_id(),
2100+
item.owner_id.def_id,
21012101
region_def_id,
21022102
),
21032103
&predicate.bounds,

‎compiler/rustc_lint/src/impl_trait_overcaptures.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -300,16 +300,17 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for VisitOpaqueTypes<'tcx> {
300300
Some(
301301
ResolvedArg::EarlyBound(def_id) | ResolvedArg::LateBound(_, _, def_id),
302302
) => {
303-
if self.tcx.def_kind(self.tcx.parent(def_id)) == DefKind::OpaqueTy {
303+
if self.tcx.def_kind(self.tcx.local_parent(def_id)) == DefKind::OpaqueTy
304+
{
304305
let def_id = self
305306
.tcx
306-
.map_opaque_lifetime_to_parent_lifetime(def_id.expect_local())
307+
.map_opaque_lifetime_to_parent_lifetime(def_id)
307308
.opt_param_def_id(self.tcx, self.parent_def_id.to_def_id())
308309
.expect("variable should have been duplicated from parent");
309310

310311
explicitly_captured.insert(def_id);
311312
} else {
312-
explicitly_captured.insert(def_id);
313+
explicitly_captured.insert(def_id.to_def_id());
313314
}
314315
}
315316
_ => {

‎compiler/rustc_middle/src/middle/resolve_bound_vars.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use rustc_data_structures::fx::FxIndexMap;
44
use rustc_errors::ErrorGuaranteed;
5-
use rustc_hir::def_id::DefId;
5+
use rustc_hir::def_id::{DefId, LocalDefId};
66
use rustc_hir::{ItemLocalId, OwnerId};
77
use rustc_macros::{Decodable, Encodable, HashStable, TyDecodable, TyEncodable};
88

@@ -11,9 +11,9 @@ use crate::ty;
1111
#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Debug, HashStable)]
1212
pub enum ResolvedArg {
1313
StaticLifetime,
14-
EarlyBound(/* decl */ DefId),
15-
LateBound(ty::DebruijnIndex, /* late-bound index */ u32, /* decl */ DefId),
16-
Free(DefId, /* lifetime decl */ DefId),
14+
EarlyBound(/* decl */ LocalDefId),
15+
LateBound(ty::DebruijnIndex, /* late-bound index */ u32, /* decl */ LocalDefId),
16+
Free(LocalDefId, /* lifetime decl */ LocalDefId),
1717
Error(ErrorGuaranteed),
1818
}
1919

‎compiler/rustc_middle/src/ty/context.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -3035,13 +3035,13 @@ impl<'tcx> TyCtxt<'tcx> {
30353035

30363036
match self.named_bound_var(lifetime.hir_id) {
30373037
Some(resolve_bound_vars::ResolvedArg::EarlyBound(ebv)) => {
3038-
let new_parent = self.parent(ebv);
3038+
let new_parent = self.local_parent(ebv);
30393039

30403040
// If we map to another opaque, then it should be a parent
30413041
// of the opaque we mapped from. Continue mapping.
30423042
if matches!(self.def_kind(new_parent), DefKind::OpaqueTy) {
3043-
debug_assert_eq!(self.parent(parent.to_def_id()), new_parent);
3044-
opaque_lifetime_param_def_id = ebv.expect_local();
3043+
debug_assert_eq!(self.local_parent(parent), new_parent);
3044+
opaque_lifetime_param_def_id = ebv;
30453045
continue;
30463046
}
30473047

@@ -3050,20 +3050,20 @@ impl<'tcx> TyCtxt<'tcx> {
30503050
self,
30513051
ty::EarlyParamRegion {
30523052
index: generics
3053-
.param_def_id_to_index(self, ebv)
3053+
.param_def_id_to_index(self, ebv.to_def_id())
30543054
.expect("early-bound var should be present in fn generics"),
3055-
name: self.hir().name(self.local_def_id_to_hir_id(ebv.expect_local())),
3055+
name: self.item_name(ebv.to_def_id()),
30563056
},
30573057
);
30583058
}
30593059
Some(resolve_bound_vars::ResolvedArg::LateBound(_, _, lbv)) => {
3060-
let new_parent = self.parent(lbv);
3060+
let new_parent = self.local_parent(lbv);
30613061
return ty::Region::new_late_param(
30623062
self,
3063-
new_parent,
3063+
new_parent.to_def_id(),
30643064
ty::BoundRegionKind::BrNamed(
3065-
lbv,
3066-
self.hir().name(self.local_def_id_to_hir_id(lbv.expect_local())),
3065+
lbv.to_def_id(),
3066+
self.item_name(lbv.to_def_id()),
30673067
),
30683068
);
30693069
}

‎compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/find_anon_type.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl<'tcx> Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
101101
// region at the right depth with the same index
102102
(Some(rbv::ResolvedArg::EarlyBound(id)), ty::BrNamed(def_id, _)) => {
103103
debug!("EarlyBound id={:?} def_id={:?}", id, def_id);
104-
if id == def_id {
104+
if id.to_def_id() == def_id {
105105
return ControlFlow::Break(arg);
106106
}
107107
}
@@ -118,7 +118,7 @@ impl<'tcx> Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
118118
debruijn_index
119119
);
120120
debug!("LateBound id={:?} def_id={:?}", id, def_id);
121-
if debruijn_index == self.current_index && id == def_id {
121+
if debruijn_index == self.current_index && id.to_def_id() == def_id {
122122
return ControlFlow::Break(arg);
123123
}
124124
}
@@ -192,7 +192,7 @@ impl<'tcx> Visitor<'tcx> for TyPathVisitor<'tcx> {
192192
// the lifetime of the TyPath!
193193
(Some(rbv::ResolvedArg::EarlyBound(id)), ty::BrNamed(def_id, _)) => {
194194
debug!("EarlyBound id={:?} def_id={:?}", id, def_id);
195-
if id == def_id {
195+
if id.to_def_id() == def_id {
196196
return ControlFlow::Break(());
197197
}
198198
}
@@ -201,7 +201,7 @@ impl<'tcx> Visitor<'tcx> for TyPathVisitor<'tcx> {
201201
debug!("FindNestedTypeVisitor::visit_ty: LateBound depth = {:?}", debruijn_index,);
202202
debug!("id={:?}", id);
203203
debug!("def_id={:?}", def_id);
204-
if debruijn_index == self.current_index && id == def_id {
204+
if debruijn_index == self.current_index && id.to_def_id() == def_id {
205205
return ControlFlow::Break(());
206206
}
207207
}

‎src/librustdoc/clean/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ fn clean_lifetime<'tcx>(lifetime: &hir::Lifetime, cx: &mut DocContext<'tcx>) ->
272272
| rbv::ResolvedArg::LateBound(_, _, did)
273273
| rbv::ResolvedArg::Free(_, did),
274274
) = cx.tcx.named_bound_var(lifetime.hir_id)
275-
&& let Some(lt) = cx.args.get(&did).and_then(|arg| arg.as_lt())
275+
&& let Some(lt) = cx.args.get(&did.to_def_id()).and_then(|arg| arg.as_lt())
276276
{
277277
return lt.clone();
278278
}

0 commit comments

Comments
 (0)
Failed to load comments.