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 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<ReprKind> {
|
||||
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
|
||||
|
@ -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![@] => {
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user