Skip to content

Fix PathSource lifetimes. #142554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,24 +415,24 @@ pub(crate) enum AliasPossibility {
}

#[derive(Copy, Clone, Debug)]
pub(crate) enum PathSource<'a, 'c> {
pub(crate) enum PathSource<'a, 'ast, 'ra> {
/// Type paths `Path`.
Type,
/// Trait paths in bounds or impls.
Trait(AliasPossibility),
/// Expression paths `path`, with optional parent context.
Expr(Option<&'a Expr>),
Expr(Option<&'ast Expr>),
/// Paths in path patterns `Path`.
Pat,
/// Paths in struct expressions and patterns `Path { .. }`.
Struct,
/// Paths in tuple struct patterns `Path(..)`.
TupleStruct(Span, &'a [Span]),
TupleStruct(Span, &'ra [Span]),
/// `m::A::B` in `<T as m::A>::B::C`.
///
/// Second field holds the "cause" of this one, i.e. the context within
/// which the trait item is resolved. Used for diagnostics.
TraitItem(Namespace, &'c PathSource<'a, 'c>),
TraitItem(Namespace, &'a PathSource<'a, 'ast, 'ra>),
/// Paths in delegation item
Delegation,
/// An arg in a `use<'a, N>` precise-capturing bound.
Expand All @@ -443,7 +443,7 @@ pub(crate) enum PathSource<'a, 'c> {
DefineOpaques,
}

impl<'a> PathSource<'a, '_> {
impl PathSource<'_, '_, '_> {
fn namespace(self) -> Namespace {
match self {
PathSource::Type
Expand Down Expand Up @@ -773,7 +773,7 @@ struct LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
}

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

impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
fn new(resolver: &'a mut Resolver<'ra, 'tcx>) -> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
// During late resolution we only track the module component of the parent scope,
// although it may be useful to track other components as well for diagnostics.
Expand Down Expand Up @@ -2010,7 +2010,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
&mut self,
partial_res: PartialRes,
path: &[Segment],
source: PathSource<'_, '_>,
source: PathSource<'_, '_, '_>,
path_span: Span,
) {
let proj_start = path.len() - partial_res.unresolved_segments();
Expand Down Expand Up @@ -4161,7 +4161,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
id: NodeId,
qself: &Option<P<QSelf>>,
path: &Path,
source: PathSource<'ast, '_>,
source: PathSource<'_, 'ast, '_>,
) {
self.smart_resolve_path_fragment(
qself,
Expand All @@ -4178,7 +4178,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
&mut self,
qself: &Option<P<QSelf>>,
path: &[Segment],
source: PathSource<'ast, '_>,
source: PathSource<'_, 'ast, '_>,
finalize: Finalize,
record_partial_res: RecordPartialRes,
parent_qself: Option<&QSelf>,
Expand Down Expand Up @@ -4482,7 +4482,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
span: Span,
defer_to_typeck: bool,
finalize: Finalize,
source: PathSource<'ast, '_>,
source: PathSource<'_, 'ast, '_>,
) -> Result<Option<PartialRes>, Spanned<ResolutionError<'ra>>> {
let mut fin_res = None;

Expand Down Expand Up @@ -4525,7 +4525,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
path: &[Segment],
ns: Namespace,
finalize: Finalize,
source: PathSource<'ast, '_>,
source: PathSource<'_, 'ast, '_>,
) -> Result<Option<PartialRes>, Spanned<ResolutionError<'ra>>> {
debug!(
"resolve_qpath(qself={:?}, path={:?}, ns={:?}, finalize={:?})",
Expand Down
42 changes: 21 additions & 21 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,12 @@ impl TypoCandidate {
}
}

impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
fn make_base_error(
&mut self,
path: &[Segment],
span: Span,
source: PathSource<'_, '_>,
source: PathSource<'_, '_, '_>,
res: Option<Res>,
) -> BaseError {
// Make the base error.
Expand Down Expand Up @@ -421,7 +421,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
path: &[Segment],
following_seg: Option<&Segment>,
span: Span,
source: PathSource<'_, '_>,
source: PathSource<'_, '_, '_>,
res: Option<Res>,
qself: Option<&QSelf>,
) -> (Diag<'tcx>, Vec<ImportSuggestion>) {
Expand Down Expand Up @@ -539,7 +539,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
path: &[Segment],
following_seg: Option<&Segment>,
span: Span,
source: PathSource<'_, '_>,
source: PathSource<'_, '_, '_>,
res: Option<Res>,
qself: Option<&QSelf>,
) {
Expand Down Expand Up @@ -650,7 +650,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
fn try_lookup_name_relaxed(
&mut self,
err: &mut Diag<'_>,
source: PathSource<'_, '_>,
source: PathSource<'_, '_, '_>,
path: &[Segment],
following_seg: Option<&Segment>,
span: Span,
Expand Down Expand Up @@ -940,7 +940,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
fn suggest_trait_and_bounds(
&mut self,
err: &mut Diag<'_>,
source: PathSource<'_, '_>,
source: PathSource<'_, '_, '_>,
res: Option<Res>,
span: Span,
base_error: &BaseError,
Expand Down Expand Up @@ -1017,7 +1017,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
fn suggest_typo(
&mut self,
err: &mut Diag<'_>,
source: PathSource<'_, '_>,
source: PathSource<'_, '_, '_>,
path: &[Segment],
following_seg: Option<&Segment>,
span: Span,
Expand Down Expand Up @@ -1063,7 +1063,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
fn suggest_shadowed(
&mut self,
err: &mut Diag<'_>,
source: PathSource<'_, '_>,
source: PathSource<'_, '_, '_>,
path: &[Segment],
following_seg: Option<&Segment>,
span: Span,
Expand Down Expand Up @@ -1096,7 +1096,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
fn err_code_special_cases(
&mut self,
err: &mut Diag<'_>,
source: PathSource<'_, '_>,
source: PathSource<'_, '_, '_>,
path: &[Segment],
span: Span,
) {
Expand Down Expand Up @@ -1141,7 +1141,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
fn suggest_self_ty(
&mut self,
err: &mut Diag<'_>,
source: PathSource<'_, '_>,
source: PathSource<'_, '_, '_>,
path: &[Segment],
span: Span,
) -> bool {
Expand All @@ -1164,7 +1164,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
fn suggest_self_value(
&mut self,
err: &mut Diag<'_>,
source: PathSource<'_, '_>,
source: PathSource<'_, '_, '_>,
path: &[Segment],
span: Span,
) -> bool {
Expand Down Expand Up @@ -1332,7 +1332,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
fn suggest_swapping_misplaced_self_ty_and_trait(
&mut self,
err: &mut Diag<'_>,
source: PathSource<'_, '_>,
source: PathSource<'_, '_, '_>,
res: Option<Res>,
span: Span,
) {
Expand Down Expand Up @@ -1361,7 +1361,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
&mut self,
err: &mut Diag<'_>,
res: Option<Res>,
source: PathSource<'_, '_>,
source: PathSource<'_, '_, '_>,
) {
let PathSource::TupleStruct(_, _) = source else { return };
let Some(Res::Def(DefKind::Fn, _)) = res else { return };
Expand All @@ -1373,7 +1373,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
&mut self,
err: &mut Diag<'_>,
res: Option<Res>,
source: PathSource<'_, '_>,
source: PathSource<'_, '_, '_>,
span: Span,
) {
let PathSource::Trait(_) = source else { return };
Expand Down Expand Up @@ -1422,7 +1422,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
fn suggest_pattern_match_with_let(
&mut self,
err: &mut Diag<'_>,
source: PathSource<'_, '_>,
source: PathSource<'_, '_, '_>,
span: Span,
) -> bool {
if let PathSource::Expr(_) = source
Expand All @@ -1448,7 +1448,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
fn get_single_associated_item(
&mut self,
path: &[Segment],
source: &PathSource<'_, '_>,
source: &PathSource<'_, '_, '_>,
filter_fn: &impl Fn(Res) -> bool,
) -> Option<TypoSuggestion> {
if let crate::PathSource::TraitItem(_, _) = source {
Expand Down Expand Up @@ -1556,7 +1556,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {

/// Check if the source is call expression and the first argument is `self`. If true,
/// return the span of whole call and the span for all arguments expect the first one (`self`).
fn call_has_self_arg(&self, source: PathSource<'_, '_>) -> Option<(Span, Option<Span>)> {
fn call_has_self_arg(&self, source: PathSource<'_, '_, '_>) -> Option<(Span, Option<Span>)> {
let mut has_self_arg = None;
if let PathSource::Expr(Some(parent)) = source
&& let ExprKind::Call(_, args) = &parent.kind
Expand Down Expand Up @@ -1614,7 +1614,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
&mut self,
err: &mut Diag<'_>,
span: Span,
source: PathSource<'_, '_>,
source: PathSource<'_, '_, '_>,
path: &[Segment],
res: Res,
path_str: &str,
Expand Down Expand Up @@ -1666,7 +1666,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
}
};

let find_span = |source: &PathSource<'_, '_>, err: &mut Diag<'_>| {
let find_span = |source: &PathSource<'_, '_, '_>, err: &mut Diag<'_>| {
match source {
PathSource::Expr(Some(Expr { span, kind: ExprKind::Call(_, _), .. }))
| PathSource::TupleStruct(span, _) => {
Expand Down Expand Up @@ -2699,7 +2699,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
fn suggest_using_enum_variant(
&mut self,
err: &mut Diag<'_>,
source: PathSource<'_, '_>,
source: PathSource<'_, '_, '_>,
def_id: DefId,
span: Span,
) {
Expand Down Expand Up @@ -2877,7 +2877,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
pub(crate) fn suggest_adding_generic_parameter(
&self,
path: &[Segment],
source: PathSource<'_, '_>,
source: PathSource<'_, '_, '_>,
) -> Option<(Span, &'static str, String, Applicability)> {
let (ident, span) = match path {
[segment]
Expand Down
Loading