@@ -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,9 @@ 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 ( pkg : & Package , gctx : & GlobalContext , reg_or_index : Option < & RegistryOrIndex > ) -> CargoResult < ( ) > {
812814 let md = pkg. manifest ( ) . metadata ( ) ;
813815
814816 let mut missing = vec ! [ ] ;
@@ -829,20 +831,29 @@ fn check_metadata(pkg: &Package, gctx: &GlobalContext) -> CargoResult<()> {
829831 ) ;
830832
831833 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 " ) ;
834+ // Only warn if publishing to crates.io based on resolved registry
835+ let should_warn = match reg_or_index {
836+ Some ( RegistryOrIndex :: Registry ( reg_name) ) => reg_name == CRATES_IO_REGISTRY ,
837+ None => true , // Default is crates.io
838+ Some ( RegistryOrIndex :: Index ( _) ) => false , // Custom index, not crates.io
839+ } ;
840+
841+ if should_warn {
842+ let mut things = missing[ ..missing. len ( ) - 1 ] . join ( ", " ) ;
843+ // `things` will be empty if and only if its length is 1 (i.e., the only case
844+ // to have no `or`).
845+ if !things. is_empty ( ) {
846+ things. push_str ( " or " ) ;
847+ }
848+ things. push_str ( missing. last ( ) . unwrap ( ) ) ;
849+
850+ gctx. shell ( ) . print_report ( & [
851+ Level :: WARNING . secondary_title ( format ! ( "manifest has no {things}" ) )
852+ . element ( Level :: NOTE . message ( "see https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info" ) )
853+ ] ,
854+ false
855+ ) ?
837856 }
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- ) ?
846857 }
847858
848859 Ok ( ( ) )
0 commit comments