@@ -439,6 +439,7 @@ fn calculate_new_project_kind(
439
439
440
440
pub fn new ( opts : & NewOptions , config : & Config ) -> CargoResult < ( ) > {
441
441
let path = & opts. path ;
442
+ let name = get_name ( path, opts) ?;
442
443
443
444
if path. exists ( ) {
444
445
anyhow:: bail!(
@@ -451,7 +452,6 @@ pub fn new(opts: &NewOptions, config: &Config) -> CargoResult<()> {
451
452
452
453
let is_bin = opts. kind . is_bin ( ) ;
453
454
454
- let name = get_name ( path, opts) ?;
455
455
check_name ( name, opts. name . is_none ( ) , is_bin, & mut config. shell ( ) ) ?;
456
456
457
457
let mkopts = MkOptions {
@@ -480,18 +480,16 @@ pub fn init(opts: &NewOptions, config: &Config) -> CargoResult<NewProjectKind> {
480
480
}
481
481
482
482
let path = & opts. path ;
483
+ let name = get_name ( path, opts) ?;
484
+ let mut src_paths_types = vec ! [ ] ;
485
+ detect_source_paths_and_types ( path, name, & mut src_paths_types) ?;
486
+ let kind = calculate_new_project_kind ( opts. kind , opts. auto_detect_kind , & src_paths_types) ;
483
487
484
488
if path. join ( "Cargo.toml" ) . exists ( ) {
485
489
anyhow:: bail!( "`cargo init` cannot be run on existing Cargo packages" )
486
490
}
487
491
check_path ( path, & mut config. shell ( ) ) ?;
488
492
489
- let name = get_name ( path, opts) ?;
490
-
491
- let mut src_paths_types = vec ! [ ] ;
492
- detect_source_paths_and_types ( path, name, & mut src_paths_types) ?;
493
-
494
- let kind = calculate_new_project_kind ( opts. kind , opts. auto_detect_kind , & src_paths_types) ;
495
493
let has_bin = kind. is_bin ( ) ;
496
494
497
495
if src_paths_types. is_empty ( ) {
0 commit comments