21
21
use std:: borrow:: Cow ;
22
22
use std:: { cmp, fmt, mem} ;
23
23
24
+ pub use GenericArgs :: * ;
25
+ pub use UnsafeSource :: * ;
24
26
pub use rustc_ast_ir:: { Movability , Mutability } ;
25
27
use rustc_data_structures:: packed:: Pu128 ;
26
28
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
27
29
use rustc_data_structures:: stack:: ensure_sufficient_stack;
28
30
use rustc_data_structures:: sync:: Lrc ;
29
31
use rustc_macros:: { Decodable , Encodable , HashStable_Generic } ;
30
- use rustc_span:: source_map:: { respan, Spanned } ;
31
- use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
32
32
pub use rustc_span:: AttrId ;
33
- use rustc_span:: { ErrorGuaranteed , Span , DUMMY_SP } ;
34
- use thin_vec :: { thin_vec , ThinVec } ;
35
- pub use GenericArgs :: * ;
36
- pub use UnsafeSource :: * ;
33
+ use rustc_span:: source_map :: { Spanned , respan } ;
34
+ use rustc_span :: symbol :: { Ident , Symbol , kw , sym } ;
35
+ use rustc_span :: { DUMMY_SP , ErrorGuaranteed , Span } ;
36
+ use thin_vec :: { ThinVec , thin_vec } ;
37
37
38
38
pub use crate :: format:: * ;
39
39
use crate :: ptr:: P ;
@@ -288,7 +288,7 @@ impl ParenthesizedArgs {
288
288
}
289
289
}
290
290
291
- pub use crate :: node_id:: { NodeId , CRATE_NODE_ID , DUMMY_NODE_ID } ;
291
+ pub use crate :: node_id:: { CRATE_NODE_ID , DUMMY_NODE_ID , NodeId } ;
292
292
293
293
/// Modifiers on a trait bound like `~const`, `?` and `!`.
294
294
#[ derive( Copy , Clone , PartialEq , Eq , Encodable , Decodable , Debug ) ]
@@ -1187,8 +1187,8 @@ impl Expr {
1187
1187
/// `min_const_generics` as more complex expressions are not supported.
1188
1188
///
1189
1189
/// Does not ensure that the path resolves to a const param, the caller should check this.
1190
- pub fn is_potential_trivial_const_arg ( & self ) -> bool {
1191
- let this = self . maybe_unwrap_block ( ) ;
1190
+ pub fn is_potential_trivial_const_arg ( & self , strip_identity_block : bool ) -> bool {
1191
+ let this = if strip_identity_block { self . maybe_unwrap_block ( ) . 1 } else { self } ;
1192
1192
1193
1193
if let ExprKind :: Path ( None , path) = & this. kind
1194
1194
&& path. is_potential_trivial_const_arg ( )
@@ -1199,14 +1199,15 @@ impl Expr {
1199
1199
}
1200
1200
}
1201
1201
1202
- pub fn maybe_unwrap_block ( & self ) -> & Expr {
1202
+ /// Returns an expression with (when possible) *one* outter brace removed
1203
+ pub fn maybe_unwrap_block ( & self ) -> ( bool , & Expr ) {
1203
1204
if let ExprKind :: Block ( block, None ) = & self . kind
1204
1205
&& let [ stmt] = block. stmts . as_slice ( )
1205
1206
&& let StmtKind :: Expr ( expr) = & stmt. kind
1206
1207
{
1207
- expr
1208
+ ( true , expr)
1208
1209
} else {
1209
- self
1210
+ ( false , self )
1210
1211
}
1211
1212
}
1212
1213
0 commit comments