Skip to content

Commit 949769c

Browse files
authoredDec 29, 2021
Rollup merge of #92372 - dtolnay:fntype, r=jackh726
Print space after formal generic params in fn type Follow-up to #92238 fixing one of the FIXMEs. ```rust macro_rules! repro { ($ty:ty) => { stringify!($ty) }; } fn main() { println!("{}", repro!(for<'a> fn(&'a u8))); } ``` Before:&ensp;`for<'a>fn(&'a u8)` After:&ensp;`for<'a> fn(&'a u8)` The pretty printer's `print_formal_generic_params` already prints formal generic params correctly with a space, we just need to call it when printing BareFn types instead of reimplementing the printing incorrectly without a space. https://github.com/rust-lang/rust/blob/83b15bfe1c15f325bc186ebfe3691b729ed59f2b/compiler/rustc_ast_pretty/src/pprust/state.rs#L1394-L1400
2 parents 5583010 + ad29c17 commit 949769c

File tree

3 files changed

+3
-9
lines changed

3 files changed

+3
-9
lines changed
 

‎compiler/rustc_ast_pretty/src/pprust/state.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -2909,10 +2909,7 @@ impl<'a> State<'a> {
29092909
generic_params: &[ast::GenericParam],
29102910
) {
29112911
self.ibox(INDENT_UNIT);
2912-
if !generic_params.is_empty() {
2913-
self.word("for");
2914-
self.print_generic_params(generic_params);
2915-
}
2912+
self.print_formal_generic_params(generic_params);
29162913
let generics = ast::Generics {
29172914
params: Vec::new(),
29182915
where_clause: ast::WhereClause {

‎compiler/rustc_hir_pretty/src/lib.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -2327,10 +2327,7 @@ impl<'a> State<'a> {
23272327
arg_names: &[Ident],
23282328
) {
23292329
self.ibox(INDENT_UNIT);
2330-
if !generic_params.is_empty() {
2331-
self.word("for");
2332-
self.print_generic_params(generic_params);
2333-
}
2330+
self.print_formal_generic_params(generic_params);
23342331
let generics = hir::Generics {
23352332
params: &[],
23362333
where_clause: hir::WhereClause { predicates: &[], span: rustc_span::DUMMY_SP },

‎src/test/ui/macros/stringify.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ fn test_ty() {
803803
assert_eq!(stringify_ty!(fn(x: u8)), "fn(x: u8)");
804804
#[rustfmt::skip]
805805
assert_eq!(stringify_ty!(for<> fn()), "fn()");
806-
assert_eq!(stringify_ty!(for<'a> fn()), "for<'a>fn()"); // FIXME
806+
assert_eq!(stringify_ty!(for<'a> fn()), "for<'a> fn()");
807807

808808
// TyKind::Never
809809
assert_eq!(stringify_ty!(!), "!");

0 commit comments

Comments
 (0)
Please sign in to comment.