@@ -34,14 +34,18 @@ pub fn split_input(
34
34
let ( part_mani, source, template, sub_prelude) = match input {
35
35
Input :: File ( _, _, content) => {
36
36
assert_eq ! ( prelude_items. len( ) , 0 ) ;
37
- let content = strip_shebang ( content) ;
37
+ let ( content, shebang_used ) = strip_shebang ( content) ;
38
38
let ( manifest, source) =
39
39
find_embedded_manifest ( content) . unwrap_or ( ( Manifest :: Toml ( "" ) , content) ) ;
40
40
41
41
let source = if contains_main_method ( source) {
42
- source. to_string ( )
42
+ if shebang_used {
43
+ format ! ( "//\n {}" , source)
44
+ } else {
45
+ source. to_string ( )
46
+ }
43
47
} else {
44
- format ! ( "fn main() -> Result<(), Box<dyn std::error::Error+Sync+Send>> {{\n {{\n {} }}\n Ok(())\n }}" , source)
48
+ format ! ( "fn main() -> Result<(), Box<dyn std::error::Error+Sync+Send>> {{ {{\n {} }}\n Ok(())\n }}" , source)
45
49
} ;
46
50
( manifest, source, consts:: FILE_TEMPLATE , false )
47
51
}
@@ -169,7 +173,8 @@ name = "n"
169
173
version = "0.1.0""# ,
170
174
STRIP_SECTION
171
175
) ,
172
- r#"fn main() {}"#
176
+ r#"//
177
+ fn main() {}"#
173
178
)
174
179
) ;
175
180
@@ -395,11 +400,11 @@ fn main() {}
395
400
/**
396
401
Returns a slice of the input string with the leading shebang, if there is one, omitted.
397
402
*/
398
- fn strip_shebang ( s : & str ) -> & str {
403
+ fn strip_shebang ( s : & str ) -> ( & str , bool ) {
399
404
let re_shebang: Regex = Regex :: new ( r"^#![^\[].*?(\r\n|\n)" ) . unwrap ( ) ;
400
405
match re_shebang. find ( s) {
401
- Some ( m) => & s[ m. end ( ) ..] ,
402
- None => s ,
406
+ Some ( m) => ( & s[ m. end ( ) ..] , true ) ,
407
+ None => ( s , false ) ,
403
408
}
404
409
}
405
410
0 commit comments