Update RSPEC

This commit is contained in:
yassin-kammoun-sonarsource 2025-03-26 10:56:28 +01:00
parent 8415f8deec
commit 1b014dc06b
2 changed files with 19 additions and 32 deletions

View File

@ -1,12 +1,13 @@
{
"title": "FIXME",
"type": "CODE_SMELL",
"title": "Functions should not return mutable references from immutable parameters",
"type": "BUG",
"status": "ready",
"remediation": {
"func": "Constant\/Issue",
"constantCost": "5min"
},
"tags": [
"clippy"
],
"defaultSeverity": "Major",
"ruleSpecification": "RSPEC-7453",
@ -16,10 +17,8 @@
"quickfix": "unknown",
"code": {
"impacts": {
"MAINTAINABILITY": "HIGH",
"RELIABILITY": "MEDIUM",
"SECURITY": "LOW"
"RELIABILITY": "MEDIUM"
},
"attribute": "CONVENTIONAL"
"attribute": "LOGICAL"
}
}

View File

@ -1,16 +1,6 @@
FIXME: add a description
// If you want to factorize the description uncomment the following line and create the file.
//include::../description.adoc[]
== Why is this an issue?
FIXME: remove the unused optional headers (that are commented out)
//=== What is the potential impact?
== How to fix it
//== How to fix it in FRAMEWORK NAME
Creating a mutable reference from an immutable one is unsound because it can lead to multiple live mutable references to the same object, breaking Rust's guarantees of memory safety. Such patterns are particularly dangerous if unsafe code is present as it can lead to undefined behavior.
=== Code examples
@ -18,27 +8,25 @@ FIXME: remove the unused optional headers (that are commented out)
[source,rust,diff-id=1,diff-type=noncompliant]
----
FIXME
fn foo(x: &Foo) -> &mut Bar {
unsafe {
// Noncompliant: Converting immutable reference to mutable.
&mut *(x as *const Foo as *mut Foo).bar
}
}
----
==== Compliant solution
[source,rust,diff-id=1,diff-type=compliant]
----
FIXME
fn foo(x: &mut Foo) -> &mut Bar {
// Compliant: Taking a mutable reference and returning a mutable reference.
&mut x.bar
}
----
//=== How does this work?
== Resources
=== Documentation
//=== Pitfalls
//=== Going the extra mile
//== Resources
//=== Documentation
//=== Articles & blog posts
//=== Conference presentations
//=== Standards
//=== External coding guidelines
//=== Benchmarks
* Clippy Lints - https://rust-lang.github.io/rust-clippy/master/index.html#mut_from_ref