Skip to content

Commit 93d60d7

Browse files
committed
Reject removed share parameter effect
1 parent e0df925 commit 93d60d7

3 files changed

Lines changed: 43 additions & 1 deletion

File tree

src/analyzer.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,33 @@ impl Analyzer<'_> {
138138
),
139139
);
140140
}
141-
if param.effect.is_none() && !param.ty.name.is_empty() && !is_copy_type(&param.ty) {
141+
if param.effect.is_none() && param.ty.name == "share" {
142+
self.diagnostics.push(
143+
Diagnostic::error(
144+
code::REMOVED_SHARE_EFFECT,
145+
format!(
146+
"parameter `{}` in `{}` uses removed `share` data effect.",
147+
param.name, function.name
148+
),
149+
param.ty.span.clone(),
150+
"removed share data effect",
151+
)
152+
.with_cause("RSScript v0.4.1 has exactly three data effects: `read`, `mut`, and `take`.")
153+
.with_fix(
154+
"replace_share_effect",
155+
format!(
156+
"Use `{}: read T` and add `effects(retains({}))` if the function retains it.",
157+
param.name, param.name
158+
),
159+
"manual",
160+
),
161+
);
162+
}
163+
if param.effect.is_none()
164+
&& !param.ty.name.is_empty()
165+
&& param.ty.name != "share"
166+
&& !is_copy_type(&param.ty)
167+
{
142168
self.diagnostics.push(
143169
Diagnostic::error(
144170
code::MISSING_PARAMETER_EFFECT,

src/diagnostic.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub mod code {
1111
pub const MISSING_PARAMETER_EFFECT: &str = "RS0008";
1212
pub const INVALID_PURE_EFFECT: &str = "RS0009";
1313
pub const REMOVED_PROFILE_DECLARATION: &str = "RS0010";
14+
pub const REMOVED_SHARE_EFFECT: &str = "RS0011";
1415
pub const FILE_MODE_VIOLATION: &str = "RS0101";
1516
pub const UNNAMED_ARGUMENT: &str = "RS0201";
1617
pub const MISSING_DATA_EFFECT: &str = "RS0202";
@@ -249,6 +250,11 @@ static DIAGNOSTIC_EXPLANATIONS: &[DiagnosticExplanation] = &[
249250
title: "removed profile declaration",
250251
explanation: "RSScript v0.4.1 removed `profile:` declarations. The only top-level semantic file declaration is `mode:`.",
251252
},
253+
DiagnosticExplanation {
254+
code: code::REMOVED_SHARE_EFFECT,
255+
title: "removed share data effect",
256+
explanation: "RSScript v0.4.1 removed `share` as a data effect. Retention must be declared with `effects(retains(param))`.",
257+
},
252258
DiagnosticExplanation {
253259
code: code::FILE_MODE_VIOLATION,
254260
title: "file mode violation",
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// expect: RS0011
2+
mode: managed
3+
4+
struct Image {
5+
pixels: Buffer
6+
}
7+
8+
fn cache_put(value: share Image) -> Unit {
9+
return Unit
10+
}

0 commit comments

Comments
 (0)