@@ -2,8 +2,8 @@ use std::borrow::Cow;
22
33use rustc_ast:: YieldKind ;
44use rustc_ast:: ast:: {
5- self , Attribute , MetaItem , MetaItemInner , MetaItemKind , NodeId , Path , Visibility ,
6- VisibilityKind ,
5+ self , Attribute , ImplRestriction , MetaItem , MetaItemInner , MetaItemKind , NodeId , Path ,
6+ RestrictionKind , Visibility , VisibilityKind ,
77} ;
88use rustc_ast_pretty:: pprust;
99use rustc_span:: { BytePos , LocalExpnId , Span , Symbol , SyntaxContext , sym, symbol} ;
@@ -74,6 +74,40 @@ pub(crate) fn format_visibility(
7474 }
7575}
7676
77+ pub ( crate ) fn format_impl_restriction (
78+ context : & RewriteContext < ' _ > ,
79+ impl_restriction : & ImplRestriction ,
80+ ) -> String {
81+ format_restriction ( "impl" , context, & impl_restriction. kind )
82+ }
83+
84+ fn format_restriction (
85+ kw : & ' static str ,
86+ context : & RewriteContext < ' _ > ,
87+ restriction : & RestrictionKind ,
88+ ) -> String {
89+ match restriction {
90+ RestrictionKind :: Unrestricted => format ! ( "{kw} " ) ,
91+ RestrictionKind :: Restricted {
92+ ref path,
93+ id : _,
94+ shorthand,
95+ } => {
96+ let Path { ref segments, .. } = * * path;
97+ let mut segments_iter = segments. iter ( ) . map ( |seg| rewrite_ident ( context, seg. ident ) ) ;
98+ if path. is_global ( ) && segments_iter. next ( ) . is_none ( ) {
99+ panic ! ( "non-global path in {kw}(restricted)?" ) ;
100+ }
101+ // FIXME use `segments_iter.intersperse("::").collect::<String>()` once
102+ // `#![feature(iter_intersperse)]` is re-stabilized.
103+ let path = itertools:: join ( segments_iter, "::" ) ;
104+ let in_str = if * shorthand { "" } else { "in " } ;
105+
106+ format ! ( "{kw}({in_str}{path}) " )
107+ }
108+ }
109+ }
110+
77111#[ inline]
78112pub ( crate ) fn format_coro ( coroutine_kind : & ast:: CoroutineKind ) -> & ' static str {
79113 match coroutine_kind {
0 commit comments