Limit scope of unsafe to & instead of all ref exprs, add test showing missing support for autoref behavior

This commit is contained in:
Paul Daniel Faria 2020-06-15 07:41:13 -04:00 committed by Paul Daniel Faria
parent fd30134cf8
commit 4a4b1f48ef
2 changed files with 20 additions and 1 deletions

View File

@ -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 {

View File

@ -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();
}
}
"#