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:
parent
70168e8e61
commit
d4cbb1c40b
2
rules/S7449/metadata.json
Normal file
2
rules/S7449/metadata.json
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
{
|
||||||
|
}
|
24
rules/S7449/rust/metadata.json
Normal file
24
rules/S7449/rust/metadata.json
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
29
rules/S7449/rust/rule.adoc
Normal file
29
rules/S7449/rust/rule.adoc
Normal 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
|
Loading…
x
Reference in New Issue
Block a user