mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 15:15:24 +00:00
Fix default enum representation not being isize
This commit is contained in:
parent
2119c1f351
commit
9bf386f4c0
3 changed files with 69 additions and 22 deletions
|
@ -223,7 +223,7 @@ impl EnumData {
|
||||||
pub fn variant_body_type(&self) -> Either<BuiltinInt, BuiltinUint> {
|
pub fn variant_body_type(&self) -> Either<BuiltinInt, BuiltinUint> {
|
||||||
match self.repr {
|
match self.repr {
|
||||||
Some(ReprData { kind: ReprKind::BuiltinInt { builtin, .. }, .. }) => builtin,
|
Some(ReprData { kind: ReprKind::BuiltinInt { builtin, .. }, .. }) => builtin,
|
||||||
_ => Either::Right(BuiltinUint::U32),
|
_ => Either::Left(BuiltinInt::Isize),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -461,6 +461,18 @@ fn visit_module(
|
||||||
let body = db.body(def);
|
let body = db.body(def);
|
||||||
visit_body(db, &body, cb);
|
visit_body(db, &body, cb);
|
||||||
}
|
}
|
||||||
|
ModuleDefId::AdtId(hir_def::AdtId::EnumId(it)) => {
|
||||||
|
db.enum_data(it)
|
||||||
|
.variants
|
||||||
|
.iter()
|
||||||
|
.map(|(id, _)| hir_def::EnumVariantId { parent: it, local_id: id })
|
||||||
|
.for_each(|it| {
|
||||||
|
let def = it.into();
|
||||||
|
cb(def);
|
||||||
|
let body = db.body(def);
|
||||||
|
visit_body(db, &body, cb);
|
||||||
|
});
|
||||||
|
}
|
||||||
ModuleDefId::TraitId(it) => {
|
ModuleDefId::TraitId(it) => {
|
||||||
let trait_data = db.trait_data(it);
|
let trait_data = db.trait_data(it);
|
||||||
for &(_, item) in trait_data.items.iter() {
|
for &(_, item) in trait_data.items.iter() {
|
||||||
|
|
|
@ -1693,16 +1693,16 @@ fn infer_type_param() {
|
||||||
fn infer_const() {
|
fn infer_const() {
|
||||||
check_infer(
|
check_infer(
|
||||||
r#"
|
r#"
|
||||||
struct Foo;
|
struct Foo;
|
||||||
impl Foo { const ASSOC_CONST: u32 = 0; }
|
impl Foo { const ASSOC_CONST: u32 = 0; }
|
||||||
const GLOBAL_CONST: u32 = 101;
|
const GLOBAL_CONST: u32 = 101;
|
||||||
fn test() {
|
fn test() {
|
||||||
const LOCAL_CONST: u32 = 99;
|
const LOCAL_CONST: u32 = 99;
|
||||||
let x = LOCAL_CONST;
|
let x = LOCAL_CONST;
|
||||||
let z = GLOBAL_CONST;
|
let z = GLOBAL_CONST;
|
||||||
let id = Foo::ASSOC_CONST;
|
let id = Foo::ASSOC_CONST;
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
48..49 '0': u32
|
48..49 '0': u32
|
||||||
79..82 '101': u32
|
79..82 '101': u32
|
||||||
|
@ -1722,17 +1722,17 @@ fn infer_const() {
|
||||||
fn infer_static() {
|
fn infer_static() {
|
||||||
check_infer(
|
check_infer(
|
||||||
r#"
|
r#"
|
||||||
static GLOBAL_STATIC: u32 = 101;
|
static GLOBAL_STATIC: u32 = 101;
|
||||||
static mut GLOBAL_STATIC_MUT: u32 = 101;
|
static mut GLOBAL_STATIC_MUT: u32 = 101;
|
||||||
fn test() {
|
fn test() {
|
||||||
static LOCAL_STATIC: u32 = 99;
|
static LOCAL_STATIC: u32 = 99;
|
||||||
static mut LOCAL_STATIC_MUT: u32 = 99;
|
static mut LOCAL_STATIC_MUT: u32 = 99;
|
||||||
let x = LOCAL_STATIC;
|
let x = LOCAL_STATIC;
|
||||||
let y = LOCAL_STATIC_MUT;
|
let y = LOCAL_STATIC_MUT;
|
||||||
let z = GLOBAL_STATIC;
|
let z = GLOBAL_STATIC;
|
||||||
let w = GLOBAL_STATIC_MUT;
|
let w = GLOBAL_STATIC_MUT;
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
28..31 '101': u32
|
28..31 '101': u32
|
||||||
69..72 '101': u32
|
69..72 '101': u32
|
||||||
|
@ -1751,6 +1751,41 @@ fn infer_static() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn infer_enum_variant() {
|
||||||
|
check_infer(
|
||||||
|
r#"
|
||||||
|
enum Foo {
|
||||||
|
A = 15,
|
||||||
|
B = Foo::A as isize + 1
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
19..21 '15': isize
|
||||||
|
31..37 'Foo::A': Foo
|
||||||
|
31..46 'Foo::A as isize': isize
|
||||||
|
31..50 'Foo::A...ze + 1': isize
|
||||||
|
49..50 '1': isize
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
check_infer(
|
||||||
|
r#"
|
||||||
|
#[repr(u32)]
|
||||||
|
enum Foo {
|
||||||
|
A = 15,
|
||||||
|
B = Foo::A as u32 + 1
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
32..34 '15': u32
|
||||||
|
44..50 'Foo::A': Foo
|
||||||
|
44..57 'Foo::A as u32': u32
|
||||||
|
44..61 'Foo::A...32 + 1': u32
|
||||||
|
60..61 '1': u32
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn shadowing_primitive() {
|
fn shadowing_primitive() {
|
||||||
check_types(
|
check_types(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue