@@ -36,17 +36,17 @@ impl AttrProcMacro for ExpandEnsures {
3636}
3737
3838fn expand_injecting_circa_where_clause (
39- _ecx : & mut ExtCtxt < ' _ > ,
39+ ecx : & mut ExtCtxt < ' _ > ,
4040 attr_span : Span ,
4141 annotated : TokenStream ,
4242 inject : impl FnOnce ( & mut Vec < TokenTree > ) -> Result < ( ) , ErrorGuaranteed > ,
4343) -> Result < TokenStream , ErrorGuaranteed > {
4444 let mut new_tts = Vec :: with_capacity ( annotated. len ( ) ) ;
45- let mut cursor = annotated. into_trees ( ) ;
45+ let mut cursor = annotated. iter ( ) ;
4646
4747 // Find the `fn name<G,...>(x:X,...)` and inject the AST contract forms right after
4848 // the formal parameters (and return type if any).
49- while let Some ( tt) = cursor. next_ref ( ) {
49+ while let Some ( tt) = cursor. next ( ) {
5050 new_tts. push ( tt. clone ( ) ) ;
5151 if let TokenTree :: Token ( tok, _) = tt
5252 && tok. is_ident_named ( kw:: Fn )
@@ -58,7 +58,7 @@ fn expand_injecting_circa_where_clause(
5858 // Found the `fn` keyword, now find the formal parameters.
5959 //
6060 // FIXME: can this fail if you have parentheticals in a generics list, like `fn foo<F: Fn(X) -> Y>` ?
61- while let Some ( tt) = cursor. next_ref ( ) {
61+ while let Some ( tt) = cursor. next ( ) {
6262 new_tts. push ( tt. clone ( ) ) ;
6363
6464 if let TokenTree :: Delimited ( _, _, token:: Delimiter :: Parenthesis , _) = tt {
@@ -81,7 +81,7 @@ fn expand_injecting_circa_where_clause(
8181 // parse the type expression itself. But rather than try to fix things with hacks like that,
8282 // time might be better spent extending the attribute expander to suport tt-annotation atop
8383 // ast-annotated, which would be an elegant way to sidestep all of this.
84- let mut opt_next_tt = cursor. next_ref ( ) ;
84+ let mut opt_next_tt = cursor. next ( ) ;
8585 while let Some ( next_tt) = opt_next_tt {
8686 if let TokenTree :: Token ( tok, _) = next_tt
8787 && tok. is_ident_named ( kw:: Where )
@@ -97,8 +97,7 @@ fn expand_injecting_circa_where_clause(
9797
9898 // for anything else, transcribe the tt and keep looking.
9999 new_tts. push ( next_tt. clone ( ) ) ;
100- opt_next_tt = cursor. next_ref ( ) ;
101- continue ;
100+ opt_next_tt = cursor. next ( ) ;
102101 }
103102
104103 // At this point, we've transcribed everything from the `fn` through the formal parameter list
@@ -118,10 +117,15 @@ fn expand_injecting_circa_where_clause(
118117 if let Some ( tt) = opt_next_tt {
119118 new_tts. push ( tt. clone ( ) ) ;
120119 }
121- while let Some ( tt) = cursor. next_ref ( ) {
120+ while let Some ( tt) = cursor. next ( ) {
122121 new_tts. push ( tt. clone ( ) ) ;
123122 }
124123
124+ // Record the span as a contract attribute expansion.
125+ // This is used later to stop users from using the extended syntax directly
126+ // which is gated via `rustc_contracts_internals`.
127+ ecx. psess ( ) . contract_attribute_spans . push ( attr_span) ;
128+
125129 Ok ( TokenStream :: new ( new_tts) )
126130}
127131
0 commit comments