@@ -36,17 +36,17 @@ impl AttrProcMacro for ExpandEnsures {
36
36
}
37
37
38
38
fn expand_injecting_circa_where_clause (
39
- _ecx : & mut ExtCtxt < ' _ > ,
39
+ ecx : & mut ExtCtxt < ' _ > ,
40
40
attr_span : Span ,
41
41
annotated : TokenStream ,
42
42
inject : impl FnOnce ( & mut Vec < TokenTree > ) -> Result < ( ) , ErrorGuaranteed > ,
43
43
) -> Result < TokenStream , ErrorGuaranteed > {
44
44
let mut new_tts = Vec :: with_capacity ( annotated. len ( ) ) ;
45
- let mut cursor = annotated. into_trees ( ) ;
45
+ let mut cursor = annotated. iter ( ) ;
46
46
47
47
// Find the `fn name<G,...>(x:X,...)` and inject the AST contract forms right after
48
48
// the formal parameters (and return type if any).
49
- while let Some ( tt) = cursor. next_ref ( ) {
49
+ while let Some ( tt) = cursor. next ( ) {
50
50
new_tts. push ( tt. clone ( ) ) ;
51
51
if let TokenTree :: Token ( tok, _) = tt
52
52
&& tok. is_ident_named ( kw:: Fn )
@@ -58,7 +58,7 @@ fn expand_injecting_circa_where_clause(
58
58
// Found the `fn` keyword, now find the formal parameters.
59
59
//
60
60
// 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 ( ) {
62
62
new_tts. push ( tt. clone ( ) ) ;
63
63
64
64
if let TokenTree :: Delimited ( _, _, token:: Delimiter :: Parenthesis , _) = tt {
@@ -81,7 +81,7 @@ fn expand_injecting_circa_where_clause(
81
81
// parse the type expression itself. But rather than try to fix things with hacks like that,
82
82
// time might be better spent extending the attribute expander to suport tt-annotation atop
83
83
// 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 ( ) ;
85
85
while let Some ( next_tt) = opt_next_tt {
86
86
if let TokenTree :: Token ( tok, _) = next_tt
87
87
&& tok. is_ident_named ( kw:: Where )
@@ -97,8 +97,7 @@ fn expand_injecting_circa_where_clause(
97
97
98
98
// for anything else, transcribe the tt and keep looking.
99
99
new_tts. push ( next_tt. clone ( ) ) ;
100
- opt_next_tt = cursor. next_ref ( ) ;
101
- continue ;
100
+ opt_next_tt = cursor. next ( ) ;
102
101
}
103
102
104
103
// 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(
118
117
if let Some ( tt) = opt_next_tt {
119
118
new_tts. push ( tt. clone ( ) ) ;
120
119
}
121
- while let Some ( tt) = cursor. next_ref ( ) {
120
+ while let Some ( tt) = cursor. next ( ) {
122
121
new_tts. push ( tt. clone ( ) ) ;
123
122
}
124
123
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
+
125
129
Ok ( TokenStream :: new ( new_tts) )
126
130
}
127
131
0 commit comments