Skip to content

Commit 6f18f0a

Browse files
committed
Auto merge of #99953 - cjgillot:in-path-always, r=petrochenkov
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
2 parents 2f2243c + ec3f307 commit 6f18f0a

File tree

2 files changed

+37
-23
lines changed

2 files changed

+37
-23
lines changed

compiler/rustc_resolve/src/late.rs

+20-23
Original file line numberDiff line numberDiff line change
@@ -1644,14 +1644,30 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
16441644
continue;
16451645
}
16461646

1647-
let missing = match source {
1648-
PathSource::Trait(..) | PathSource::TraitItem(..) | PathSource::Type => true,
1647+
let node_ids = self.r.next_node_ids(expected_lifetimes);
1648+
self.record_lifetime_res(
1649+
segment_id,
1650+
LifetimeRes::ElidedAnchor { start: node_ids.start, end: node_ids.end },
1651+
LifetimeElisionCandidate::Ignore,
1652+
);
1653+
1654+
let inferred = match source {
1655+
PathSource::Trait(..) | PathSource::TraitItem(..) | PathSource::Type => false,
16491656
PathSource::Expr(..)
16501657
| PathSource::Pat
16511658
| PathSource::Struct
1652-
| PathSource::TupleStruct(..) => false,
1659+
| PathSource::TupleStruct(..) => true,
16531660
};
1654-
if !missing && !segment.has_generic_args {
1661+
if inferred {
1662+
// Do not create a parameter for patterns and expressions: type checking can infer
1663+
// the appropriate lifetime for us.
1664+
for id in node_ids {
1665+
self.record_lifetime_res(
1666+
id,
1667+
LifetimeRes::Infer,
1668+
LifetimeElisionCandidate::Named,
1669+
);
1670+
}
16551671
continue;
16561672
}
16571673

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

1669-
let node_ids = self.r.next_node_ids(expected_lifetimes);
1670-
self.record_lifetime_res(
1671-
segment_id,
1672-
LifetimeRes::ElidedAnchor { start: node_ids.start, end: node_ids.end },
1673-
LifetimeElisionCandidate::Ignore,
1674-
);
1675-
1676-
if !missing {
1677-
// Do not create a parameter for patterns and expressions.
1678-
for id in node_ids {
1679-
self.record_lifetime_res(
1680-
id,
1681-
LifetimeRes::Infer,
1682-
LifetimeElisionCandidate::Named,
1683-
);
1684-
}
1685-
continue;
1686-
}
1687-
16881685
let missing_lifetime = MissingLifetime {
16891686
id: node_ids.start,
16901687
span: elided_lifetime_span,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// check-pass
2+
3+
struct Sqlite {}
4+
5+
trait HasArguments<'q> {
6+
type Arguments;
7+
}
8+
9+
impl<'q> HasArguments<'q> for Sqlite {
10+
type Arguments = std::marker::PhantomData<&'q ()>;
11+
}
12+
13+
fn foo() {
14+
let _ = <Sqlite as HasArguments>::Arguments::default();
15+
}
16+
17+
fn main() {}

0 commit comments

Comments
 (0)