mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-13 00:56:14 +00:00
In field patterns, don't highlight local binding as a field
This commit is contained in:
parent
560b98bc50
commit
db1cadd444
@ -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 New Issue
Block a user