@@ -176,68 +176,49 @@ macro_rules! __property {
176176#[ doc( hidden) ]
177177#[ macro_export]
178178macro_rules! property_internal {
179- ( & $( $t: ident) ::+ $( :: <$( $t_ty_args: ty) ,* $( , ) ?>) ?
179+ // `ref` variant.
180+ (
181+ // The 3 cases of `$(& $($_amp:literal)?)?` -> `$(& $($_amp)*)*`
182+ // 1. outer group captures nothing => expansion produces nothing
183+ // 2. outer group captures just `&` => expansion produces `&`
184+ // 3. outer group captures `& <literal>` => disallowed by `@assert_empty` subrule invocation
185+ //
186+ // `$_amp:literal` works only because the following `$t:ident` or `::` can't be captured by
187+ // it.
188+ $( & $( $_amp: literal) ?) ? // Optional `&`'s presence is implicitly captured by `_amp`.
189+ $( :: $( $_cs: literal) ?) ? // Optional `::`'s presence is implicitly captured by `_cs`.
190+ $( $t: ident) ::+ $( :: <$( $t_ty_args: ty) ,* $( , ) ?>) ?
180191 . $method: tt $( :: <$( $m_ty_args: ty) ,* $( , ) ?>) ? ( $( $argument: expr) ,* $( , ) ?) ,
181- ref $m: expr) => { {
182- $crate:: property_internal!( @self_arg
183- struct_type: [ & $( $t) ::+ $( <$( $t_ty_args) ,* >) * ]
184- method_prefix: [ $( $t) ::+ $( :: <$( $t_ty_args) ,* >) * ]
185- [ $method $( :: <$( $m_ty_args) ,* >) * ] [ $( $argument) ,* ] [ $m] )
186- } } ;
187- ( $( $t: ident) ::+ $( :: <$( $t_ty_args: ty) ,* $( , ) ?>) ?
188- . $method: tt $( :: <$( $m_ty_args: ty) ,* $( , ) ?>) ? ( $( $argument: expr) ,* $( , ) ?) ,
189- ref $m: expr) => { {
190- $crate:: property_internal!( @self_arg
191- struct_type: [ $( $t) ::+ $( <$( $t_ty_args) ,* >) * ]
192- method_prefix: [ $( $t) ::+ $( :: <$( $t_ty_args) ,* >) * ]
193- [ $method $( :: <$( $m_ty_args) ,* >) * ] [ $( $argument) ,* ] [ $m] )
194- } } ;
195- ( & :: $( $t: ident) ::+ $( :: <$( $t_ty_args: ty) ,* $( , ) ?>) ?
196- . $method: tt $( :: <$( $m_ty_args: ty) ,* $( , ) ?>) ? ( $( $argument: expr) ,* $( , ) ?) ,
197- ref $m: expr) => { {
198- $crate:: property_internal!( @self_arg
199- struct_type: [ & :: $( $t) ::+ $( <$( $t_ty_args) ,* >) * ]
200- method_prefix: [ :: $( $t) ::+ $( :: <$( $t_ty_args) ,* >) * ]
201- [ $method $( :: <$( $m_ty_args) ,* >) * ] [ $( $argument) ,* ] [ $m] )
202- } } ;
203- ( :: $( $t: ident) ::+ $( :: <$( $t_ty_args: ty) ,* $( , ) ?>) ?
204- . $method: tt $( :: <$( $m_ty_args: ty) ,* $( , ) ?>) ? ( $( $argument: expr) ,* $( , ) ?) ,
205- ref $m: expr) => { {
206- $crate:: property_internal!( @self_arg
207- struct_type: [ :: $( $t) ::+ $( <$( $t_ty_args) ,* >) * ]
208- method_prefix: [ :: $( $t) ::+ $( :: <$( $t_ty_args) ,* >) * ]
192+ ref $m: expr
193+ ) => { {
194+ $crate:: property_internal!( @assert_empty $( $( $_amp) * ) * $( $( $_cs) * ) * ) ;
195+ $crate:: property_internal!(
196+ @self_arg
197+ struct_type: [ $( & $( $_amp) * ) * $( :: $( $_cs) * ) * $( $t) ::+ $( <$( $t_ty_args) ,* >) * ]
198+ method_prefix: [ $( :: $( $_cs) * ) * $( $t) ::+ $( :: <$( $t_ty_args) ,* >) * ]
209199 [ $method $( :: <$( $m_ty_args) ,* >) * ] [ $( $argument) ,* ] [ $m] )
210200 } } ;
211201
212- ( & $( $t: ident) ::+ $( :: <$( $t_ty_args: ty) ,* $( , ) ?>) ?
202+ // Non-`ref` variant.
203+ (
204+ // See comment on previous variant above.
205+ $( & $( $_amp: literal) ?) ? // Optional `&`'s presence is implicitly captured by `_amp`.
206+ $( :: $( $_cs: literal) ?) ? // Optional `::`'s presence is implicitly captured by `_cs`.
207+ $( $t: ident) ::+ $( :: <$( $t_ty_args: ty) ,* $( , ) ?>) ?
213208 . $method: tt $( :: <$( $m_ty_args: ty) ,* $( , ) ?>) ? ( $( $argument: expr) ,* $( , ) ?) ,
214209 $m: expr) => { {
215- $crate:: property_internal!( @self_dot
216- struct_type: [ &&$( $t) ::+ $( <$( $t_ty_args) ,* >) * ]
217- [ $method $( :: <$( $m_ty_args) ,* >) * ] [ $( $argument) ,* ] [ $m] )
218- } } ;
219- ( $( $t: ident) ::+ $( :: <$( $t_ty_args: ty) ,* $( , ) ?>) ?
220- . $method: tt $( :: <$( $m_ty_args: ty) ,* $( , ) ?>) ? ( $( $argument: expr) ,* $( , ) ?) ,
221- $m: expr) => { {
222- $crate:: property_internal!( @self_dot
223- struct_type: [ & $( $t) ::+ $( <$( $t_ty_args) ,* >) * ]
224- [ $method $( :: <$( $m_ty_args) ,* >) * ] [ $( $argument) ,* ] [ $m] )
225- } } ;
226- ( & :: $( $t: ident) ::+ $( :: <$( $t_ty_args: ty) ,* $( , ) ?>) ?
227- . $method: tt $( :: <$( $m_ty_args: ty) ,* $( , ) ?>) ? ( $( $argument: expr) ,* $( , ) ?) ,
228- $m: expr) => { {
229- $crate:: property_internal!( @self_dot
230- struct_type: [ &&:: $( $t) ::+ $( <$( $t_ty_args) ,* >) * ]
231- [ $method $( :: <$( $m_ty_args) ,* >) * ] [ $( $argument) ,* ] [ $m] )
232- } } ;
233- ( :: $( $t: ident) ::+ $( :: <$( $t_ty_args: ty) ,* $( , ) ?>) ?
234- . $method: tt $( :: <$( $m_ty_args: ty) ,* $( , ) ?>) ? ( $( $argument: expr) ,* $( , ) ?) ,
235- $m: expr) => { {
236- $crate:: property_internal!( @self_dot
237- struct_type: [ & :: $( $t) ::+ $( <$( $t_ty_args) ,* >) * ]
210+ $crate:: property_internal!( @assert_empty $( $( $_amp) * ) * $( $( $_cs) * ) * ) ;
211+ $crate:: property_internal!(
212+ @self_dot
213+ struct_type: [ $( & $( $_amp) * ) * $( :: $( $_cs) * ) * $( $t) ::+ $( <$( $t_ty_args) ,* >) * ]
238214 [ $method $( :: <$( $m_ty_args) ,* >) * ] [ $( $argument) ,* ] [ $m] )
239215 } } ;
240216
217+ ( @assert_empty) => { } ;
218+ ( @assert_empty $( $l: literal) +) => {
219+ compile_error!( "property! argument must start with an optional `&` followed by a path" )
220+ } ;
221+
241222 ( @self_arg struct_type: [ $struct_ty: ty]
242223 method_prefix: [ $( $method_prefix: tt) +]
243224 [ $( $method: tt) * ] [ $( $argument: expr) ,* ] [ $m: expr] ) => { {
@@ -250,7 +231,7 @@ macro_rules! property_internal {
250231 ( @self_dot struct_type: [ $struct_ty: ty]
251232 [ $( $method: tt) * ] [ $( $argument: expr) ,* ] [ $m: expr] ) => { {
252233 $crate:: matchers:: __internal_unstable_do_not_depend_on_these:: property_matcher(
253- |o: $struct_ty| o. $( $method) * ( $( $argument) ,* ) ,
234+ |o: & $struct_ty| o. $( $method) * ( $( $argument) ,* ) ,
254235 & stringify!( $( $method) * ( $( $argument) ,* ) ) ,
255236 $crate:: matcher_support:: __internal_unstable_do_not_depend_on_these:: auto_eq!( $m) )
256237 } } ;
0 commit comments