diff options
Diffstat (limited to 'crates/ide/src/syntax_highlighting')
7 files changed, 147 insertions, 150 deletions
diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs index 18552459b..8731699dc 100644 --- a/crates/ide/src/syntax_highlighting/highlight.rs +++ b/crates/ide/src/syntax_highlighting/highlight.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | //! Computes color for a single element. | 1 | //! Computes color for a single element. |
2 | 2 | ||
3 | use hir::{AsAssocItem, AssocItemContainer, Semantics, VariantDef}; | 3 | use hir::{AsAssocItem, Semantics}; |
4 | use ide_db::{ | 4 | use ide_db::{ |
5 | defs::{Definition, NameClass, NameRefClass}, | 5 | defs::{Definition, NameClass, NameRefClass}, |
6 | RootDatabase, SymbolKind, | 6 | RootDatabase, SymbolKind, |
@@ -45,28 +45,26 @@ pub(super) fn element( | |||
45 | }; | 45 | }; |
46 | 46 | ||
47 | match name_kind { | 47 | match name_kind { |
48 | Some(NameClass::ExternCrate(_)) => HlTag::Symbol(SymbolKind::Module).into(), | 48 | Some(NameClass::ExternCrate(_)) => SymbolKind::Module.into(), |
49 | Some(NameClass::Definition(def)) => highlight_def(db, def) | HlMod::Definition, | 49 | Some(NameClass::Definition(def)) => highlight_def(db, def) | HlMod::Definition, |
50 | Some(NameClass::ConstReference(def)) => highlight_def(db, def), | 50 | Some(NameClass::ConstReference(def)) => highlight_def(db, def), |
51 | Some(NameClass::PatFieldShorthand { field_ref, .. }) => { | 51 | Some(NameClass::PatFieldShorthand { field_ref, .. }) => { |
52 | let mut h = HlTag::Symbol(SymbolKind::Field).into(); | 52 | let mut h = HlTag::Symbol(SymbolKind::Field).into(); |
53 | if let Definition::Field(field) = field_ref { | 53 | if let Definition::Field(field) = field_ref { |
54 | if let VariantDef::Union(_) = field.parent_def(db) { | 54 | if let hir::VariantDef::Union(_) = field.parent_def(db) { |
55 | h |= HlMod::Unsafe; | 55 | h |= HlMod::Unsafe; |
56 | } | 56 | } |
57 | } | 57 | } |
58 | |||
59 | h | 58 | h |
60 | } | 59 | } |
61 | None => highlight_name_by_syntax(name) | HlMod::Definition, | 60 | None => highlight_name_by_syntax(name) | HlMod::Definition, |
62 | } | 61 | } |
63 | } | 62 | } |
64 | |||
65 | // Highlight references like the definitions they resolve to | 63 | // Highlight references like the definitions they resolve to |
66 | NAME_REF if element.ancestors().any(|it| it.kind() == ATTR) => { | 64 | NAME_REF if element.ancestors().any(|it| it.kind() == ATTR) => { |
67 | // even though we track whether we are in an attribute or not we still need this special case | 65 | // even though we track whether we are in an attribute or not we still need this special case |
68 | // as otherwise we would emit unresolved references for name refs inside attributes | 66 | // as otherwise we would emit unresolved references for name refs inside attributes |
69 | Highlight::from(HlTag::Symbol(SymbolKind::Function)) | 67 | SymbolKind::Function.into() |
70 | } | 68 | } |
71 | NAME_REF => { | 69 | NAME_REF => { |
72 | let name_ref = element.into_node().and_then(ast::NameRef::cast).unwrap(); | 70 | let name_ref = element.into_node().and_then(ast::NameRef::cast).unwrap(); |
@@ -74,7 +72,7 @@ pub(super) fn element( | |||
74 | let is_self = name_ref.self_token().is_some(); | 72 | let is_self = name_ref.self_token().is_some(); |
75 | let h = match NameRefClass::classify(sema, &name_ref) { | 73 | let h = match NameRefClass::classify(sema, &name_ref) { |
76 | Some(name_kind) => match name_kind { | 74 | Some(name_kind) => match name_kind { |
77 | NameRefClass::ExternCrate(_) => HlTag::Symbol(SymbolKind::Module).into(), | 75 | NameRefClass::ExternCrate(_) => SymbolKind::Module.into(), |
78 | NameRefClass::Definition(def) => { | 76 | NameRefClass::Definition(def) => { |
79 | if let Definition::Local(local) = &def { | 77 | if let Definition::Local(local) = &def { |
80 | if let Some(name) = local.name(db) { | 78 | if let Some(name) = local.name(db) { |
@@ -95,7 +93,7 @@ pub(super) fn element( | |||
95 | if let Some(parent) = name_ref.syntax().parent() { | 93 | if let Some(parent) = name_ref.syntax().parent() { |
96 | if matches!(parent.kind(), FIELD_EXPR | RECORD_PAT_FIELD) { | 94 | if matches!(parent.kind(), FIELD_EXPR | RECORD_PAT_FIELD) { |
97 | if let Definition::Field(field) = def { | 95 | if let Definition::Field(field) = def { |
98 | if let VariantDef::Union(_) = field.parent_def(db) { | 96 | if let hir::VariantDef::Union(_) = field.parent_def(db) { |
99 | h |= HlMod::Unsafe; | 97 | h |= HlMod::Unsafe; |
100 | } | 98 | } |
101 | } | 99 | } |
@@ -104,9 +102,7 @@ pub(super) fn element( | |||
104 | 102 | ||
105 | h | 103 | h |
106 | } | 104 | } |
107 | NameRefClass::FieldShorthand { .. } => { | 105 | NameRefClass::FieldShorthand { .. } => SymbolKind::Field.into(), |
108 | HlTag::Symbol(SymbolKind::Field).into() | ||
109 | } | ||
110 | }, | 106 | }, |
111 | None if syntactic_name_ref_highlighting => { | 107 | None if syntactic_name_ref_highlighting => { |
112 | highlight_name_ref_by_syntax(name_ref, sema) | 108 | highlight_name_ref_by_syntax(name_ref, sema) |
@@ -114,7 +110,7 @@ pub(super) fn element( | |||
114 | None => HlTag::UnresolvedReference.into(), | 110 | None => HlTag::UnresolvedReference.into(), |
115 | }; | 111 | }; |
116 | if h.tag == HlTag::Symbol(SymbolKind::Module) && is_self { | 112 | if h.tag == HlTag::Symbol(SymbolKind::Module) && is_self { |
117 | HlTag::Symbol(SymbolKind::SelfParam).into() | 113 | SymbolKind::SelfParam.into() |
118 | } else { | 114 | } else { |
119 | h | 115 | h |
120 | } | 116 | } |
@@ -135,7 +131,7 @@ pub(super) fn element( | |||
135 | INT_NUMBER | FLOAT_NUMBER => HlTag::NumericLiteral.into(), | 131 | INT_NUMBER | FLOAT_NUMBER => HlTag::NumericLiteral.into(), |
136 | BYTE => HlTag::ByteLiteral.into(), | 132 | BYTE => HlTag::ByteLiteral.into(), |
137 | CHAR => HlTag::CharLiteral.into(), | 133 | CHAR => HlTag::CharLiteral.into(), |
138 | QUESTION => Highlight::new(HlTag::Operator(HlOperator::Other)) | HlMod::ControlFlow, | 134 | QUESTION => HlTag::Operator(HlOperator::Other) | HlMod::ControlFlow, |
139 | LIFETIME => { | 135 | LIFETIME => { |
140 | let lifetime = element.into_node().and_then(ast::Lifetime::cast).unwrap(); | 136 | let lifetime = element.into_node().and_then(ast::Lifetime::cast).unwrap(); |
141 | 137 | ||
@@ -143,44 +139,31 @@ pub(super) fn element( | |||
143 | Some(NameClass::Definition(def)) => highlight_def(db, def) | HlMod::Definition, | 139 | Some(NameClass::Definition(def)) => highlight_def(db, def) | HlMod::Definition, |
144 | None => match NameRefClass::classify_lifetime(sema, &lifetime) { | 140 | None => match NameRefClass::classify_lifetime(sema, &lifetime) { |
145 | Some(NameRefClass::Definition(def)) => highlight_def(db, def), | 141 | Some(NameRefClass::Definition(def)) => highlight_def(db, def), |
146 | _ => Highlight::new(HlTag::Symbol(SymbolKind::LifetimeParam)), | 142 | _ => SymbolKind::LifetimeParam.into(), |
147 | }, | 143 | }, |
148 | _ => Highlight::new(HlTag::Symbol(SymbolKind::LifetimeParam)) | HlMod::Definition, | 144 | _ => Highlight::from(SymbolKind::LifetimeParam) | HlMod::Definition, |
149 | } | 145 | } |
150 | } | 146 | } |
151 | p if p.is_punct() => match p { | 147 | p if p.is_punct() => match p { |
152 | T![&] if element.parent().and_then(ast::BinExpr::cast).is_some() => { | 148 | T![&] if parent_matches::<ast::BinExpr>(&element) => HlOperator::Bitwise.into(), |
153 | HlTag::Operator(HlOperator::Bitwise).into() | ||
154 | } | ||
155 | T![&] => { | 149 | T![&] => { |
156 | let h = HlTag::Operator(HlOperator::Other).into(); | 150 | let h = HlTag::Operator(HlOperator::Other).into(); |
157 | let is_unsafe = element | 151 | let is_unsafe = element |
158 | .parent() | 152 | .parent() |
159 | .and_then(ast::RefExpr::cast) | 153 | .and_then(ast::RefExpr::cast) |
160 | .map(|ref_expr| sema.is_unsafe_ref_expr(&ref_expr)) | 154 | .map_or(false, |ref_expr| sema.is_unsafe_ref_expr(&ref_expr)); |
161 | .unwrap_or(false); | ||
162 | if is_unsafe { | 155 | if is_unsafe { |
163 | h | HlMod::Unsafe | 156 | h | HlMod::Unsafe |
164 | } else { | 157 | } else { |
165 | h | 158 | h |
166 | } | 159 | } |
167 | } | 160 | } |
168 | T![::] | T![->] | T![=>] | T![..] | T![=] | T![@] | T![.] => { | 161 | T![::] | T![->] | T![=>] | T![..] | T![=] | T![@] | T![.] => HlOperator::Other.into(), |
169 | HlTag::Operator(HlOperator::Other).into() | 162 | T![!] if parent_matches::<ast::MacroCall>(&element) => SymbolKind::Macro.into(), |
170 | } | 163 | T![!] if parent_matches::<ast::NeverType>(&element) => HlTag::BuiltinType.into(), |
171 | T![!] if element.parent().and_then(ast::MacroCall::cast).is_some() => { | 164 | T![!] if parent_matches::<ast::PrefixExpr>(&element) => HlOperator::Logical.into(), |
172 | HlTag::Symbol(SymbolKind::Macro).into() | 165 | T![*] if parent_matches::<ast::PtrType>(&element) => HlTag::Keyword.into(), |
173 | } | 166 | T![*] if parent_matches::<ast::PrefixExpr>(&element) => { |
174 | T![!] if element.parent().and_then(ast::NeverType::cast).is_some() => { | ||
175 | HlTag::BuiltinType.into() | ||
176 | } | ||
177 | T![!] if element.parent().and_then(ast::PrefixExpr::cast).is_some() => { | ||
178 | HlTag::Operator(HlOperator::Logical).into() | ||
179 | } | ||
180 | T![*] if element.parent().and_then(ast::PtrType::cast).is_some() => { | ||
181 | HlTag::Keyword.into() | ||
182 | } | ||
183 | T![*] if element.parent().and_then(ast::PrefixExpr::cast).is_some() => { | ||
184 | let prefix_expr = element.parent().and_then(ast::PrefixExpr::cast)?; | 167 | let prefix_expr = element.parent().and_then(ast::PrefixExpr::cast)?; |
185 | 168 | ||
186 | let expr = prefix_expr.expr()?; | 169 | let expr = prefix_expr.expr()?; |
@@ -188,12 +171,12 @@ pub(super) fn element( | |||
188 | if ty.is_raw_ptr() { | 171 | if ty.is_raw_ptr() { |
189 | HlTag::Operator(HlOperator::Other) | HlMod::Unsafe | 172 | HlTag::Operator(HlOperator::Other) | HlMod::Unsafe |
190 | } else if let Some(ast::PrefixOp::Deref) = prefix_expr.op_kind() { | 173 | } else if let Some(ast::PrefixOp::Deref) = prefix_expr.op_kind() { |
191 | HlTag::Operator(HlOperator::Other).into() | 174 | HlOperator::Other.into() |
192 | } else { | 175 | } else { |
193 | HlTag::Punctuation(HlPunct::Other).into() | 176 | HlPunct::Other.into() |
194 | } | 177 | } |
195 | } | 178 | } |
196 | T![-] if element.parent().and_then(ast::PrefixExpr::cast).is_some() => { | 179 | T![-] if parent_matches::<ast::PrefixExpr>(&element) => { |
197 | let prefix_expr = element.parent().and_then(ast::PrefixExpr::cast)?; | 180 | let prefix_expr = element.parent().and_then(ast::PrefixExpr::cast)?; |
198 | 181 | ||
199 | let expr = prefix_expr.expr()?; | 182 | let expr = prefix_expr.expr()?; |
@@ -203,41 +186,31 @@ pub(super) fn element( | |||
203 | } | 186 | } |
204 | .into() | 187 | .into() |
205 | } | 188 | } |
206 | _ if element.parent().and_then(ast::PrefixExpr::cast).is_some() => { | 189 | _ if parent_matches::<ast::PrefixExpr>(&element) => HlOperator::Other.into(), |
207 | HlTag::Operator(HlOperator::Other).into() | ||
208 | } | ||
209 | T![+] | T![-] | T![*] | T![/] | T![+=] | T![-=] | T![*=] | T![/=] | 190 | T![+] | T![-] | T![*] | T![/] | T![+=] | T![-=] | T![*=] | T![/=] |
210 | if element.parent().and_then(ast::BinExpr::cast).is_some() => | 191 | if parent_matches::<ast::BinExpr>(&element) => |
211 | { | 192 | { |
212 | HlTag::Operator(HlOperator::Arithmetic).into() | 193 | HlOperator::Arithmetic.into() |
213 | } | 194 | } |
214 | T![|] | T![&] | T![!] | T![^] | T![|=] | T![&=] | T![^=] | 195 | T![|] | T![&] | T![!] | T![^] | T![|=] | T![&=] | T![^=] |
215 | if element.parent().and_then(ast::BinExpr::cast).is_some() => | 196 | if parent_matches::<ast::BinExpr>(&element) => |
216 | { | 197 | { |
217 | HlTag::Operator(HlOperator::Bitwise).into() | 198 | HlOperator::Bitwise.into() |
218 | } | 199 | } |
219 | T![&&] | T![||] if element.parent().and_then(ast::BinExpr::cast).is_some() => { | 200 | T![&&] | T![||] if parent_matches::<ast::BinExpr>(&element) => { |
220 | HlTag::Operator(HlOperator::Logical).into() | 201 | HlOperator::Logical.into() |
221 | } | 202 | } |
222 | T![>] | T![<] | T![==] | T![>=] | T![<=] | T![!=] | 203 | T![>] | T![<] | T![==] | T![>=] | T![<=] | T![!=] |
223 | if element.parent().and_then(ast::BinExpr::cast).is_some() => | 204 | if parent_matches::<ast::BinExpr>(&element) => |
224 | { | 205 | { |
225 | HlTag::Operator(HlOperator::Comparison).into() | 206 | HlOperator::Comparison.into() |
226 | } | ||
227 | _ if element.parent().and_then(ast::BinExpr::cast).is_some() => { | ||
228 | HlTag::Operator(HlOperator::Other).into() | ||
229 | } | 207 | } |
230 | _ if element.parent().and_then(ast::RangeExpr::cast).is_some() => { | 208 | _ if parent_matches::<ast::BinExpr>(&element) => HlOperator::Other.into(), |
231 | HlTag::Operator(HlOperator::Other).into() | 209 | _ if parent_matches::<ast::RangeExpr>(&element) => HlOperator::Other.into(), |
232 | } | 210 | _ if parent_matches::<ast::RangePat>(&element) => HlOperator::Other.into(), |
233 | _ if element.parent().and_then(ast::RangePat::cast).is_some() => { | 211 | _ if parent_matches::<ast::RestPat>(&element) => HlOperator::Other.into(), |
234 | HlTag::Operator(HlOperator::Other).into() | 212 | _ if parent_matches::<ast::Attr>(&element) => HlTag::Attribute.into(), |
235 | } | 213 | kind => match kind { |
236 | _ if element.parent().and_then(ast::RestPat::cast).is_some() => { | ||
237 | HlTag::Operator(HlOperator::Other).into() | ||
238 | } | ||
239 | _ if element.parent().and_then(ast::Attr::cast).is_some() => HlTag::Attribute.into(), | ||
240 | kind => HlTag::Punctuation(match kind { | ||
241 | T!['['] | T![']'] => HlPunct::Bracket, | 214 | T!['['] | T![']'] => HlPunct::Bracket, |
242 | T!['{'] | T!['}'] => HlPunct::Brace, | 215 | T!['{'] | T!['}'] => HlPunct::Brace, |
243 | T!['('] | T![')'] => HlPunct::Parenthesis, | 216 | T!['('] | T![')'] => HlPunct::Parenthesis, |
@@ -247,22 +220,24 @@ pub(super) fn element( | |||
247 | T![;] => HlPunct::Semi, | 220 | T![;] => HlPunct::Semi, |
248 | T![.] => HlPunct::Dot, | 221 | T![.] => HlPunct::Dot, |
249 | _ => HlPunct::Other, | 222 | _ => HlPunct::Other, |
250 | }) | 223 | } |
251 | .into(), | 224 | .into(), |
252 | }, | 225 | }, |
253 | 226 | ||
254 | k if k.is_keyword() => { | 227 | k if k.is_keyword() => { |
255 | let h = Highlight::new(HlTag::Keyword); | 228 | let h = Highlight::new(HlTag::Keyword); |
256 | match k { | 229 | match k { |
257 | T![break] | 230 | T![await] |
231 | | T![break] | ||
258 | | T![continue] | 232 | | T![continue] |
259 | | T![else] | 233 | | T![else] |
260 | | T![if] | 234 | | T![if] |
235 | | T![in] | ||
261 | | T![loop] | 236 | | T![loop] |
262 | | T![match] | 237 | | T![match] |
263 | | T![return] | 238 | | T![return] |
264 | | T![while] | 239 | | T![while] |
265 | | T![in] => h | HlMod::ControlFlow, | 240 | | T![yield] => h | HlMod::ControlFlow, |
266 | T![for] if !is_child_of_impl(&element) => h | HlMod::ControlFlow, | 241 | T![for] if !is_child_of_impl(&element) => h | HlMod::ControlFlow, |
267 | T![unsafe] => h | HlMod::Unsafe, | 242 | T![unsafe] => h | HlMod::Unsafe, |
268 | T![true] | T![false] => HlTag::BoolLiteral.into(), | 243 | T![true] | T![false] => HlTag::BoolLiteral.into(), |
@@ -301,7 +276,6 @@ pub(super) fn element( | |||
301 | hash((name, shadow_count)) | 276 | hash((name, shadow_count)) |
302 | } | 277 | } |
303 | } | 278 | } |
304 | |||
305 | fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight { | 279 | fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight { |
306 | match def { | 280 | match def { |
307 | Definition::Macro(_) => HlTag::Symbol(SymbolKind::Macro), | 281 | Definition::Macro(_) => HlTag::Symbol(SymbolKind::Macro), |
@@ -317,12 +291,12 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight { | |||
317 | } | 291 | } |
318 | 292 | ||
319 | match item.container(db) { | 293 | match item.container(db) { |
320 | AssocItemContainer::Impl(i) => { | 294 | hir::AssocItemContainer::Impl(i) => { |
321 | if i.trait_(db).is_some() { | 295 | if i.trait_(db).is_some() { |
322 | h |= HlMod::Trait; | 296 | h |= HlMod::Trait; |
323 | } | 297 | } |
324 | } | 298 | } |
325 | AssocItemContainer::Trait(_t) => { | 299 | hir::AssocItemContainer::Trait(_t) => { |
326 | h |= HlMod::Trait; | 300 | h |= HlMod::Trait; |
327 | } | 301 | } |
328 | } | 302 | } |
@@ -342,12 +316,12 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight { | |||
342 | if let Some(item) = konst.as_assoc_item(db) { | 316 | if let Some(item) = konst.as_assoc_item(db) { |
343 | h |= HlMod::Associated; | 317 | h |= HlMod::Associated; |
344 | match item.container(db) { | 318 | match item.container(db) { |
345 | AssocItemContainer::Impl(i) => { | 319 | hir::AssocItemContainer::Impl(i) => { |
346 | if i.trait_(db).is_some() { | 320 | if i.trait_(db).is_some() { |
347 | h |= HlMod::Trait; | 321 | h |= HlMod::Trait; |
348 | } | 322 | } |
349 | } | 323 | } |
350 | AssocItemContainer::Trait(_t) => { | 324 | hir::AssocItemContainer::Trait(_t) => { |
351 | h |= HlMod::Trait; | 325 | h |= HlMod::Trait; |
352 | } | 326 | } |
353 | } | 327 | } |
@@ -361,12 +335,12 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight { | |||
361 | if let Some(item) = type_.as_assoc_item(db) { | 335 | if let Some(item) = type_.as_assoc_item(db) { |
362 | h |= HlMod::Associated; | 336 | h |= HlMod::Associated; |
363 | match item.container(db) { | 337 | match item.container(db) { |
364 | AssocItemContainer::Impl(i) => { | 338 | hir::AssocItemContainer::Impl(i) => { |
365 | if i.trait_(db).is_some() { | 339 | if i.trait_(db).is_some() { |
366 | h |= HlMod::Trait; | 340 | h |= HlMod::Trait; |
367 | } | 341 | } |
368 | } | 342 | } |
369 | AssocItemContainer::Trait(_t) => { | 343 | hir::AssocItemContainer::Trait(_t) => { |
370 | h |= HlMod::Trait; | 344 | h |= HlMod::Trait; |
371 | } | 345 | } |
372 | } | 346 | } |
@@ -425,7 +399,7 @@ fn highlight_method_call( | |||
425 | method_call: &ast::MethodCallExpr, | 399 | method_call: &ast::MethodCallExpr, |
426 | ) -> Option<Highlight> { | 400 | ) -> Option<Highlight> { |
427 | let func = sema.resolve_method_call(&method_call)?; | 401 | let func = sema.resolve_method_call(&method_call)?; |
428 | let mut h = HlTag::Symbol(SymbolKind::Function).into(); | 402 | let mut h = SymbolKind::Function.into(); |
429 | h |= HlMod::Associated; | 403 | h |= HlMod::Associated; |
430 | if func.is_unsafe(sema.db) || sema.is_unsafe_method_call(&method_call) { | 404 | if func.is_unsafe(sema.db) || sema.is_unsafe_method_call(&method_call) { |
431 | h |= HlMod::Unsafe; | 405 | h |= HlMod::Unsafe; |
@@ -461,20 +435,20 @@ fn highlight_name_by_syntax(name: ast::Name) -> Highlight { | |||
461 | }; | 435 | }; |
462 | 436 | ||
463 | let tag = match parent.kind() { | 437 | let tag = match parent.kind() { |
464 | STRUCT => HlTag::Symbol(SymbolKind::Struct), | 438 | STRUCT => SymbolKind::Struct, |
465 | ENUM => HlTag::Symbol(SymbolKind::Enum), | 439 | ENUM => SymbolKind::Enum, |
466 | VARIANT => HlTag::Symbol(SymbolKind::Variant), | 440 | VARIANT => SymbolKind::Variant, |
467 | UNION => HlTag::Symbol(SymbolKind::Union), | 441 | UNION => SymbolKind::Union, |
468 | TRAIT => HlTag::Symbol(SymbolKind::Trait), | 442 | TRAIT => SymbolKind::Trait, |
469 | TYPE_ALIAS => HlTag::Symbol(SymbolKind::TypeAlias), | 443 | TYPE_ALIAS => SymbolKind::TypeAlias, |
470 | TYPE_PARAM => HlTag::Symbol(SymbolKind::TypeParam), | 444 | TYPE_PARAM => SymbolKind::TypeParam, |
471 | RECORD_FIELD => HlTag::Symbol(SymbolKind::Field), | 445 | RECORD_FIELD => SymbolKind::Field, |
472 | MODULE => HlTag::Symbol(SymbolKind::Module), | 446 | MODULE => SymbolKind::Module, |
473 | FN => HlTag::Symbol(SymbolKind::Function), | 447 | FN => SymbolKind::Function, |
474 | CONST => HlTag::Symbol(SymbolKind::Const), | 448 | CONST => SymbolKind::Const, |
475 | STATIC => HlTag::Symbol(SymbolKind::Static), | 449 | STATIC => SymbolKind::Static, |
476 | IDENT_PAT => HlTag::Symbol(SymbolKind::Local), | 450 | IDENT_PAT => SymbolKind::Local, |
477 | _ => default, | 451 | _ => return default.into(), |
478 | }; | 452 | }; |
479 | 453 | ||
480 | tag.into() | 454 | tag.into() |
@@ -492,20 +466,15 @@ fn highlight_name_ref_by_syntax(name: ast::NameRef, sema: &Semantics<RootDatabas | |||
492 | METHOD_CALL_EXPR => { | 466 | METHOD_CALL_EXPR => { |
493 | return ast::MethodCallExpr::cast(parent) | 467 | return ast::MethodCallExpr::cast(parent) |
494 | .and_then(|it| highlight_method_call(sema, &it)) | 468 | .and_then(|it| highlight_method_call(sema, &it)) |
495 | .unwrap_or_else(|| HlTag::Symbol(SymbolKind::Function).into()); | 469 | .unwrap_or_else(|| SymbolKind::Function.into()); |
496 | } | 470 | } |
497 | FIELD_EXPR => { | 471 | FIELD_EXPR => { |
498 | let h = HlTag::Symbol(SymbolKind::Field); | 472 | let h = HlTag::Symbol(SymbolKind::Field); |
499 | let is_union = ast::FieldExpr::cast(parent) | 473 | let is_union = ast::FieldExpr::cast(parent) |
500 | .and_then(|field_expr| { | 474 | .and_then(|field_expr| sema.resolve_field(&field_expr)) |
501 | let field = sema.resolve_field(&field_expr)?; | 475 | .map_or(false, |field| { |
502 | Some(if let VariantDef::Union(_) = field.parent_def(sema.db) { | 476 | matches!(field.parent_def(sema.db), hir::VariantDef::Union(_)) |
503 | true | 477 | }); |
504 | } else { | ||
505 | false | ||
506 | }) | ||
507 | }) | ||
508 | .unwrap_or(false); | ||
509 | if is_union { | 478 | if is_union { |
510 | h | HlMod::Unsafe | 479 | h | HlMod::Unsafe |
511 | } else { | 480 | } else { |
@@ -522,9 +491,9 @@ fn highlight_name_ref_by_syntax(name: ast::NameRef, sema: &Semantics<RootDatabas | |||
522 | _ => { | 491 | _ => { |
523 | // within path, decide whether it is module or adt by checking for uppercase name | 492 | // within path, decide whether it is module or adt by checking for uppercase name |
524 | return if name.text().chars().next().unwrap_or_default().is_uppercase() { | 493 | return if name.text().chars().next().unwrap_or_default().is_uppercase() { |
525 | HlTag::Symbol(SymbolKind::Struct) | 494 | SymbolKind::Struct |
526 | } else { | 495 | } else { |
527 | HlTag::Symbol(SymbolKind::Module) | 496 | SymbolKind::Module |
528 | } | 497 | } |
529 | .into(); | 498 | .into(); |
530 | } | 499 | } |
@@ -535,11 +504,11 @@ fn highlight_name_ref_by_syntax(name: ast::NameRef, sema: &Semantics<RootDatabas | |||
535 | }; | 504 | }; |
536 | 505 | ||
537 | match parent.kind() { | 506 | match parent.kind() { |
538 | CALL_EXPR => HlTag::Symbol(SymbolKind::Function).into(), | 507 | CALL_EXPR => SymbolKind::Function.into(), |
539 | _ => if name.text().chars().next().unwrap_or_default().is_uppercase() { | 508 | _ => if name.text().chars().next().unwrap_or_default().is_uppercase() { |
540 | HlTag::Symbol(SymbolKind::Struct) | 509 | SymbolKind::Struct |
541 | } else { | 510 | } else { |
542 | HlTag::Symbol(SymbolKind::Const) | 511 | SymbolKind::Const |
543 | } | 512 | } |
544 | .into(), | 513 | .into(), |
545 | } | 514 | } |
@@ -574,6 +543,11 @@ fn parents_match(mut node: NodeOrToken<SyntaxNode, SyntaxToken>, mut kinds: &[Sy | |||
574 | kinds.len() == 0 | 543 | kinds.len() == 0 |
575 | } | 544 | } |
576 | 545 | ||
546 | #[inline] | ||
547 | fn parent_matches<N: AstNode>(element: &SyntaxElement) -> bool { | ||
548 | element.parent().map_or(false, |it| N::can_cast(it.kind())) | ||
549 | } | ||
550 | |||
577 | fn is_child_of_impl(element: &SyntaxElement) -> bool { | 551 | fn is_child_of_impl(element: &SyntaxElement) -> bool { |
578 | match element.parent() { | 552 | match element.parent() { |
579 | Some(e) => e.kind() == IMPL, | 553 | Some(e) => e.kind() == IMPL, |
diff --git a/crates/ide/src/syntax_highlighting/tags.rs b/crates/ide/src/syntax_highlighting/tags.rs index e58392d67..a304b3250 100644 --- a/crates/ide/src/syntax_highlighting/tags.rs +++ b/crates/ide/src/syntax_highlighting/tags.rs | |||
@@ -40,28 +40,33 @@ pub enum HlTag { | |||
40 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] | 40 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] |
41 | #[repr(u8)] | 41 | #[repr(u8)] |
42 | pub enum HlMod { | 42 | pub enum HlMod { |
43 | /// Used for items in traits and impls. | ||
44 | Associated = 0, | ||
43 | /// Used to differentiate individual elements within attributes. | 45 | /// Used to differentiate individual elements within attributes. |
44 | Attribute = 0, | 46 | Attribute, |
47 | /// Callable item or value. | ||
48 | Callable, | ||
49 | /// Value that is being consumed in a function call | ||
50 | Consuming, | ||
45 | /// Used with keywords like `if` and `break`. | 51 | /// Used with keywords like `if` and `break`. |
46 | ControlFlow, | 52 | ControlFlow, |
47 | /// `foo` in `fn foo(x: i32)` is a definition, `foo` in `foo(90 + 2)` is | 53 | /// `foo` in `fn foo(x: i32)` is a definition, `foo` in `foo(90 + 2)` is |
48 | /// not. | 54 | /// not. |
49 | Definition, | 55 | Definition, |
56 | /// Doc-strings like this one. | ||
50 | Documentation, | 57 | Documentation, |
58 | /// Highlighting injection like rust code in doc strings or ra_fixture. | ||
51 | Injected, | 59 | Injected, |
52 | Mutable, | ||
53 | Consuming, | ||
54 | Callable, | ||
55 | /// Used for associated functions | ||
56 | Static, | ||
57 | /// Used for items in impls&traits. | ||
58 | Associated, | ||
59 | /// Used for intra doc links in doc injection. | 60 | /// Used for intra doc links in doc injection. |
60 | IntraDocLink, | 61 | IntraDocLink, |
62 | /// Mutable binding. | ||
63 | Mutable, | ||
64 | /// Used for associated functions. | ||
65 | Static, | ||
61 | /// Used for items in traits and trait impls. | 66 | /// Used for items in traits and trait impls. |
62 | Trait, | 67 | Trait, |
63 | 68 | // Keep this last! | |
64 | /// Keep this last! | 69 | /// Used for unsafe functions, mutable statics, union accesses and unsafe operations. |
65 | Unsafe, | 70 | Unsafe, |
66 | } | 71 | } |
67 | 72 | ||
@@ -169,17 +174,17 @@ impl fmt::Display for HlTag { | |||
169 | 174 | ||
170 | impl HlMod { | 175 | impl HlMod { |
171 | const ALL: &'static [HlMod; HlMod::Unsafe as u8 as usize + 1] = &[ | 176 | const ALL: &'static [HlMod; HlMod::Unsafe as u8 as usize + 1] = &[ |
177 | HlMod::Associated, | ||
172 | HlMod::Attribute, | 178 | HlMod::Attribute, |
179 | HlMod::Callable, | ||
180 | HlMod::Consuming, | ||
173 | HlMod::ControlFlow, | 181 | HlMod::ControlFlow, |
174 | HlMod::Definition, | 182 | HlMod::Definition, |
175 | HlMod::Documentation, | 183 | HlMod::Documentation, |
176 | HlMod::IntraDocLink, | ||
177 | HlMod::Injected, | 184 | HlMod::Injected, |
185 | HlMod::IntraDocLink, | ||
178 | HlMod::Mutable, | 186 | HlMod::Mutable, |
179 | HlMod::Consuming, | ||
180 | HlMod::Callable, | ||
181 | HlMod::Static, | 187 | HlMod::Static, |
182 | HlMod::Associated, | ||
183 | HlMod::Trait, | 188 | HlMod::Trait, |
184 | HlMod::Unsafe, | 189 | HlMod::Unsafe, |
185 | ]; | 190 | ]; |
@@ -229,6 +234,24 @@ impl From<HlTag> for Highlight { | |||
229 | } | 234 | } |
230 | } | 235 | } |
231 | 236 | ||
237 | impl From<HlOperator> for Highlight { | ||
238 | fn from(op: HlOperator) -> Highlight { | ||
239 | Highlight::new(HlTag::Operator(op)) | ||
240 | } | ||
241 | } | ||
242 | |||
243 | impl From<HlPunct> for Highlight { | ||
244 | fn from(punct: HlPunct) -> Highlight { | ||
245 | Highlight::new(HlTag::Punctuation(punct)) | ||
246 | } | ||
247 | } | ||
248 | |||
249 | impl From<SymbolKind> for Highlight { | ||
250 | fn from(sym: SymbolKind) -> Highlight { | ||
251 | Highlight::new(HlTag::Symbol(sym)) | ||
252 | } | ||
253 | } | ||
254 | |||
232 | impl Highlight { | 255 | impl Highlight { |
233 | pub(crate) fn new(tag: HlTag) -> Highlight { | 256 | pub(crate) fn new(tag: HlTag) -> Highlight { |
234 | Highlight { tag, mods: HlMods::default() } | 257 | Highlight { tag, mods: HlMods::default() } |
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_assoc_functions.html b/crates/ide/src/syntax_highlighting/test_data/highlight_assoc_functions.html index 8cde3906c..a0ea1db34 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_assoc_functions.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_assoc_functions.html | |||
@@ -42,17 +42,17 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
42 | <span class="keyword">struct</span> <span class="struct declaration">foo</span> <span class="brace">{</span><span class="brace">}</span> | 42 | <span class="keyword">struct</span> <span class="struct declaration">foo</span> <span class="brace">{</span><span class="brace">}</span> |
43 | 43 | ||
44 | <span class="keyword">impl</span> <span class="struct">foo</span> <span class="brace">{</span> | 44 | <span class="keyword">impl</span> <span class="struct">foo</span> <span class="brace">{</span> |
45 | <span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function declaration static associated">is_static</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span> | 45 | <span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function associated declaration static">is_static</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span> |
46 | <span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function declaration associated">is_not_static</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span> | 46 | <span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function associated declaration">is_not_static</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span> |
47 | <span class="brace">}</span> | 47 | <span class="brace">}</span> |
48 | 48 | ||
49 | <span class="keyword">trait</span> <span class="trait declaration">t</span> <span class="brace">{</span> | 49 | <span class="keyword">trait</span> <span class="trait declaration">t</span> <span class="brace">{</span> |
50 | <span class="keyword">fn</span> <span class="function declaration static associated trait">t_is_static</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span> | 50 | <span class="keyword">fn</span> <span class="function associated declaration static trait">t_is_static</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span> |
51 | <span class="keyword">fn</span> <span class="function declaration associated trait">t_is_not_static</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span> | 51 | <span class="keyword">fn</span> <span class="function associated declaration trait">t_is_not_static</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span> |
52 | <span class="brace">}</span> | 52 | <span class="brace">}</span> |
53 | 53 | ||
54 | <span class="keyword">impl</span> <span class="trait">t</span> <span class="keyword">for</span> <span class="struct">foo</span> <span class="brace">{</span> | 54 | <span class="keyword">impl</span> <span class="trait">t</span> <span class="keyword">for</span> <span class="struct">foo</span> <span class="brace">{</span> |
55 | <span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function declaration static associated trait">is_static</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span> | 55 | <span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function associated declaration static trait">is_static</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span> |
56 | <span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function declaration associated trait">is_not_static</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span> | 56 | <span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function associated declaration trait">is_not_static</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span> |
57 | <span class="brace">}</span> | 57 | <span class="brace">}</span> |
58 | </code></pre> \ No newline at end of file | 58 | </code></pre> \ No newline at end of file |
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html b/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html index 6ee6d85fb..638f42c2f 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html | |||
@@ -50,7 +50,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
50 | <span class="comment">// KILLER WHALE</span> | 50 | <span class="comment">// KILLER WHALE</span> |
51 | <span class="comment documentation">/// </span><span class="string_literal injected"> Ishmael."</span><span class="semicolon injected">;</span> | 51 | <span class="comment documentation">/// </span><span class="string_literal injected"> Ishmael."</span><span class="semicolon injected">;</span> |
52 | <span class="comment documentation">/// ```</span> | 52 | <span class="comment documentation">/// ```</span> |
53 | <span class="keyword">pub</span> <span class="keyword">const</span> <span class="constant declaration associated">bar</span><span class="colon">:</span> <span class="builtin_type">bool</span> <span class="operator">=</span> <span class="bool_literal">true</span><span class="semicolon">;</span> | 53 | <span class="keyword">pub</span> <span class="keyword">const</span> <span class="constant associated declaration">bar</span><span class="colon">:</span> <span class="builtin_type">bool</span> <span class="operator">=</span> <span class="bool_literal">true</span><span class="semicolon">;</span> |
54 | 54 | ||
55 | <span class="comment documentation">/// Constructs a new `Foo`.</span> | 55 | <span class="comment documentation">/// Constructs a new `Foo`.</span> |
56 | <span class="comment documentation">///</span> | 56 | <span class="comment documentation">///</span> |
@@ -60,7 +60,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
60 | <span class="comment documentation">/// #</span><span class="none injected"> </span><span class="attribute attribute injected">#</span><span class="attribute attribute injected">!</span><span class="attribute attribute injected">[</span><span class="function attribute injected">allow</span><span class="parenthesis attribute injected">(</span><span class="attribute attribute injected">unused_mut</span><span class="parenthesis attribute injected">)</span><span class="attribute attribute injected">]</span> | 60 | <span class="comment documentation">/// #</span><span class="none injected"> </span><span class="attribute attribute injected">#</span><span class="attribute attribute injected">!</span><span class="attribute attribute injected">[</span><span class="function attribute injected">allow</span><span class="parenthesis attribute injected">(</span><span class="attribute attribute injected">unused_mut</span><span class="parenthesis attribute injected">)</span><span class="attribute attribute injected">]</span> |
61 | <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="none injected"> </span><span class="keyword injected">mut</span><span class="none injected"> </span><span class="variable declaration injected mutable">foo</span><span class="colon injected">:</span><span class="none injected"> </span><span class="struct injected">Foo</span><span class="none injected"> </span><span class="operator injected">=</span><span class="none injected"> </span><span class="struct injected">Foo</span><span class="operator injected">::</span><span class="function injected">new</span><span class="parenthesis injected">(</span><span class="parenthesis injected">)</span><span class="semicolon injected">;</span> | 61 | <span class="comment documentation">/// </span><span class="keyword injected">let</span><span class="none injected"> </span><span class="keyword injected">mut</span><span class="none injected"> </span><span class="variable declaration injected mutable">foo</span><span class="colon injected">:</span><span class="none injected"> </span><span class="struct injected">Foo</span><span class="none injected"> </span><span class="operator injected">=</span><span class="none injected"> </span><span class="struct injected">Foo</span><span class="operator injected">::</span><span class="function injected">new</span><span class="parenthesis injected">(</span><span class="parenthesis injected">)</span><span class="semicolon injected">;</span> |
62 | <span class="comment documentation">/// ```</span> | 62 | <span class="comment documentation">/// ```</span> |
63 | <span class="keyword">pub</span> <span class="keyword">const</span> <span class="keyword">fn</span> <span class="function declaration static associated">new</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="struct">Foo</span> <span class="brace">{</span> | 63 | <span class="keyword">pub</span> <span class="keyword">const</span> <span class="keyword">fn</span> <span class="function associated declaration static">new</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="struct">Foo</span> <span class="brace">{</span> |
64 | <span class="struct">Foo</span> <span class="brace">{</span> <span class="field">bar</span><span class="colon">:</span> <span class="bool_literal">true</span> <span class="brace">}</span> | 64 | <span class="struct">Foo</span> <span class="brace">{</span> <span class="field">bar</span><span class="colon">:</span> <span class="bool_literal">true</span> <span class="brace">}</span> |
65 | <span class="brace">}</span> | 65 | <span class="brace">}</span> |
66 | 66 | ||
@@ -94,15 +94,15 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
94 | <span class="comment documentation">/// ```sh</span> | 94 | <span class="comment documentation">/// ```sh</span> |
95 | <span class="comment documentation">/// echo 1</span> | 95 | <span class="comment documentation">/// echo 1</span> |
96 | <span class="comment documentation">/// ```</span> | 96 | <span class="comment documentation">/// ```</span> |
97 | <span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function declaration associated">foo</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="builtin_type">bool</span> <span class="brace">{</span> | 97 | <span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function associated declaration">foo</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="builtin_type">bool</span> <span class="brace">{</span> |
98 | <span class="bool_literal">true</span> | 98 | <span class="bool_literal">true</span> |
99 | <span class="brace">}</span> | 99 | <span class="brace">}</span> |
100 | <span class="brace">}</span> | 100 | <span class="brace">}</span> |
101 | 101 | ||
102 | <span class="comment documentation">/// </span><span class="struct documentation intra_doc_link injected">[`Foo`](Foo)</span><span class="comment documentation"> is a struct</span> | 102 | <span class="comment documentation">/// </span><span class="struct documentation injected intra_doc_link">[`Foo`](Foo)</span><span class="comment documentation"> is a struct</span> |
103 | <span class="comment documentation">/// This function is > </span><span class="function documentation intra_doc_link injected">[`all_the_links`](all_the_links)</span><span class="comment documentation"> <</span> | 103 | <span class="comment documentation">/// This function is > </span><span class="function documentation injected intra_doc_link">[`all_the_links`](all_the_links)</span><span class="comment documentation"> <</span> |
104 | <span class="comment documentation">/// [`noop`](noop) is a macro below</span> | 104 | <span class="comment documentation">/// [`noop`](noop) is a macro below</span> |
105 | <span class="comment documentation">/// </span><span class="struct documentation intra_doc_link injected">[`Item`]</span><span class="comment documentation"> is a struct in the module </span><span class="module documentation intra_doc_link injected">[`module`]</span> | 105 | <span class="comment documentation">/// </span><span class="struct documentation injected intra_doc_link">[`Item`]</span><span class="comment documentation"> is a struct in the module </span><span class="module documentation injected intra_doc_link">[`module`]</span> |
106 | <span class="comment documentation">///</span> | 106 | <span class="comment documentation">///</span> |
107 | <span class="comment documentation">/// [`Item`]: module::Item</span> | 107 | <span class="comment documentation">/// [`Item`]: module::Item</span> |
108 | <span class="comment documentation">/// [mix_and_match]: ThisShouldntResolve</span> | 108 | <span class="comment documentation">/// [mix_and_match]: ThisShouldntResolve</span> |
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_injection.html b/crates/ide/src/syntax_highlighting/test_data/highlight_injection.html index 7c6694a27..6202a03ce 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_injection.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_injection.html | |||
@@ -42,7 +42,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
42 | <span class="keyword">fn</span> <span class="function declaration">main</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span> | 42 | <span class="keyword">fn</span> <span class="function declaration">main</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span> |
43 | <span class="function">fixture</span><span class="parenthesis">(</span><span class="string_literal">r#"</span> | 43 | <span class="function">fixture</span><span class="parenthesis">(</span><span class="string_literal">r#"</span> |
44 | <span class="keyword">trait</span> <span class="trait declaration">Foo</span> <span class="brace">{</span> | 44 | <span class="keyword">trait</span> <span class="trait declaration">Foo</span> <span class="brace">{</span> |
45 | <span class="keyword">fn</span> <span class="function declaration static associated trait">foo</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span> | 45 | <span class="keyword">fn</span> <span class="function associated declaration static trait">foo</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span> |
46 | <span class="macro">println!</span><span class="parenthesis">(</span><span class="string_literal">"2 + 2 = {}"</span><span class="comma">,</span> <span class="numeric_literal">4</span><span class="parenthesis">)</span><span class="semicolon">;</span> | 46 | <span class="macro">println!</span><span class="parenthesis">(</span><span class="string_literal">"2 + 2 = {}"</span><span class="comma">,</span> <span class="numeric_literal">4</span><span class="parenthesis">)</span><span class="semicolon">;</span> |
47 | <span class="brace">}</span> | 47 | <span class="brace">}</span> |
48 | <span class="brace">}</span><span class="string_literal">"#</span> | 48 | <span class="brace">}</span><span class="string_literal">"#</span> |
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html b/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html index 72910421d..68165bdbf 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html | |||
@@ -47,7 +47,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
47 | <span class="keyword">struct</span> <span class="struct declaration">HasUnsafeFn</span><span class="semicolon">;</span> | 47 | <span class="keyword">struct</span> <span class="struct declaration">HasUnsafeFn</span><span class="semicolon">;</span> |
48 | 48 | ||
49 | <span class="keyword">impl</span> <span class="struct">HasUnsafeFn</span> <span class="brace">{</span> | 49 | <span class="keyword">impl</span> <span class="struct">HasUnsafeFn</span> <span class="brace">{</span> |
50 | <span class="keyword unsafe">unsafe</span> <span class="keyword">fn</span> <span class="function declaration associated unsafe">unsafe_method</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span> | 50 | <span class="keyword unsafe">unsafe</span> <span class="keyword">fn</span> <span class="function associated declaration unsafe">unsafe_method</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span> |
51 | <span class="brace">}</span> | 51 | <span class="brace">}</span> |
52 | 52 | ||
53 | <span class="keyword">struct</span> <span class="struct declaration">TypeForStaticMut</span> <span class="brace">{</span> | 53 | <span class="keyword">struct</span> <span class="struct declaration">TypeForStaticMut</span> <span class="brace">{</span> |
@@ -62,11 +62,11 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
62 | <span class="brace">}</span> | 62 | <span class="brace">}</span> |
63 | 63 | ||
64 | <span class="keyword">trait</span> <span class="trait declaration">DoTheAutoref</span> <span class="brace">{</span> | 64 | <span class="keyword">trait</span> <span class="trait declaration">DoTheAutoref</span> <span class="brace">{</span> |
65 | <span class="keyword">fn</span> <span class="function declaration associated trait">calls_autoref</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span><span class="semicolon">;</span> | 65 | <span class="keyword">fn</span> <span class="function associated declaration trait">calls_autoref</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span><span class="semicolon">;</span> |
66 | <span class="brace">}</span> | 66 | <span class="brace">}</span> |
67 | 67 | ||
68 | <span class="keyword">impl</span> <span class="trait">DoTheAutoref</span> <span class="keyword">for</span> <span class="builtin_type">u16</span> <span class="brace">{</span> | 68 | <span class="keyword">impl</span> <span class="trait">DoTheAutoref</span> <span class="keyword">for</span> <span class="builtin_type">u16</span> <span class="brace">{</span> |
69 | <span class="keyword">fn</span> <span class="function declaration associated trait">calls_autoref</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span> | 69 | <span class="keyword">fn</span> <span class="function associated declaration trait">calls_autoref</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span> |
70 | <span class="brace">}</span> | 70 | <span class="brace">}</span> |
71 | 71 | ||
72 | <span class="keyword">fn</span> <span class="function declaration">main</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span> | 72 | <span class="keyword">fn</span> <span class="function declaration">main</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span> |
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlighting.html b/crates/ide/src/syntax_highlighting/test_data/highlighting.html index c43bcb691..4319e8b50 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlighting.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlighting.html | |||
@@ -67,25 +67,25 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
67 | <span class="brace">}</span> | 67 | <span class="brace">}</span> |
68 | 68 | ||
69 | <span class="keyword">trait</span> <span class="trait declaration">Bar</span> <span class="brace">{</span> | 69 | <span class="keyword">trait</span> <span class="trait declaration">Bar</span> <span class="brace">{</span> |
70 | <span class="keyword">fn</span> <span class="function declaration associated trait">bar</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="builtin_type">i32</span><span class="semicolon">;</span> | 70 | <span class="keyword">fn</span> <span class="function associated declaration trait">bar</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="builtin_type">i32</span><span class="semicolon">;</span> |
71 | <span class="brace">}</span> | 71 | <span class="brace">}</span> |
72 | 72 | ||
73 | <span class="keyword">impl</span> <span class="trait">Bar</span> <span class="keyword">for</span> <span class="struct">Foo</span> <span class="brace">{</span> | 73 | <span class="keyword">impl</span> <span class="trait">Bar</span> <span class="keyword">for</span> <span class="struct">Foo</span> <span class="brace">{</span> |
74 | <span class="keyword">fn</span> <span class="function declaration associated trait">bar</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="builtin_type">i32</span> <span class="brace">{</span> | 74 | <span class="keyword">fn</span> <span class="function associated declaration trait">bar</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="builtin_type">i32</span> <span class="brace">{</span> |
75 | <span class="self_keyword">self</span><span class="operator">.</span><span class="field">x</span> | 75 | <span class="self_keyword">self</span><span class="operator">.</span><span class="field">x</span> |
76 | <span class="brace">}</span> | 76 | <span class="brace">}</span> |
77 | <span class="brace">}</span> | 77 | <span class="brace">}</span> |
78 | 78 | ||
79 | <span class="keyword">impl</span> <span class="struct">Foo</span> <span class="brace">{</span> | 79 | <span class="keyword">impl</span> <span class="struct">Foo</span> <span class="brace">{</span> |
80 | <span class="keyword">fn</span> <span class="function declaration associated">baz</span><span class="parenthesis">(</span><span class="keyword">mut</span> <span class="self_keyword declaration mutable">self</span><span class="comma">,</span> <span class="value_param declaration">f</span><span class="colon">:</span> <span class="struct">Foo</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="builtin_type">i32</span> <span class="brace">{</span> | 80 | <span class="keyword">fn</span> <span class="function associated declaration">baz</span><span class="parenthesis">(</span><span class="keyword">mut</span> <span class="self_keyword declaration mutable">self</span><span class="comma">,</span> <span class="value_param declaration">f</span><span class="colon">:</span> <span class="struct">Foo</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="builtin_type">i32</span> <span class="brace">{</span> |
81 | <span class="value_param">f</span><span class="operator">.</span><span class="function consuming associated">baz</span><span class="parenthesis">(</span><span class="self_keyword mutable consuming">self</span><span class="parenthesis">)</span> | 81 | <span class="value_param">f</span><span class="operator">.</span><span class="function associated consuming">baz</span><span class="parenthesis">(</span><span class="self_keyword consuming mutable">self</span><span class="parenthesis">)</span> |
82 | <span class="brace">}</span> | 82 | <span class="brace">}</span> |
83 | 83 | ||
84 | <span class="keyword">fn</span> <span class="function declaration associated">qux</span><span class="parenthesis">(</span><span class="operator">&</span><span class="keyword">mut</span> <span class="self_keyword declaration mutable">self</span><span class="parenthesis">)</span> <span class="brace">{</span> | 84 | <span class="keyword">fn</span> <span class="function associated declaration">qux</span><span class="parenthesis">(</span><span class="operator">&</span><span class="keyword">mut</span> <span class="self_keyword declaration mutable">self</span><span class="parenthesis">)</span> <span class="brace">{</span> |
85 | <span class="self_keyword mutable">self</span><span class="operator">.</span><span class="field">x</span> <span class="operator">=</span> <span class="numeric_literal">0</span><span class="semicolon">;</span> | 85 | <span class="self_keyword mutable">self</span><span class="operator">.</span><span class="field">x</span> <span class="operator">=</span> <span class="numeric_literal">0</span><span class="semicolon">;</span> |
86 | <span class="brace">}</span> | 86 | <span class="brace">}</span> |
87 | 87 | ||
88 | <span class="keyword">fn</span> <span class="function declaration associated">quop</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="builtin_type">i32</span> <span class="brace">{</span> | 88 | <span class="keyword">fn</span> <span class="function associated declaration">quop</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="builtin_type">i32</span> <span class="brace">{</span> |
89 | <span class="self_keyword">self</span><span class="operator">.</span><span class="field">x</span> | 89 | <span class="self_keyword">self</span><span class="operator">.</span><span class="field">x</span> |
90 | <span class="brace">}</span> | 90 | <span class="brace">}</span> |
91 | <span class="brace">}</span> | 91 | <span class="brace">}</span> |
@@ -96,15 +96,15 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
96 | <span class="brace">}</span> | 96 | <span class="brace">}</span> |
97 | 97 | ||
98 | <span class="keyword">impl</span> <span class="struct">FooCopy</span> <span class="brace">{</span> | 98 | <span class="keyword">impl</span> <span class="struct">FooCopy</span> <span class="brace">{</span> |
99 | <span class="keyword">fn</span> <span class="function declaration associated">baz</span><span class="parenthesis">(</span><span class="self_keyword declaration">self</span><span class="comma">,</span> <span class="value_param declaration">f</span><span class="colon">:</span> <span class="struct">FooCopy</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="builtin_type">u32</span> <span class="brace">{</span> | 99 | <span class="keyword">fn</span> <span class="function associated declaration">baz</span><span class="parenthesis">(</span><span class="self_keyword declaration">self</span><span class="comma">,</span> <span class="value_param declaration">f</span><span class="colon">:</span> <span class="struct">FooCopy</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="builtin_type">u32</span> <span class="brace">{</span> |
100 | <span class="value_param">f</span><span class="operator">.</span><span class="function associated">baz</span><span class="parenthesis">(</span><span class="self_keyword">self</span><span class="parenthesis">)</span> | 100 | <span class="value_param">f</span><span class="operator">.</span><span class="function associated">baz</span><span class="parenthesis">(</span><span class="self_keyword">self</span><span class="parenthesis">)</span> |
101 | <span class="brace">}</span> | 101 | <span class="brace">}</span> |
102 | 102 | ||
103 | <span class="keyword">fn</span> <span class="function declaration associated">qux</span><span class="parenthesis">(</span><span class="operator">&</span><span class="keyword">mut</span> <span class="self_keyword declaration mutable">self</span><span class="parenthesis">)</span> <span class="brace">{</span> | 103 | <span class="keyword">fn</span> <span class="function associated declaration">qux</span><span class="parenthesis">(</span><span class="operator">&</span><span class="keyword">mut</span> <span class="self_keyword declaration mutable">self</span><span class="parenthesis">)</span> <span class="brace">{</span> |
104 | <span class="self_keyword mutable">self</span><span class="operator">.</span><span class="field">x</span> <span class="operator">=</span> <span class="numeric_literal">0</span><span class="semicolon">;</span> | 104 | <span class="self_keyword mutable">self</span><span class="operator">.</span><span class="field">x</span> <span class="operator">=</span> <span class="numeric_literal">0</span><span class="semicolon">;</span> |
105 | <span class="brace">}</span> | 105 | <span class="brace">}</span> |
106 | 106 | ||
107 | <span class="keyword">fn</span> <span class="function declaration associated">quop</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="builtin_type">u32</span> <span class="brace">{</span> | 107 | <span class="keyword">fn</span> <span class="function associated declaration">quop</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="builtin_type">u32</span> <span class="brace">{</span> |
108 | <span class="self_keyword">self</span><span class="operator">.</span><span class="field">x</span> | 108 | <span class="self_keyword">self</span><span class="operator">.</span><span class="field">x</span> |
109 | <span class="brace">}</span> | 109 | <span class="brace">}</span> |
110 | <span class="brace">}</span> | 110 | <span class="brace">}</span> |
@@ -128,7 +128,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
128 | <span class="brace">}</span> | 128 | <span class="brace">}</span> |
129 | 129 | ||
130 | <span class="keyword">use</span> <span class="module">ops</span><span class="operator">::</span><span class="trait">Fn</span><span class="semicolon">;</span> | 130 | <span class="keyword">use</span> <span class="module">ops</span><span class="operator">::</span><span class="trait">Fn</span><span class="semicolon">;</span> |
131 | <span class="keyword">fn</span> <span class="function declaration">baz</span><span class="angle"><</span><span class="type_param declaration">F</span><span class="colon">:</span> <span class="trait">Fn</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="parenthesis">(</span><span class="parenthesis">)</span><span class="angle">></span><span class="parenthesis">(</span><span class="value_param declaration callable">f</span><span class="colon">:</span> <span class="type_param">F</span><span class="parenthesis">)</span> <span class="brace">{</span> | 131 | <span class="keyword">fn</span> <span class="function declaration">baz</span><span class="angle"><</span><span class="type_param declaration">F</span><span class="colon">:</span> <span class="trait">Fn</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="parenthesis">(</span><span class="parenthesis">)</span><span class="angle">></span><span class="parenthesis">(</span><span class="value_param callable declaration">f</span><span class="colon">:</span> <span class="type_param">F</span><span class="parenthesis">)</span> <span class="brace">{</span> |
132 | <span class="value_param callable">f</span><span class="parenthesis">(</span><span class="parenthesis">)</span> | 132 | <span class="value_param callable">f</span><span class="parenthesis">(</span><span class="parenthesis">)</span> |
133 | <span class="brace">}</span> | 133 | <span class="brace">}</span> |
134 | 134 | ||
@@ -199,16 +199,16 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
199 | <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable">foo</span> <span class="operator">=</span> <span class="struct">Foo</span> <span class="brace">{</span> <span class="field">x</span><span class="comma">,</span> <span class="field">y</span><span class="colon">:</span> <span class="variable mutable">x</span> <span class="brace">}</span><span class="semicolon">;</span> | 199 | <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable">foo</span> <span class="operator">=</span> <span class="struct">Foo</span> <span class="brace">{</span> <span class="field">x</span><span class="comma">,</span> <span class="field">y</span><span class="colon">:</span> <span class="variable mutable">x</span> <span class="brace">}</span><span class="semicolon">;</span> |
200 | <span class="keyword">let</span> <span class="variable declaration">foo2</span> <span class="operator">=</span> <span class="struct">Foo</span> <span class="brace">{</span> <span class="field">x</span><span class="comma">,</span> <span class="field">y</span><span class="colon">:</span> <span class="variable mutable">x</span> <span class="brace">}</span><span class="semicolon">;</span> | 200 | <span class="keyword">let</span> <span class="variable declaration">foo2</span> <span class="operator">=</span> <span class="struct">Foo</span> <span class="brace">{</span> <span class="field">x</span><span class="comma">,</span> <span class="field">y</span><span class="colon">:</span> <span class="variable mutable">x</span> <span class="brace">}</span><span class="semicolon">;</span> |
201 | <span class="variable mutable">foo</span><span class="operator">.</span><span class="function associated">quop</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="semicolon">;</span> | 201 | <span class="variable mutable">foo</span><span class="operator">.</span><span class="function associated">quop</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="semicolon">;</span> |
202 | <span class="variable mutable">foo</span><span class="operator">.</span><span class="function mutable associated">qux</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="semicolon">;</span> | 202 | <span class="variable mutable">foo</span><span class="operator">.</span><span class="function associated mutable">qux</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="semicolon">;</span> |
203 | <span class="variable mutable">foo</span><span class="operator">.</span><span class="function consuming associated">baz</span><span class="parenthesis">(</span><span class="variable consuming">foo2</span><span class="parenthesis">)</span><span class="semicolon">;</span> | 203 | <span class="variable mutable">foo</span><span class="operator">.</span><span class="function associated consuming">baz</span><span class="parenthesis">(</span><span class="variable consuming">foo2</span><span class="parenthesis">)</span><span class="semicolon">;</span> |
204 | 204 | ||
205 | <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable">copy</span> <span class="operator">=</span> <span class="struct">FooCopy</span> <span class="brace">{</span> <span class="field">x</span> <span class="brace">}</span><span class="semicolon">;</span> | 205 | <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable">copy</span> <span class="operator">=</span> <span class="struct">FooCopy</span> <span class="brace">{</span> <span class="field">x</span> <span class="brace">}</span><span class="semicolon">;</span> |
206 | <span class="variable mutable">copy</span><span class="operator">.</span><span class="function associated">quop</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="semicolon">;</span> | 206 | <span class="variable mutable">copy</span><span class="operator">.</span><span class="function associated">quop</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="semicolon">;</span> |
207 | <span class="variable mutable">copy</span><span class="operator">.</span><span class="function mutable associated">qux</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="semicolon">;</span> | 207 | <span class="variable mutable">copy</span><span class="operator">.</span><span class="function associated mutable">qux</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="semicolon">;</span> |
208 | <span class="variable mutable">copy</span><span class="operator">.</span><span class="function associated">baz</span><span class="parenthesis">(</span><span class="variable mutable">copy</span><span class="parenthesis">)</span><span class="semicolon">;</span> | 208 | <span class="variable mutable">copy</span><span class="operator">.</span><span class="function associated">baz</span><span class="parenthesis">(</span><span class="variable mutable">copy</span><span class="parenthesis">)</span><span class="semicolon">;</span> |
209 | 209 | ||
210 | <span class="keyword">let</span> <span class="variable declaration callable">a</span> <span class="operator">=</span> <span class="punctuation">|</span><span class="value_param declaration">x</span><span class="punctuation">|</span> <span class="value_param">x</span><span class="semicolon">;</span> | 210 | <span class="keyword">let</span> <span class="variable callable declaration">a</span> <span class="operator">=</span> <span class="punctuation">|</span><span class="value_param declaration">x</span><span class="punctuation">|</span> <span class="value_param">x</span><span class="semicolon">;</span> |
211 | <span class="keyword">let</span> <span class="variable declaration callable">bar</span> <span class="operator">=</span> <span class="struct">Foo</span><span class="operator">::</span><span class="function associated">baz</span><span class="semicolon">;</span> | 211 | <span class="keyword">let</span> <span class="variable callable declaration">bar</span> <span class="operator">=</span> <span class="struct">Foo</span><span class="operator">::</span><span class="function associated">baz</span><span class="semicolon">;</span> |
212 | 212 | ||
213 | <span class="keyword">let</span> <span class="variable declaration">baz</span> <span class="operator">=</span> <span class="numeric_literal">-</span><span class="numeric_literal">42</span><span class="semicolon">;</span> | 213 | <span class="keyword">let</span> <span class="variable declaration">baz</span> <span class="operator">=</span> <span class="numeric_literal">-</span><span class="numeric_literal">42</span><span class="semicolon">;</span> |
214 | <span class="keyword">let</span> <span class="variable declaration">baz</span> <span class="operator">=</span> <span class="operator">-</span><span class="variable">baz</span><span class="semicolon">;</span> | 214 | <span class="keyword">let</span> <span class="variable declaration">baz</span> <span class="operator">=</span> <span class="operator">-</span><span class="variable">baz</span><span class="semicolon">;</span> |
@@ -228,7 +228,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
228 | <span class="keyword">use</span> <span class="enum">Option</span><span class="operator">::</span><span class="punctuation">*</span><span class="semicolon">;</span> | 228 | <span class="keyword">use</span> <span class="enum">Option</span><span class="operator">::</span><span class="punctuation">*</span><span class="semicolon">;</span> |
229 | 229 | ||
230 | <span class="keyword">impl</span><span class="angle"><</span><span class="type_param declaration">T</span><span class="angle">></span> <span class="enum">Option</span><span class="angle"><</span><span class="type_param">T</span><span class="angle">></span> <span class="brace">{</span> | 230 | <span class="keyword">impl</span><span class="angle"><</span><span class="type_param declaration">T</span><span class="angle">></span> <span class="enum">Option</span><span class="angle"><</span><span class="type_param">T</span><span class="angle">></span> <span class="brace">{</span> |
231 | <span class="keyword">fn</span> <span class="function declaration associated">and</span><span class="angle"><</span><span class="type_param declaration">U</span><span class="angle">></span><span class="parenthesis">(</span><span class="self_keyword declaration">self</span><span class="comma">,</span> <span class="value_param declaration">other</span><span class="colon">:</span> <span class="enum">Option</span><span class="angle"><</span><span class="type_param">U</span><span class="angle">></span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="enum">Option</span><span class="angle"><</span><span class="parenthesis">(</span><span class="type_param">T</span><span class="comma">,</span> <span class="type_param">U</span><span class="parenthesis">)</span><span class="angle">></span> <span class="brace">{</span> | 231 | <span class="keyword">fn</span> <span class="function associated declaration">and</span><span class="angle"><</span><span class="type_param declaration">U</span><span class="angle">></span><span class="parenthesis">(</span><span class="self_keyword declaration">self</span><span class="comma">,</span> <span class="value_param declaration">other</span><span class="colon">:</span> <span class="enum">Option</span><span class="angle"><</span><span class="type_param">U</span><span class="angle">></span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="enum">Option</span><span class="angle"><</span><span class="parenthesis">(</span><span class="type_param">T</span><span class="comma">,</span> <span class="type_param">U</span><span class="parenthesis">)</span><span class="angle">></span> <span class="brace">{</span> |
232 | <span class="keyword control">match</span> <span class="value_param">other</span> <span class="brace">{</span> | 232 | <span class="keyword control">match</span> <span class="value_param">other</span> <span class="brace">{</span> |
233 | <span class="enum_variant">None</span> <span class="operator">=></span> <span class="macro">unimplemented!</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="comma">,</span> | 233 | <span class="enum_variant">None</span> <span class="operator">=></span> <span class="macro">unimplemented!</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="comma">,</span> |
234 | <span class="variable declaration">Nope</span> <span class="operator">=></span> <span class="variable">Nope</span><span class="comma">,</span> | 234 | <span class="variable declaration">Nope</span> <span class="operator">=></span> <span class="variable">Nope</span><span class="comma">,</span> |