Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbd6344d

Browse files
committed
RemoveDefId fromEarlyParamRegion (type system)
1 parentb7b350c commitbd6344d

File tree

5 files changed

+38
-44
lines changed

5 files changed

+38
-44
lines changed

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -538,11 +538,9 @@ fn check_opaque_precise_captures<'tcx>(tcx: TyCtxt<'tcx>, opaque_def_id: LocalDe
538538
// the cases that were stabilized with the `impl_trait_projection`
539539
// feature -- see <https://github.com/rust-lang/rust/pull/115659>.
540540
ifletDefKind::LifetimeParam = tcx.def_kind(def_id)
541-
&&let ty::ReEarlyParam(ty::EarlyParamRegion{ def_id, ..})
542-
| ty::ReLateParam(ty::LateParamRegion{
543-
bound_region: ty::BoundRegionKind::BrNamed(def_id, _),
544-
..
545-
}) =*tcx.map_opaque_lifetime_to_parent_lifetime(def_id.expect_local())
541+
&&letSome(def_id) = tcx
542+
.map_opaque_lifetime_to_parent_lifetime(def_id.expect_local())
543+
.opt_param_def_id(tcx, tcx.parent(opaque_def_id.to_def_id()))
546544
{
547545
shadowed_captures.insert(def_id);
548546
}
@@ -585,12 +583,9 @@ fn check_opaque_precise_captures<'tcx>(tcx: TyCtxt<'tcx>, opaque_def_id: LocalDe
585583
// Check if the lifetime param was captured but isn't named in the precise captures list.
586584
if variances[param.indexasusize] == ty::Invariant{
587585
ifletDefKind::OpaqueTy = tcx.def_kind(tcx.parent(param.def_id))
588-
&&let ty::ReEarlyParam(ty::EarlyParamRegion{ def_id, ..})
589-
| ty::ReLateParam(ty::LateParamRegion{
590-
bound_region: ty::BoundRegionKind::BrNamed(def_id, _),
591-
..
592-
}) =*tcx
586+
&&letSome(def_id) = tcx
593587
.map_opaque_lifetime_to_parent_lifetime(param.def_id.expect_local())
588+
.opt_param_def_id(tcx, tcx.parent(opaque_def_id.to_def_id()))
594589
{
595590
tcx.dcx().emit_err(errors::LifetimeNotCaptured{
596591
opaque_span,

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,8 @@ impl<'tcx> ty::FallibleTypeFolder<TyCtxt<'tcx>> for RemapHiddenTyRegions<'tcx> {
876876
ty::ReLateParam(_) =>{}
877877
// Remap early-bound regions as long as they don't come from the `impl` itself,
878878
// in which case we don't really need to renumber them.
879-
ty::ReEarlyParam(ebr)ifself.tcx.parent(ebr.def_id) !=self.impl_def_id =>{}
879+
ty::ReEarlyParam(ebr)
880+
if ebr.index >=self.tcx.generics_of(self.impl_def_id).count()asu32 =>{}
880881
_ =>returnOk(region),
881882
}
882883

@@ -889,12 +890,8 @@ impl<'tcx> ty::FallibleTypeFolder<TyCtxt<'tcx>> for RemapHiddenTyRegions<'tcx> {
889890
);
890891
}
891892
}else{
892-
let guar =match region.kind(){
893-
ty::ReEarlyParam(ty::EarlyParamRegion{ def_id, ..})
894-
| ty::ReLateParam(ty::LateParamRegion{
895-
bound_region: ty::BoundRegionKind::BrNamed(def_id, _),
896-
..
897-
}) =>{
893+
let guar =match region.opt_param_def_id(self.tcx,self.tcx.parent(self.def_id)){
894+
Some(def_id) =>{
898895
let return_span =iflet ty::Alias(ty::Opaque, opaque_ty) =self.ty.kind(){
899896
self.tcx.def_span(opaque_ty.def_id)
900897
}else{
@@ -914,7 +911,7 @@ impl<'tcx> ty::FallibleTypeFolder<TyCtxt<'tcx>> for RemapHiddenTyRegions<'tcx> {
914911
.with_note(format!("hidden type inferred to be `{}`",self.ty))
915912
.emit()
916913
}
917-
_ =>{
914+
None =>{
918915
// This code path is not reached in any tests, but may be
919916
// reachable. If this is triggered, it should be converted
920917
// to `delayed_bug` and the triggering case turned into a

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,16 +2101,14 @@ fn lint_redundant_lifetimes<'tcx>(
21012101
}
21022102

21032103
for&victimin&lifetimes[(idx +1)..]{
2104-
// We should only have late-bound lifetimes of the `BrNamed` variety,
2105-
// since we get these signatures straight from `hir_lowering`. And any
2106-
// other regions (ReError/ReStatic/etc.) shouldn't matter, since we
2104+
// All region parameters should have a `DefId` available as:
2105+
// - Late-bound parameters should be of the`BrNamed` variety,
2106+
// since we get these signatures straight from `hir_lowering`.
2107+
// - Early-bound parameters unconditionally have a `DefId` available.
2108+
//
2109+
// Any other regions (ReError/ReStatic/etc.) shouldn't matter, since we
21072110
// can't really suggest to remove them.
2108-
let(ty::ReEarlyParam(ty::EarlyParamRegion{ def_id, ..})
2109-
| ty::ReLateParam(ty::LateParamRegion{
2110-
bound_region: ty::BoundRegionKind::BrNamed(def_id, _),
2111-
..
2112-
})) = victim.kind()
2113-
else{
2111+
letSome(def_id) = victim.opt_param_def_id(tcx, owner_id.to_def_id())else{
21142112
continue;
21152113
};
21162114

‎compiler/rustc_lint/src/impl_trait_overcaptures.rs‎

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ use rustc_hir as hir;
55
use rustc_hir::def::DefKind;
66
use rustc_hir::def_id::{DefId,LocalDefId};
77
use rustc_macros::LintDiagnostic;
8+
use rustc_middle::bug;
89
use rustc_middle::middle::resolve_bound_vars::ResolvedArg;
910
use rustc_middle::ty::{
1011
self,Ty,TyCtxt,TypeSuperVisitable,TypeVisitable,TypeVisitableExt,TypeVisitor,
1112
};
12-
use rustc_middle::{bug, span_bug};
1313
use rustc_session::{declare_lint, declare_lint_pass};
1414
use rustc_span::{sym,BytePos,Span};
1515

@@ -303,20 +303,12 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for VisitOpaqueTypes<'tcx> {
303303
ResolvedArg::EarlyBound(def_id) |ResolvedArg::LateBound(_, _, def_id),
304304
) =>{
305305
ifself.tcx.def_kind(self.tcx.parent(def_id)) ==DefKind::OpaqueTy{
306-
let(ty::ReEarlyParam(ty::EarlyParamRegion{ def_id, ..})
307-
| ty::ReLateParam(ty::LateParamRegion{
308-
bound_region: ty::BoundRegionKind::BrNamed(def_id, _),
309-
..
310-
})) =self
306+
let def_id =self
311307
.tcx
312308
.map_opaque_lifetime_to_parent_lifetime(def_id.expect_local())
313-
.kind()
314-
else{
315-
span_bug!(
316-
self.tcx.def_span(def_id),
317-
"variable should have been duplicated from a parent"
318-
);
319-
};
309+
.opt_param_def_id(self.tcx,self.parent_def_id.to_def_id())
310+
.expect("variable should have been duplicated from parent");
311+
320312
explicitly_captured.insert(def_id);
321313
}else{
322314
explicitly_captured.insert(def_id);

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,21 @@ impl<'tcx> Region<'tcx> {
321321
_ =>bug!("expected region {:?} to be of kind ReVar",self),
322322
}
323323
}
324+
325+
/// Given some item `binding_item`, check if this region is a generic parameter introduced by it
326+
/// or one of the parent generics. Returns the `DefId` of the parameter definition if so.
327+
pubfnopt_param_def_id(self,tcx:TyCtxt<'tcx>,binding_item:DefId) ->Option<DefId>{
328+
matchself.kind(){
329+
ty::ReEarlyParam(ebr) =>{
330+
Some(tcx.generics_of(binding_item).region_param(ebr, tcx).def_id)
331+
}
332+
ty::ReLateParam(ty::LateParamRegion{
333+
bound_region: ty::BoundRegionKind::BrNamed(def_id, _),
334+
..
335+
}) =>Some(def_id),
336+
_ =>None,
337+
}
338+
}
324339
}
325340

326341
impl<'tcx>DerefforRegion<'tcx>{
@@ -335,16 +350,13 @@ impl<'tcx> Deref for Region<'tcx> {
335350
#[derive(Copy,Clone,PartialEq,Eq,Hash,TyEncodable,TyDecodable)]
336351
#[derive(HashStable)]
337352
pubstructEarlyParamRegion{
338-
pubdef_id:DefId,
339353
pubindex:u32,
340354
pubname:Symbol,
341355
}
342356

343357
impl std::fmt::DebugforEarlyParamRegion{
344358
fnfmt(&self,f:&mut std::fmt::Formatter<'_>) -> std::fmt::Result{
345-
// FIXME(BoxyUwU): self.def_id goes first because of `erased-regions-in-hidden-ty.rs` being impossible to write
346-
// error annotations for otherwise. :). Ideally this would be `self.name, self.index, self.def_id`.
347-
write!(f,"{:?}_{}/#{}",self.def_id,self.name,self.index)
359+
write!(f,"{}/#{}",self.name,self.index)
348360
}
349361
}
350362

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp