@@ -558,12 +558,19 @@ Run `{cmd}` to see possible targets."
558558
559559 fn get_profile_name (
560560 & self ,
561- gctx : & GlobalContext ,
562561 default : & str ,
563562 profile_checking : ProfileChecking ,
564563 ) -> CargoResult < InternedString > {
565564 let specified_profile = self . _value_of ( "profile" ) ;
566565
566+ let err_message = |flag : & str | {
567+ format ! (
568+ "\
569+ the `--{flag}` flag can not be specified with the `--profile` flag
570+ Please remove one of the flags."
571+ )
572+ } ;
573+
567574 // Check for allowed legacy names.
568575 // This is an early exit, since it allows combination with `--release`.
569576 match ( specified_profile, profile_checking) {
@@ -572,39 +579,23 @@ Run `{cmd}` to see possible targets."
572579 // `cargo fix` and `cargo check` has legacy handling of this profile name
573580 | ( Some ( name @ "test" ) , ProfileChecking :: LegacyTestOnly ) => {
574581 if self . maybe_flag ( "release" ) {
575- gctx. shell ( ) . warn (
576- "the `--release` flag should not be specified with the `--profile` flag\n \
577- The `--release` flag will be ignored.\n \
578- This was historically accepted, but will become an error \
579- in a future release."
580- ) ?;
582+ bail ! ( err_message( "release" ) ) ;
581583 }
582584 return Ok ( InternedString :: new ( name) ) ;
583585 }
584586 _ => { }
585587 }
586588
587- let conflict = |flag : & str , equiv : & str , specified : & str | -> anyhow:: Error {
588- anyhow:: format_err!(
589- "conflicting usage of --profile={} and --{flag}\n \
590- The `--{flag}` flag is the same as `--profile={equiv}`.\n \
591- Remove one flag or the other to continue.",
592- specified,
593- flag = flag,
594- equiv = equiv
595- )
596- } ;
597-
598589 let name = match (
599590 self . maybe_flag ( "release" ) ,
600591 self . maybe_flag ( "debug" ) ,
601592 specified_profile,
602593 ) {
603594 ( false , false , None ) => default,
604- ( true , _, None | Some ( "release" ) ) => "release" ,
605- ( true , _, Some ( name ) ) => return Err ( conflict ( "release" , "release" , name ) ) ,
606- ( _, true , None | Some ( "dev" ) ) => "dev" ,
607- ( _, true , Some ( name ) ) => return Err ( conflict ( "debug" , "dev" , name ) ) ,
595+ ( true , _, None ) => "release" ,
596+ ( true , _, Some ( _ ) ) => bail ! ( err_message ( "release" ) ) ,
597+ ( _, true , None ) => "dev" ,
598+ ( _, true , Some ( _ ) ) => bail ! ( err_message ( "debug" ) ) ,
608599 // `doc` is separate from all the other reservations because
609600 // [profile.doc] was historically allowed, but is deprecated and
610601 // has no effect. To avoid potentially breaking projects, it is a
@@ -710,7 +701,7 @@ Run `{cmd}` to see possible targets."
710701 mode,
711702 ) ?;
712703 build_config. message_format = message_format. unwrap_or ( MessageFormat :: Human ) ;
713- build_config. requested_profile = self . get_profile_name ( gctx , "dev" , profile_checking) ?;
704+ build_config. requested_profile = self . get_profile_name ( "dev" , profile_checking) ?;
714705 build_config. build_plan = self . flag ( "build-plan" ) ;
715706 build_config. unit_graph = self . flag ( "unit-graph" ) ;
716707 build_config. future_incompat_report = self . flag ( "future-incompat-report" ) ;
0 commit comments