mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
Support expect in attribute completion and hover
This commit is contained in:
parent
b3a3bf770a
commit
a6572e9234
4 changed files with 52 additions and 5 deletions
|
@ -56,7 +56,7 @@ pub(crate) fn complete_known_attribute_input(
|
||||||
&parse_tt_as_comma_sep_paths(tt, ctx.edition)?,
|
&parse_tt_as_comma_sep_paths(tt, ctx.edition)?,
|
||||||
FEATURES,
|
FEATURES,
|
||||||
),
|
),
|
||||||
"allow" | "warn" | "deny" | "forbid" => {
|
"allow" | "expect" | "deny" | "forbid" | "warn" => {
|
||||||
let existing_lints = parse_tt_as_comma_sep_paths(tt, ctx.edition)?;
|
let existing_lints = parse_tt_as_comma_sep_paths(tt, ctx.edition)?;
|
||||||
|
|
||||||
let lints: Vec<Lint> = CLIPPY_LINT_GROUPS
|
let lints: Vec<Lint> = CLIPPY_LINT_GROUPS
|
||||||
|
@ -222,7 +222,7 @@ macro_rules! attrs {
|
||||||
[@ {} {$($tt:tt)*}] => { &[$($tt)*] as _ };
|
[@ {} {$($tt:tt)*}] => { &[$($tt)*] as _ };
|
||||||
// starting matcher
|
// starting matcher
|
||||||
[$($tt:tt),*] => {
|
[$($tt:tt),*] => {
|
||||||
attrs!(@ { $($tt)* } { "allow", "cfg", "cfg_attr", "deny", "forbid", "warn" })
|
attrs!(@ { $($tt)* } { "allow", "cfg", "cfg_attr", "deny", "expect", "forbid", "warn" })
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,6 +303,7 @@ const ATTRIBUTES: &[AttrCompletion] = &[
|
||||||
attr(r#"doc = "…""#, Some("doc"), Some(r#"doc = "${0:docs}""#)),
|
attr(r#"doc = "…""#, Some("doc"), Some(r#"doc = "${0:docs}""#)),
|
||||||
attr(r#"doc(alias = "…")"#, Some("docalias"), Some(r#"doc(alias = "${0:docs}")"#)),
|
attr(r#"doc(alias = "…")"#, Some("docalias"), Some(r#"doc(alias = "${0:docs}")"#)),
|
||||||
attr(r#"doc(hidden)"#, Some("dochidden"), Some(r#"doc(hidden)"#)),
|
attr(r#"doc(hidden)"#, Some("dochidden"), Some(r#"doc(hidden)"#)),
|
||||||
|
attr("expect(…)", Some("expect"), Some("expect(${0:lint})")),
|
||||||
attr(
|
attr(
|
||||||
r#"export_name = "…""#,
|
r#"export_name = "…""#,
|
||||||
Some("export_name"),
|
Some("export_name"),
|
||||||
|
|
|
@ -26,6 +26,7 @@ struct Foo;
|
||||||
at doc = "…"
|
at doc = "…"
|
||||||
at doc(alias = "…")
|
at doc(alias = "…")
|
||||||
at doc(hidden)
|
at doc(hidden)
|
||||||
|
at expect(…)
|
||||||
at forbid(…)
|
at forbid(…)
|
||||||
at must_use
|
at must_use
|
||||||
at no_mangle
|
at no_mangle
|
||||||
|
@ -75,6 +76,7 @@ fn with_existing_attr() {
|
||||||
at cfg(…)
|
at cfg(…)
|
||||||
at cfg_attr(…)
|
at cfg_attr(…)
|
||||||
at deny(…)
|
at deny(…)
|
||||||
|
at expect(…)
|
||||||
at forbid(…)
|
at forbid(…)
|
||||||
at warn(…)
|
at warn(…)
|
||||||
kw crate::
|
kw crate::
|
||||||
|
@ -97,6 +99,7 @@ fn attr_on_source_file() {
|
||||||
at doc = "…"
|
at doc = "…"
|
||||||
at doc(alias = "…")
|
at doc(alias = "…")
|
||||||
at doc(hidden)
|
at doc(hidden)
|
||||||
|
at expect(…)
|
||||||
at feature(…)
|
at feature(…)
|
||||||
at forbid(…)
|
at forbid(…)
|
||||||
at must_use
|
at must_use
|
||||||
|
@ -127,6 +130,7 @@ fn attr_on_module() {
|
||||||
at doc = "…"
|
at doc = "…"
|
||||||
at doc(alias = "…")
|
at doc(alias = "…")
|
||||||
at doc(hidden)
|
at doc(hidden)
|
||||||
|
at expect(…)
|
||||||
at forbid(…)
|
at forbid(…)
|
||||||
at macro_use
|
at macro_use
|
||||||
at must_use
|
at must_use
|
||||||
|
@ -149,6 +153,7 @@ fn attr_on_module() {
|
||||||
at doc = "…"
|
at doc = "…"
|
||||||
at doc(alias = "…")
|
at doc(alias = "…")
|
||||||
at doc(hidden)
|
at doc(hidden)
|
||||||
|
at expect(…)
|
||||||
at forbid(…)
|
at forbid(…)
|
||||||
at must_use
|
at must_use
|
||||||
at no_implicit_prelude
|
at no_implicit_prelude
|
||||||
|
@ -174,6 +179,7 @@ fn attr_on_macro_rules() {
|
||||||
at doc = "…"
|
at doc = "…"
|
||||||
at doc(alias = "…")
|
at doc(alias = "…")
|
||||||
at doc(hidden)
|
at doc(hidden)
|
||||||
|
at expect(…)
|
||||||
at forbid(…)
|
at forbid(…)
|
||||||
at macro_export
|
at macro_export
|
||||||
at macro_use
|
at macro_use
|
||||||
|
@ -199,6 +205,7 @@ fn attr_on_macro_def() {
|
||||||
at doc = "…"
|
at doc = "…"
|
||||||
at doc(alias = "…")
|
at doc(alias = "…")
|
||||||
at doc(hidden)
|
at doc(hidden)
|
||||||
|
at expect(…)
|
||||||
at forbid(…)
|
at forbid(…)
|
||||||
at must_use
|
at must_use
|
||||||
at no_mangle
|
at no_mangle
|
||||||
|
@ -222,6 +229,7 @@ fn attr_on_extern_crate() {
|
||||||
at doc = "…"
|
at doc = "…"
|
||||||
at doc(alias = "…")
|
at doc(alias = "…")
|
||||||
at doc(hidden)
|
at doc(hidden)
|
||||||
|
at expect(…)
|
||||||
at forbid(…)
|
at forbid(…)
|
||||||
at macro_use
|
at macro_use
|
||||||
at must_use
|
at must_use
|
||||||
|
@ -246,6 +254,7 @@ fn attr_on_use() {
|
||||||
at doc = "…"
|
at doc = "…"
|
||||||
at doc(alias = "…")
|
at doc(alias = "…")
|
||||||
at doc(hidden)
|
at doc(hidden)
|
||||||
|
at expect(…)
|
||||||
at forbid(…)
|
at forbid(…)
|
||||||
at must_use
|
at must_use
|
||||||
at no_mangle
|
at no_mangle
|
||||||
|
@ -269,6 +278,7 @@ fn attr_on_type_alias() {
|
||||||
at doc = "…"
|
at doc = "…"
|
||||||
at doc(alias = "…")
|
at doc(alias = "…")
|
||||||
at doc(hidden)
|
at doc(hidden)
|
||||||
|
at expect(…)
|
||||||
at forbid(…)
|
at forbid(…)
|
||||||
at must_use
|
at must_use
|
||||||
at no_mangle
|
at no_mangle
|
||||||
|
@ -299,6 +309,7 @@ struct Foo;
|
||||||
at doc = "…"
|
at doc = "…"
|
||||||
at doc(alias = "…")
|
at doc(alias = "…")
|
||||||
at doc(hidden)
|
at doc(hidden)
|
||||||
|
at expect(…)
|
||||||
at forbid(…)
|
at forbid(…)
|
||||||
at must_use
|
at must_use
|
||||||
at no_mangle
|
at no_mangle
|
||||||
|
@ -326,6 +337,7 @@ fn attr_on_enum() {
|
||||||
at doc = "…"
|
at doc = "…"
|
||||||
at doc(alias = "…")
|
at doc(alias = "…")
|
||||||
at doc(hidden)
|
at doc(hidden)
|
||||||
|
at expect(…)
|
||||||
at forbid(…)
|
at forbid(…)
|
||||||
at must_use
|
at must_use
|
||||||
at no_mangle
|
at no_mangle
|
||||||
|
@ -351,6 +363,7 @@ fn attr_on_const() {
|
||||||
at doc = "…"
|
at doc = "…"
|
||||||
at doc(alias = "…")
|
at doc(alias = "…")
|
||||||
at doc(hidden)
|
at doc(hidden)
|
||||||
|
at expect(…)
|
||||||
at forbid(…)
|
at forbid(…)
|
||||||
at must_use
|
at must_use
|
||||||
at no_mangle
|
at no_mangle
|
||||||
|
@ -374,6 +387,7 @@ fn attr_on_static() {
|
||||||
at doc = "…"
|
at doc = "…"
|
||||||
at doc(alias = "…")
|
at doc(alias = "…")
|
||||||
at doc(hidden)
|
at doc(hidden)
|
||||||
|
at expect(…)
|
||||||
at export_name = "…"
|
at export_name = "…"
|
||||||
at forbid(…)
|
at forbid(…)
|
||||||
at global_allocator
|
at global_allocator
|
||||||
|
@ -402,6 +416,7 @@ fn attr_on_trait() {
|
||||||
at doc = "…"
|
at doc = "…"
|
||||||
at doc(alias = "…")
|
at doc(alias = "…")
|
||||||
at doc(hidden)
|
at doc(hidden)
|
||||||
|
at expect(…)
|
||||||
at forbid(…)
|
at forbid(…)
|
||||||
at must_use
|
at must_use
|
||||||
at must_use
|
at must_use
|
||||||
|
@ -427,6 +442,7 @@ fn attr_on_impl() {
|
||||||
at doc = "…"
|
at doc = "…"
|
||||||
at doc(alias = "…")
|
at doc(alias = "…")
|
||||||
at doc(hidden)
|
at doc(hidden)
|
||||||
|
at expect(…)
|
||||||
at forbid(…)
|
at forbid(…)
|
||||||
at must_use
|
at must_use
|
||||||
at no_mangle
|
at no_mangle
|
||||||
|
@ -446,6 +462,7 @@ fn attr_on_impl() {
|
||||||
at doc = "…"
|
at doc = "…"
|
||||||
at doc(alias = "…")
|
at doc(alias = "…")
|
||||||
at doc(hidden)
|
at doc(hidden)
|
||||||
|
at expect(…)
|
||||||
at forbid(…)
|
at forbid(…)
|
||||||
at must_use
|
at must_use
|
||||||
at no_mangle
|
at no_mangle
|
||||||
|
@ -469,6 +486,7 @@ fn attr_on_extern_block() {
|
||||||
at doc = "…"
|
at doc = "…"
|
||||||
at doc(alias = "…")
|
at doc(alias = "…")
|
||||||
at doc(hidden)
|
at doc(hidden)
|
||||||
|
at expect(…)
|
||||||
at forbid(…)
|
at forbid(…)
|
||||||
at link
|
at link
|
||||||
at must_use
|
at must_use
|
||||||
|
@ -489,6 +507,7 @@ fn attr_on_extern_block() {
|
||||||
at doc = "…"
|
at doc = "…"
|
||||||
at doc(alias = "…")
|
at doc(alias = "…")
|
||||||
at doc(hidden)
|
at doc(hidden)
|
||||||
|
at expect(…)
|
||||||
at forbid(…)
|
at forbid(…)
|
||||||
at link
|
at link
|
||||||
at must_use
|
at must_use
|
||||||
|
@ -509,6 +528,7 @@ fn attr_on_variant() {
|
||||||
at cfg(…)
|
at cfg(…)
|
||||||
at cfg_attr(…)
|
at cfg_attr(…)
|
||||||
at deny(…)
|
at deny(…)
|
||||||
|
at expect(…)
|
||||||
at forbid(…)
|
at forbid(…)
|
||||||
at non_exhaustive
|
at non_exhaustive
|
||||||
at warn(…)
|
at warn(…)
|
||||||
|
@ -532,6 +552,7 @@ fn attr_on_fn() {
|
||||||
at doc = "…"
|
at doc = "…"
|
||||||
at doc(alias = "…")
|
at doc(alias = "…")
|
||||||
at doc(hidden)
|
at doc(hidden)
|
||||||
|
at expect(…)
|
||||||
at export_name = "…"
|
at export_name = "…"
|
||||||
at forbid(…)
|
at forbid(…)
|
||||||
at ignore = "…"
|
at ignore = "…"
|
||||||
|
@ -572,6 +593,7 @@ fn attr_in_source_file_end() {
|
||||||
at doc = "…"
|
at doc = "…"
|
||||||
at doc(alias = "…")
|
at doc(alias = "…")
|
||||||
at doc(hidden)
|
at doc(hidden)
|
||||||
|
at expect(…)
|
||||||
at export_name = "…"
|
at export_name = "…"
|
||||||
at forbid(…)
|
at forbid(…)
|
||||||
at global_allocator
|
at global_allocator
|
||||||
|
|
|
@ -329,7 +329,7 @@ pub(super) fn try_for_lint(attr: &ast::Attr, token: &SyntaxToken) -> Option<Hove
|
||||||
}
|
}
|
||||||
let (is_clippy, lints) = match &*path {
|
let (is_clippy, lints) = match &*path {
|
||||||
"feature" => (false, FEATURES),
|
"feature" => (false, FEATURES),
|
||||||
"allow" | "deny" | "forbid" | "warn" => {
|
"allow" | "deny" | "expect" | "forbid" | "warn" => {
|
||||||
let is_clippy = algo::non_trivia_sibling(token.clone().into(), Direction::Prev)
|
let is_clippy = algo::non_trivia_sibling(token.clone().into(), Direction::Prev)
|
||||||
.filter(|t| t.kind() == T![:])
|
.filter(|t| t.kind() == T![:])
|
||||||
.and_then(|t| algo::non_trivia_sibling(t, Direction::Prev))
|
.and_then(|t| algo::non_trivia_sibling(t, Direction::Prev))
|
||||||
|
|
|
@ -6336,7 +6336,19 @@ fn hover_lint() {
|
||||||
|
|
||||||
arithmetic operation overflows
|
arithmetic operation overflows
|
||||||
"#]],
|
"#]],
|
||||||
)
|
);
|
||||||
|
check(
|
||||||
|
r#"#![expect(arithmetic_overflow$0)]"#,
|
||||||
|
expect![[r#"
|
||||||
|
*arithmetic_overflow*
|
||||||
|
```
|
||||||
|
arithmetic_overflow
|
||||||
|
```
|
||||||
|
___
|
||||||
|
|
||||||
|
arithmetic operation overflows
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -6352,7 +6364,19 @@ fn hover_clippy_lint() {
|
||||||
|
|
||||||
Checks for `foo = bar; bar = foo` sequences.
|
Checks for `foo = bar; bar = foo` sequences.
|
||||||
"#]],
|
"#]],
|
||||||
)
|
);
|
||||||
|
check(
|
||||||
|
r#"#![expect(clippy::almost_swapped$0)]"#,
|
||||||
|
expect![[r#"
|
||||||
|
*almost_swapped*
|
||||||
|
```
|
||||||
|
clippy::almost_swapped
|
||||||
|
```
|
||||||
|
___
|
||||||
|
|
||||||
|
Checks for `foo = bar; bar = foo` sequences.
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue