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

Commitfe2d779

Browse files
committed
RemoveDefId fromEarlyParamRegion (tedium/diagnostics)
1 parentbd6344d commitfe2d779

File tree

27 files changed

+266
-157
lines changed

27 files changed

+266
-157
lines changed

‎compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs‎

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use rustc_errors::Diag;
2+
use rustc_hir::def_id::LocalDefId;
23
use rustc_infer::infer::canonical::Canonical;
34
use rustc_infer::infer::error_reporting::nice_region_error::NiceRegionError;
45
use rustc_infer::infer::region_constraints::Constraint;
@@ -241,7 +242,7 @@ impl<'tcx> TypeOpInfo<'tcx> for PredicateQuery<'tcx> {
241242
mbcx.infcx.tcx.infer_ctxt().build_with_canonical(cause.span,&self.canonical_query);
242243
let ocx =ObligationCtxt::new(&infcx);
243244
type_op_prove_predicate_with_cause(&ocx, key, cause);
244-
try_extract_error_from_fulfill_cx(&ocx, placeholder_region, error_region)
245+
try_extract_error_from_fulfill_cx(&ocx,mbcx.mir_def_id(),placeholder_region, error_region)
245246
}
246247
}
247248

@@ -287,7 +288,7 @@ where
287288
let(param_env, value) = key.into_parts();
288289
let _ = ocx.normalize(&cause, param_env, value.value);
289290

290-
try_extract_error_from_fulfill_cx(&ocx, placeholder_region, error_region)
291+
try_extract_error_from_fulfill_cx(&ocx,mbcx.mir_def_id(),placeholder_region, error_region)
291292
}
292293
}
293294

@@ -318,7 +319,7 @@ impl<'tcx> TypeOpInfo<'tcx> for AscribeUserTypeQuery<'tcx> {
318319
mbcx.infcx.tcx.infer_ctxt().build_with_canonical(cause.span,&self.canonical_query);
319320
let ocx =ObligationCtxt::new(&infcx);
320321
type_op_ascribe_user_type_with_span(&ocx, key,Some(cause.span)).ok()?;
321-
try_extract_error_from_fulfill_cx(&ocx, placeholder_region, error_region)
322+
try_extract_error_from_fulfill_cx(&ocx,mbcx.mir_def_id(),placeholder_region, error_region)
322323
}
323324
}
324325

@@ -342,6 +343,7 @@ impl<'tcx> TypeOpInfo<'tcx> for crate::type_check::InstantiateOpaqueType<'tcx> {
342343
) ->Option<Diag<'tcx>>{
343344
try_extract_error_from_region_constraints(
344345
mbcx.infcx,
346+
mbcx.mir_def_id(),
345347
placeholder_region,
346348
error_region,
347349
self.region_constraints.as_ref().unwrap(),
@@ -358,6 +360,7 @@ impl<'tcx> TypeOpInfo<'tcx> for crate::type_check::InstantiateOpaqueType<'tcx> {
358360
#[instrument(skip(ocx), level ="debug")]
359361
fntry_extract_error_from_fulfill_cx<'tcx>(
360362
ocx:&ObligationCtxt<'_,'tcx>,
363+
generic_param_scope:LocalDefId,
361364
placeholder_region: ty::Region<'tcx>,
362365
error_region:Option<ty::Region<'tcx>>,
363366
) ->Option<Diag<'tcx>>{
@@ -368,6 +371,7 @@ fn try_extract_error_from_fulfill_cx<'tcx>(
368371
let region_constraints = ocx.infcx.with_region_constraints(|r| r.clone());
369372
try_extract_error_from_region_constraints(
370373
ocx.infcx,
374+
generic_param_scope,
371375
placeholder_region,
372376
error_region,
373377
&region_constraints,
@@ -379,6 +383,7 @@ fn try_extract_error_from_fulfill_cx<'tcx>(
379383
#[instrument(level ="debug", skip(infcx, region_var_origin, universe_of_region))]
380384
fntry_extract_error_from_region_constraints<'tcx>(
381385
infcx:&InferCtxt<'tcx>,
386+
generic_param_scope:LocalDefId,
382387
placeholder_region: ty::Region<'tcx>,
383388
error_region:Option<ty::Region<'tcx>>,
384389
region_constraints:&RegionConstraintData<'tcx>,
@@ -452,15 +457,18 @@ fn try_extract_error_from_region_constraints<'tcx>(
452457
RegionResolutionError::ConcreteFailure(cause.clone(), sub_region, placeholder_region)
453458
}
454459
};
455-
NiceRegionError::new(&infcx.err_ctxt(), error).try_report_from_nll().or_else(||{
456-
ifletSubregionOrigin::Subtype(trace) = cause{
457-
Some(
458-
infcx
459-
.err_ctxt()
460-
.report_and_explain_type_error(*trace,TypeError::RegionsPlaceholderMismatch),
461-
)
462-
}else{
463-
None
464-
}
465-
})
460+
NiceRegionError::new(&infcx.err_ctxt(), generic_param_scope, error)
461+
.try_report_from_nll()
462+
.or_else(||{
463+
ifletSubregionOrigin::Subtype(trace) = cause{
464+
Some(
465+
infcx.err_ctxt().report_and_explain_type_error(
466+
*trace,
467+
TypeError::RegionsPlaceholderMismatch,
468+
),
469+
)
470+
}else{
471+
None
472+
}
473+
})
466474
}

‎compiler/rustc_borrowck/src/diagnostics/region_errors.rs‎

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
361361
let named_region =self.regioncx.name_regions(self.infcx.tcx, member_region);
362362
let diag =unexpected_hidden_region_diagnostic(
363363
self.infcx.tcx,
364+
self.mir_def_id(),
364365
span,
365366
named_ty,
366367
named_region,
@@ -453,7 +454,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
453454
// Check if we can use one of the "nice region errors".
454455
iflet(Some(f),Some(o)) =(self.to_error_region(fr),self.to_error_region(outlived_fr)){
455456
let infer_err =self.infcx.err_ctxt();
456-
let nice =NiceRegionError::new_from_span(&infer_err, cause.span, o, f);
457+
let nice =
458+
NiceRegionError::new_from_span(&infer_err,self.mir_def_id(), cause.span, o, f);
457459
ifletSome(diag) = nice.try_report_from_nll(){
458460
self.buffer_error(diag);
459461
return;
@@ -843,14 +845,16 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
843845
if*outlived_f != ty::ReStatic{
844846
return;
845847
}
846-
let suitable_region =self.infcx.tcx.is_suitable_region(f);
848+
let suitable_region =self.infcx.tcx.is_suitable_region(self.mir_def_id(),f);
847849
letSome(suitable_region) = suitable_regionelse{
848850
return;
849851
};
850852

851853
let fn_returns =self.infcx.tcx.return_type_impl_or_dyn_traits(suitable_region.def_id);
852854

853-
let param =ifletSome(param) =find_param_with_region(self.infcx.tcx, f, outlived_f){
855+
let param =ifletSome(param) =
856+
find_param_with_region(self.infcx.tcx,self.mir_def_id(), f, outlived_f)
857+
{
854858
param
855859
}else{
856860
return;
@@ -959,7 +963,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
959963
return;
960964
};
961965

962-
let param =matchfind_param_with_region(tcx, f, o){
966+
let param =matchfind_param_with_region(tcx,self.mir_def_id(),f, o){
963967
Some(param) => param,
964968
None =>return,
965969
};
@@ -1022,25 +1026,30 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
10221026
return;
10231027
};
10241028

1025-
letSome((ty_sub, _)) =self
1026-
.infcx
1027-
.tcx
1028-
.is_suitable_region(sub)
1029-
.and_then(|anon_reg|find_anon_type(self.infcx.tcx, sub,&anon_reg.bound_region))
1029+
letSome((ty_sub, _)) =
1030+
self.infcx.tcx.is_suitable_region(self.mir_def_id(), sub).and_then(|anon_reg|{
1031+
find_anon_type(self.infcx.tcx,self.mir_def_id(), sub,&anon_reg.bound_region)
1032+
})
10301033
else{
10311034
return;
10321035
};
10331036

1034-
letSome((ty_sup, _)) =self
1035-
.infcx
1036-
.tcx
1037-
.is_suitable_region(sup)
1038-
.and_then(|anon_reg|find_anon_type(self.infcx.tcx, sup,&anon_reg.bound_region))
1037+
letSome((ty_sup, _)) =
1038+
self.infcx.tcx.is_suitable_region(self.mir_def_id(), sup).and_then(|anon_reg|{
1039+
find_anon_type(self.infcx.tcx,self.mir_def_id(), sup,&anon_reg.bound_region)
1040+
})
10391041
else{
10401042
return;
10411043
};
10421044

1043-
suggest_adding_lifetime_params(self.infcx.tcx, sub, ty_sup, ty_sub, diag);
1045+
suggest_adding_lifetime_params(
1046+
self.infcx.tcx,
1047+
diag,
1048+
self.mir_def_id(),
1049+
sub,
1050+
ty_sup,
1051+
ty_sub,
1052+
);
10441053
}
10451054

10461055
#[allow(rustc::diagnostic_outside_of_impl)]

‎compiler/rustc_borrowck/src/diagnostics/region_name.rs‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
289289
debug!("give_region_a_name: error_region = {:?}", error_region);
290290
match*error_region{
291291
ty::ReEarlyParam(ebr) => ebr.has_name().then(||{
292-
let span = tcx.hir().span_if_local(ebr.def_id).unwrap_or(DUMMY_SP);
292+
let def_id = tcx.generics_of(self.mir_def_id()).region_param(ebr, tcx).def_id;
293+
let span = tcx.hir().span_if_local(def_id).unwrap_or(DUMMY_SP);
293294
RegionName{name: ebr.name,source:RegionNameSource::NamedEarlyParamRegion(span)}
294295
}),
295296

@@ -912,7 +913,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
912913
};
913914

914915
let tcx =self.infcx.tcx;
915-
let region_parent = tcx.parent(region.def_id);
916+
let region_def = tcx.generics_of(self.mir_def_id()).region_param(region, tcx).def_id;
917+
let region_parent = tcx.parent(region_def);
916918
letDefKind::Impl{ ..} = tcx.def_kind(region_parent)else{
917919
returnNone;
918920
};
@@ -925,7 +927,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
925927
Some(RegionName{
926928
name:self.synthesize_region_name(),
927929
source:RegionNameSource::AnonRegionFromImplSignature(
928-
tcx.def_span(region.def_id),
930+
tcx.def_span(region_def),
929931
// FIXME(compiler-errors): Does this ever actually show up
930932
// anywhere other than the self type? I couldn't create an
931933
// example of a `'_` in the impl's trait being referenceable.

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,6 @@ impl<'tcx> ty::FallibleTypeFolder<TyCtxt<'tcx>> for RemapHiddenTyRegions<'tcx> {
925925
Ok(ty::Region::new_early_param(
926926
self.tcx,
927927
ty::EarlyParamRegion{
928-
def_id: e.def_id,
929928
name: e.name,
930929
index:(e.indexasusize -self.num_trait_args +self.num_impl_args)asu32,
931930
},

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

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -675,11 +675,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
675675
let region_param = gat_generics.param_at(*region_a_idx, tcx);
676676
let region_param = ty::Region::new_early_param(
677677
tcx,
678-
ty::EarlyParamRegion{
679-
def_id: region_param.def_id,
680-
index: region_param.index,
681-
name: region_param.name,
682-
},
678+
ty::EarlyParamRegion{index: region_param.index,name: region_param.name},
683679
);
684680
// The predicate we expect to see. (In our example,
685681
// `Self: 'me`.)
@@ -708,21 +704,13 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
708704
let region_a_param = gat_generics.param_at(*region_a_idx, tcx);
709705
let region_a_param = ty::Region::new_early_param(
710706
tcx,
711-
ty::EarlyParamRegion{
712-
def_id: region_a_param.def_id,
713-
index: region_a_param.index,
714-
name: region_a_param.name,
715-
},
707+
ty::EarlyParamRegion{index: region_a_param.index,name: region_a_param.name},
716708
);
717709
// Same for the region.
718710
let region_b_param = gat_generics.param_at(*region_b_idx, tcx);
719711
let region_b_param = ty::Region::new_early_param(
720712
tcx,
721-
ty::EarlyParamRegion{
722-
def_id: region_b_param.def_id,
723-
index: region_b_param.index,
724-
name: region_b_param.name,
725-
},
713+
ty::EarlyParamRegion{index: region_b_param.index,name: region_b_param.name},
726714
);
727715
// The predicate we expect to see.
728716
bounds.insert(

‎compiler/rustc_hir_analysis/src/collect.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,6 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
453453
poly_trait_ref,
454454
|_|{
455455
ty::Region::new_early_param(self.tcx, ty::EarlyParamRegion{
456-
def_id: item_def_id,
457456
index:0,
458457
name:Symbol::intern(&lt_name),
459458
})

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ fn compute_bidirectional_outlives_predicates<'tcx>(
323323
iflet ty::ReEarlyParam(..) =*orig_lifetime{
324324
let dup_lifetime = ty::Region::new_early_param(
325325
tcx,
326-
ty::EarlyParamRegion{def_id: param.def_id,index: param.index,name: param.name},
326+
ty::EarlyParamRegion{index: param.index,name: param.name},
327327
);
328328
let span = tcx.def_span(param.def_id);
329329
predicates.push((

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
280280
let item_def_id = tcx.hir().ty_param_owner(def_id.expect_local());
281281
let generics = tcx.generics_of(item_def_id);
282282
let index = generics.param_def_id_to_index[&def_id];
283-
ty::Region::new_early_param(tcx, ty::EarlyParamRegion{def_id,index, name})
283+
ty::Region::new_early_param(tcx, ty::EarlyParamRegion{ index, name})
284284
}
285285

286286
Some(rbv::ResolvedArg::Free(scope, id)) =>{

‎compiler/rustc_infer/src/errors/mod.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use rustc_errors::{
55
MultiSpan,SubdiagMessageOp,Subdiagnostic,
66
};
77
use rustc_hiras hir;
8+
use rustc_hir::def_id::LocalDefId;
89
use rustc_hir::intravisit::{walk_ty,Visitor};
910
use rustc_hir::FnRetTy;
1011
use rustc_macros::{Diagnostic,Subdiagnostic};
@@ -344,6 +345,7 @@ impl Subdiagnostic for LifetimeMismatchLabels {
344345

345346
pubstructAddLifetimeParamsSuggestion<'a>{
346347
pubtcx:TyCtxt<'a>,
348+
pubgeneric_param_scope:LocalDefId,
347349
pubsub:Region<'a>,
348350
pubty_sup:&'a hir::Ty<'a>,
349351
pubty_sub:&'a hir::Ty<'a>,
@@ -357,7 +359,8 @@ impl Subdiagnostic for AddLifetimeParamsSuggestion<'_> {
357359
_f:&F,
358360
){
359361
letmut mk_suggestion = ||{
360-
letSome(anon_reg) =self.tcx.is_suitable_region(self.sub)else{
362+
letSome(anon_reg) =self.tcx.is_suitable_region(self.generic_param_scope,self.sub)
363+
else{
361364
returnfalse;
362365
};
363366

‎compiler/rustc_infer/src/errors/note_and_explain.rs‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
usecrate::fluent_generatedas fluent;
22
usecrate::infer::error_reporting::nice_region_error::find_anon_type;
33
use rustc_errors::{Diag,EmissionGuarantee,IntoDiagArg,SubdiagMessageOp,Subdiagnostic};
4+
use rustc_hir::def_id::LocalDefId;
45
use rustc_middle::bug;
56
use rustc_middle::ty::{self,TyCtxt};
67
use rustc_span::{symbol::kw,Span};
@@ -14,12 +15,15 @@ struct DescriptionCtx<'a> {
1415
impl<'a>DescriptionCtx<'a>{
1516
fnnew<'tcx>(
1617
tcx:TyCtxt<'tcx>,
18+
generic_param_scope:LocalDefId,
1719
region: ty::Region<'tcx>,
1820
alt_span:Option<Span>,
1921
) ->Option<Self>{
2022
let(span, kind, arg) =match*region{
21-
ty::ReEarlyParam(ref br) =>{
22-
let scope = region.free_region_binding_scope(tcx).expect_local();
23+
ty::ReEarlyParam(br) =>{
24+
let scope = tcx
25+
.parent(tcx.generics_of(generic_param_scope).region_param(br, tcx).def_id)
26+
.expect_local();
2327
let span =ifletSome(param) =
2428
tcx.hir().get_generics(scope).and_then(|generics| generics.get_named(br.name))
2529
{
@@ -35,11 +39,12 @@ impl<'a> DescriptionCtx<'a> {
3539
}
3640
ty::ReLateParam(ref fr) =>{
3741
if !fr.bound_region.is_named()
38-
&&letSome((ty, _)) =find_anon_type(tcx, region,&fr.bound_region)
42+
&&letSome((ty, _)) =
43+
find_anon_type(tcx, generic_param_scope, region,&fr.bound_region)
3944
{
4045
(Some(ty.span),"defined_here",String::new())
4146
}else{
42-
let scope =region.free_region_binding_scope(tcx).expect_local();
47+
let scope =fr.scope.expect_local();
4348
match fr.bound_region{
4449
ty::BoundRegionKind::BrNamed(_, name) =>{
4550
let span =ifletSome(param) = tcx
@@ -143,12 +148,17 @@ pub struct RegionExplanation<'a> {
143148
implRegionExplanation<'_>{
144149
pubfnnew<'tcx>(
145150
tcx:TyCtxt<'tcx>,
151+
generic_param_scope:LocalDefId,
146152
region: ty::Region<'tcx>,
147153
alt_span:Option<Span>,
148154
prefix:PrefixKind,
149155
suffix:SuffixKind,
150156
) ->Option<Self>{
151-
Some(Self{desc:DescriptionCtx::new(tcx, region, alt_span)?, prefix, suffix})
157+
Some(Self{
158+
desc:DescriptionCtx::new(tcx, generic_param_scope, region, alt_span)?,
159+
prefix,
160+
suffix,
161+
})
152162
}
153163
}
154164

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp