Skip to content

Commit

Permalink
Auto merge of #99953 - cjgillot:in-path-always, r=petrochenkov
Browse files Browse the repository at this point in the history
Always create elided lifetimes, even if inferred.

`PathSource` gives the context in which a path is encountered.  The same `PathSource` is used for the full path and the `QSelf` part.

Therefore, we can only rely on `PathSource` to know whether typechecking will be able to infer the lifetimes, not whether we need to insert them at all.

Fixes #99949
  • Loading branch information
bors committed Aug 4, 2022
2 parents 2f2243c + ec3f307 commit 6f18f0a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 23 deletions.
43 changes: 20 additions & 23 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1644,14 +1644,30 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
continue;
}

let missing = match source {
PathSource::Trait(..) | PathSource::TraitItem(..) | PathSource::Type => true,
let node_ids = self.r.next_node_ids(expected_lifetimes);
self.record_lifetime_res(
segment_id,
LifetimeRes::ElidedAnchor { start: node_ids.start, end: node_ids.end },
LifetimeElisionCandidate::Ignore,
);

let inferred = match source {
PathSource::Trait(..) | PathSource::TraitItem(..) | PathSource::Type => false,
PathSource::Expr(..)
| PathSource::Pat
| PathSource::Struct
| PathSource::TupleStruct(..) => false,
| PathSource::TupleStruct(..) => true,
};
if !missing && !segment.has_generic_args {
if inferred {
// Do not create a parameter for patterns and expressions: type checking can infer
// the appropriate lifetime for us.
for id in node_ids {
self.record_lifetime_res(
id,
LifetimeRes::Infer,
LifetimeElisionCandidate::Named,
);
}
continue;
}

Expand All @@ -1666,25 +1682,6 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
};
let ident = Ident::new(kw::UnderscoreLifetime, elided_lifetime_span);

let node_ids = self.r.next_node_ids(expected_lifetimes);
self.record_lifetime_res(
segment_id,
LifetimeRes::ElidedAnchor { start: node_ids.start, end: node_ids.end },
LifetimeElisionCandidate::Ignore,
);

if !missing {
// Do not create a parameter for patterns and expressions.
for id in node_ids {
self.record_lifetime_res(
id,
LifetimeRes::Infer,
LifetimeElisionCandidate::Named,
);
}
continue;
}

let missing_lifetime = MissingLifetime {
id: node_ids.start,
span: elided_lifetime_span,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// check-pass

struct Sqlite {}

trait HasArguments<'q> {
type Arguments;
}

impl<'q> HasArguments<'q> for Sqlite {
type Arguments = std::marker::PhantomData<&'q ()>;
}

fn foo() {
let _ = <Sqlite as HasArguments>::Arguments::default();
}

fn main() {}

0 comments on commit 6f18f0a

Please sign in to comment.