@@ -483,7 +483,7 @@ fn prepare_archive(
483483 src. load ( ) ?;
484484
485485 if opts. check_metadata {
486- check_metadata ( pkg, gctx) ?;
486+ check_metadata ( pkg, gctx, opts . reg_or_index . as_ref ( ) ) ?;
487487 }
488488
489489 if !pkg. manifest ( ) . exclude ( ) . is_empty ( ) && !pkg. manifest ( ) . include ( ) . is_empty ( ) {
@@ -808,7 +808,13 @@ fn build_lock(
808808
809809// Checks that the package has some piece of metadata that a human can
810810// use to tell what the package is about.
811- fn check_metadata ( pkg : & Package , gctx : & GlobalContext ) -> CargoResult < ( ) > {
811+ // Checks that the package has some piece of metadata that a human can
812+ // use to tell what the package is about.
813+ fn check_metadata (
814+ pkg : & Package ,
815+ gctx : & GlobalContext ,
816+ reg_or_index : Option < & RegistryOrIndex > ,
817+ ) -> CargoResult < ( ) > {
812818 let md = pkg. manifest ( ) . metadata ( ) ;
813819
814820 let mut missing = vec ! [ ] ;
@@ -829,20 +835,29 @@ fn check_metadata(pkg: &Package, gctx: &GlobalContext) -> CargoResult<()> {
829835 ) ;
830836
831837 if !missing. is_empty ( ) {
832- let mut things = missing[ ..missing. len ( ) - 1 ] . join ( ", " ) ;
833- // `things` will be empty if and only if its length is 1 (i.e., the only case
834- // to have no `or`).
835- if !things. is_empty ( ) {
836- things. push_str ( " or " ) ;
838+ // Only warn if publishing to crates.io based on resolved registry
839+ let should_warn = match reg_or_index {
840+ Some ( RegistryOrIndex :: Registry ( reg_name) ) => reg_name == CRATES_IO_REGISTRY ,
841+ None => true , // Default is crates.io
842+ Some ( RegistryOrIndex :: Index ( _) ) => false , // Custom index, not crates.io
843+ } ;
844+
845+ if should_warn {
846+ let mut things = missing[ ..missing. len ( ) - 1 ] . join ( ", " ) ;
847+ // `things` will be empty if and only if its length is 1 (i.e., the only case
848+ // to have no `or`).
849+ if !things. is_empty ( ) {
850+ things. push_str ( " or " ) ;
851+ }
852+ things. push_str ( missing. last ( ) . unwrap ( ) ) ;
853+
854+ gctx. shell ( ) . print_report ( & [
855+ Level :: WARNING . secondary_title ( format ! ( "manifest has no {things}" ) )
856+ . element ( Level :: NOTE . message ( "see https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info" ) )
857+ ] ,
858+ false
859+ ) ?
837860 }
838- things. push_str ( missing. last ( ) . unwrap ( ) ) ;
839-
840- gctx. shell ( ) . print_report ( & [
841- Level :: WARNING . secondary_title ( format ! ( "manifest has no {things}" ) )
842- . element ( Level :: NOTE . message ( "see https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info" ) )
843- ] ,
844- false
845- ) ?
846861 }
847862
848863 Ok ( ( ) )
0 commit comments