@@ -141,16 +141,11 @@ impl Path {
141141 /// Check if this path is potentially a trivial const arg, i.e., one that can _potentially_
142142 /// be represented without an anon const in the HIR.
143143 ///
144- /// If `allow_mgca_arg` is true (as should be the case in most situations when
145- /// `#![feature(min_generic_const_args)]` is enabled), then this always returns true
146- /// because all paths are valid.
147- ///
148- /// Otherwise, it returns true iff the path has exactly one segment, and it has no generic args
144+ /// Returns true iff the path has exactly one segment, and it has no generic args
149145 /// (i.e., it is _potentially_ a const parameter).
150146 #[ tracing:: instrument( level = "debug" , ret) ]
151- pub fn is_potential_trivial_const_arg ( & self , allow_mgca_arg : bool ) -> bool {
152- allow_mgca_arg
153- || self . segments . len ( ) == 1 && self . segments . iter ( ) . all ( |seg| seg. args . is_none ( ) )
147+ pub fn is_potential_trivial_const_arg ( & self ) -> bool {
148+ self . segments . len ( ) == 1 && self . segments . iter ( ) . all ( |seg| seg. args . is_none ( ) )
154149 }
155150}
156151
@@ -1385,6 +1380,15 @@ pub enum UnsafeSource {
13851380 UserProvided ,
13861381}
13871382
1383+ /// Track whether under `feature(min_generic_const_args)` this anon const
1384+ /// was explicitly disambiguated as an anon const or not through the use of
1385+ /// `const { ... }` syntax.
1386+ #[ derive( Clone , PartialEq , Encodable , Decodable , Debug , Copy , Walkable ) ]
1387+ pub enum MgcaDisambiguation {
1388+ AnonConst ,
1389+ Direct ,
1390+ }
1391+
13881392/// A constant (expression) that's not an item or associated item,
13891393/// but needs its own `DefId` for type-checking, const-eval, etc.
13901394/// These are usually found nested inside types (e.g., array lengths)
@@ -1394,6 +1398,7 @@ pub enum UnsafeSource {
13941398pub struct AnonConst {
13951399 pub id : NodeId ,
13961400 pub value : Box < Expr > ,
1401+ pub mgca_disambiguation : MgcaDisambiguation ,
13971402}
13981403
13991404/// An expression.
@@ -1412,26 +1417,20 @@ impl Expr {
14121417 ///
14131418 /// This will unwrap at most one block level (curly braces). After that, if the expression
14141419 /// is a path, it mostly dispatches to [`Path::is_potential_trivial_const_arg`].
1415- /// See there for more info about `allow_mgca_arg`.
14161420 ///
1417- /// The only additional thing to note is that when `allow_mgca_arg` is false, this function
1418- /// will only allow paths with no qself, before dispatching to the `Path` function of
1419- /// the same name.
1421+ /// This function will only allow paths with no qself, before dispatching to the `Path`
1422+ /// function of the same name.
14201423 ///
14211424 /// Does not ensure that the path resolves to a const param/item, the caller should check this.
14221425 /// This also does not consider macros, so it's only correct after macro-expansion.
1423- pub fn is_potential_trivial_const_arg ( & self , allow_mgca_arg : bool ) -> bool {
1426+ pub fn is_potential_trivial_const_arg ( & self ) -> bool {
14241427 let this = self . maybe_unwrap_block ( ) ;
1425- if allow_mgca_arg {
1426- matches ! ( this. kind, ExprKind :: Path ( ..) )
1428+ if let ExprKind :: Path ( None , path) = & this. kind
1429+ && path. is_potential_trivial_const_arg ( )
1430+ {
1431+ true
14271432 } else {
1428- if let ExprKind :: Path ( None , path) = & this. kind
1429- && path. is_potential_trivial_const_arg ( allow_mgca_arg)
1430- {
1431- true
1432- } else {
1433- false
1434- }
1433+ false
14351434 }
14361435 }
14371436
@@ -1534,11 +1533,10 @@ impl Expr {
15341533 // then type of result is trait object.
15351534 // Otherwise we don't assume the result type.
15361535 ExprKind :: Binary ( binop, lhs, rhs) if binop. node == BinOpKind :: Add => {
1537- if let ( Some ( lhs) , Some ( rhs) ) = ( lhs. to_bound ( ) , rhs. to_bound ( ) ) {
1538- TyKind :: TraitObject ( vec ! [ lhs, rhs] , TraitObjectSyntax :: None )
1539- } else {
1536+ let ( Some ( lhs) , Some ( rhs) ) = ( lhs. to_bound ( ) , rhs. to_bound ( ) ) else {
15401537 return None ;
1541- }
1538+ } ;
1539+ TyKind :: TraitObject ( vec ! [ lhs, rhs] , TraitObjectSyntax :: None )
15421540 }
15431541
15441542 ExprKind :: Underscore => TyKind :: Infer ,
@@ -2109,6 +2107,19 @@ pub struct MacroDef {
21092107 pub body : Box < DelimArgs > ,
21102108 /// `true` if macro was defined with `macro_rules`.
21112109 pub macro_rules : bool ,
2110+
2111+ /// If this is a macro used for externally implementable items,
2112+ /// it refers to an extern item which is its "target". This requires
2113+ /// name resolution so can't just be an attribute, so we store it in this field.
2114+ pub eii_extern_target : Option < EiiExternTarget > ,
2115+ }
2116+
2117+ #[ derive( Clone , Encodable , Decodable , Debug , HashStable_Generic , Walkable ) ]
2118+ pub struct EiiExternTarget {
2119+ /// path to the extern item we're targetting
2120+ pub extern_item_path : Path ,
2121+ pub impl_unsafe : bool ,
2122+ pub span : Span ,
21122123}
21132124
21142125#[ derive( Clone , Encodable , Decodable , Debug , Copy , Hash , Eq , PartialEq ) ]
@@ -3748,6 +3759,21 @@ pub struct Fn {
37483759 pub contract : Option < Box < FnContract > > ,
37493760 pub define_opaque : Option < ThinVec < ( NodeId , Path ) > > ,
37503761 pub body : Option < Box < Block > > ,
3762+
3763+ /// This function is an implementation of an externally implementable item (EII).
3764+ /// This means, there was an EII declared somewhere and this function is the
3765+ /// implementation that should be run when the declaration is called.
3766+ pub eii_impls : ThinVec < EiiImpl > ,
3767+ }
3768+
3769+ #[ derive( Clone , Encodable , Decodable , Debug , Walkable ) ]
3770+ pub struct EiiImpl {
3771+ pub node_id : NodeId ,
3772+ pub eii_macro_path : Path ,
3773+ pub impl_safety : Safety ,
3774+ pub span : Span ,
3775+ pub inner_span : Span ,
3776+ pub is_default : bool ,
37513777}
37523778
37533779#[ derive( Clone , Encodable , Decodable , Debug , Walkable ) ]
@@ -4114,7 +4140,7 @@ mod size_asserts {
41144140 static_assert_size ! ( Block , 32 ) ;
41154141 static_assert_size ! ( Expr , 72 ) ;
41164142 static_assert_size ! ( ExprKind , 40 ) ;
4117- static_assert_size ! ( Fn , 184 ) ;
4143+ static_assert_size ! ( Fn , 192 ) ;
41184144 static_assert_size ! ( ForeignItem , 80 ) ;
41194145 static_assert_size ! ( ForeignItemKind , 16 ) ;
41204146 static_assert_size ! ( GenericArg , 24 ) ;
0 commit comments