Skip to content

Commit bcdde4e

Browse files
authored
Rollup merge of rust-lang#134601 - dtolnay:dynstar, r=compiler-errors
Support pretty-printing `dyn*` trait objects - Tracking issue: rust-lang#102425
2 parents 3a94f4c + 23a2507 commit bcdde4e

File tree

6 files changed

+15
-11
lines changed

6 files changed

+15
-11
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

-4
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,6 @@ static EXPRS: &[&str] = &[
135135
"(0.).to_string()",
136136
"0. .. 1.",
137137
*/
138-
/*
139-
// FIXME: pretty-printer loses the dyn*. `i as Trait`
140-
"i as dyn* Trait",
141-
*/
142138
];
143139

144140
// 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
|

tests/ui/unpretty/expanded-exhaustive.rs

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#![feature(const_trait_impl)]
1010
#![feature(decl_macro)]
1111
#![feature(deref_patterns)]
12+
#![feature(dyn_star)]
1213
#![feature(explicit_tail_calls)]
1314
#![feature(gen_blocks)]
1415
#![feature(let_chains)]
@@ -800,6 +801,7 @@ mod types {
800801
let _: dyn Send + 'static;
801802
let _: dyn 'static + Send;
802803
let _: dyn for<'a> Send;
804+
let _: dyn* Send;
803805
}
804806

805807
/// TyKind::ImplTrait

tests/ui/unpretty/expanded-exhaustive.stdout

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#![feature(const_trait_impl)]
1111
#![feature(decl_macro)]
1212
#![feature(deref_patterns)]
13+
#![feature(dyn_star)]
1314
#![feature(explicit_tail_calls)]
1415
#![feature(gen_blocks)]
1516
#![feature(let_chains)]
@@ -647,6 +648,7 @@ mod types {
647648
let _: dyn Send + 'static;
648649
let _: dyn 'static + Send;
649650
let _: dyn for<'a> Send;
651+
let _: dyn* Send;
650652
}
651653
/// TyKind::ImplTrait
652654
const fn ty_impl_trait() {

0 commit comments

Comments
 (0)