From 4a4b1f48efeff4ebe578eb92b7bb8338d0181a83 Mon Sep 17 00:00:00 2001 From: Paul Daniel Faria Date: Mon, 15 Jun 2020 07:41:13 -0400 Subject: Limit scope of unsafe to & instead of all ref exprs, add test showing missing support for autoref behavior --- crates/ra_ide/src/syntax_highlighting.rs | 2 +- crates/ra_ide/src/syntax_highlighting/tests.rs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index b82b51efd..c5098189b 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, } } - REF_EXPR => { + T![&] => { let ref_expr = element.into_node().and_then(ast::RefExpr::cast)?; let expr = ref_expr.expr()?; let field_expr = match expr { diff --git a/crates/ra_ide/src/syntax_highlighting/tests.rs b/crates/ra_ide/src/syntax_highlighting/tests.rs index f2c078d34..c40805850 100644 --- a/crates/ra_ide/src/syntax_highlighting/tests.rs +++ b/crates/ra_ide/src/syntax_highlighting/tests.rs @@ -299,6 +299,23 @@ struct Packed { c: u32, } +trait DoTheAutoref { + fn calls_autoref(&self); +} + +struct NeedsAlign { + a: u16 +} + +#[repr(packed)] +struct HasAligned { + a: NeedsAlign +} + +impl DoTheAutoref for NeedsAlign { + fn calls_autored(&self) {} +} + fn main() { let x = &5 as *const usize; let u = Union { b: 0 }; @@ -317,6 +334,8 @@ fn main() { let a = &packed.a; let b = &packed.b; let c = &packed.c; + let h = HasAligned{ a: NeedsAlign { a: 1 } }; + h.a.calls_autoref(); } } "# -- cgit v1.2.3