mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-12 16:45:37 +00:00
Correctly flag 'lifetime definitions as definitions
This commit is contained in:
parent
5ebfcb9cb7
commit
56ce34c6a7
@ -3,7 +3,7 @@
|
||||
body { margin: 0; }
|
||||
pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; }
|
||||
|
||||
|
||||
.lifetime { color: #DFAF8F; font-style: italic; }
|
||||
.comment { color: #7F9F7F; }
|
||||
.struct, .enum { color: #7CB8BB; }
|
||||
.enum_variant { color: #BDE0F3; }
|
||||
@ -27,14 +27,13 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
||||
.control { font-style: italic; }
|
||||
</style>
|
||||
<pre><code><span class="attribute">#</span><span class="attribute">[</span><span class="attribute">derive</span><span class="attribute">(</span><span class="attribute">Clone</span><span class="attribute">,</span><span class="attribute"> </span><span class="attribute">Debug</span><span class="attribute">)</span><span class="attribute">]</span>
|
||||
<span class="keyword">struct</span> <span class="struct">Foo</span> {
|
||||
<span class="keyword">pub</span> <span class="field">x</span>: <span class="builtin_type">i32</span>,
|
||||
<span class="keyword">pub</span> <span class="field">y</span>: <span class="builtin_type">i32</span>,
|
||||
<span class="keyword">struct</span> <span class="struct declaration">Foo</span> {
|
||||
<span class="keyword">pub</span> <span class="field declaration">x</span>: <span class="builtin_type">i32</span>,
|
||||
<span class="keyword">pub</span> <span class="field declaration">y</span>: <span class="builtin_type">i32</span>,
|
||||
}
|
||||
|
||||
<span class="keyword">fn</span> <span class="function">foo</span><<span class="type_param">T</span>>() -> <span class="type_param">T</span> {
|
||||
<span class="macro">unimplemented</span><span class="macro">!</span>();
|
||||
<span class="function">foo</span>::<<span class="builtin_type">i32</span>>();
|
||||
<span class="keyword">fn</span> <span class="function declaration">foo</span><<span class="lifetime declaration">'a</span>, <span class="type_param declaration">T</span>>() -> <span class="type_param">T</span> {
|
||||
<span class="function">foo</span>::<<span class="lifetime">'a</span>, <span class="builtin_type">i32</span>>()
|
||||
}
|
||||
|
||||
<span class="macro">macro_rules</span><span class="macro">!</span> def_fn {
|
||||
@ -42,40 +41,40 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
||||
}
|
||||
|
||||
<span class="macro">def_fn</span><span class="macro">!</span> {
|
||||
<span class="keyword">fn</span> <span class="function">bar</span>() -> <span class="builtin_type">u32</span> {
|
||||
<span class="keyword">fn</span> <span class="function declaration">bar</span>() -> <span class="builtin_type">u32</span> {
|
||||
<span class="numeric_literal">100</span>
|
||||
}
|
||||
}
|
||||
|
||||
<span class="comment">// comment</span>
|
||||
<span class="keyword">fn</span> <span class="function">main</span>() {
|
||||
<span class="keyword">fn</span> <span class="function declaration">main</span>() {
|
||||
<span class="macro">println</span><span class="macro">!</span>(<span class="string_literal">"Hello, {}!"</span>, <span class="numeric_literal">92</span>);
|
||||
|
||||
<span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable mutable">vec</span> = Vec::new();
|
||||
<span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable">vec</span> = Vec::new();
|
||||
<span class="keyword control">if</span> <span class="keyword">true</span> {
|
||||
<span class="keyword">let</span> <span class="variable">x</span> = <span class="numeric_literal">92</span>;
|
||||
<span class="keyword">let</span> <span class="variable declaration">x</span> = <span class="numeric_literal">92</span>;
|
||||
<span class="variable mutable">vec</span>.push(<span class="struct">Foo</span> { <span class="field">x</span>, <span class="field">y</span>: <span class="numeric_literal">1</span> });
|
||||
}
|
||||
<span class="keyword unsafe">unsafe</span> { <span class="variable mutable">vec</span>.set_len(<span class="numeric_literal">0</span>); }
|
||||
|
||||
<span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable mutable">x</span> = <span class="numeric_literal">42</span>;
|
||||
<span class="keyword">let</span> <span class="variable mutable">y</span> = &<span class="keyword">mut</span> <span class="variable mutable">x</span>;
|
||||
<span class="keyword">let</span> <span class="variable">z</span> = &<span class="variable mutable">y</span>;
|
||||
<span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable">x</span> = <span class="numeric_literal">42</span>;
|
||||
<span class="keyword">let</span> <span class="variable declaration mutable">y</span> = &<span class="keyword">mut</span> <span class="variable mutable">x</span>;
|
||||
<span class="keyword">let</span> <span class="variable declaration">z</span> = &<span class="variable mutable">y</span>;
|
||||
|
||||
<span class="variable mutable">y</span>;
|
||||
}
|
||||
|
||||
<span class="keyword">enum</span> <span class="enum">Option</span><<span class="type_param">T</span>> {
|
||||
<span class="enum_variant">Some</span>(<span class="type_param">T</span>),
|
||||
<span class="enum_variant">None</span>,
|
||||
<span class="keyword">enum</span> <span class="enum declaration">Option</span><<span class="type_param declaration">T</span>> {
|
||||
<span class="enum_variant declaration">Some</span>(<span class="type_param">T</span>),
|
||||
<span class="enum_variant declaration">None</span>,
|
||||
}
|
||||
<span class="keyword">use</span> <span class="enum">Option</span>::*;
|
||||
|
||||
<span class="keyword">impl</span><<span class="type_param">T</span>> <span class="enum">Option</span><<span class="type_param">T</span>> {
|
||||
<span class="keyword">fn</span> <span class="function">and</span><<span class="type_param">U</span>>(<span class="keyword">self</span>, <span class="variable">other</span>: <span class="enum">Option</span><<span class="type_param">U</span>>) -> <span class="enum">Option</span><(<span class="type_param">T</span>, <span class="type_param">U</span>)> {
|
||||
<span class="keyword">impl</span><<span class="type_param declaration">T</span>> <span class="enum">Option</span><<span class="type_param">T</span>> {
|
||||
<span class="keyword">fn</span> <span class="function declaration">and</span><<span class="type_param declaration">U</span>>(<span class="keyword">self</span>, <span class="variable declaration">other</span>: <span class="enum">Option</span><<span class="type_param">U</span>>) -> <span class="enum">Option</span><(<span class="type_param">T</span>, <span class="type_param">U</span>)> {
|
||||
<span class="keyword control">match</span> <span class="variable">other</span> {
|
||||
<span class="enum_variant">None</span> => <span class="macro">todo</span><span class="macro">!</span>(),
|
||||
<span class="variable">Nope</span> => <span class="variable">Nope</span>,
|
||||
<span class="enum_variant">None</span> => <span class="macro">unimplemented</span><span class="macro">!</span>(),
|
||||
<span class="variable declaration">Nope</span> => <span class="variable">Nope</span>,
|
||||
}
|
||||
}
|
||||
}</code></pre>
|
@ -3,7 +3,7 @@
|
||||
body { margin: 0; }
|
||||
pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; }
|
||||
|
||||
|
||||
.lifetime { color: #DFAF8F; font-style: italic; }
|
||||
.comment { color: #7F9F7F; }
|
||||
.struct, .enum { color: #7CB8BB; }
|
||||
.enum_variant { color: #BDE0F3; }
|
||||
@ -26,15 +26,15 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
||||
.keyword.unsafe { color: #BC8383; font-weight: bold; }
|
||||
.control { font-style: italic; }
|
||||
</style>
|
||||
<pre><code><span class="keyword">fn</span> <span class="function">main</span>() {
|
||||
<span class="keyword">let</span> <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span> = <span class="string_literal">"hello"</span>;
|
||||
<span class="keyword">let</span> <span class="variable" data-binding-hash="2705725358298919760" style="color: hsl(17,51%,74%);">x</span> = <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span>.to_string();
|
||||
<span class="keyword">let</span> <span class="variable" data-binding-hash="3365759661443752373" style="color: hsl(127,76%,66%);">y</span> = <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span>.to_string();
|
||||
<pre><code><span class="keyword">fn</span> <span class="function declaration">main</span>() {
|
||||
<span class="keyword">let</span> <span class="variable declaration" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span> = <span class="string_literal">"hello"</span>;
|
||||
<span class="keyword">let</span> <span class="variable declaration" data-binding-hash="2705725358298919760" style="color: hsl(17,51%,74%);">x</span> = <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span>.to_string();
|
||||
<span class="keyword">let</span> <span class="variable declaration" data-binding-hash="3365759661443752373" style="color: hsl(127,76%,66%);">y</span> = <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span>.to_string();
|
||||
|
||||
<span class="keyword">let</span> <span class="variable" data-binding-hash="794745962933817518" style="color: hsl(19,74%,76%);">x</span> = <span class="string_literal">"other color please!"</span>;
|
||||
<span class="keyword">let</span> <span class="variable" data-binding-hash="6717528807933952652" style="color: hsl(85,49%,84%);">y</span> = <span class="variable" data-binding-hash="794745962933817518" style="color: hsl(19,74%,76%);">x</span>.to_string();
|
||||
<span class="keyword">let</span> <span class="variable declaration" data-binding-hash="794745962933817518" style="color: hsl(19,74%,76%);">x</span> = <span class="string_literal">"other color please!"</span>;
|
||||
<span class="keyword">let</span> <span class="variable declaration" data-binding-hash="6717528807933952652" style="color: hsl(85,49%,84%);">y</span> = <span class="variable" data-binding-hash="794745962933817518" style="color: hsl(19,74%,76%);">x</span>.to_string();
|
||||
}
|
||||
|
||||
<span class="keyword">fn</span> <span class="function">bar</span>() {
|
||||
<span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable mutable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span> = <span class="string_literal">"hello"</span>;
|
||||
<span class="keyword">fn</span> <span class="function declaration">bar</span>() {
|
||||
<span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span> = <span class="string_literal">"hello"</span>;
|
||||
}</code></pre>
|
@ -214,8 +214,13 @@ fn highlight_element(
|
||||
INT_NUMBER | FLOAT_NUMBER => HighlightTag::NumericLiteral.into(),
|
||||
BYTE => HighlightTag::ByteLiteral.into(),
|
||||
CHAR => HighlightTag::CharLiteral.into(),
|
||||
// FIXME: set Declaration for decls
|
||||
LIFETIME => HighlightTag::Lifetime.into(),
|
||||
LIFETIME => {
|
||||
let h = Highlight::new(HighlightTag::Lifetime);
|
||||
dbg!(match element.parent().map(|it| it.kind()) {
|
||||
Some(LIFETIME_PARAM) | Some(LABEL) => h | HighlightModifier::Definition,
|
||||
_ => h,
|
||||
})
|
||||
}
|
||||
|
||||
k if k.is_keyword() => {
|
||||
let h = Highlight::new(HighlightTag::Keyword);
|
||||
|
@ -80,7 +80,7 @@ const STYLE: &str = "
|
||||
body { margin: 0; }
|
||||
pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; }
|
||||
|
||||
|
||||
.lifetime { color: #DFAF8F; font-style: italic; }
|
||||
.comment { color: #7F9F7F; }
|
||||
.struct, .enum { color: #7CB8BB; }
|
||||
.enum_variant { color: #BDE0F3; }
|
||||
|
@ -90,8 +90,12 @@ impl fmt::Display for HighlightTag {
|
||||
}
|
||||
|
||||
impl HighlightModifier {
|
||||
const ALL: &'static [HighlightModifier] =
|
||||
&[HighlightModifier::Mutable, HighlightModifier::Unsafe, HighlightModifier::Control];
|
||||
const ALL: &'static [HighlightModifier] = &[
|
||||
HighlightModifier::Control,
|
||||
HighlightModifier::Definition,
|
||||
HighlightModifier::Mutable,
|
||||
HighlightModifier::Unsafe,
|
||||
];
|
||||
|
||||
fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
|
@ -17,9 +17,8 @@ struct Foo {
|
||||
pub y: i32,
|
||||
}
|
||||
|
||||
fn foo<T>() -> T {
|
||||
unimplemented!();
|
||||
foo::<i32>();
|
||||
fn foo<'a, T>() -> T {
|
||||
foo::<'a, i32>()
|
||||
}
|
||||
|
||||
macro_rules! def_fn {
|
||||
@ -59,7 +58,7 @@ use Option::*;
|
||||
impl<T> Option<T> {
|
||||
fn and<U>(self, other: Option<U>) -> Option<(T, U)> {
|
||||
match other {
|
||||
None => todo!(),
|
||||
None => unimplemented!(),
|
||||
Nope => Nope,
|
||||
}
|
||||
}
|
||||
@ -130,5 +129,5 @@ fn test_ranges() {
|
||||
.highlight_range(FileRange { file_id, range: TextRange::offset_len(82.into(), 1.into()) })
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(&highlights[0].highlight.to_string(), "field");
|
||||
assert_eq!(&highlights[0].highlight.to_string(), "field.declaration");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user