File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ pub use UnsafeSource::*;
2525use crate :: ptr:: P ;
2626use crate :: token:: { self , DelimToken } ;
2727use crate :: tokenstream:: { DelimSpan , TokenStream , TokenTree } ;
28+ use crate :: visit:: { walk_ty, Visitor } ;
2829
2930use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
3031use rustc_data_structures:: sync:: Lrc ;
@@ -1795,6 +1796,26 @@ pub struct Ty {
17951796 pub span : Span ,
17961797}
17971798
1799+ impl Ty {
1800+ /// Returns `true` if the kind of this type or any types contained within are `impl Trait`.
1801+ pub fn contains_impl_trait ( & self ) -> bool {
1802+ struct ContainsImplTrait ( bool ) ;
1803+
1804+ impl < ' ast > Visitor < ' ast > for ContainsImplTrait {
1805+ fn visit_ty ( & mut self , t : & ' ast Ty ) {
1806+ self . 0 |= matches ! ( t. kind, TyKind :: ImplTrait ( ..) ) ;
1807+ if !self . 0 {
1808+ walk_ty ( self , t) ;
1809+ }
1810+ }
1811+ }
1812+
1813+ let mut vis = ContainsImplTrait ( false ) ;
1814+ vis. visit_ty ( self ) ;
1815+ vis. 0
1816+ }
1817+ }
1818+
17981819#[ derive( Clone , RustcEncodable , RustcDecodable , Debug ) ]
17991820pub struct BareFnTy {
18001821 pub unsafety : Unsafe ,
You can’t perform that action at this time.
0 commit comments