Skip to content

Commit f66de50

Browse files
committed
Use the correct lifetime binder for elided lifetimes in path.
1 parent e85edd9 commit f66de50

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

compiler/rustc_resolve/src/late.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,8 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
13191319
| PathSource::Struct
13201320
| PathSource::TupleStruct(..) => false,
13211321
};
1322-
let mut error = false;
1322+
let mut error = true;
1323+
let mut res = LifetimeRes::Error;
13231324
for rib in self.lifetime_ribs.iter().rev() {
13241325
match rib.kind {
13251326
// In create-parameter mode we error here because we don't want to support
@@ -1329,7 +1330,6 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
13291330
// impl Foo for std::cell::Ref<u32> // note lack of '_
13301331
// async fn foo(_: std::cell::Ref<u32>) { ... }
13311332
LifetimeRibKind::AnonymousCreateParameter(_) => {
1332-
error = true;
13331333
break;
13341334
}
13351335
// `PassThrough` is the normal case.
@@ -1338,19 +1338,22 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
13381338
// `PathSegment`, for which there is no associated `'_` or `&T` with no explicit
13391339
// lifetime. Instead, we simply create an implicit lifetime, which will be checked
13401340
// later, at which point a suitable error will be emitted.
1341-
LifetimeRibKind::AnonymousPassThrough(..)
1342-
| LifetimeRibKind::AnonymousReportError
1343-
| LifetimeRibKind::Item => break,
1341+
LifetimeRibKind::AnonymousPassThrough(binder) => {
1342+
error = false;
1343+
res = LifetimeRes::Anonymous { binder, elided: true };
1344+
break;
1345+
}
1346+
LifetimeRibKind::AnonymousReportError | LifetimeRibKind::Item => {
1347+
// FIXME(cjgillot) This resolution is wrong, but this does not matter
1348+
// since these cases are erroneous anyway.
1349+
res = LifetimeRes::Anonymous { binder: DUMMY_NODE_ID, elided: true };
1350+
error = false;
1351+
break;
1352+
}
13441353
_ => {}
13451354
}
13461355
}
13471356

1348-
let res = if error {
1349-
LifetimeRes::Error
1350-
} else {
1351-
LifetimeRes::Anonymous { binder: segment_id, elided: true }
1352-
};
1353-
13541357
let node_ids = self.r.next_node_ids(expected_lifetimes);
13551358
self.record_lifetime_res(
13561359
segment_id,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// check-pass
2+
3+
struct Foo<'a>(&'a ());
4+
5+
fn with_fn() -> fn(Foo) {
6+
|_| ()
7+
}
8+
9+
fn with_impl_fn() -> impl Fn(Foo) {
10+
|_| ()
11+
}
12+
13+
fn with_where_fn<T>()
14+
where
15+
T: Fn(Foo),
16+
{
17+
}
18+
19+
fn main() {}

0 commit comments

Comments
 (0)