File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ impl Analyzer<'_> {
3232 fn run ( & mut self ) {
3333 self . check_file_mode_present ( ) ;
3434 self . check_single_file_mode ( ) ;
35+ self . check_removed_profile_declarations ( ) ;
3536 self . check_duplicate_declarations ( ) ;
3637 self . check_signature_explicitness ( ) ;
3738 self . check_resource_fields ( ) ;
@@ -81,6 +82,25 @@ impl Analyzer<'_> {
8182 }
8283 }
8384
85+ fn check_removed_profile_declarations ( & mut self ) {
86+ for span in & self . syntax_program . profile_spans {
87+ self . diagnostics . push (
88+ Diagnostic :: error (
89+ code:: REMOVED_PROFILE_DECLARATION ,
90+ "`profile:` declarations were removed in RSScript v0.4.1." ,
91+ span. clone ( ) ,
92+ "removed profile declaration" ,
93+ )
94+ . with_cause ( "v0.4.1 has one canonical surface style and only `mode:` as the top-level semantic file declaration." )
95+ . with_fix (
96+ "remove_profile" ,
97+ "Remove `profile:` and keep exactly one `mode: managed` or `mode: uses-local` declaration." ,
98+ "manual" ,
99+ ) ,
100+ ) ;
101+ }
102+ }
103+
84104 fn check_signature_explicitness ( & mut self ) {
85105 for item in & self . syntax_program . items {
86106 let Item :: Function ( function) = item else {
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ pub mod code {
1010 pub const UNKNOWN_RETAINED_PARAMETER : & str = "RS0007" ;
1111 pub const MISSING_PARAMETER_EFFECT : & str = "RS0008" ;
1212 pub const INVALID_PURE_EFFECT : & str = "RS0009" ;
13+ pub const REMOVED_PROFILE_DECLARATION : & str = "RS0010" ;
1314 pub const FILE_MODE_VIOLATION : & str = "RS0101" ;
1415 pub const UNNAMED_ARGUMENT : & str = "RS0201" ;
1516 pub const MISSING_DATA_EFFECT : & str = "RS0202" ;
@@ -243,6 +244,11 @@ static DIAGNOSTIC_EXPLANATIONS: &[DiagnosticExplanation] = &[
243244 title : "invalid pure effect" ,
244245 explanation : "`effects(pure)` is a guarantee that the function does not mutate reachable managed state and does not retain parameters." ,
245246 } ,
247+ DiagnosticExplanation {
248+ code : code:: REMOVED_PROFILE_DECLARATION ,
249+ title : "removed profile declaration" ,
250+ explanation : "RSScript v0.4.1 removed `profile:` declarations. The only top-level semantic file declaration is `mode:`." ,
251+ } ,
246252 DiagnosticExplanation {
247253 code : code:: FILE_MODE_VIOLATION ,
248254 title : "file mode violation" ,
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ pub enum FileMode {
1010pub struct Program {
1111 pub mode : Option < FileMode > ,
1212 pub mode_spans : Vec < Span > ,
13+ pub profile_spans : Vec < Span > ,
1314 pub items : Vec < Item > ,
1415}
1516
Original file line number Diff line number Diff line change @@ -23,12 +23,16 @@ impl Parser<'_> {
2323 fn parse_program ( & mut self ) -> Program {
2424 let mut mode = None ;
2525 let mut mode_spans = Vec :: new ( ) ;
26+ let mut profile_spans = Vec :: new ( ) ;
2627 let mut items = Vec :: new ( ) ;
2728
2829 while !self . is_eof ( ) {
2930 if self . at_ident ( "mode" ) && self . peek_symbol ( 1 , ":" ) {
3031 mode_spans. push ( self . tokens [ self . index ] . span . clone ( ) ) ;
3132 mode = self . parse_mode ( ) ;
33+ } else if self . at_ident ( "profile" ) && self . peek_symbol ( 1 , ":" ) {
34+ profile_spans. push ( self . tokens [ self . index ] . span . clone ( ) ) ;
35+ self . index += 1 ;
3236 } else if self . at_ident ( "class" ) || self . at_ident ( "struct" ) || self . at_ident ( "resource" )
3337 {
3438 if let Some ( item) = self . parse_type_decl ( ) {
@@ -46,6 +50,7 @@ impl Parser<'_> {
4650 Program {
4751 mode,
4852 mode_spans,
53+ profile_spans,
4954 items,
5055 }
5156 }
Original file line number Diff line number Diff line change 1+ // expect: RS0010
2+ mode: managed
3+ profile: review
4+
5+ fn main() -> Unit {
6+ return Unit
7+ }
Original file line number Diff line number Diff line change 1+ mode: managed
2+
3+ struct Settings {
4+ profile: String
5+ }
6+
7+ fn load_settings() -> Settings {
8+ return Settings(profile: "review")
9+ }
You can’t perform that action at this time.
0 commit comments