From 38440d53d8329ac9f3f2013c6e32b3f69b069c72 Mon Sep 17 00:00:00 2001 From: Paul Daniel Faria Date: Sat, 27 Jun 2020 14:42:42 -0400 Subject: Cleanup repr check, fix packed repr check and test --- crates/ra_hir_def/src/adt.rs | 11 ++++++++--- crates/ra_ide/src/syntax_highlighting.rs | 4 ++-- crates/ra_ide/src/syntax_highlighting/tests.rs | 14 +++++--------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs index 6d59c8642..4ba694480 100644 --- a/crates/ra_hir_def/src/adt.rs +++ b/crates/ra_hir_def/src/adt.rs @@ -12,10 +12,11 @@ use ra_syntax::ast::{self, NameOwner, VisibilityOwner}; use tt::{Delimiter, DelimiterKind, Leaf, Subtree, TokenTree}; use crate::{ - attr::AttrInput, + attr::{Attr, AttrInput}, body::{CfgExpander, LowerCtx}, db::DefDatabase, item_tree::{AttrOwner, Field, Fields, ItemTree, ModItem}, + path::{ModPath, PathKind}, src::HasChildSource, src::HasSource, trace::Trace, @@ -69,8 +70,12 @@ pub enum ReprKind { fn repr_from_value(item_tree: &ItemTree, of: AttrOwner) -> Option { item_tree.attrs(of).iter().find_map(|a| { - if a.path.segments[0].to_string() == "repr" { - if let Some(AttrInput::TokenTree(subtree)) = &a.input { + if let Attr { + path: ModPath { kind: PathKind::Plain, segments }, + input: Some(AttrInput::TokenTree(subtree)), + } = a + { + if segments.len() == 1 && segments[0].to_string() == "repr" { parse_repr_tt(subtree) } else { None diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 9e8419c5f..a4a7aa228 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -565,7 +565,7 @@ fn highlight_element( _ => h, } } - T![&] => { + REF_EXPR => { let ref_expr = element.into_node().and_then(ast::RefExpr::cast)?; let expr = ref_expr.expr()?; let field_expr = match expr { @@ -582,7 +582,7 @@ fn highlight_element( // FIXME This needs layout computation to be correct. It will highlight // more than it should with the current implementation. - Highlight::new(HighlightTag::Operator) | HighlightModifier::Unsafe + HighlightTag::Operator | HighlightModifier::Unsafe } p if p.is_punct() => match p { T![::] | T![->] | T![=>] | T![&] | T![..] | T![=] | T![@] => { diff --git a/crates/ra_ide/src/syntax_highlighting/tests.rs b/crates/ra_ide/src/syntax_highlighting/tests.rs index c40805850..a7f5ad862 100644 --- a/crates/ra_ide/src/syntax_highlighting/tests.rs +++ b/crates/ra_ide/src/syntax_highlighting/tests.rs @@ -295,8 +295,6 @@ static mut global_mut: TypeForStaticMut = TypeForStaticMut { a: 0 }; #[repr(packed)] struct Packed { a: u16, - b: u8, - c: u32, } trait DoTheAutoref { @@ -313,11 +311,11 @@ struct HasAligned { } impl DoTheAutoref for NeedsAlign { - fn calls_autored(&self) {} + fn calls_autoref(&self) {} } fn main() { - let x = &5 as *const usize; + let x = &5 as *const _ as *const usize; let u = Union { b: 0 }; unsafe { unsafe_fn(); @@ -327,13 +325,11 @@ fn main() { Union { a } => (), } HasUnsafeFn.unsafe_method(); - let y = *(x); + let _y = *(x); let z = -x; let a = global_mut.a; - let packed = Packed { a: 0, b: 0, c: 0 }; - let a = &packed.a; - let b = &packed.b; - let c = &packed.c; + let packed = Packed { a: 0 }; + let _a = &packed.a; let h = HasAligned{ a: NeedsAlign { a: 1 } }; h.a.calls_autoref(); } -- cgit v1.2.3