Auto merge of #16366 - Veykril:transp-queries, r=Veykril

internal: Make data queries transparent over their diagnostics variant

And a few other QoL things
This commit is contained in:
bors 2024-01-16 10:09:05 +00:00
commit 2d5ce888de
17 changed files with 329 additions and 157 deletions

4
Cargo.lock generated
View file

@ -1712,9 +1712,9 @@ checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"
[[package]] [[package]]
name = "smol_str" name = "smol_str"
version = "0.2.0" version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74212e6bbe9a4352329b2f68ba3130c15a3f26fe88ff22dbdc6cdd58fa85e99c" checksum = "e6845563ada680337a52d43bb0b29f396f2d911616f6573012645b9e3d048a49"
dependencies = [ dependencies = [
"serde", "serde",
] ]

View file

@ -122,7 +122,7 @@ smallvec = { version = "1.10.0", features = [
"union", "union",
"const_generics", "const_generics",
] } ] }
smol_str = "0.2.0" smol_str = "0.2.1"
text-size = "1.1.1" text-size = "1.1.1"
tracing = "0.1.40" tracing = "0.1.40"
tracing-tree = "0.3.0" tracing-tree = "0.3.0"

View file

@ -233,6 +233,7 @@ pub struct TraitData {
} }
impl TraitData { impl TraitData {
#[inline]
pub(crate) fn trait_data_query(db: &dyn DefDatabase, tr: TraitId) -> Arc<TraitData> { pub(crate) fn trait_data_query(db: &dyn DefDatabase, tr: TraitId) -> Arc<TraitData> {
db.trait_data_with_diagnostics(tr).0 db.trait_data_with_diagnostics(tr).0
} }
@ -241,12 +242,9 @@ impl TraitData {
db: &dyn DefDatabase, db: &dyn DefDatabase,
tr: TraitId, tr: TraitId,
) -> (Arc<TraitData>, DefDiagnostics) { ) -> (Arc<TraitData>, DefDiagnostics) {
let tr_loc @ ItemLoc { container: module_id, id: tree_id } = tr.lookup(db); let ItemLoc { container: module_id, id: tree_id } = tr.lookup(db);
let item_tree = tree_id.item_tree(db); let item_tree = tree_id.item_tree(db);
let tr_def = &item_tree[tree_id.value]; let tr_def = &item_tree[tree_id.value];
let _cx = stdx::panic_context::enter(format!(
"trait_data_query({tr:?} -> {tr_loc:?} -> {tr_def:?})"
));
let name = tr_def.name.clone(); let name = tr_def.name.clone();
let is_auto = tr_def.is_auto; let is_auto = tr_def.is_auto;
let is_unsafe = tr_def.is_unsafe; let is_unsafe = tr_def.is_unsafe;
@ -333,6 +331,7 @@ pub struct ImplData {
} }
impl ImplData { impl ImplData {
#[inline]
pub(crate) fn impl_data_query(db: &dyn DefDatabase, id: ImplId) -> Arc<ImplData> { pub(crate) fn impl_data_query(db: &dyn DefDatabase, id: ImplId) -> Arc<ImplData> {
db.impl_data_with_diagnostics(id).0 db.impl_data_with_diagnostics(id).0
} }

View file

@ -180,6 +180,7 @@ fn parse_repr_tt(tt: &Subtree) -> Option<ReprOptions> {
} }
impl StructData { impl StructData {
#[inline]
pub(crate) fn struct_data_query(db: &dyn DefDatabase, id: StructId) -> Arc<StructData> { pub(crate) fn struct_data_query(db: &dyn DefDatabase, id: StructId) -> Arc<StructData> {
db.struct_data_with_diagnostics(id).0 db.struct_data_with_diagnostics(id).0
} }
@ -236,6 +237,7 @@ impl StructData {
) )
} }
#[inline]
pub(crate) fn union_data_query(db: &dyn DefDatabase, id: UnionId) -> Arc<StructData> { pub(crate) fn union_data_query(db: &dyn DefDatabase, id: UnionId) -> Arc<StructData> {
db.union_data_with_diagnostics(id).0 db.union_data_with_diagnostics(id).0
} }
@ -322,6 +324,7 @@ impl EnumData {
} }
impl EnumVariantData { impl EnumVariantData {
#[inline]
pub(crate) fn enum_variant_data_query( pub(crate) fn enum_variant_data_query(
db: &dyn DefDatabase, db: &dyn DefDatabase,
e: EnumVariantId, e: EnumVariantId,

View file

@ -117,12 +117,14 @@ pub trait DefDatabase: InternDatabase + ExpandDatabase + Upcast<dyn ExpandDataba
// region:data // region:data
#[salsa::transparent]
#[salsa::invoke(StructData::struct_data_query)] #[salsa::invoke(StructData::struct_data_query)]
fn struct_data(&self, id: StructId) -> Arc<StructData>; fn struct_data(&self, id: StructId) -> Arc<StructData>;
#[salsa::invoke(StructData::struct_data_with_diagnostics_query)] #[salsa::invoke(StructData::struct_data_with_diagnostics_query)]
fn struct_data_with_diagnostics(&self, id: StructId) -> (Arc<StructData>, DefDiagnostics); fn struct_data_with_diagnostics(&self, id: StructId) -> (Arc<StructData>, DefDiagnostics);
#[salsa::transparent]
#[salsa::invoke(StructData::union_data_query)] #[salsa::invoke(StructData::union_data_query)]
fn union_data(&self, id: UnionId) -> Arc<StructData>; fn union_data(&self, id: UnionId) -> Arc<StructData>;
@ -132,6 +134,7 @@ pub trait DefDatabase: InternDatabase + ExpandDatabase + Upcast<dyn ExpandDataba
#[salsa::invoke(EnumData::enum_data_query)] #[salsa::invoke(EnumData::enum_data_query)]
fn enum_data(&self, e: EnumId) -> Arc<EnumData>; fn enum_data(&self, e: EnumId) -> Arc<EnumData>;
#[salsa::transparent]
#[salsa::invoke(EnumVariantData::enum_variant_data_query)] #[salsa::invoke(EnumVariantData::enum_variant_data_query)]
fn enum_variant_data(&self, id: EnumVariantId) -> Arc<EnumVariantData>; fn enum_variant_data(&self, id: EnumVariantId) -> Arc<EnumVariantData>;
@ -141,12 +144,14 @@ pub trait DefDatabase: InternDatabase + ExpandDatabase + Upcast<dyn ExpandDataba
id: EnumVariantId, id: EnumVariantId,
) -> (Arc<EnumVariantData>, DefDiagnostics); ) -> (Arc<EnumVariantData>, DefDiagnostics);
#[salsa::transparent]
#[salsa::invoke(ImplData::impl_data_query)] #[salsa::invoke(ImplData::impl_data_query)]
fn impl_data(&self, e: ImplId) -> Arc<ImplData>; fn impl_data(&self, e: ImplId) -> Arc<ImplData>;
#[salsa::invoke(ImplData::impl_data_with_diagnostics_query)] #[salsa::invoke(ImplData::impl_data_with_diagnostics_query)]
fn impl_data_with_diagnostics(&self, e: ImplId) -> (Arc<ImplData>, DefDiagnostics); fn impl_data_with_diagnostics(&self, e: ImplId) -> (Arc<ImplData>, DefDiagnostics);
#[salsa::transparent]
#[salsa::invoke(TraitData::trait_data_query)] #[salsa::invoke(TraitData::trait_data_query)]
fn trait_data(&self, e: TraitId) -> Arc<TraitData>; fn trait_data(&self, e: TraitId) -> Arc<TraitData>;

View file

@ -2,6 +2,8 @@
use std::fmt::{self, Write}; use std::fmt::{self, Write};
use span::ErasedFileAstId;
use crate::{ use crate::{
generics::{TypeOrConstParamData, WherePredicate, WherePredicateTypeTarget}, generics::{TypeOrConstParamData, WherePredicate, WherePredicateTypeTarget},
pretty::{print_path, print_type_bounds, print_type_ref}, pretty::{print_path, print_type_bounds, print_type_ref},
@ -118,7 +120,11 @@ impl Printer<'_> {
w!(self, "{{"); w!(self, "{{");
self.indented(|this| { self.indented(|this| {
for field in fields.clone() { for field in fields.clone() {
let Field { visibility, name, type_ref, ast_id: _ } = &this.tree[field]; let Field { visibility, name, type_ref, ast_id } = &this.tree[field];
this.print_ast_id(match ast_id {
FieldAstId::Record(it) => it.erase(),
FieldAstId::Tuple(it) => it.erase(),
});
this.print_attrs_of(field, "\n"); this.print_attrs_of(field, "\n");
this.print_visibility(*visibility); this.print_visibility(*visibility);
w!(this, "{}: ", name.display(self.db.upcast())); w!(this, "{}: ", name.display(self.db.upcast()));
@ -132,7 +138,11 @@ impl Printer<'_> {
w!(self, "("); w!(self, "(");
self.indented(|this| { self.indented(|this| {
for field in fields.clone() { for field in fields.clone() {
let Field { visibility, name, type_ref, ast_id: _ } = &this.tree[field]; let Field { visibility, name, type_ref, ast_id } = &this.tree[field];
this.print_ast_id(match ast_id {
FieldAstId::Record(it) => it.erase(),
FieldAstId::Tuple(it) => it.erase(),
});
this.print_attrs_of(field, "\n"); this.print_attrs_of(field, "\n");
this.print_visibility(*visibility); this.print_visibility(*visibility);
w!(this, "{}: ", name.display(self.db.upcast())); w!(this, "{}: ", name.display(self.db.upcast()));
@ -200,14 +210,16 @@ impl Printer<'_> {
match item { match item {
ModItem::Use(it) => { ModItem::Use(it) => {
let Use { visibility, use_tree, ast_id: _ } = &self.tree[it]; let Use { visibility, use_tree, ast_id } = &self.tree[it];
self.print_ast_id(ast_id.erase());
self.print_visibility(*visibility); self.print_visibility(*visibility);
w!(self, "use "); w!(self, "use ");
self.print_use_tree(use_tree); self.print_use_tree(use_tree);
wln!(self, ";"); wln!(self, ";");
} }
ModItem::ExternCrate(it) => { ModItem::ExternCrate(it) => {
let ExternCrate { name, alias, visibility, ast_id: _ } = &self.tree[it]; let ExternCrate { name, alias, visibility, ast_id } = &self.tree[it];
self.print_ast_id(ast_id.erase());
self.print_visibility(*visibility); self.print_visibility(*visibility);
w!(self, "extern crate {}", name.display(self.db.upcast())); w!(self, "extern crate {}", name.display(self.db.upcast()));
if let Some(alias) = alias { if let Some(alias) = alias {
@ -216,7 +228,8 @@ impl Printer<'_> {
wln!(self, ";"); wln!(self, ";");
} }
ModItem::ExternBlock(it) => { ModItem::ExternBlock(it) => {
let ExternBlock { abi, ast_id: _, children } = &self.tree[it]; let ExternBlock { abi, ast_id, children } = &self.tree[it];
self.print_ast_id(ast_id.erase());
w!(self, "extern "); w!(self, "extern ");
if let Some(abi) = abi { if let Some(abi) = abi {
w!(self, "\"{}\" ", abi); w!(self, "\"{}\" ", abi);
@ -237,9 +250,10 @@ impl Printer<'_> {
abi, abi,
params, params,
ret_type, ret_type,
ast_id: _, ast_id,
flags, flags,
} = &self.tree[it]; } = &self.tree[it];
self.print_ast_id(ast_id.erase());
self.print_visibility(*visibility); self.print_visibility(*visibility);
if flags.contains(FnFlags::HAS_DEFAULT_KW) { if flags.contains(FnFlags::HAS_DEFAULT_KW) {
w!(self, "default "); w!(self, "default ");
@ -263,7 +277,12 @@ impl Printer<'_> {
self.indented(|this| { self.indented(|this| {
for param in params.clone() { for param in params.clone() {
this.print_attrs_of(param, "\n"); this.print_attrs_of(param, "\n");
match &this.tree[param].type_ref { let Param { type_ref, ast_id } = &this.tree[param];
this.print_ast_id(match ast_id {
ParamAstId::Param(it) => it.erase(),
ParamAstId::SelfParam(it) => it.erase(),
});
match type_ref {
Some(ty) => { Some(ty) => {
if flags.contains(FnFlags::HAS_SELF_PARAM) { if flags.contains(FnFlags::HAS_SELF_PARAM) {
w!(this, "self: "); w!(this, "self: ");
@ -288,7 +307,8 @@ impl Printer<'_> {
} }
} }
ModItem::Struct(it) => { ModItem::Struct(it) => {
let Struct { visibility, name, fields, generic_params, ast_id: _ } = &self.tree[it]; let Struct { visibility, name, fields, generic_params, ast_id } = &self.tree[it];
self.print_ast_id(ast_id.erase());
self.print_visibility(*visibility); self.print_visibility(*visibility);
w!(self, "struct {}", name.display(self.db.upcast())); w!(self, "struct {}", name.display(self.db.upcast()));
self.print_generic_params(generic_params); self.print_generic_params(generic_params);
@ -300,7 +320,8 @@ impl Printer<'_> {
} }
} }
ModItem::Union(it) => { ModItem::Union(it) => {
let Union { name, visibility, fields, generic_params, ast_id: _ } = &self.tree[it]; let Union { name, visibility, fields, generic_params, ast_id } = &self.tree[it];
self.print_ast_id(ast_id.erase());
self.print_visibility(*visibility); self.print_visibility(*visibility);
w!(self, "union {}", name.display(self.db.upcast())); w!(self, "union {}", name.display(self.db.upcast()));
self.print_generic_params(generic_params); self.print_generic_params(generic_params);
@ -312,14 +333,16 @@ impl Printer<'_> {
} }
} }
ModItem::Enum(it) => { ModItem::Enum(it) => {
let Enum { name, visibility, variants, generic_params, ast_id: _ } = &self.tree[it]; let Enum { name, visibility, variants, generic_params, ast_id } = &self.tree[it];
self.print_ast_id(ast_id.erase());
self.print_visibility(*visibility); self.print_visibility(*visibility);
w!(self, "enum {}", name.display(self.db.upcast())); w!(self, "enum {}", name.display(self.db.upcast()));
self.print_generic_params(generic_params); self.print_generic_params(generic_params);
self.print_where_clause_and_opening_brace(generic_params); self.print_where_clause_and_opening_brace(generic_params);
self.indented(|this| { self.indented(|this| {
for variant in FileItemTreeId::range_iter(variants.clone()) { for variant in FileItemTreeId::range_iter(variants.clone()) {
let Variant { name, fields, ast_id: _ } = &this.tree[variant]; let Variant { name, fields, ast_id } = &this.tree[variant];
this.print_ast_id(ast_id.erase());
this.print_attrs_of(variant, "\n"); this.print_attrs_of(variant, "\n");
w!(this, "{}", name.display(self.db.upcast())); w!(this, "{}", name.display(self.db.upcast()));
this.print_fields(fields); this.print_fields(fields);
@ -329,7 +352,8 @@ impl Printer<'_> {
wln!(self, "}}"); wln!(self, "}}");
} }
ModItem::Const(it) => { ModItem::Const(it) => {
let Const { name, visibility, type_ref, ast_id: _ } = &self.tree[it]; let Const { name, visibility, type_ref, ast_id } = &self.tree[it];
self.print_ast_id(ast_id.erase());
self.print_visibility(*visibility); self.print_visibility(*visibility);
w!(self, "const "); w!(self, "const ");
match name { match name {
@ -341,7 +365,8 @@ impl Printer<'_> {
wln!(self, " = _;"); wln!(self, " = _;");
} }
ModItem::Static(it) => { ModItem::Static(it) => {
let Static { name, visibility, mutable, type_ref, ast_id: _ } = &self.tree[it]; let Static { name, visibility, mutable, type_ref, ast_id } = &self.tree[it];
self.print_ast_id(ast_id.erase());
self.print_visibility(*visibility); self.print_visibility(*visibility);
w!(self, "static "); w!(self, "static ");
if *mutable { if *mutable {
@ -353,15 +378,9 @@ impl Printer<'_> {
wln!(self); wln!(self);
} }
ModItem::Trait(it) => { ModItem::Trait(it) => {
let Trait { let Trait { name, visibility, is_auto, is_unsafe, items, generic_params, ast_id } =
name, &self.tree[it];
visibility, self.print_ast_id(ast_id.erase());
is_auto,
is_unsafe,
items,
generic_params,
ast_id: _,
} = &self.tree[it];
self.print_visibility(*visibility); self.print_visibility(*visibility);
if *is_unsafe { if *is_unsafe {
w!(self, "unsafe "); w!(self, "unsafe ");
@ -380,7 +399,8 @@ impl Printer<'_> {
wln!(self, "}}"); wln!(self, "}}");
} }
ModItem::TraitAlias(it) => { ModItem::TraitAlias(it) => {
let TraitAlias { name, visibility, generic_params, ast_id: _ } = &self.tree[it]; let TraitAlias { name, visibility, generic_params, ast_id } = &self.tree[it];
self.print_ast_id(ast_id.erase());
self.print_visibility(*visibility); self.print_visibility(*visibility);
w!(self, "trait {}", name.display(self.db.upcast())); w!(self, "trait {}", name.display(self.db.upcast()));
self.print_generic_params(generic_params); self.print_generic_params(generic_params);
@ -397,8 +417,9 @@ impl Printer<'_> {
is_unsafe, is_unsafe,
items, items,
generic_params, generic_params,
ast_id: _, ast_id,
} = &self.tree[it]; } = &self.tree[it];
self.print_ast_id(ast_id.erase());
if *is_unsafe { if *is_unsafe {
w!(self, "unsafe"); w!(self, "unsafe");
} }
@ -422,8 +443,9 @@ impl Printer<'_> {
wln!(self, "}}"); wln!(self, "}}");
} }
ModItem::TypeAlias(it) => { ModItem::TypeAlias(it) => {
let TypeAlias { name, visibility, bounds, type_ref, generic_params, ast_id: _ } = let TypeAlias { name, visibility, bounds, type_ref, generic_params, ast_id } =
&self.tree[it]; &self.tree[it];
self.print_ast_id(ast_id.erase());
self.print_visibility(*visibility); self.print_visibility(*visibility);
w!(self, "type {}", name.display(self.db.upcast())); w!(self, "type {}", name.display(self.db.upcast()));
self.print_generic_params(generic_params); self.print_generic_params(generic_params);
@ -440,7 +462,8 @@ impl Printer<'_> {
wln!(self); wln!(self);
} }
ModItem::Mod(it) => { ModItem::Mod(it) => {
let Mod { name, visibility, kind, ast_id: _ } = &self.tree[it]; let Mod { name, visibility, kind, ast_id } = &self.tree[it];
self.print_ast_id(ast_id.erase());
self.print_visibility(*visibility); self.print_visibility(*visibility);
w!(self, "mod {}", name.display(self.db.upcast())); w!(self, "mod {}", name.display(self.db.upcast()));
match kind { match kind {
@ -459,15 +482,24 @@ impl Printer<'_> {
} }
} }
ModItem::MacroCall(it) => { ModItem::MacroCall(it) => {
let MacroCall { path, ast_id: _, expand_to: _, call_site: _ } = &self.tree[it]; let MacroCall { path, ast_id, expand_to, call_site } = &self.tree[it];
let _ = writeln!(
self,
"// AstId: {:?}, Span: {}, ExpandTo: {:?}",
ast_id.erase().into_raw(),
call_site,
expand_to
);
wln!(self, "{}!(...);", path.display(self.db.upcast())); wln!(self, "{}!(...);", path.display(self.db.upcast()));
} }
ModItem::MacroRules(it) => { ModItem::MacroRules(it) => {
let MacroRules { name, ast_id: _ } = &self.tree[it]; let MacroRules { name, ast_id } = &self.tree[it];
self.print_ast_id(ast_id.erase());
wln!(self, "macro_rules! {} {{ ... }}", name.display(self.db.upcast())); wln!(self, "macro_rules! {} {{ ... }}", name.display(self.db.upcast()));
} }
ModItem::Macro2(it) => { ModItem::Macro2(it) => {
let Macro2 { name, visibility, ast_id: _ } = &self.tree[it]; let Macro2 { name, visibility, ast_id } = &self.tree[it];
self.print_ast_id(ast_id.erase());
self.print_visibility(*visibility); self.print_visibility(*visibility);
wln!(self, "macro {} {{ ... }}", name.display(self.db.upcast())); wln!(self, "macro {} {{ ... }}", name.display(self.db.upcast()));
} }
@ -583,6 +615,10 @@ impl Printer<'_> {
}); });
true true
} }
fn print_ast_id(&mut self, ast_id: ErasedFileAstId) {
wln!(self, "// AstId: {:?}", ast_id.into_raw());
}
} }
impl Write for Printer<'_> { impl Write for Printer<'_> {

View file

@ -34,17 +34,23 @@ use a::{c, d::{e}};
#![no_std] #![no_std]
#![doc = " another file comment"] #![doc = " another file comment"]
// AstId: 1
pub(self) extern crate self as renamed; pub(self) extern crate self as renamed;
// AstId: 2
pub(super) extern crate bli; pub(super) extern crate bli;
// AstId: 3
pub use crate::path::{nested, items as renamed, Trait as _}; pub use crate::path::{nested, items as renamed, Trait as _};
// AstId: 4
pub(self) use globs::*; pub(self) use globs::*;
#[doc = " docs on import"] #[doc = " docs on import"]
// AstId: 5
pub(self) use crate::{A, B}; pub(self) use crate::{A, B};
// AstId: 6
pub(self) use a::{c, d::{e}}; pub(self) use a::{c, d::{e}};
"##]], "##]],
); );
@ -68,14 +74,18 @@ extern "C" {
"#, "#,
expect![[r##" expect![[r##"
#[on_extern_block] #[on_extern_block]
// AstId: 1
extern "C" { extern "C" {
#[on_extern_type] #[on_extern_type]
// AstId: 2
pub(self) type ExType; pub(self) type ExType;
#[on_extern_static] #[on_extern_static]
// AstId: 3
pub(self) static EX_STATIC: u8 = _; pub(self) static EX_STATIC: u8 = _;
#[on_extern_fn] #[on_extern_fn]
// AstId: 4
pub(self) fn ex_fn() -> (); pub(self) fn ex_fn() -> ();
} }
"##]], "##]],
@ -112,38 +122,52 @@ enum E {
} }
} }
"#, "#,
expect![[r##" expect![[r#"
// AstId: 1
pub(self) struct Unit; pub(self) struct Unit;
#[derive(Debug)] #[derive(Debug)]
// AstId: 2
pub(self) struct Struct { pub(self) struct Struct {
// AstId: 6
#[doc = " fld docs"] #[doc = " fld docs"]
pub(self) fld: (), pub(self) fld: (),
} }
// AstId: 3
pub(self) struct Tuple( pub(self) struct Tuple(
// AstId: 7
#[attr] #[attr]
pub(self) 0: u8, pub(self) 0: u8,
); );
// AstId: 4
pub(self) union Ize { pub(self) union Ize {
// AstId: 8
pub(self) a: (), pub(self) a: (),
// AstId: 9
pub(self) b: (), pub(self) b: (),
} }
// AstId: 5
pub(self) enum E { pub(self) enum E {
// AstId: 10
#[doc = " comment on Unit"] #[doc = " comment on Unit"]
Unit, Unit,
// AstId: 11
#[doc = " comment on Tuple"] #[doc = " comment on Tuple"]
Tuple( Tuple(
// AstId: 13
pub(self) 0: u8, pub(self) 0: u8,
), ),
// AstId: 12
Struct { Struct {
// AstId: 14
#[doc = " comment on a: u8"] #[doc = " comment on a: u8"]
pub(self) a: u8, pub(self) a: u8,
}, },
} }
"##]], "#]],
); );
} }
@ -166,26 +190,35 @@ trait Tr: SuperTrait + 'lifetime {
} }
"#, "#,
expect![[r#" expect![[r#"
// AstId: 1
pub static mut ST: () = _; pub static mut ST: () = _;
// AstId: 2
pub(self) const _: Anon = _; pub(self) const _: Anon = _;
#[attr] #[attr]
#[inner_attr_in_fn] #[inner_attr_in_fn]
// AstId: 3
pub(self) fn f( pub(self) fn f(
#[attr] #[attr]
// AstId: 5
u8, u8,
// AstId: 6
(), (),
) -> () { ... } ) -> () { ... }
// AstId: 4
pub(self) trait Tr<Self> pub(self) trait Tr<Self>
where where
Self: SuperTrait, Self: SuperTrait,
Self: 'lifetime Self: 'lifetime
{ {
// AstId: 8
pub(self) type Assoc: AssocBound = Default; pub(self) type Assoc: AssocBound = Default;
// AstId: 9
pub(self) fn method( pub(self) fn method(
// AstId: 10
self: &Self, self: &Self,
) -> (); ) -> ();
} }
@ -211,12 +244,16 @@ mod outline;
expect![[r##" expect![[r##"
#[doc = " outer"] #[doc = " outer"]
#[doc = " inner"] #[doc = " inner"]
// AstId: 1
pub(self) mod inline { pub(self) mod inline {
// AstId: 3
pub(self) use super::*; pub(self) use super::*;
// AstId: 4
pub(self) fn fn_in_module() -> () { ... } pub(self) fn fn_in_module() -> () { ... }
} }
// AstId: 2
pub(self) mod outline; pub(self) mod outline;
"##]], "##]],
); );
@ -235,10 +272,13 @@ pub macro m2() {}
m!(); m!();
"#, "#,
expect![[r#" expect![[r#"
// AstId: 1
macro_rules! m { ... } macro_rules! m { ... }
// AstId: 2
pub macro m2 { ... } pub macro m2 { ... }
// AstId: 3, Span: 0:3@0..5#0, ExpandTo: Items
m!(...); m!(...);
"#]], "#]],
); );
@ -258,12 +298,19 @@ struct S {
} }
"#, "#,
expect![[r#" expect![[r#"
// AstId: 1
pub(self) struct S { pub(self) struct S {
// AstId: 2
pub(self) a: self::Ty, pub(self) a: self::Ty,
// AstId: 3
pub(self) b: super::SuperTy, pub(self) b: super::SuperTy,
// AstId: 4
pub(self) c: super::super::SuperSuperTy, pub(self) c: super::super::SuperSuperTy,
// AstId: 5
pub(self) d: ::abs::Path, pub(self) d: ::abs::Path,
// AstId: 6
pub(self) e: crate::Crate, pub(self) e: crate::Crate,
// AstId: 7
pub(self) f: plain::path::Ty, pub(self) f: plain::path::Ty,
} }
"#]], "#]],
@ -282,10 +329,15 @@ struct S {
} }
"#, "#,
expect![[r#" expect![[r#"
// AstId: 1
pub(self) struct S { pub(self) struct S {
// AstId: 2
pub(self) a: Mixed::<'a, T, Item = (), OtherItem = u8>, pub(self) a: Mixed::<'a, T, Item = (), OtherItem = u8>,
// AstId: 3
pub(self) b: Qualified::<Self=Fully>::Syntax, pub(self) b: Qualified::<Self=Fully>::Syntax,
// AstId: 4
pub(self) c: <TypeAnchored>::Path::<'a>, pub(self) c: <TypeAnchored>::Path::<'a>,
// AstId: 5
pub(self) d: dyn for<'a> Trait::<'a>, pub(self) d: dyn for<'a> Trait::<'a>,
} }
"#]], "#]],
@ -312,42 +364,53 @@ union Union<'a, T, const U: u8> {}
trait Tr<'a, T: 'a>: Super where Self: for<'a> Tr<'a, T> {} trait Tr<'a, T: 'a>: Super where Self: for<'a> Tr<'a, T> {}
"#, "#,
expect![[r#" expect![[r#"
// AstId: 1
pub(self) struct S<'a, 'b, T, const K: u8> pub(self) struct S<'a, 'b, T, const K: u8>
where where
T: Copy, T: Copy,
T: 'a, T: 'a,
T: 'b T: 'b
{ {
// AstId: 8
pub(self) field: &'a &'b T, pub(self) field: &'a &'b T,
} }
// AstId: 2
pub(self) struct Tuple<T, U>( pub(self) struct Tuple<T, U>(
// AstId: 9
pub(self) 0: T, pub(self) 0: T,
// AstId: 10
pub(self) 1: U, pub(self) 1: U,
) )
where where
T: Copy, T: Copy,
U: ?Sized; U: ?Sized;
// AstId: 3
impl<'a, 'b, T, const K: u8> S::<'a, 'b, T, K> impl<'a, 'b, T, const K: u8> S::<'a, 'b, T, K>
where where
T: Copy, T: Copy,
T: 'a, T: 'a,
T: 'b T: 'b
{ {
// AstId: 12
pub(self) fn f<G>( pub(self) fn f<G>(
// AstId: 13
impl Copy, impl Copy,
) -> impl Copy ) -> impl Copy
where where
G: 'a { ... } G: 'a { ... }
} }
// AstId: 4
pub(self) enum Enum<'a, T, const U: u8> { pub(self) enum Enum<'a, T, const U: u8> {
} }
// AstId: 5
pub(self) union Union<'a, T, const U: u8> { pub(self) union Union<'a, T, const U: u8> {
} }
// AstId: 6
pub(self) trait Tr<'a, Self, T> pub(self) trait Tr<'a, Self, T>
where where
Self: Super, Self: Super,
@ -366,6 +429,7 @@ fn generics_with_attributes() {
struct S<#[cfg(never)] T>; struct S<#[cfg(never)] T>;
"#, "#,
expect![[r#" expect![[r#"
// AstId: 1
pub(self) struct S<#[cfg(never)] T>; pub(self) struct S<#[cfg(never)] T>;
"#]], "#]],
) )
@ -378,6 +442,7 @@ fn pub_self() {
pub(self) struct S; pub(self) struct S;
"#, "#,
expect![[r#" expect![[r#"
// AstId: 1
pub(self) struct S; pub(self) struct S;
"#]], "#]],
) )

View file

@ -35,9 +35,9 @@ macro_rules! f {
}; };
} }
struct#FileId(0):1@58..64\2# MyTraitMap2#FileId(0):2@31..42\0# {#FileId(0):1@72..73\2# struct#0:1@58..64#2# MyTraitMap2#0:2@31..42#0# {#0:1@72..73#2#
map#FileId(0):1@86..89\2#:#FileId(0):1@89..90\2# #FileId(0):1@89..90\2#::#FileId(0):1@91..92\2#std#FileId(0):1@93..96\2#::#FileId(0):1@96..97\2#collections#FileId(0):1@98..109\2#::#FileId(0):1@109..110\2#HashSet#FileId(0):1@111..118\2#<#FileId(0):1@118..119\2#(#FileId(0):1@119..120\2#)#FileId(0):1@120..121\2#>#FileId(0):1@121..122\2#,#FileId(0):1@122..123\2# map#0:1@86..89#2#:#0:1@89..90#2# #0:1@89..90#2#::#0:1@91..92#2#std#0:1@93..96#2#::#0:1@96..97#2#collections#0:1@98..109#2#::#0:1@109..110#2#HashSet#0:1@111..118#2#<#0:1@118..119#2#(#0:1@119..120#2#)#0:1@120..121#2#>#0:1@121..122#2#,#0:1@122..123#2#
}#FileId(0):1@132..133\2# }#0:1@132..133#2#
"#]], "#]],
); );
} }
@ -75,12 +75,12 @@ macro_rules! f {
}; };
} }
fn#FileId(0):2@30..32\0# main#FileId(0):2@33..37\0#(#FileId(0):2@37..38\0#)#FileId(0):2@38..39\0# {#FileId(0):2@40..41\0# fn#0:2@30..32#0# main#0:2@33..37#0#(#0:2@37..38#0#)#0:2@38..39#0# {#0:2@40..41#0#
1#FileId(0):2@50..51\0#;#FileId(0):2@51..52\0# 1#0:2@50..51#0#;#0:2@51..52#0#
1.0#FileId(0):2@61..64\0#;#FileId(0):2@64..65\0# 1.0#0:2@61..64#0#;#0:2@64..65#0#
(#FileId(0):2@74..75\0#(#FileId(0):2@75..76\0#1#FileId(0):2@76..77\0#,#FileId(0):2@77..78\0# )#FileId(0):2@78..79\0#,#FileId(0):2@79..80\0# )#FileId(0):2@80..81\0#.#FileId(0):2@81..82\0#0#FileId(0):2@82..85\0#.#FileId(0):2@82..85\0#0#FileId(0):2@82..85\0#;#FileId(0):2@85..86\0# (#0:2@74..75#0#(#0:2@75..76#0#1#0:2@76..77#0#,#0:2@77..78#0# )#0:2@78..79#0#,#0:2@79..80#0# )#0:2@80..81#0#.#0:2@81..82#0#0#0:2@82..85#0#.#0:2@82..85#0#0#0:2@82..85#0#;#0:2@85..86#0#
let#FileId(0):2@95..98\0# x#FileId(0):2@99..100\0# =#FileId(0):2@101..102\0# 1#FileId(0):2@103..104\0#;#FileId(0):2@104..105\0# let#0:2@95..98#0# x#0:2@99..100#0# =#0:2@101..102#0# 1#0:2@103..104#0#;#0:2@104..105#0#
}#FileId(0):2@110..111\0# }#0:2@110..111#0#
"#]], "#]],
@ -171,7 +171,7 @@ fn main(foo: ()) {
} }
fn main(foo: ()) { fn main(foo: ()) {
/* error: unresolved macro unresolved */"helloworld!"#FileId(0):3@207..323\6#; /* error: unresolved macro unresolved */"helloworld!"#0:3@207..323#6#;
} }
} }
@ -197,7 +197,7 @@ macro_rules! mk_struct {
#[macro_use] #[macro_use]
mod foo; mod foo;
struct#FileId(1):1@59..65\2# Foo#FileId(0):2@32..35\0#(#FileId(1):1@70..71\2#u32#FileId(0):2@41..44\0#)#FileId(1):1@74..75\2#;#FileId(1):1@75..76\2# struct#1:1@59..65#2# Foo#0:2@32..35#0#(#1:1@70..71#2#u32#0:2@41..44#0#)#1:1@74..75#2#;#1:1@75..76#2#
"#]], "#]],
); );
} }

View file

@ -291,15 +291,8 @@ fn pretty_print_macro_expansion(
let span = map.span_for_range(token.text_range()); let span = map.span_for_range(token.text_range());
format_to!(res, "#"); format_to!(res, "#");
if show_spans { if show_spans {
format_to!( format_to!(res, "{span}",);
res, } else if show_ctxt {
"{:?}:{:?}@{:?}",
span.anchor.file_id,
span.anchor.ast_id.into_raw(),
span.range,
);
}
if show_ctxt {
format_to!(res, "\\{}", span.ctx); format_to!(res, "\\{}", span.ctx);
} }
format_to!(res, "#"); format_to!(res, "#");

View file

@ -181,8 +181,8 @@ fn foo(&self) {
self.0. 1; self.0. 1;
} }
fn#FileId(0):1@45..47\0# foo#FileId(0):1@48..51\0#(#FileId(0):1@51..52\0#&#FileId(0):1@52..53\0#self#FileId(0):1@53..57\0# )#FileId(0):1@57..58\0# {#FileId(0):1@59..60\0# fn#0:1@45..47#0# foo#0:1@48..51#0#(#0:1@51..52#0#&#0:1@52..53#0#self#0:1@53..57#0# )#0:1@57..58#0# {#0:1@59..60#0#
self#FileId(0):1@65..69\0# .#FileId(0):1@69..70\0#0#FileId(0):1@70..71\0#.#FileId(0):1@71..72\0#1#FileId(0):1@73..74\0#;#FileId(0):1@74..75\0# self#0:1@65..69#0# .#0:1@69..70#0#0#0:1@70..71#0#.#0:1@71..72#0#1#0:1@73..74#0#;#0:1@74..75#0#
}#FileId(0):1@76..77\0#"#]], }#0:1@76..77#0#"#]],
); );
} }

View file

@ -6,20 +6,18 @@
pub use hir_def::db::{ pub use hir_def::db::{
AttrsQuery, BlockDefMapQuery, BlockItemTreeQueryQuery, BodyQuery, BodyWithSourceMapQuery, AttrsQuery, BlockDefMapQuery, BlockItemTreeQueryQuery, BodyQuery, BodyWithSourceMapQuery,
ConstDataQuery, ConstVisibilityQuery, CrateDefMapQueryQuery, CrateLangItemsQuery, ConstDataQuery, ConstVisibilityQuery, CrateDefMapQueryQuery, CrateLangItemsQuery,
CrateSupportsNoStdQuery, DefDatabase, DefDatabaseStorage, EnumDataQuery, EnumVariantDataQuery, CrateSupportsNoStdQuery, DefDatabase, DefDatabaseStorage, EnumDataQuery,
EnumVariantDataWithDiagnosticsQuery, ExprScopesQuery, ExternCrateDeclDataQuery, EnumVariantDataWithDiagnosticsQuery, ExprScopesQuery, ExternCrateDeclDataQuery,
FieldVisibilitiesQuery, FieldsAttrsQuery, FieldsAttrsSourceMapQuery, FileItemTreeQuery, FieldVisibilitiesQuery, FieldsAttrsQuery, FieldsAttrsSourceMapQuery, FileItemTreeQuery,
FunctionDataQuery, FunctionVisibilityQuery, GenericParamsQuery, ImplDataQuery, FunctionDataQuery, FunctionVisibilityQuery, GenericParamsQuery, ImplDataWithDiagnosticsQuery,
ImplDataWithDiagnosticsQuery, ImportMapQuery, InternAnonymousConstQuery, InternBlockQuery, ImportMapQuery, InternAnonymousConstQuery, InternBlockQuery, InternConstQuery, InternDatabase,
InternConstQuery, InternDatabase, InternDatabaseStorage, InternEnumQuery, InternDatabaseStorage, InternEnumQuery, InternExternBlockQuery, InternExternCrateQuery,
InternExternBlockQuery, InternExternCrateQuery, InternFunctionQuery, InternImplQuery, InternFunctionQuery, InternImplQuery, InternInTypeConstQuery, InternMacro2Query,
InternInTypeConstQuery, InternMacro2Query, InternMacroRulesQuery, InternProcMacroQuery, InternMacroRulesQuery, InternProcMacroQuery, InternStaticQuery, InternStructQuery,
InternStaticQuery, InternStructQuery, InternTraitAliasQuery, InternTraitQuery, InternTraitAliasQuery, InternTraitQuery, InternTypeAliasQuery, InternUnionQuery,
InternTypeAliasQuery, InternUnionQuery, InternUseQuery, LangItemQuery, Macro2DataQuery, InternUseQuery, LangItemQuery, Macro2DataQuery, MacroRulesDataQuery, ProcMacroDataQuery,
MacroRulesDataQuery, ProcMacroDataQuery, StaticDataQuery, StructDataQuery, StaticDataQuery, StructDataWithDiagnosticsQuery, TraitAliasDataQuery,
StructDataWithDiagnosticsQuery, TraitAliasDataQuery, TraitDataQuery, TraitDataWithDiagnosticsQuery, TypeAliasDataQuery, UnionDataWithDiagnosticsQuery,
TraitDataWithDiagnosticsQuery, TypeAliasDataQuery, UnionDataQuery,
UnionDataWithDiagnosticsQuery,
}; };
pub use hir_expand::db::{ pub use hir_expand::db::{
AstIdMapQuery, DeclMacroExpanderQuery, ExpandDatabase, ExpandDatabaseStorage, AstIdMapQuery, DeclMacroExpanderQuery, ExpandDatabase, ExpandDatabaseStorage,

View file

@ -136,16 +136,11 @@ impl RootDatabase {
hir::db::FileItemTreeQuery hir::db::FileItemTreeQuery
hir::db::CrateDefMapQueryQuery hir::db::CrateDefMapQueryQuery
hir::db::BlockDefMapQuery hir::db::BlockDefMapQuery
hir::db::StructDataQuery
hir::db::StructDataWithDiagnosticsQuery hir::db::StructDataWithDiagnosticsQuery
hir::db::UnionDataQuery
hir::db::UnionDataWithDiagnosticsQuery hir::db::UnionDataWithDiagnosticsQuery
hir::db::EnumDataQuery hir::db::EnumDataQuery
hir::db::EnumVariantDataWithDiagnosticsQuery hir::db::EnumVariantDataWithDiagnosticsQuery
hir::db::EnumVariantDataQuery
hir::db::ImplDataQuery
hir::db::ImplDataWithDiagnosticsQuery hir::db::ImplDataWithDiagnosticsQuery
hir::db::TraitDataQuery
hir::db::TraitDataWithDiagnosticsQuery hir::db::TraitDataWithDiagnosticsQuery
hir::db::TraitAliasDataQuery hir::db::TraitAliasDataQuery
hir::db::TypeAliasDataQuery hir::db::TypeAliasDataQuery

View file

@ -217,16 +217,11 @@ impl RootDatabase {
hir_db::FileItemTreeQuery hir_db::FileItemTreeQuery
hir_db::CrateDefMapQueryQuery hir_db::CrateDefMapQueryQuery
hir_db::BlockDefMapQuery hir_db::BlockDefMapQuery
hir_db::StructDataQuery
hir_db::StructDataWithDiagnosticsQuery hir_db::StructDataWithDiagnosticsQuery
hir_db::UnionDataQuery
hir_db::UnionDataWithDiagnosticsQuery hir_db::UnionDataWithDiagnosticsQuery
hir_db::EnumDataQuery hir_db::EnumDataQuery
hir_db::EnumDataQuery
hir_db::EnumVariantDataWithDiagnosticsQuery hir_db::EnumVariantDataWithDiagnosticsQuery
hir_db::ImplDataQuery
hir_db::ImplDataWithDiagnosticsQuery hir_db::ImplDataWithDiagnosticsQuery
hir_db::TraitDataQuery
hir_db::TraitDataWithDiagnosticsQuery hir_db::TraitDataWithDiagnosticsQuery
hir_db::TraitAliasDataQuery hir_db::TraitAliasDataQuery
hir_db::TypeAliasDataQuery hir_db::TypeAliasDataQuery

View file

@ -463,9 +463,9 @@ pub(super) fn definition(
}; };
let label = match (value, layout_info) { let label = match (value, layout_info) {
(Some(value), Some(layout_info)) => format!("{label} = {value}{layout_info}"), (Some(value), Some(layout_info)) => format!("{layout_info}\n{label} = {value}"),
(Some(value), None) => format!("{label} = {value}"), (Some(value), None) => format!("{label} = {value}"),
(None, Some(layout_info)) => format!("{label}{layout_info}"), (None, Some(layout_info)) => format!("{layout_info}\n{label}"),
(None, None) => label, (None, None) => label,
}; };
@ -617,8 +617,6 @@ fn render_memory_layout(
offset: impl FnOnce(&Layout) -> Option<u64>, offset: impl FnOnce(&Layout) -> Option<u64>,
tag: impl FnOnce(&Layout) -> Option<usize>, tag: impl FnOnce(&Layout) -> Option<usize>,
) -> Option<String> { ) -> Option<String> {
// field
let config = config?; let config = config?;
let layout = layout().ok()?; let layout = layout().ok()?;

View file

@ -157,7 +157,8 @@ fn foo() {
*local* *local*
```rust ```rust
let local: i32 // size = 4, align = 4 // size = 4, align = 4
let local: i32
``` ```
"#]], "#]],
); );
@ -433,7 +434,8 @@ fn main() {
*iter* *iter*
```rust ```rust
let mut iter: Iter<Scan<OtherStruct<OtherStruct<i32>>, impl Fn(&mut u32, &u32, &mut u32) -> Option<u32>, u32>> // size = 8, align = 4 // size = 8, align = 4
let mut iter: Iter<Scan<OtherStruct<OtherStruct<i32>>, impl Fn(&mut u32, &u32, &mut u32) -> Option<u32>, u32>>
``` ```
"#]], "#]],
); );
@ -674,7 +676,8 @@ struct Foo { fiel$0d_a: u8, field_b: i32, field_c: i16 }
``` ```
```rust ```rust
field_a: u8 // size = 1, align = 1, offset = 6 // size = 1, align = 1, offset = 6
field_a: u8
``` ```
"#]], "#]],
); );
@ -699,7 +702,8 @@ fn main() {
``` ```
```rust ```rust
field_a: u32 // size = 4, align = 4, offset = 0 // size = 4, align = 4, offset = 0
field_a: u32
``` ```
"#]], "#]],
); );
@ -721,7 +725,8 @@ fn main() {
``` ```
```rust ```rust
field_a: u32 // size = 4, align = 4, offset = 0 // size = 4, align = 4, offset = 0
field_a: u32
``` ```
"#]], "#]],
); );
@ -848,7 +853,8 @@ fn main() {
*zz* *zz*
```rust ```rust
let zz: Test<i32> // size = 8, align = 4 // size = 8, align = 4
let zz: Test<i32>
``` ```
"#]], "#]],
); );
@ -899,7 +905,8 @@ fn main() { let b$0ar = Some(12); }
*bar* *bar*
```rust ```rust
let bar: Option<i32> // size = 4, align = 4 // size = 4, align = 4
let bar: Option<i32>
``` ```
"#]], "#]],
); );
@ -968,7 +975,8 @@ fn hover_for_local_variable() {
*foo* *foo*
```rust ```rust
foo: i32 // size = 4, align = 4 // size = 4, align = 4
foo: i32
``` ```
"#]], "#]],
) )
@ -982,7 +990,8 @@ fn hover_for_local_variable_pat() {
*foo* *foo*
```rust ```rust
foo: i32 // size = 4, align = 4 // size = 4, align = 4
foo: i32
``` ```
"#]], "#]],
) )
@ -996,7 +1005,8 @@ fn hover_local_var_edge() {
*foo* *foo*
```rust ```rust
foo: i32 // size = 4, align = 4 // size = 4, align = 4
foo: i32
``` ```
"#]], "#]],
) )
@ -1010,7 +1020,8 @@ fn hover_for_param_edge() {
*foo* *foo*
```rust ```rust
foo: i32 // size = 4, align = 4 // size = 4, align = 4
foo: i32
``` ```
"#]], "#]],
) )
@ -1054,7 +1065,8 @@ fn main() { let foo_$0test = Thing::new(); }
*foo_test* *foo_test*
```rust ```rust
let foo_test: Thing // size = 4, align = 4 // size = 4, align = 4
let foo_test: Thing
``` ```
"#]], "#]],
) )
@ -1222,7 +1234,8 @@ fn y() {
*x* *x*
```rust ```rust
let x: i32 // size = 4, align = 4 // size = 4, align = 4
let x: i32
``` ```
"#]], "#]],
) )
@ -1352,7 +1365,8 @@ fn foo(bar:u32) { let a = id!(ba$0r); }
*bar* *bar*
```rust ```rust
bar: u32 // size = 4, align = 4 // size = 4, align = 4
bar: u32
``` ```
"#]], "#]],
); );
@ -1370,7 +1384,8 @@ fn foo(bar:u32) { let a = id!(ba$0r); }
*bar* *bar*
```rust ```rust
bar: u32 // size = 4, align = 4 // size = 4, align = 4
bar: u32
``` ```
"#]], "#]],
); );
@ -1619,7 +1634,8 @@ fn test_hover_function_pointer_show_identifiers() {
``` ```
```rust ```rust
type foo = fn(a: i32, b: i32) -> i32 // size = 8, align = 8, niches = 1 // size = 8, align = 8, niches = 1
type foo = fn(a: i32, b: i32) -> i32
``` ```
"#]], "#]],
); );
@ -1637,7 +1653,8 @@ fn test_hover_function_pointer_no_identifier() {
``` ```
```rust ```rust
type foo = fn(i32, i32) -> i32 // size = 8, align = 8, niches = 1 // size = 8, align = 8, niches = 1
type foo = fn(i32, i32) -> i32
``` ```
"#]], "#]],
); );
@ -1783,7 +1800,8 @@ fn foo() { let bar = Ba$0r; }
``` ```
```rust ```rust
struct Bar // size = 0, align = 1 // size = 0, align = 1
struct Bar
``` ```
--- ---
@ -1819,7 +1837,8 @@ fn foo() { let bar = Ba$0r; }
``` ```
```rust ```rust
struct Bar // size = 0, align = 1 // size = 0, align = 1
struct Bar
``` ```
--- ---
@ -1848,7 +1867,8 @@ fn foo() { let bar = Ba$0r; }
``` ```
```rust ```rust
struct Bar // size = 0, align = 1 // size = 0, align = 1
struct Bar
``` ```
--- ---
@ -1876,7 +1896,8 @@ pub struct B$0ar
``` ```
```rust ```rust
pub struct Bar // size = 0, align = 1 // size = 0, align = 1
pub struct Bar
``` ```
--- ---
@ -1903,7 +1924,8 @@ pub struct B$0ar
``` ```
```rust ```rust
pub struct Bar // size = 0, align = 1 // size = 0, align = 1
pub struct Bar
``` ```
--- ---
@ -1992,7 +2014,8 @@ fn test_hover_layout_of_variant() {
``` ```
```rust ```rust
Variant1(u8, u16) // size = 4, align = 2 // size = 4, align = 2
Variant1(u8, u16)
``` ```
"#]], "#]],
); );
@ -2013,10 +2036,11 @@ fn test_hover_layout_of_enum() {
``` ```
```rust ```rust
// size = 16 (0x10), align = 8, niches = 254
enum Foo { enum Foo {
Variant1(u8, u16), Variant1(u8, u16),
Variant2(i32, u8, i64), Variant2(i32, u8, i64),
} // size = 16 (0x10), align = 8, niches = 254 }
``` ```
"#]], "#]],
); );
@ -3316,7 +3340,8 @@ fn main() {
*f* *f*
```rust ```rust
f: &i32 // size = 8, align = 8, niches = 1 // size = 8, align = 8, niches = 1
f: &i32
``` ```
--- ---
@ -3325,7 +3350,8 @@ fn main() {
``` ```
```rust ```rust
f: i32 // size = 4, align = 4, offset = 0 // size = 4, align = 4, offset = 0
f: i32
``` ```
"#]], "#]],
); );
@ -3409,7 +3435,8 @@ fn main() {
*value* *value*
```rust ```rust
let value: Const<1> // size = 0, align = 1 // size = 0, align = 1
let value: Const<1>
``` ```
"#]], "#]],
); );
@ -3429,7 +3456,8 @@ fn main() {
*value* *value*
```rust ```rust
let value: Const<0> // size = 0, align = 1 // size = 0, align = 1
let value: Const<0>
``` ```
"#]], "#]],
); );
@ -3449,7 +3477,8 @@ fn main() {
*value* *value*
```rust ```rust
let value: Const<-1> // size = 0, align = 1 // size = 0, align = 1
let value: Const<-1>
``` ```
"#]], "#]],
); );
@ -3469,7 +3498,8 @@ fn main() {
*value* *value*
```rust ```rust
let value: Const<true> // size = 0, align = 1 // size = 0, align = 1
let value: Const<true>
``` ```
"#]], "#]],
); );
@ -3489,7 +3519,8 @@ fn main() {
*value* *value*
```rust ```rust
let value: Const<'🦀'> // size = 0, align = 1 // size = 0, align = 1
let value: Const<'🦀'>
``` ```
"#]], "#]],
); );
@ -3508,7 +3539,8 @@ impl Foo {
*self* *self*
```rust ```rust
self: &Foo // size = 8, align = 8, niches = 1 // size = 8, align = 8, niches = 1
self: &Foo
``` ```
"#]], "#]],
); );
@ -3528,7 +3560,8 @@ impl Foo {
*self* *self*
```rust ```rust
self: Arc<Foo> // size = 0, align = 1 // size = 0, align = 1
self: Arc<Foo>
``` ```
"#]], "#]],
); );
@ -3913,7 +3946,8 @@ type Fo$0o2 = Foo<2>;
``` ```
```rust ```rust
type Foo2 = Foo<2> // size = 0, align = 1 // size = 0, align = 1
type Foo2 = Foo<2>
``` ```
"#]], "#]],
); );
@ -3955,7 +3989,8 @@ enum E {
``` ```
```rust ```rust
A = 8 // size = 1, align = 1 // size = 1, align = 1
A = 8
``` ```
--- ---
@ -3980,7 +4015,8 @@ enum E {
``` ```
```rust ```rust
A = 12 (0xC) // size = 1, align = 1 // size = 1, align = 1
A = 12 (0xC)
``` ```
--- ---
@ -4006,7 +4042,8 @@ enum E {
``` ```
```rust ```rust
B = 2 // size = 1, align = 1 // size = 1, align = 1
B = 2
``` ```
--- ---
@ -4032,7 +4069,8 @@ enum E {
``` ```
```rust ```rust
B = 5 // size = 1, align = 1 // size = 1, align = 1
B = 5
``` ```
--- ---
@ -4838,7 +4876,8 @@ fn foo(e: E) {
``` ```
```rust ```rust
A = 3 // size = 0, align = 1 // size = 0, align = 1
A = 3
``` ```
--- ---
@ -4860,7 +4899,8 @@ fn main() {
*tile4* *tile4*
```rust ```rust
let tile4: [u32; 8] // size = 32 (0x20), align = 4 // size = 32 (0x20), align = 4
let tile4: [u32; 8]
``` ```
"#]], "#]],
); );
@ -5096,7 +5136,8 @@ pub fn gimme() -> theitem::TheItem {
``` ```
```rust ```rust
pub struct TheItem // size = 0, align = 1 // size = 0, align = 1
pub struct TheItem
``` ```
--- ---
@ -5244,7 +5285,8 @@ mod string {
``` ```
```rust ```rust
struct String // size = 0, align = 1 // size = 0, align = 1
struct String
``` ```
--- ---
@ -5921,7 +5963,8 @@ foo_macro!(
``` ```
```rust ```rust
pub struct Foo // size = 0, align = 1 // size = 0, align = 1
pub struct Foo
``` ```
--- ---
@ -5946,7 +5989,8 @@ pub struct Foo(i32);
``` ```
```rust ```rust
pub struct Foo(i32); // size = 4, align = 4 // size = 4, align = 4
pub struct Foo(i32);
``` ```
--- ---
@ -6045,7 +6089,8 @@ enum Enum {
``` ```
```rust ```rust
RecordV { field: u32 } // size = 4, align = 4 // size = 4, align = 4
RecordV { field: u32 }
``` ```
"#]], "#]],
); );
@ -6067,7 +6112,8 @@ enum Enum {
``` ```
```rust ```rust
field: u32 // size = 4, align = 4 // size = 4, align = 4
field: u32
``` ```
"#]], "#]],
); );
@ -6569,7 +6615,8 @@ fn test() {
``` ```
```rust ```rust
f: u32 // size = 4, align = 4, offset = 0 // size = 4, align = 4, offset = 0
f: u32
``` ```
"#]], "#]],
); );
@ -6588,7 +6635,8 @@ fn test() {
*s* *s*
```rust ```rust
let s: S // size = 0, align = 1 // size = 0, align = 1
let s: S
``` ```
"#]], "#]],
); );
@ -6608,7 +6656,8 @@ fn test() {
*foo* *foo*
```rust ```rust
let foo: i32 // size = 4, align = 4 // size = 4, align = 4
let foo: i32
``` ```
"#]], "#]],
); );
@ -6628,7 +6677,8 @@ format_args!("{aaaaa$0}");
*aaaaa* *aaaaa*
```rust ```rust
let aaaaa: &str // size = 16 (0x10), align = 8, niches = 1 // size = 16 (0x10), align = 8, niches = 1
let aaaaa: &str
``` ```
"#]], "#]],
); );
@ -6648,7 +6698,8 @@ format_args!("{$0aaaaa}");
*aaaaa* *aaaaa*
```rust ```rust
let aaaaa: &str // size = 16 (0x10), align = 8, niches = 1 // size = 16 (0x10), align = 8, niches = 1
let aaaaa: &str
``` ```
"#]], "#]],
); );
@ -6668,7 +6719,8 @@ format_args!(r"{$0aaaaa}");
*aaaaa* *aaaaa*
```rust ```rust
let aaaaa: &str // size = 16 (0x10), align = 8, niches = 1 // size = 16 (0x10), align = 8, niches = 1
let aaaaa: &str
``` ```
"#]], "#]],
); );
@ -6693,7 +6745,8 @@ foo!(r"{$0aaaaa}");
*aaaaa* *aaaaa*
```rust ```rust
let aaaaa: &str // size = 16 (0x10), align = 8, niches = 1 // size = 16 (0x10), align = 8, niches = 1
let aaaaa: &str
``` ```
"#]], "#]],
); );

View file

@ -55,7 +55,9 @@ fn detect_errors_from_rustc_stderr_file(p: PathBuf) -> HashMap<DiagnosticCode, u
impl Tester { impl Tester {
fn new() -> Result<Self> { fn new() -> Result<Self> {
let tmp_file = AbsPathBuf::assert("/tmp/ra-rustc-test.rs".into()); let mut path = std::env::temp_dir();
path.push("ra-rustc-test.rs");
let tmp_file = AbsPathBuf::try_from(path).unwrap();
std::fs::write(&tmp_file, "")?; std::fs::write(&tmp_file, "")?;
let mut cargo_config = CargoConfig::default(); let mut cargo_config = CargoConfig::default();
cargo_config.sysroot = Some(RustLibSource::Discover); cargo_config.sysroot = Some(RustLibSource::Discover);
@ -122,12 +124,16 @@ impl Tester {
change.change_file(self.root_file, Some(Arc::from(text))); change.change_file(self.root_file, Some(Arc::from(text)));
self.host.apply_change(change); self.host.apply_change(change);
let diagnostic_config = DiagnosticsConfig::test_sample(); let diagnostic_config = DiagnosticsConfig::test_sample();
let diags = self
.host let mut actual = HashMap::new();
let panicked = match std::panic::catch_unwind(|| {
self.host
.analysis() .analysis()
.diagnostics(&diagnostic_config, ide::AssistResolveStrategy::None, self.root_file) .diagnostics(&diagnostic_config, ide::AssistResolveStrategy::None, self.root_file)
.unwrap(); .unwrap()
let mut actual = HashMap::new(); }) {
Err(e) => Some(e),
Ok(diags) => {
for diag in diags { for diag in diags {
if !matches!(diag.code, DiagnosticCode::RustcHardError(_)) { if !matches!(diag.code, DiagnosticCode::RustcHardError(_)) {
continue; continue;
@ -137,11 +143,24 @@ impl Tester {
} }
*actual.entry(diag.code).or_insert(0) += 1; *actual.entry(diag.code).or_insert(0) += 1;
} }
None
}
};
// Ignore tests with diagnostics that we don't emit. // Ignore tests with diagnostics that we don't emit.
ignore_test |= expected.keys().any(|k| !SUPPORTED_DIAGNOSTICS.contains(k)); ignore_test |= expected.keys().any(|k| !SUPPORTED_DIAGNOSTICS.contains(k));
if ignore_test { if ignore_test {
println!("{p:?} IGNORE"); println!("{p:?} IGNORE");
self.ignore_count += 1; self.ignore_count += 1;
} else if let Some(panic) = panicked {
if let Some(msg) = panic
.downcast_ref::<String>()
.map(String::as_str)
.or_else(|| panic.downcast_ref::<&str>().copied())
{
println!("{msg:?} ")
}
println!("PANIC");
self.fail_count += 1;
} else if actual == expected { } else if actual == expected {
println!("{p:?} PASS"); println!("{p:?} PASS");
self.pass_count += 1; self.pass_count += 1;
@ -225,11 +244,11 @@ impl flags::RustcTests {
let tester = AssertUnwindSafe(&mut tester); let tester = AssertUnwindSafe(&mut tester);
let p = p.clone(); let p = p.clone();
move || { move || {
let _guard = stdx::panic_context::enter(p.display().to_string());
let tester = tester; let tester = tester;
tester.0.test(p); tester.0.test(p);
} }
}) { }) {
println!("panic detected at test {:?}", p);
std::panic::resume_unwind(e); std::panic::resume_unwind(e);
} }
} }

View file

@ -2,7 +2,7 @@
// FIXME: This should be moved into its own crate to get rid of the dependency inversion, base-db // FIXME: This should be moved into its own crate to get rid of the dependency inversion, base-db
// has business depending on tt, tt should depend on a span crate only (which unforunately will have // has business depending on tt, tt should depend on a span crate only (which unforunately will have
// to depend on salsa) // to depend on salsa)
use std::fmt; use std::fmt::{self, Write};
use salsa::InternId; use salsa::InternId;
@ -37,6 +37,8 @@ pub const FIXUP_ERASED_FILE_AST_ID_MARKER: ErasedFileAstId =
// is required to be stable for the proc-macro-server // is required to be stable for the proc-macro-server
la_arena::Idx::from_raw(la_arena::RawIdx::from_u32(!0 - 1)); la_arena::Idx::from_raw(la_arena::RawIdx::from_u32(!0 - 1));
pub type Span = SpanData<SyntaxContextId>;
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
pub struct SpanData<Ctx> { pub struct SpanData<Ctx> {
/// The text range of this span, relative to the anchor. /// The text range of this span, relative to the anchor.
@ -47,6 +49,7 @@ pub struct SpanData<Ctx> {
/// The syntax context of the span. /// The syntax context of the span.
pub ctx: Ctx, pub ctx: Ctx,
} }
impl Span { impl Span {
#[deprecated = "dummy spans will panic if surfaced incorrectly, as such they should be replaced appropriately"] #[deprecated = "dummy spans will panic if surfaced incorrectly, as such they should be replaced appropriately"]
pub const DUMMY: Self = SpanData { pub const DUMMY: Self = SpanData {
@ -56,7 +59,17 @@ impl Span {
}; };
} }
pub type Span = SpanData<SyntaxContextId>; impl fmt::Display for Span {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&self.anchor.file_id.index(), f)?;
f.write_char(':')?;
fmt::Debug::fmt(&self.anchor.ast_id.into_raw(), f)?;
f.write_char('@')?;
fmt::Debug::fmt(&self.range, f)?;
f.write_char('#')?;
self.ctx.fmt(f)
}
}
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct SyntaxContextId(InternId); pub struct SyntaxContextId(InternId);