mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 20:43:21 +00:00
Merge #4834
4834: In field patterns, don't highlight local binding as a field r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
f632727b2a
3 changed files with 23 additions and 16 deletions
|
@ -84,7 +84,9 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
|||
<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">let</span> <span class="struct">Foo</span> { <span class="field">x</span>: <span class="variable declaration">z</span>, <span class="field">y</span> } = <span class="struct">Foo</span> { <span class="field">x</span>: <span class="variable">z</span>, <span class="field">y</span> };
|
||||
|
||||
<span class="variable">y</span>;
|
||||
}
|
||||
|
||||
<span class="keyword">enum</span> <span class="enum declaration">Option</span><<span class="type_param declaration">T</span>> {
|
||||
|
|
|
@ -7,18 +7,6 @@ use crate::{
|
|||
FileRange, TextRange,
|
||||
};
|
||||
|
||||
/// Highlights the code given by the `ra_fixture` argument, renders the
|
||||
/// result as HTML, and compares it with the HTML file given as `snapshot`.
|
||||
/// Note that the `snapshot` file is overwritten by the rendered HTML.
|
||||
fn check_highlighting(ra_fixture: &str, snapshot: &str, rainbow: bool) {
|
||||
let (analysis, file_id) = single_file(ra_fixture);
|
||||
let dst_file = project_dir().join(snapshot);
|
||||
let actual_html = &analysis.highlight_as_html(file_id, rainbow).unwrap();
|
||||
let expected_html = &read_text(&dst_file);
|
||||
fs::write(dst_file, &actual_html).unwrap();
|
||||
assert_eq_text!(expected_html, actual_html);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_highlighting() {
|
||||
check_highlighting(
|
||||
|
@ -77,6 +65,8 @@ fn main() {
|
|||
let y = &mut x;
|
||||
let z = &y;
|
||||
|
||||
let Foo { x: z, y } = Foo { x: z, y };
|
||||
|
||||
y;
|
||||
}
|
||||
|
||||
|
@ -334,3 +324,15 @@ impl Foo {
|
|||
false,
|
||||
)
|
||||
}
|
||||
|
||||
/// Highlights the code given by the `ra_fixture` argument, renders the
|
||||
/// result as HTML, and compares it with the HTML file given as `snapshot`.
|
||||
/// Note that the `snapshot` file is overwritten by the rendered HTML.
|
||||
fn check_highlighting(ra_fixture: &str, snapshot: &str, rainbow: bool) {
|
||||
let (analysis, file_id) = single_file(ra_fixture);
|
||||
let dst_file = project_dir().join(snapshot);
|
||||
let actual_html = &analysis.highlight_as_html(file_id, rainbow).unwrap();
|
||||
let expected_html = &read_text(&dst_file);
|
||||
fs::write(dst_file, &actual_html).unwrap();
|
||||
assert_eq_text!(expected_html, actual_html);
|
||||
}
|
||||
|
|
|
@ -78,6 +78,7 @@ impl Definition {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum NameClass {
|
||||
Definition(Definition),
|
||||
/// `None` in `if let None = Some(82) {}`
|
||||
|
@ -131,9 +132,11 @@ pub fn classify_name(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Option
|
|||
let local = sema.to_def(&it)?;
|
||||
|
||||
if let Some(record_field_pat) = it.syntax().parent().and_then(ast::RecordFieldPat::cast) {
|
||||
if let Some(field) = sema.resolve_record_field_pat(&record_field_pat) {
|
||||
let field = Definition::Field(field);
|
||||
return Some(NameClass::FieldShorthand { local, field });
|
||||
if record_field_pat.name_ref().is_none() {
|
||||
if let Some(field) = sema.resolve_record_field_pat(&record_field_pat) {
|
||||
let field = Definition::Field(field);
|
||||
return Some(NameClass::FieldShorthand { local, field });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue