mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 07:04:49 +00:00
beginning of MIR
This commit is contained in:
parent
b881deb66a
commit
cd67589f63
41 changed files with 4452 additions and 702 deletions
|
@ -3,7 +3,8 @@ use std::fmt::Display;
|
|||
|
||||
use either::Either;
|
||||
use hir::{
|
||||
Adt, AsAssocItem, AttributeTemplate, HasAttrs, HasSource, HirDisplay, Semantics, TypeInfo,
|
||||
db::DefDatabase, Adt, AsAssocItem, AttributeTemplate, HasAttrs, HasSource, HirDisplay,
|
||||
MirEvalError, Semantics, TypeInfo,
|
||||
};
|
||||
use ide_db::{
|
||||
base_db::SourceDatabase,
|
||||
|
@ -402,7 +403,20 @@ pub(super) fn definition(
|
|||
))
|
||||
}),
|
||||
Definition::Module(it) => label_and_docs(db, it),
|
||||
Definition::Function(it) => label_and_docs(db, it),
|
||||
Definition::Function(it) => label_and_layout_info_and_docs(db, it, |_| {
|
||||
if !config.interpret_tests {
|
||||
return None;
|
||||
}
|
||||
match it.eval(db) {
|
||||
Ok(()) => Some("pass".into()),
|
||||
Err(MirEvalError::Panic) => Some("fail".into()),
|
||||
Err(MirEvalError::MirLowerError(f, e)) => {
|
||||
let name = &db.function_data(f).name;
|
||||
Some(format!("error: fail to lower {name} due {e:?}"))
|
||||
}
|
||||
Err(e) => Some(format!("error: {e:?}")),
|
||||
}
|
||||
}),
|
||||
Definition::Adt(it) => label_and_layout_info_and_docs(db, it, |&it| {
|
||||
let layout = it.layout(db).ok()?;
|
||||
Some(format!("size = {}, align = {}", layout.size.bytes(), layout.align.abi.bytes()))
|
||||
|
@ -410,7 +424,7 @@ pub(super) fn definition(
|
|||
Definition::Variant(it) => label_value_and_docs(db, it, |&it| {
|
||||
if !it.parent_enum(db).is_data_carrying(db) {
|
||||
match it.eval(db) {
|
||||
Ok(x) => Some(format!("{x}")),
|
||||
Ok(x) => Some(if x >= 10 { format!("{x} ({x:#X})") } else { format!("{x}") }),
|
||||
Err(_) => it.value(db).map(|x| format!("{x:?}")),
|
||||
}
|
||||
} else {
|
||||
|
@ -420,7 +434,7 @@ pub(super) fn definition(
|
|||
Definition::Const(it) => label_value_and_docs(db, it, |it| {
|
||||
let body = it.eval(db);
|
||||
match body {
|
||||
Ok(x) => Some(format!("{x}")),
|
||||
Ok(x) => Some(format!("{}", x.display(db))),
|
||||
Err(_) => {
|
||||
let source = it.source(db)?;
|
||||
let mut body = source.value.body()?.syntax().clone();
|
||||
|
|
|
@ -4,16 +4,19 @@ use syntax::TextRange;
|
|||
|
||||
use crate::{fixture, HoverConfig, HoverDocFormat};
|
||||
|
||||
const HOVER_BASE_CONFIG: HoverConfig = HoverConfig {
|
||||
links_in_hover: false,
|
||||
documentation: true,
|
||||
format: HoverDocFormat::Markdown,
|
||||
keywords: true,
|
||||
interpret_tests: false,
|
||||
};
|
||||
|
||||
fn check_hover_no_result(ra_fixture: &str) {
|
||||
let (analysis, position) = fixture::position(ra_fixture);
|
||||
let hover = analysis
|
||||
.hover(
|
||||
&HoverConfig {
|
||||
links_in_hover: true,
|
||||
documentation: true,
|
||||
keywords: true,
|
||||
format: HoverDocFormat::Markdown,
|
||||
},
|
||||
&HoverConfig { links_in_hover: true, ..HOVER_BASE_CONFIG },
|
||||
FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
|
||||
)
|
||||
.unwrap();
|
||||
|
@ -25,12 +28,7 @@ fn check(ra_fixture: &str, expect: Expect) {
|
|||
let (analysis, position) = fixture::position(ra_fixture);
|
||||
let hover = analysis
|
||||
.hover(
|
||||
&HoverConfig {
|
||||
links_in_hover: true,
|
||||
documentation: true,
|
||||
keywords: true,
|
||||
format: HoverDocFormat::Markdown,
|
||||
},
|
||||
&HoverConfig { links_in_hover: true, ..HOVER_BASE_CONFIG },
|
||||
FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
|
||||
)
|
||||
.unwrap()
|
||||
|
@ -47,12 +45,7 @@ fn check_hover_no_links(ra_fixture: &str, expect: Expect) {
|
|||
let (analysis, position) = fixture::position(ra_fixture);
|
||||
let hover = analysis
|
||||
.hover(
|
||||
&HoverConfig {
|
||||
links_in_hover: false,
|
||||
documentation: true,
|
||||
keywords: true,
|
||||
format: HoverDocFormat::Markdown,
|
||||
},
|
||||
&HOVER_BASE_CONFIG,
|
||||
FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
|
||||
)
|
||||
.unwrap()
|
||||
|
@ -71,9 +64,8 @@ fn check_hover_no_markdown(ra_fixture: &str, expect: Expect) {
|
|||
.hover(
|
||||
&HoverConfig {
|
||||
links_in_hover: true,
|
||||
documentation: true,
|
||||
keywords: true,
|
||||
format: HoverDocFormat::PlainText,
|
||||
..HOVER_BASE_CONFIG
|
||||
},
|
||||
FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
|
||||
)
|
||||
|
@ -91,12 +83,7 @@ fn check_actions(ra_fixture: &str, expect: Expect) {
|
|||
let (analysis, file_id, position) = fixture::range_or_position(ra_fixture);
|
||||
let hover = analysis
|
||||
.hover(
|
||||
&HoverConfig {
|
||||
links_in_hover: true,
|
||||
documentation: true,
|
||||
keywords: true,
|
||||
format: HoverDocFormat::Markdown,
|
||||
},
|
||||
&HoverConfig { links_in_hover: true, ..HOVER_BASE_CONFIG },
|
||||
FileRange { file_id, range: position.range_or_empty() },
|
||||
)
|
||||
.unwrap()
|
||||
|
@ -106,34 +93,13 @@ fn check_actions(ra_fixture: &str, expect: Expect) {
|
|||
|
||||
fn check_hover_range(ra_fixture: &str, expect: Expect) {
|
||||
let (analysis, range) = fixture::range(ra_fixture);
|
||||
let hover = analysis
|
||||
.hover(
|
||||
&HoverConfig {
|
||||
links_in_hover: false,
|
||||
documentation: true,
|
||||
keywords: true,
|
||||
format: HoverDocFormat::Markdown,
|
||||
},
|
||||
range,
|
||||
)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
let hover = analysis.hover(&HOVER_BASE_CONFIG, range).unwrap().unwrap();
|
||||
expect.assert_eq(hover.info.markup.as_str())
|
||||
}
|
||||
|
||||
fn check_hover_range_no_results(ra_fixture: &str) {
|
||||
let (analysis, range) = fixture::range(ra_fixture);
|
||||
let hover = analysis
|
||||
.hover(
|
||||
&HoverConfig {
|
||||
links_in_hover: false,
|
||||
documentation: true,
|
||||
keywords: true,
|
||||
format: HoverDocFormat::Markdown,
|
||||
},
|
||||
range,
|
||||
)
|
||||
.unwrap();
|
||||
let hover = analysis.hover(&HOVER_BASE_CONFIG, range).unwrap();
|
||||
assert!(hover.is_none());
|
||||
}
|
||||
|
||||
|
@ -490,7 +456,6 @@ fn hover_field_offset() {
|
|||
// Hovering over the field when instantiating
|
||||
check(
|
||||
r#"
|
||||
//- /main.rs target_data_layout:e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128
|
||||
struct Foo { fiel$0d_a: u8, field_b: i32, field_c: i16 }
|
||||
"#,
|
||||
expect![[r#"
|
||||
|
@ -512,7 +477,6 @@ fn hover_shows_struct_field_info() {
|
|||
// Hovering over the field when instantiating
|
||||
check(
|
||||
r#"
|
||||
//- /main.rs target_data_layout:e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128
|
||||
struct Foo { field_a: u32 }
|
||||
|
||||
fn main() {
|
||||
|
@ -535,7 +499,6 @@ fn main() {
|
|||
// Hovering over the field in the definition
|
||||
check(
|
||||
r#"
|
||||
//- /main.rs target_data_layout:e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128
|
||||
struct Foo { field_a$0: u32 }
|
||||
|
||||
fn main() {
|
||||
|
@ -568,7 +531,7 @@ fn hover_const_static() {
|
|||
```
|
||||
|
||||
```rust
|
||||
const foo: u32 = 123 (0x7B)
|
||||
const foo: u32 = 123
|
||||
```
|
||||
"#]],
|
||||
);
|
||||
|
@ -1467,8 +1430,6 @@ fn my() {}
|
|||
fn test_hover_struct_doc_comment() {
|
||||
check(
|
||||
r#"
|
||||
//- /main.rs target_data_layout:e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128
|
||||
|
||||
/// This is an example
|
||||
/// multiline doc
|
||||
///
|
||||
|
@ -1527,7 +1488,7 @@ fn foo() { let bar = Ba$0r; }
|
|||
```
|
||||
|
||||
```rust
|
||||
struct Bar
|
||||
struct Bar // size = 0, align = 1
|
||||
```
|
||||
|
||||
---
|
||||
|
@ -1556,7 +1517,7 @@ fn foo() { let bar = Ba$0r; }
|
|||
```
|
||||
|
||||
```rust
|
||||
struct Bar
|
||||
struct Bar // size = 0, align = 1
|
||||
```
|
||||
|
||||
---
|
||||
|
@ -1584,7 +1545,7 @@ pub struct B$0ar
|
|||
```
|
||||
|
||||
```rust
|
||||
pub struct Bar
|
||||
pub struct Bar // size = 0, align = 1
|
||||
```
|
||||
|
||||
---
|
||||
|
@ -1611,7 +1572,7 @@ pub struct B$0ar
|
|||
```
|
||||
|
||||
```rust
|
||||
pub struct Bar
|
||||
pub struct Bar // size = 0, align = 1
|
||||
```
|
||||
|
||||
---
|
||||
|
@ -2913,8 +2874,6 @@ fn main() { let foo_test = name_with_dashes::wrapper::Thing::new$0(); }
|
|||
fn hover_field_pat_shorthand_ref_match_ergonomics() {
|
||||
check(
|
||||
r#"
|
||||
//- /main.rs target_data_layout:e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128
|
||||
|
||||
struct S {
|
||||
f: i32,
|
||||
}
|
||||
|
@ -3506,8 +3465,8 @@ impl<const LEN: usize> Foo<LEN$0> {}
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn hover_const_eval_variant() {
|
||||
// show hex for <10
|
||||
fn hover_const_eval_discriminant() {
|
||||
// Don't show hex for <10
|
||||
check(
|
||||
r#"
|
||||
#[repr(u8)]
|
||||
|
@ -3532,7 +3491,7 @@ enum E {
|
|||
This is a doc
|
||||
"#]],
|
||||
);
|
||||
// show hex for >10
|
||||
// Show hex for >10
|
||||
check(
|
||||
r#"
|
||||
#[repr(u8)]
|
||||
|
@ -3656,7 +3615,7 @@ trait T {
|
|||
}
|
||||
impl T for i32 {
|
||||
const AA: A = A {
|
||||
i: 2
|
||||
i: 2 + 3
|
||||
}
|
||||
}
|
||||
fn main() {
|
||||
|
@ -3671,9 +3630,7 @@ fn main() {
|
|||
```
|
||||
|
||||
```rust
|
||||
const AA: A = A {
|
||||
i: 2
|
||||
}
|
||||
const AA: A = A { i: 5 }
|
||||
```
|
||||
"#]],
|
||||
);
|
||||
|
@ -3792,7 +3749,7 @@ const FOO$0: usize = 1 << 3;
|
|||
This is a doc
|
||||
"#]],
|
||||
);
|
||||
// show hex for >10
|
||||
// FIXME: show hex for >10
|
||||
check(
|
||||
r#"
|
||||
/// This is a doc
|
||||
|
@ -3806,7 +3763,7 @@ const FOO$0: usize = (1 << 3) + (1 << 2);
|
|||
```
|
||||
|
||||
```rust
|
||||
const FOO: usize = 12 (0xC)
|
||||
const FOO: usize = 12
|
||||
```
|
||||
|
||||
---
|
||||
|
@ -3937,7 +3894,7 @@ const FOO$0: u8 = b'a';
|
|||
```
|
||||
|
||||
```rust
|
||||
const FOO: u8 = 97 (0x61)
|
||||
const FOO: u8 = 97
|
||||
```
|
||||
|
||||
---
|
||||
|
@ -3959,7 +3916,7 @@ const FOO$0: u8 = b'\x61';
|
|||
```
|
||||
|
||||
```rust
|
||||
const FOO: u8 = 97 (0x61)
|
||||
const FOO: u8 = 97
|
||||
```
|
||||
|
||||
---
|
||||
|
@ -4354,8 +4311,6 @@ fn main() {
|
|||
fn hover_intra_doc_links() {
|
||||
check(
|
||||
r#"
|
||||
//- /main.rs target_data_layout:e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128
|
||||
|
||||
pub mod theitem {
|
||||
/// This is the item. Cool!
|
||||
pub struct TheItem;
|
||||
|
@ -4496,7 +4451,7 @@ trait A where
|
|||
fn string_shadowed_with_inner_items() {
|
||||
check(
|
||||
r#"
|
||||
//- /main.rs crate:main deps:alloc target_data_layout:e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128
|
||||
//- /main.rs crate:main deps:alloc
|
||||
|
||||
/// Custom `String` type.
|
||||
struct String;
|
||||
|
@ -5191,7 +5146,7 @@ foo_macro!(
|
|||
```
|
||||
|
||||
```rust
|
||||
pub struct Foo
|
||||
pub struct Foo // size = 0, align = 1
|
||||
```
|
||||
|
||||
---
|
||||
|
@ -5205,8 +5160,6 @@ foo_macro!(
|
|||
fn hover_intra_in_attr() {
|
||||
check(
|
||||
r#"
|
||||
//- /main.rs target_data_layout:e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128
|
||||
|
||||
#[doc = "Doc comment for [`Foo$0`]"]
|
||||
pub struct Foo(i32);
|
||||
"#,
|
||||
|
@ -5295,7 +5248,7 @@ pub struct Type;
|
|||
```
|
||||
|
||||
```rust
|
||||
const KONST: dep::Type = $crate::Type
|
||||
const KONST: dep::Type = Type
|
||||
```
|
||||
"#]],
|
||||
);
|
||||
|
@ -5327,8 +5280,6 @@ enum Enum {
|
|||
fn hover_record_variant_field() {
|
||||
check(
|
||||
r#"
|
||||
//- /main.rs target_data_layout:e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128
|
||||
|
||||
enum Enum {
|
||||
RecordV { field$0: u32 }
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue