Cleanup repr check, fix packed repr check and test
This commit is contained in:
parent
c9e670b875
commit
38440d53d8
@ -12,10 +12,11 @@ use ra_syntax::ast::{self, NameOwner, VisibilityOwner};
|
|||||||
use tt::{Delimiter, DelimiterKind, Leaf, Subtree, TokenTree};
|
use tt::{Delimiter, DelimiterKind, Leaf, Subtree, TokenTree};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
attr::AttrInput,
|
attr::{Attr, AttrInput},
|
||||||
body::{CfgExpander, LowerCtx},
|
body::{CfgExpander, LowerCtx},
|
||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
item_tree::{AttrOwner, Field, Fields, ItemTree, ModItem},
|
item_tree::{AttrOwner, Field, Fields, ItemTree, ModItem},
|
||||||
|
path::{ModPath, PathKind},
|
||||||
src::HasChildSource,
|
src::HasChildSource,
|
||||||
src::HasSource,
|
src::HasSource,
|
||||||
trace::Trace,
|
trace::Trace,
|
||||||
@ -69,8 +70,12 @@ pub enum ReprKind {
|
|||||||
|
|
||||||
fn repr_from_value(item_tree: &ItemTree, of: AttrOwner) -> Option<ReprKind> {
|
fn repr_from_value(item_tree: &ItemTree, of: AttrOwner) -> Option<ReprKind> {
|
||||||
item_tree.attrs(of).iter().find_map(|a| {
|
item_tree.attrs(of).iter().find_map(|a| {
|
||||||
if a.path.segments[0].to_string() == "repr" {
|
if let Attr {
|
||||||
if let Some(AttrInput::TokenTree(subtree)) = &a.input {
|
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)
|
parse_repr_tt(subtree)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -565,7 +565,7 @@ fn highlight_element(
|
|||||||
_ => h,
|
_ => h,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
T![&] => {
|
REF_EXPR => {
|
||||||
let ref_expr = element.into_node().and_then(ast::RefExpr::cast)?;
|
let ref_expr = element.into_node().and_then(ast::RefExpr::cast)?;
|
||||||
let expr = ref_expr.expr()?;
|
let expr = ref_expr.expr()?;
|
||||||
let field_expr = match expr {
|
let field_expr = match expr {
|
||||||
@ -582,7 +582,7 @@ fn highlight_element(
|
|||||||
// FIXME This needs layout computation to be correct. It will highlight
|
// FIXME This needs layout computation to be correct. It will highlight
|
||||||
// more than it should with the current implementation.
|
// 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 {
|
p if p.is_punct() => match p {
|
||||||
T![::] | T![->] | T![=>] | T![&] | T![..] | T![=] | T![@] => {
|
T![::] | T![->] | T![=>] | T![&] | T![..] | T![=] | T![@] => {
|
||||||
|
@ -295,8 +295,6 @@ static mut global_mut: TypeForStaticMut = TypeForStaticMut { a: 0 };
|
|||||||
#[repr(packed)]
|
#[repr(packed)]
|
||||||
struct Packed {
|
struct Packed {
|
||||||
a: u16,
|
a: u16,
|
||||||
b: u8,
|
|
||||||
c: u32,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
trait DoTheAutoref {
|
trait DoTheAutoref {
|
||||||
@ -313,11 +311,11 @@ struct HasAligned {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl DoTheAutoref for NeedsAlign {
|
impl DoTheAutoref for NeedsAlign {
|
||||||
fn calls_autored(&self) {}
|
fn calls_autoref(&self) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = &5 as *const usize;
|
let x = &5 as *const _ as *const usize;
|
||||||
let u = Union { b: 0 };
|
let u = Union { b: 0 };
|
||||||
unsafe {
|
unsafe {
|
||||||
unsafe_fn();
|
unsafe_fn();
|
||||||
@ -327,13 +325,11 @@ fn main() {
|
|||||||
Union { a } => (),
|
Union { a } => (),
|
||||||
}
|
}
|
||||||
HasUnsafeFn.unsafe_method();
|
HasUnsafeFn.unsafe_method();
|
||||||
let y = *(x);
|
let _y = *(x);
|
||||||
let z = -x;
|
let z = -x;
|
||||||
let a = global_mut.a;
|
let a = global_mut.a;
|
||||||
let packed = Packed { a: 0, b: 0, c: 0 };
|
let packed = Packed { a: 0 };
|
||||||
let a = &packed.a;
|
let _a = &packed.a;
|
||||||
let b = &packed.b;
|
|
||||||
let c = &packed.c;
|
|
||||||
let h = HasAligned{ a: NeedsAlign { a: 1 } };
|
let h = HasAligned{ a: NeedsAlign { a: 1 } };
|
||||||
h.a.calls_autoref();
|
h.a.calls_autoref();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user