Skip to content

Commit f75aebe

Browse files
committed
Auto merge of rust-lang#18172 - lnicola:expect-attr-completions, r=davidbarsky
fix: Support expect in attribute completion and hover Fixes rust-lang#18171
2 parents fc58c94 + 26fdbf4 commit f75aebe

File tree

4 files changed

+52
-5
lines changed

4 files changed

+52
-5
lines changed

src/tools/rust-analyzer/crates/ide-completion/src/completions/attribute.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub(crate) fn complete_known_attribute_input(
5656
&parse_tt_as_comma_sep_paths(tt, ctx.edition)?,
5757
FEATURES,
5858
),
59-
"allow" | "warn" | "deny" | "forbid" => {
59+
"allow" | "expect" | "deny" | "forbid" | "warn" => {
6060
let existing_lints = parse_tt_as_comma_sep_paths(tt, ctx.edition)?;
6161

6262
let lints: Vec<Lint> = CLIPPY_LINT_GROUPS
@@ -222,7 +222,7 @@ macro_rules! attrs {
222222
[@ {} {$($tt:tt)*}] => { &[$($tt)*] as _ };
223223
// starting matcher
224224
[$($tt:tt),*] => {
225-
attrs!(@ { $($tt)* } { "allow", "cfg", "cfg_attr", "deny", "forbid", "warn" })
225+
attrs!(@ { $($tt)* } { "allow", "cfg", "cfg_attr", "deny", "expect", "forbid", "warn" })
226226
};
227227
}
228228

@@ -303,6 +303,7 @@ const ATTRIBUTES: &[AttrCompletion] = &[
303303
attr(r#"doc = "…""#, Some("doc"), Some(r#"doc = "${0:docs}""#)),
304304
attr(r#"doc(alias = "…")"#, Some("docalias"), Some(r#"doc(alias = "${0:docs}")"#)),
305305
attr(r#"doc(hidden)"#, Some("dochidden"), Some(r#"doc(hidden)"#)),
306+
attr("expect(…)", Some("expect"), Some("expect(${0:lint})")),
306307
attr(
307308
r#"export_name = "…""#,
308309
Some("export_name"),

src/tools/rust-analyzer/crates/ide-completion/src/tests/attribute.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ struct Foo;
2626
at doc = "…"
2727
at doc(alias = "…")
2828
at doc(hidden)
29+
at expect(…)
2930
at forbid(…)
3031
at must_use
3132
at no_mangle
@@ -75,6 +76,7 @@ fn with_existing_attr() {
7576
at cfg(…)
7677
at cfg_attr(…)
7778
at deny(…)
79+
at expect(…)
7880
at forbid(…)
7981
at warn(…)
8082
kw crate::
@@ -97,6 +99,7 @@ fn attr_on_source_file() {
9799
at doc = "…"
98100
at doc(alias = "…")
99101
at doc(hidden)
102+
at expect(…)
100103
at feature(…)
101104
at forbid(…)
102105
at must_use
@@ -127,6 +130,7 @@ fn attr_on_module() {
127130
at doc = "…"
128131
at doc(alias = "…")
129132
at doc(hidden)
133+
at expect(…)
130134
at forbid(…)
131135
at macro_use
132136
at must_use
@@ -149,6 +153,7 @@ fn attr_on_module() {
149153
at doc = "…"
150154
at doc(alias = "…")
151155
at doc(hidden)
156+
at expect(…)
152157
at forbid(…)
153158
at must_use
154159
at no_implicit_prelude
@@ -174,6 +179,7 @@ fn attr_on_macro_rules() {
174179
at doc = "…"
175180
at doc(alias = "…")
176181
at doc(hidden)
182+
at expect(…)
177183
at forbid(…)
178184
at macro_export
179185
at macro_use
@@ -199,6 +205,7 @@ fn attr_on_macro_def() {
199205
at doc = "…"
200206
at doc(alias = "…")
201207
at doc(hidden)
208+
at expect(…)
202209
at forbid(…)
203210
at must_use
204211
at no_mangle
@@ -222,6 +229,7 @@ fn attr_on_extern_crate() {
222229
at doc = "…"
223230
at doc(alias = "…")
224231
at doc(hidden)
232+
at expect(…)
225233
at forbid(…)
226234
at macro_use
227235
at must_use
@@ -246,6 +254,7 @@ fn attr_on_use() {
246254
at doc = "…"
247255
at doc(alias = "…")
248256
at doc(hidden)
257+
at expect(…)
249258
at forbid(…)
250259
at must_use
251260
at no_mangle
@@ -269,6 +278,7 @@ fn attr_on_type_alias() {
269278
at doc = "…"
270279
at doc(alias = "…")
271280
at doc(hidden)
281+
at expect(…)
272282
at forbid(…)
273283
at must_use
274284
at no_mangle
@@ -299,6 +309,7 @@ struct Foo;
299309
at doc = "…"
300310
at doc(alias = "…")
301311
at doc(hidden)
312+
at expect(…)
302313
at forbid(…)
303314
at must_use
304315
at no_mangle
@@ -326,6 +337,7 @@ fn attr_on_enum() {
326337
at doc = "…"
327338
at doc(alias = "…")
328339
at doc(hidden)
340+
at expect(…)
329341
at forbid(…)
330342
at must_use
331343
at no_mangle
@@ -351,6 +363,7 @@ fn attr_on_const() {
351363
at doc = "…"
352364
at doc(alias = "…")
353365
at doc(hidden)
366+
at expect(…)
354367
at forbid(…)
355368
at must_use
356369
at no_mangle
@@ -374,6 +387,7 @@ fn attr_on_static() {
374387
at doc = "…"
375388
at doc(alias = "…")
376389
at doc(hidden)
390+
at expect(…)
377391
at export_name = "…"
378392
at forbid(…)
379393
at global_allocator
@@ -402,6 +416,7 @@ fn attr_on_trait() {
402416
at doc = "…"
403417
at doc(alias = "…")
404418
at doc(hidden)
419+
at expect(…)
405420
at forbid(…)
406421
at must_use
407422
at must_use
@@ -427,6 +442,7 @@ fn attr_on_impl() {
427442
at doc = "…"
428443
at doc(alias = "…")
429444
at doc(hidden)
445+
at expect(…)
430446
at forbid(…)
431447
at must_use
432448
at no_mangle
@@ -446,6 +462,7 @@ fn attr_on_impl() {
446462
at doc = "…"
447463
at doc(alias = "…")
448464
at doc(hidden)
465+
at expect(…)
449466
at forbid(…)
450467
at must_use
451468
at no_mangle
@@ -469,6 +486,7 @@ fn attr_on_extern_block() {
469486
at doc = "…"
470487
at doc(alias = "…")
471488
at doc(hidden)
489+
at expect(…)
472490
at forbid(…)
473491
at link
474492
at must_use
@@ -489,6 +507,7 @@ fn attr_on_extern_block() {
489507
at doc = "…"
490508
at doc(alias = "…")
491509
at doc(hidden)
510+
at expect(…)
492511
at forbid(…)
493512
at link
494513
at must_use
@@ -509,6 +528,7 @@ fn attr_on_variant() {
509528
at cfg(…)
510529
at cfg_attr(…)
511530
at deny(…)
531+
at expect(…)
512532
at forbid(…)
513533
at non_exhaustive
514534
at warn(…)
@@ -532,6 +552,7 @@ fn attr_on_fn() {
532552
at doc = "…"
533553
at doc(alias = "…")
534554
at doc(hidden)
555+
at expect(…)
535556
at export_name = "…"
536557
at forbid(…)
537558
at ignore = "…"
@@ -572,6 +593,7 @@ fn attr_in_source_file_end() {
572593
at doc = "…"
573594
at doc(alias = "…")
574595
at doc(hidden)
596+
at expect(…)
575597
at export_name = "…"
576598
at forbid(…)
577599
at global_allocator

src/tools/rust-analyzer/crates/ide/src/hover/render.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ pub(super) fn try_for_lint(attr: &ast::Attr, token: &SyntaxToken) -> Option<Hove
329329
}
330330
let (is_clippy, lints) = match &*path {
331331
"feature" => (false, FEATURES),
332-
"allow" | "deny" | "forbid" | "warn" => {
332+
"allow" | "deny" | "expect" | "forbid" | "warn" => {
333333
let is_clippy = algo::non_trivia_sibling(token.clone().into(), Direction::Prev)
334334
.filter(|t| t.kind() == T![:])
335335
.and_then(|t| algo::non_trivia_sibling(t, Direction::Prev))

src/tools/rust-analyzer/crates/ide/src/hover/tests.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6336,7 +6336,19 @@ fn hover_lint() {
63366336
63376337
arithmetic operation overflows
63386338
"#]],
6339-
)
6339+
);
6340+
check(
6341+
r#"#![expect(arithmetic_overflow$0)]"#,
6342+
expect![[r#"
6343+
*arithmetic_overflow*
6344+
```
6345+
arithmetic_overflow
6346+
```
6347+
___
6348+
6349+
arithmetic operation overflows
6350+
"#]],
6351+
);
63406352
}
63416353

63426354
#[test]
@@ -6352,7 +6364,19 @@ fn hover_clippy_lint() {
63526364
63536365
Checks for `foo = bar; bar = foo` sequences.
63546366
"#]],
6355-
)
6367+
);
6368+
check(
6369+
r#"#![expect(clippy::almost_swapped$0)]"#,
6370+
expect![[r#"
6371+
*almost_swapped*
6372+
```
6373+
clippy::almost_swapped
6374+
```
6375+
___
6376+
6377+
Checks for `foo = bar; bar = foo` sequences.
6378+
"#]],
6379+
);
63566380
}
63576381

63586382
#[test]

0 commit comments

Comments
 (0)