Skip to content

Commit 7908120

Browse files
Rollup merge of #156820 - aerooneqq:delegation-visit-body-elided-infer-lt-rib, r=petrochenkov
delegation: visit body under elided-infer lifetime rib Fixes #156806. Part of #118212. r? @petrochenkov
2 parents fc73322 + a83eba4 commit 7908120

5 files changed

Lines changed: 65 additions & 12 deletions

File tree

compiler/rustc_resolve/src/late.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3937,7 +3937,9 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
39373937

39383938
//As we lower target_expr_template body to a body of a function we need a label rib (#148889)
39393939
this.with_label_rib(RibKind::FnOrCoroutine, |this| {
3940-
this.visit_block(body);
3940+
this.with_lifetime_rib(LifetimeRibKind::Elided(LifetimeRes::Infer), |this| {
3941+
this.visit_block(body);
3942+
});
39413943
});
39423944
});
39433945
}

tests/ui/delegation/ice-line-bounds-issue-148732.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ reuse a as b {
22
//~^ ERROR cannot find function `a` in this scope
33
//~| ERROR functions delegation is not yet fully implemented
44
dbg!(b);
5-
//~^ ERROR missing lifetime specifier
5+
//~^ ERROR: `fn() {b}` doesn't implement `Debug`
66
}
77

88
fn main() {}

tests/ui/delegation/ice-line-bounds-issue-148732.stderr

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
error[E0106]: missing lifetime specifier
2-
--> $DIR/ice-line-bounds-issue-148732.rs:4:5
3-
|
4-
LL | dbg!(b);
5-
| ^^^^^^^ expected named lifetime parameter
6-
71
error[E0425]: cannot find function `a` in this scope
82
--> $DIR/ice-line-bounds-issue-148732.rs:1:7
93
|
@@ -25,7 +19,18 @@ LL | | }
2519
= help: add `#![feature(fn_delegation)]` to the crate attributes to enable
2620
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2721

22+
error[E0277]: `fn() {b}` doesn't implement `Debug`
23+
--> $DIR/ice-line-bounds-issue-148732.rs:4:5
24+
|
25+
LL | reuse a as b {
26+
| - consider calling this function
27+
...
28+
LL | dbg!(b);
29+
| ^^^^^^^ the trait `Debug` is not implemented for fn item `fn() {b}`
30+
|
31+
= help: use parentheses to call this function: `b()`
32+
2833
error: aborting due to 3 previous errors
2934

30-
Some errors have detailed explanations: E0106, E0425, E0658.
31-
For more information about an error, try `rustc --explain E0106`.
35+
Some errors have detailed explanations: E0277, E0425, E0658.
36+
For more information about an error, try `rustc --explain E0277`.

tests/ui/delegation/wrong-lifetime-rib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,14 @@ mod ice_156758 {
2929
}
3030
}
3131

32+
mod ice_156806 {
33+
trait X {}
34+
35+
impl X { //~ ERROR: expected a type, found a trait
36+
reuse Iterator::fold { //~ ERROR: `()` is not an iterator
37+
let _: &X; //~ ERROR: expected a type, found a trait
38+
}
39+
}
40+
}
41+
3242
fn main() {}

tests/ui/delegation/wrong-lifetime-rib.stderr

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ help: you might have intended to implement this trait for a given type
1919
LL | impl X for /* Type */ {
2020
| ++++++++++++++
2121

22+
error[E0782]: expected a type, found a trait
23+
--> $DIR/wrong-lifetime-rib.rs:35:10
24+
|
25+
LL | impl X {
26+
| ^
27+
|
28+
help: you can add the `dyn` keyword if you want a trait object
29+
|
30+
LL | impl dyn X {
31+
| +++
32+
help: you might have intended to implement this trait for a given type
33+
|
34+
LL | impl X for /* Type */ {
35+
| ++++++++++++++
36+
2237
error[E0116]: cannot define inherent `impl` for a type outside of the crate where the type is defined
2338
--> $DIR/wrong-lifetime-rib.rs:9:5
2439
|
@@ -40,7 +55,28 @@ LL - reuse<<<&Project> :: Ty> :: Ty as Iterator>::next;
4055
LL + reuse<<<&() as Example>::Ty> :: Ty as Iterator>::next;
4156
|
4257

43-
error: aborting due to 4 previous errors
58+
error[E0782]: expected a type, found a trait
59+
--> $DIR/wrong-lifetime-rib.rs:37:21
60+
|
61+
LL | let _: &X;
62+
| ^
63+
|
64+
help: you can add the `dyn` keyword if you want a trait object
65+
|
66+
LL | let _: &dyn X;
67+
| +++
68+
69+
error[E0599]: `()` is not an iterator
70+
--> $DIR/wrong-lifetime-rib.rs:36:25
71+
|
72+
LL | reuse Iterator::fold {
73+
| ^^^^ `()` is not an iterator
74+
|
75+
= note: the following trait bounds were not satisfied:
76+
`(): Iterator`
77+
which is required by `&mut (): Iterator`
78+
79+
error: aborting due to 7 previous errors
4480

45-
Some errors have detailed explanations: E0116, E0223, E0423, E0782.
81+
Some errors have detailed explanations: E0116, E0223, E0423, E0599, E0782.
4682
For more information about an error, try `rustc --explain E0116`.

0 commit comments

Comments
 (0)