Skip to content

Commit a3d1835

Browse files
authored
Unrolled build for #142554
Rollup merge of #142554 - nnethercote:fix-PathSource-lifetimes, r=petrochenkov Fix `PathSource` lifetimes. It currently has two, which don't accurately capture what's happening -- the `TupleStruct` spans are allocated in `ResolverArenas`, which is different to where the `Expr` is allocated -- and require some "outlives" constraints to be used. This commit adds another lifetime, renames the existing ones, and removes the "outlives" constraints. r? `@petrochenkov`
2 parents 3bc767e + 248b7a9 commit a3d1835

File tree

2 files changed

+33
-33
lines changed

2 files changed

+33
-33
lines changed

compiler/rustc_resolve/src/late.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -415,24 +415,24 @@ pub(crate) enum AliasPossibility {
415415
}
416416

417417
#[derive(Copy, Clone, Debug)]
418-
pub(crate) enum PathSource<'a, 'c> {
418+
pub(crate) enum PathSource<'a, 'ast, 'ra> {
419419
/// Type paths `Path`.
420420
Type,
421421
/// Trait paths in bounds or impls.
422422
Trait(AliasPossibility),
423423
/// Expression paths `path`, with optional parent context.
424-
Expr(Option<&'a Expr>),
424+
Expr(Option<&'ast Expr>),
425425
/// Paths in path patterns `Path`.
426426
Pat,
427427
/// Paths in struct expressions and patterns `Path { .. }`.
428428
Struct,
429429
/// Paths in tuple struct patterns `Path(..)`.
430-
TupleStruct(Span, &'a [Span]),
430+
TupleStruct(Span, &'ra [Span]),
431431
/// `m::A::B` in `<T as m::A>::B::C`.
432432
///
433433
/// Second field holds the "cause" of this one, i.e. the context within
434434
/// which the trait item is resolved. Used for diagnostics.
435-
TraitItem(Namespace, &'c PathSource<'a, 'c>),
435+
TraitItem(Namespace, &'a PathSource<'a, 'ast, 'ra>),
436436
/// Paths in delegation item
437437
Delegation,
438438
/// An arg in a `use<'a, N>` precise-capturing bound.
@@ -443,7 +443,7 @@ pub(crate) enum PathSource<'a, 'c> {
443443
DefineOpaques,
444444
}
445445

446-
impl<'a> PathSource<'a, '_> {
446+
impl PathSource<'_, '_, '_> {
447447
fn namespace(self) -> Namespace {
448448
match self {
449449
PathSource::Type
@@ -773,7 +773,7 @@ struct LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
773773
}
774774

775775
/// Walks the whole crate in DFS order, visiting each item, resolving names as it goes.
776-
impl<'ra: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
776+
impl<'ast, 'ra, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
777777
fn visit_attribute(&mut self, _: &'ast Attribute) {
778778
// We do not want to resolve expressions that appear in attributes,
779779
// as they do not correspond to actual code.
@@ -1462,7 +1462,7 @@ impl<'ra: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'r
14621462
}
14631463
}
14641464

1465-
impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
1465+
impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
14661466
fn new(resolver: &'a mut Resolver<'ra, 'tcx>) -> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
14671467
// During late resolution we only track the module component of the parent scope,
14681468
// although it may be useful to track other components as well for diagnostics.
@@ -2010,7 +2010,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
20102010
&mut self,
20112011
partial_res: PartialRes,
20122012
path: &[Segment],
2013-
source: PathSource<'_, '_>,
2013+
source: PathSource<'_, '_, '_>,
20142014
path_span: Span,
20152015
) {
20162016
let proj_start = path.len() - partial_res.unresolved_segments();
@@ -4161,7 +4161,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
41614161
id: NodeId,
41624162
qself: &Option<P<QSelf>>,
41634163
path: &Path,
4164-
source: PathSource<'ast, '_>,
4164+
source: PathSource<'_, 'ast, '_>,
41654165
) {
41664166
self.smart_resolve_path_fragment(
41674167
qself,
@@ -4178,7 +4178,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
41784178
&mut self,
41794179
qself: &Option<P<QSelf>>,
41804180
path: &[Segment],
4181-
source: PathSource<'ast, '_>,
4181+
source: PathSource<'_, 'ast, '_>,
41824182
finalize: Finalize,
41834183
record_partial_res: RecordPartialRes,
41844184
parent_qself: Option<&QSelf>,
@@ -4482,7 +4482,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
44824482
span: Span,
44834483
defer_to_typeck: bool,
44844484
finalize: Finalize,
4485-
source: PathSource<'ast, '_>,
4485+
source: PathSource<'_, 'ast, '_>,
44864486
) -> Result<Option<PartialRes>, Spanned<ResolutionError<'ra>>> {
44874487
let mut fin_res = None;
44884488

@@ -4525,7 +4525,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
45254525
path: &[Segment],
45264526
ns: Namespace,
45274527
finalize: Finalize,
4528-
source: PathSource<'ast, '_>,
4528+
source: PathSource<'_, 'ast, '_>,
45294529
) -> Result<Option<PartialRes>, Spanned<ResolutionError<'ra>>> {
45304530
debug!(
45314531
"resolve_qpath(qself={:?}, path={:?}, ns={:?}, finalize={:?})",

compiler/rustc_resolve/src/late/diagnostics.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,12 @@ impl TypoCandidate {
170170
}
171171
}
172172

173-
impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
173+
impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
174174
fn make_base_error(
175175
&mut self,
176176
path: &[Segment],
177177
span: Span,
178-
source: PathSource<'_, '_>,
178+
source: PathSource<'_, '_, '_>,
179179
res: Option<Res>,
180180
) -> BaseError {
181181
// Make the base error.
@@ -421,7 +421,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
421421
path: &[Segment],
422422
following_seg: Option<&Segment>,
423423
span: Span,
424-
source: PathSource<'_, '_>,
424+
source: PathSource<'_, '_, '_>,
425425
res: Option<Res>,
426426
qself: Option<&QSelf>,
427427
) -> (Diag<'tcx>, Vec<ImportSuggestion>) {
@@ -539,7 +539,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
539539
path: &[Segment],
540540
following_seg: Option<&Segment>,
541541
span: Span,
542-
source: PathSource<'_, '_>,
542+
source: PathSource<'_, '_, '_>,
543543
res: Option<Res>,
544544
qself: Option<&QSelf>,
545545
) {
@@ -650,7 +650,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
650650
fn try_lookup_name_relaxed(
651651
&mut self,
652652
err: &mut Diag<'_>,
653-
source: PathSource<'_, '_>,
653+
source: PathSource<'_, '_, '_>,
654654
path: &[Segment],
655655
following_seg: Option<&Segment>,
656656
span: Span,
@@ -940,7 +940,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
940940
fn suggest_trait_and_bounds(
941941
&mut self,
942942
err: &mut Diag<'_>,
943-
source: PathSource<'_, '_>,
943+
source: PathSource<'_, '_, '_>,
944944
res: Option<Res>,
945945
span: Span,
946946
base_error: &BaseError,
@@ -1017,7 +1017,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
10171017
fn suggest_typo(
10181018
&mut self,
10191019
err: &mut Diag<'_>,
1020-
source: PathSource<'_, '_>,
1020+
source: PathSource<'_, '_, '_>,
10211021
path: &[Segment],
10221022
following_seg: Option<&Segment>,
10231023
span: Span,
@@ -1063,7 +1063,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
10631063
fn suggest_shadowed(
10641064
&mut self,
10651065
err: &mut Diag<'_>,
1066-
source: PathSource<'_, '_>,
1066+
source: PathSource<'_, '_, '_>,
10671067
path: &[Segment],
10681068
following_seg: Option<&Segment>,
10691069
span: Span,
@@ -1096,7 +1096,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
10961096
fn err_code_special_cases(
10971097
&mut self,
10981098
err: &mut Diag<'_>,
1099-
source: PathSource<'_, '_>,
1099+
source: PathSource<'_, '_, '_>,
11001100
path: &[Segment],
11011101
span: Span,
11021102
) {
@@ -1141,7 +1141,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
11411141
fn suggest_self_ty(
11421142
&mut self,
11431143
err: &mut Diag<'_>,
1144-
source: PathSource<'_, '_>,
1144+
source: PathSource<'_, '_, '_>,
11451145
path: &[Segment],
11461146
span: Span,
11471147
) -> bool {
@@ -1164,7 +1164,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
11641164
fn suggest_self_value(
11651165
&mut self,
11661166
err: &mut Diag<'_>,
1167-
source: PathSource<'_, '_>,
1167+
source: PathSource<'_, '_, '_>,
11681168
path: &[Segment],
11691169
span: Span,
11701170
) -> bool {
@@ -1332,7 +1332,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
13321332
fn suggest_swapping_misplaced_self_ty_and_trait(
13331333
&mut self,
13341334
err: &mut Diag<'_>,
1335-
source: PathSource<'_, '_>,
1335+
source: PathSource<'_, '_, '_>,
13361336
res: Option<Res>,
13371337
span: Span,
13381338
) {
@@ -1361,7 +1361,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
13611361
&mut self,
13621362
err: &mut Diag<'_>,
13631363
res: Option<Res>,
1364-
source: PathSource<'_, '_>,
1364+
source: PathSource<'_, '_, '_>,
13651365
) {
13661366
let PathSource::TupleStruct(_, _) = source else { return };
13671367
let Some(Res::Def(DefKind::Fn, _)) = res else { return };
@@ -1373,7 +1373,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
13731373
&mut self,
13741374
err: &mut Diag<'_>,
13751375
res: Option<Res>,
1376-
source: PathSource<'_, '_>,
1376+
source: PathSource<'_, '_, '_>,
13771377
span: Span,
13781378
) {
13791379
let PathSource::Trait(_) = source else { return };
@@ -1422,7 +1422,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
14221422
fn suggest_pattern_match_with_let(
14231423
&mut self,
14241424
err: &mut Diag<'_>,
1425-
source: PathSource<'_, '_>,
1425+
source: PathSource<'_, '_, '_>,
14261426
span: Span,
14271427
) -> bool {
14281428
if let PathSource::Expr(_) = source
@@ -1448,7 +1448,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
14481448
fn get_single_associated_item(
14491449
&mut self,
14501450
path: &[Segment],
1451-
source: &PathSource<'_, '_>,
1451+
source: &PathSource<'_, '_, '_>,
14521452
filter_fn: &impl Fn(Res) -> bool,
14531453
) -> Option<TypoSuggestion> {
14541454
if let crate::PathSource::TraitItem(_, _) = source {
@@ -1556,7 +1556,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
15561556

15571557
/// Check if the source is call expression and the first argument is `self`. If true,
15581558
/// return the span of whole call and the span for all arguments expect the first one (`self`).
1559-
fn call_has_self_arg(&self, source: PathSource<'_, '_>) -> Option<(Span, Option<Span>)> {
1559+
fn call_has_self_arg(&self, source: PathSource<'_, '_, '_>) -> Option<(Span, Option<Span>)> {
15601560
let mut has_self_arg = None;
15611561
if let PathSource::Expr(Some(parent)) = source
15621562
&& let ExprKind::Call(_, args) = &parent.kind
@@ -1614,7 +1614,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
16141614
&mut self,
16151615
err: &mut Diag<'_>,
16161616
span: Span,
1617-
source: PathSource<'_, '_>,
1617+
source: PathSource<'_, '_, '_>,
16181618
path: &[Segment],
16191619
res: Res,
16201620
path_str: &str,
@@ -1666,7 +1666,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
16661666
}
16671667
};
16681668

1669-
let find_span = |source: &PathSource<'_, '_>, err: &mut Diag<'_>| {
1669+
let find_span = |source: &PathSource<'_, '_, '_>, err: &mut Diag<'_>| {
16701670
match source {
16711671
PathSource::Expr(Some(Expr { span, kind: ExprKind::Call(_, _), .. }))
16721672
| PathSource::TupleStruct(span, _) => {
@@ -2699,7 +2699,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
26992699
fn suggest_using_enum_variant(
27002700
&mut self,
27012701
err: &mut Diag<'_>,
2702-
source: PathSource<'_, '_>,
2702+
source: PathSource<'_, '_, '_>,
27032703
def_id: DefId,
27042704
span: Span,
27052705
) {
@@ -2877,7 +2877,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
28772877
pub(crate) fn suggest_adding_generic_parameter(
28782878
&self,
28792879
path: &[Segment],
2880-
source: PathSource<'_, '_>,
2880+
source: PathSource<'_, '_, '_>,
28812881
) -> Option<(Span, &'static str, String, Applicability)> {
28822882
let (ident, span) = match path {
28832883
[segment]

0 commit comments

Comments
 (0)