Skip to content

Commit 1fa1689

Browse files
Support dyn*
1 parent e65608f commit 1fa1689

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

compiler/rustc_hir/src/hir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ impl<'hir> Generics<'hir> {
680680
self.bounds_for_param(param_def_id).flat_map(|bp| bp.bounds.iter().rev()).find_map(
681681
|bound| {
682682
let span_for_parentheses = get_inner_ty(bound).and_then(|ty| {
683-
if let TyKind::TraitObject(_, _, TraitObjectSyntax::Dyn) = ty.kind {
683+
if let TyKind::TraitObject(_, _, TraitObjectSyntax::Dyn | TraitObjectSyntax::DynStar) = ty.kind {
684684
let span = ty.span;
685685
span.can_be_used_for_suggestions().then(|| span)
686686
} else {
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1+
#![feature(dyn_star)] //~ WARNING the feature `dyn_star` is incomplete
2+
13
use std::future::Future;
24

3-
pub fn foo<T>(
5+
pub fn dyn_func<T>(
46
executor: impl FnOnce(T) -> dyn Future<Output = ()>,
57
) -> Box<dyn FnOnce(T) -> dyn Future<Output = ()>> {
68
Box::new(executor) //~ ERROR the parameter type
79
}
810

11+
pub fn dyn_star_func<T>(
12+
executor: impl FnOnce(T) -> dyn* Future<Output = ()>,
13+
) -> Box<dyn FnOnce(T) -> dyn* Future<Output = ()>> {
14+
Box::new(executor) //~ ERROR the parameter type
15+
}
16+
917
fn main() {}

tests/ui/suggestions/wrap-dyn-in-suggestion-issue-120223.stderr

+25-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1+
warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/wrap-dyn-in-suggestion-issue-120223.rs:1:12
3+
|
4+
LL | #![feature(dyn_star)]
5+
| ^^^^^^^^
6+
|
7+
= note: see issue #102425 <https://github.com/rust-lang/rust/issues/102425> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
110
error[E0310]: the parameter type `impl FnOnce(T) -> dyn Future<Output = ()>` may not live long enough
2-
--> $DIR/wrap-dyn-in-suggestion-issue-120223.rs:6:5
11+
--> $DIR/wrap-dyn-in-suggestion-issue-120223.rs:8:5
312
|
413
LL | Box::new(executor)
514
| ^^^^^^^^^^^^^^^^^^
@@ -12,6 +21,20 @@ help: consider adding an explicit lifetime bound
1221
LL | executor: impl FnOnce(T) -> (dyn Future<Output = ()>) + 'static,
1322
| + +++++++++++
1423

15-
error: aborting due to 1 previous error
24+
error[E0310]: the parameter type `impl FnOnce(T) -> Future<Output = ()>` may not live long enough
25+
--> $DIR/wrap-dyn-in-suggestion-issue-120223.rs:14:5
26+
|
27+
LL | Box::new(executor)
28+
| ^^^^^^^^^^^^^^^^^^
29+
| |
30+
| the parameter type `impl FnOnce(T) -> Future<Output = ()>` must be valid for the static lifetime...
31+
| ...so that the type `impl FnOnce(T) -> Future<Output = ()>` will meet its required lifetime bounds
32+
|
33+
help: consider adding an explicit lifetime bound
34+
|
35+
LL | executor: impl FnOnce(T) -> (dyn* Future<Output = ()>) + 'static,
36+
| + +++++++++++
37+
38+
error: aborting due to 2 previous errors; 1 warning emitted
1639

1740
For more information about this error, try `rustc --explain E0310`.

0 commit comments

Comments
 (0)