Create rule S7449 The #[inline] attribute should not be used on trait methods without implementation (#4793)

* Create rule S7449

* Update metadata.json

* Update rule.adoc

* Update rule.adoc

* Update rule.adoc

* Update metadata.json

---------

Co-authored-by: sallaigy <sallaigy@users.noreply.github.com>
Co-authored-by: Gyula Sallai <gyula.sallai@sonarsource.com>
This commit is contained in:
github-actions[bot] 2025-03-19 14:10:41 +00:00 committed by GitHub
parent 70168e8e61
commit d4cbb1c40b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 55 additions and 0 deletions

View File

@ -0,0 +1,2 @@
{
}

View File

@ -0,0 +1,24 @@
{
"title": "The `#[inline]` attribute should not be used on trait methods without implementation",
"type": "BUG",
"status": "ready",
"remediation": {
"func": "Constant\/Issue",
"constantCost": "5min"
},
"tags": [
"clippy"
],
"defaultSeverity": "Critical",
"ruleSpecification": "RSPEC-7449",
"sqKey": "S7449",
"scope": "All",
"defaultQualityProfiles": ["Sonar way"],
"quickfix": "unknown",
"code": {
"impacts": {
"RELIABILITY": "HIGH"
},
"attribute": "LOGICAL"
}
}

View File

@ -0,0 +1,29 @@
== Why is this an issue?
Applying the `#[inline]` attribute to trait methods without provided implementations is pointless because only method implementations can be inlined. The attribute is therefore ignored in such cases, leading to unnecessary code complexity.
=== Code examples
==== Noncompliant code example
[source,rust,diff-id=1,diff-type=noncompliant]
----
trait Animal {
#[inline] // Noncompliant: Inline attribute on trait method without implementation.
fn name(&self) -> &'static str;
}
----
==== Compliant solution
[source,rust,diff-id=1,diff-type=compliant]
----
trait Animal {
fn name(&self) -> &'static str;
}
----
== Resources
=== Documentation
* Clippy Lints - https://rust-lang.github.io/rust-clippy/master/index.html#inline_fn_without_body