@@ -94,7 +94,7 @@ fn expand_derive(cx: &mut ExtCtxt,
94
94
}
95
95
96
96
let mut found_partial_eq = false ;
97
- let mut found_eq = false ;
97
+ let mut eq_span = None ;
98
98
99
99
for titem in traits. iter ( ) . rev ( ) {
100
100
let tname = match titem. node {
@@ -114,12 +114,6 @@ fn expand_derive(cx: &mut ExtCtxt,
114
114
continue ;
115
115
}
116
116
117
- if & tname[ ..] == "Eq" {
118
- found_eq = true ;
119
- } else if & tname[ ..] == "PartialEq" {
120
- found_partial_eq = true ;
121
- }
122
-
123
117
let span = Span {
124
118
expn_id : cx. codemap ( ) . record_expansion ( codemap:: ExpnInfo {
125
119
call_site : titem. span ,
@@ -131,48 +125,26 @@ fn expand_derive(cx: &mut ExtCtxt,
131
125
} ) , ..titem. span
132
126
} ;
133
127
128
+ if & tname[ ..] == "Eq" {
129
+ eq_span = Some ( span) ;
130
+ } else if & tname[ ..] == "PartialEq" {
131
+ found_partial_eq = true ;
132
+ }
133
+
134
134
// #[derive(Foo, Bar)] expands to #[derive_Foo] #[derive_Bar]
135
135
item. attrs . push ( cx. attribute ( span, cx. meta_word ( titem. span ,
136
136
intern_and_get_ident ( & format ! ( "derive_{}" , tname) ) ) ) ) ;
137
137
}
138
138
139
139
// RFC #1445. `#[derive(PartialEq, Eq)]` adds a (trusted)
140
140
// `#[structural_match]` attribute.
141
- if found_partial_eq && found_eq {
142
- // This span is **very** sensitive and crucial to
143
- // getting the stability behavior we want. What we are
144
- // doing is marking `#[structural_match]` with the
145
- // span of the `#[deriving(...)]` attribute (the
146
- // entire attribute, not just the `PartialEq` or `Eq`
147
- // part), but with the current backtrace. The current
148
- // backtrace will contain a topmost entry that IS this
149
- // `#[deriving(...)]` attribute and with the
150
- // "allow-unstable" flag set to true.
151
- //
152
- // Note that we do NOT use the span of the `Eq`
153
- // text itself. You might think this is
154
- // equivalent, because the `Eq` appears within the
155
- // `#[deriving(Eq)]` attribute, and hence we would
156
- // inherit the "allows unstable" from the
157
- // backtrace. But in fact this is not always the
158
- // case. The actual source text that led to
159
- // deriving can be `#[$attr]`, for example, where
160
- // `$attr == deriving(Eq)`. In that case, the
161
- // "#[structural_match]" would be considered to
162
- // originate not from the deriving call but from
163
- // text outside the deriving call, and hence would
164
- // be forbidden from using unstable
165
- // content.
166
- //
167
- // See tests src/run-pass/rfc1445 for
168
- // examples. --nmatsakis
169
- let span = Span { expn_id : cx. backtrace ( ) , .. span } ;
170
- assert ! ( cx. parse_sess. codemap( ) . span_allows_unstable( span) ) ;
171
- debug ! ( "inserting structural_match with span {:?}" , span) ;
172
- let structural_match = intern_and_get_ident ( "structural_match" ) ;
173
- item. attrs . push ( cx. attribute ( span,
174
- cx. meta_word ( span,
175
- structural_match) ) ) ;
141
+ if let Some ( eq_span) = eq_span {
142
+ if found_partial_eq {
143
+ let structural_match = intern_and_get_ident ( "structural_match" ) ;
144
+ item. attrs . push ( cx. attribute ( eq_span,
145
+ cx. meta_word ( eq_span,
146
+ structural_match) ) ) ;
147
+ }
176
148
}
177
149
178
150
item
0 commit comments