Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 37a8493

Browse files
committed
tests
1 parent 008b639 commit 37a8493

File tree

3 files changed

+46
-12
lines changed

3 files changed

+46
-12
lines changed

crates/hir-def/src/item_tree/pretty.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub(super) fn print_item_tree(db: &dyn ExpandDatabase, tree: &ItemTree) -> Strin
1616
let mut p = Printer { db, tree, buf: String::new(), indent_level: 0, needs_indent: true };
1717

1818
if let Some(attrs) = tree.attrs.get(&AttrOwner::TopLevel) {
19-
p.print_attrs(attrs, true);
19+
p.print_attrs(attrs, true, "\n");
2020
}
2121
p.blank();
2222

@@ -84,22 +84,23 @@ impl Printer<'_> {
8484
}
8585
}
8686

87-
fn print_attrs(&mut self, attrs: &RawAttrs, inner: bool) {
87+
fn print_attrs(&mut self, attrs: &RawAttrs, inner: bool, separated_by: &str) {
8888
let inner = if inner { "!" } else { "" };
8989
for attr in &**attrs {
90-
wln!(
90+
w!(
9191
self,
92-
"#{}[{}{}]",
92+
"#{}[{}{}]{}",
9393
inner,
9494
attr.path.display(self.db),
9595
attr.input.as_ref().map(|it| it.to_string()).unwrap_or_default(),
96+
separated_by,
9697
);
9798
}
9899
}
99100

100-
fn print_attrs_of(&mut self, of: impl Into<AttrOwner>) {
101+
fn print_attrs_of(&mut self, of: impl Into<AttrOwner>, separated_by: &str) {
101102
if let Some(attrs) = self.tree.attrs.get(&of.into()) {
102-
self.print_attrs(attrs, false);
103+
self.print_attrs(attrs, false, separated_by);
103104
}
104105
}
105106

@@ -118,7 +119,7 @@ impl Printer<'_> {
118119
self.indented(|this| {
119120
for field in fields.clone() {
120121
let Field { visibility, name, type_ref, ast_id: _ } = &this.tree[field];
121-
this.print_attrs_of(field);
122+
this.print_attrs_of(field, "\n");
122123
this.print_visibility(*visibility);
123124
w!(this, "{}: ", name.display(self.db));
124125
this.print_type_ref(type_ref);
@@ -132,7 +133,7 @@ impl Printer<'_> {
132133
self.indented(|this| {
133134
for field in fields.clone() {
134135
let Field { visibility, name, type_ref, ast_id: _ } = &this.tree[field];
135-
this.print_attrs_of(field);
136+
this.print_attrs_of(field, "\n");
136137
this.print_visibility(*visibility);
137138
w!(this, "{}: ", name.display(self.db));
138139
this.print_type_ref(type_ref);
@@ -195,7 +196,7 @@ impl Printer<'_> {
195196
}
196197

197198
fn print_mod_item(&mut self, item: ModItem) {
198-
self.print_attrs_of(item);
199+
self.print_attrs_of(item, "\n");
199200

200201
match item {
201202
ModItem::Import(it) => {
@@ -261,7 +262,7 @@ impl Printer<'_> {
261262
if !params.is_empty() {
262263
self.indented(|this| {
263264
for param in params.clone() {
264-
this.print_attrs_of(param);
265+
this.print_attrs_of(param, "\n");
265266
match &this.tree[param] {
266267
Param::Normal(ty) => {
267268
if flags.contains(FnFlags::HAS_SELF_PARAM) {
@@ -319,7 +320,7 @@ impl Printer<'_> {
319320
self.indented(|this| {
320321
for variant in variants.clone() {
321322
let Variant { name, fields, ast_id: _ } = &this.tree[variant];
322-
this.print_attrs_of(variant);
323+
this.print_attrs_of(variant, "\n");
323324
w!(this, "{}", name.display(self.db));
324325
this.print_fields(fields);
325326
wln!(this, ",");
@@ -484,18 +485,20 @@ impl Printer<'_> {
484485

485486
w!(self, "<");
486487
let mut first = true;
487-
for (_, lt) in params.lifetimes.iter() {
488+
for (idx, lt) in params.lifetimes.iter() {
488489
if !first {
489490
w!(self, ", ");
490491
}
491492
first = false;
493+
self.print_attrs_of(idx, " ");
492494
w!(self, "{}", lt.name.display(self.db));
493495
}
494496
for (idx, x) in params.type_or_consts.iter() {
495497
if !first {
496498
w!(self, ", ");
497499
}
498500
first = false;
501+
self.print_attrs_of(idx, " ");
499502
match x {
500503
TypeOrConstParamData::TypeParamData(ty) => match &ty.name {
501504
Some(name) => w!(self, "{}", name.display(self.db)),

crates/hir-def/src/item_tree/tests.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,3 +358,15 @@ trait Tr<'a, T: 'a>: Super where Self: for<'a> Tr<'a, T> {}
358358
"#]],
359359
)
360360
}
361+
362+
#[test]
363+
fn generics_with_attributes() {
364+
check(
365+
r#"
366+
struct S<#[cfg(never)] T>;
367+
"#,
368+
expect![[r#"
369+
pub(self) struct S<#[cfg(never)] T>;
370+
"#]],
371+
)
372+
}

crates/ide/src/hover/tests.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6451,3 +6451,22 @@ fn test() {
64516451
"#]],
64526452
);
64536453
}
6454+
6455+
#[test]
6456+
fn generic_params_disabled_by_cfg() {
6457+
check(
6458+
r#"
6459+
struct S<#[cfg(never)] T>;
6460+
fn test() {
6461+
let s$0: S = S;
6462+
}
6463+
"#,
6464+
expect![[r#"
6465+
*s*
6466+
6467+
```rust
6468+
let s: S // size = 0, align = 1
6469+
```
6470+
"#]],
6471+
);
6472+
}

0 commit comments

Comments
 (0)