Skip to content

Commit 1cc8289

Browse files
committed
Support pretty-printing dyn* trait objects
1 parent 13170cd commit 1cc8289

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

compiler/rustc_ast_pretty/src/pprust/state.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1204,8 +1204,10 @@ impl<'a> State<'a> {
12041204
}
12051205
ast::TyKind::Path(Some(qself), path) => self.print_qpath(path, qself, false),
12061206
ast::TyKind::TraitObject(bounds, syntax) => {
1207-
if *syntax == ast::TraitObjectSyntax::Dyn {
1208-
self.word_nbsp("dyn");
1207+
match syntax {
1208+
ast::TraitObjectSyntax::Dyn => self.word_nbsp("dyn"),
1209+
ast::TraitObjectSyntax::DynStar => self.word_nbsp("dyn*"),
1210+
ast::TraitObjectSyntax::None => {}
12091211
}
12101212
self.print_type_bounds(bounds);
12111213
}

compiler/rustc_hir_pretty/src/lib.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,10 @@ impl<'a> State<'a> {
402402
}
403403
hir::TyKind::Path(ref qpath) => self.print_qpath(qpath, false),
404404
hir::TyKind::TraitObject(bounds, lifetime, syntax) => {
405-
if syntax == ast::TraitObjectSyntax::Dyn {
406-
self.word_space("dyn");
405+
match syntax {
406+
ast::TraitObjectSyntax::Dyn => self.word_nbsp("dyn"),
407+
ast::TraitObjectSyntax::DynStar => self.word_nbsp("dyn*"),
408+
ast::TraitObjectSyntax::None => {}
407409
}
408410
let mut first = true;
409411
for bound in bounds {

tests/ui-fulldeps/pprust-parenthesis-insertion.rs

-3
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,7 @@ static EXPRS: &[&str] = &[
129129
"(0.).to_string()",
130130
"0. .. 1.",
131131
*/
132-
/*
133-
// FIXME: pretty-printer loses the dyn*. `i as Trait`
134132
"i as dyn* Trait",
135-
*/
136133
];
137134

138135
// Flatten the content of parenthesis nodes into their parent node. For example

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ help: consider adding an explicit lifetime bound
5858
LL | executor: impl FnOnce(T) -> (dyn Future<Output = ()>) + 'static,
5959
| + +++++++++++
6060

61-
error[E0310]: the parameter type `impl FnOnce(T) -> Future<Output = ()>` may not live long enough
61+
error[E0310]: the parameter type `impl FnOnce(T) -> dyn* Future<Output = ()>` may not live long enough
6262
--> $DIR/wrap-dyn-in-suggestion-issue-120223.rs:14:5
6363
|
6464
LL | Box::new(executor)
6565
| ^^^^^^^^^^^^^^^^^^
6666
| |
67-
| the parameter type `impl FnOnce(T) -> Future<Output = ()>` must be valid for the static lifetime...
68-
| ...so that the type `impl FnOnce(T) -> Future<Output = ()>` will meet its required lifetime bounds
67+
| the parameter type `impl FnOnce(T) -> dyn* Future<Output = ()>` must be valid for the static lifetime...
68+
| ...so that the type `impl FnOnce(T) -> dyn* Future<Output = ()>` will meet its required lifetime bounds
6969
|
7070
help: consider adding an explicit lifetime bound
7171
|

0 commit comments

Comments
 (0)