@@ -9,8 +9,8 @@ use crate::AlreadyPrintedError;
99use anyhow:: { anyhow, bail, Context as _} ;
1010use cargo_platform:: Platform ;
1111use cargo_util:: paths;
12- use cargo_util_schemas:: manifest;
13- use cargo_util_schemas:: manifest:: RustVersion ;
12+ use cargo_util_schemas:: manifest:: { self , InheritableDependency } ;
13+ use cargo_util_schemas:: manifest:: { RustVersion , TomlDependency } ;
1414use itertools:: Itertools ;
1515use lazycell:: LazyCell ;
1616use pathdiff:: diff_paths;
@@ -105,61 +105,62 @@ fn read_manifest_from_str(
105105
106106 let mut unused = BTreeSet :: new ( ) ;
107107 let deserializer = toml:: de:: Deserializer :: new ( contents) ;
108- let manifest: manifest:: TomlManifest = match serde_ignored:: deserialize ( deserializer, |path| {
109- let mut key = String :: new ( ) ;
110- stringify ( & mut key, & path) ;
111- unused. insert ( key) ;
112- } ) {
113- Ok ( manifest) => manifest,
114- Err ( e) => {
115- let Some ( span) = e. span ( ) else {
116- return Err ( e. into ( ) ) ;
117- } ;
108+ let mut manifest: manifest:: TomlManifest =
109+ match serde_ignored:: deserialize ( deserializer, |path| {
110+ let mut key = String :: new ( ) ;
111+ stringify ( & mut key, & path) ;
112+ unused. insert ( key) ;
113+ } ) {
114+ Ok ( manifest) => manifest,
115+ Err ( e) => {
116+ let Some ( span) = e. span ( ) else {
117+ return Err ( e. into ( ) ) ;
118+ } ;
118119
119- let ( line_num, column) = translate_position ( & contents, span. start ) ;
120- let source_start = contents[ 0 ..span. start ]
121- . rfind ( '\n' )
122- . map ( |s| s + 1 )
123- . unwrap_or ( 0 ) ;
124- let source_end = contents[ span. end - 1 ..]
125- . find ( '\n' )
126- . map ( |s| s + span. end )
127- . unwrap_or ( contents. len ( ) ) ;
128- let source = & contents[ source_start..source_end] ;
129- // Make sure we don't try to highlight past the end of the line,
130- // but also make sure we are highlighting at least one character
131- let highlight_end = ( column + contents[ span] . chars ( ) . count ( ) )
132- . min ( source. len ( ) )
133- . max ( column + 1 ) ;
134- // Get the path to the manifest, relative to the cwd
135- let manifest_path = diff_paths ( manifest_file, config. cwd ( ) )
136- . unwrap_or_else ( || manifest_file. to_path_buf ( ) )
137- . display ( )
138- . to_string ( ) ;
139- let snippet = Snippet {
140- title : Some ( Annotation {
141- id : None ,
142- label : Some ( e. message ( ) ) ,
143- annotation_type : AnnotationType :: Error ,
144- } ) ,
145- footer : vec ! [ ] ,
146- slices : vec ! [ Slice {
147- source: & source,
148- line_start: line_num + 1 ,
149- origin: Some ( manifest_path. as_str( ) ) ,
150- annotations: vec![ SourceAnnotation {
151- range: ( column, highlight_end) ,
152- label: "" ,
120+ let ( line_num, column) = translate_position ( & contents, span. start ) ;
121+ let source_start = contents[ 0 ..span. start ]
122+ . rfind ( '\n' )
123+ . map ( |s| s + 1 )
124+ . unwrap_or ( 0 ) ;
125+ let source_end = contents[ span. end - 1 ..]
126+ . find ( '\n' )
127+ . map ( |s| s + span. end )
128+ . unwrap_or ( contents. len ( ) ) ;
129+ let source = & contents[ source_start..source_end] ;
130+ // Make sure we don't try to highlight past the end of the line,
131+ // but also make sure we are highlighting at least one character
132+ let highlight_end = ( column + contents[ span] . chars ( ) . count ( ) )
133+ . min ( source. len ( ) )
134+ . max ( column + 1 ) ;
135+ // Get the path to the manifest, relative to the cwd
136+ let manifest_path = diff_paths ( manifest_file, config. cwd ( ) )
137+ . unwrap_or_else ( || manifest_file. to_path_buf ( ) )
138+ . display ( )
139+ . to_string ( ) ;
140+ let snippet = Snippet {
141+ title : Some ( Annotation {
142+ id : None ,
143+ label : Some ( e. message ( ) ) ,
153144 annotation_type : AnnotationType :: Error ,
145+ } ) ,
146+ footer : vec ! [ ] ,
147+ slices : vec ! [ Slice {
148+ source: & source,
149+ line_start: line_num + 1 ,
150+ origin: Some ( manifest_path. as_str( ) ) ,
151+ annotations: vec![ SourceAnnotation {
152+ range: ( column, highlight_end) ,
153+ label: "" ,
154+ annotation_type: AnnotationType :: Error ,
155+ } ] ,
156+ fold: false ,
154157 } ] ,
155- fold: false ,
156- } ] ,
157- } ;
158- let renderer = Renderer :: styled ( ) ;
159- writeln ! ( config. shell( ) . err( ) , "{}" , renderer. render( snippet) ) ?;
160- return Err ( AlreadyPrintedError :: new ( e. into ( ) ) . into ( ) ) ;
161- }
162- } ;
158+ } ;
159+ let renderer = Renderer :: styled ( ) ;
160+ writeln ! ( config. shell( ) . err( ) , "{}" , renderer. render( snippet) ) ?;
161+ return Err ( AlreadyPrintedError :: new ( e. into ( ) ) . into ( ) ) ;
162+ }
163+ } ;
163164 let add_unused = |warnings : & mut Warnings | {
164165 for key in unused {
165166 warnings. add_warning ( format ! ( "unused manifest key: {}" , key) ) ;
@@ -183,10 +184,33 @@ fn read_manifest_from_str(
183184 }
184185 }
185186 }
187+
188+ let mut public_deps_without_z = BTreeSet :: new ( ) ;
189+ if let Some ( deps) = & mut manifest. dependencies {
190+ for ( name, dep) in deps {
191+ if let InheritableDependency :: Value ( toml_dep) = dep {
192+ if toml_dep. is_public ( ) && !config. cli_unstable ( ) . public_dependency {
193+ if let TomlDependency :: Detailed ( d) = toml_dep {
194+ d. public = Some ( false )
195+ }
196+ public_deps_without_z. insert ( name. clone ( ) ) ;
197+ }
198+ }
199+ }
200+ }
201+ let public_warn = |warnings : & mut Warnings | {
202+ for name in public_deps_without_z {
203+ warnings. add_warning ( format ! (
204+ "{name} is public, pass `-Zpublic-dependency` to enable support for it" ,
205+ ) )
206+ }
207+ } ;
208+
186209 return if manifest. project . is_some ( ) || manifest. package . is_some ( ) {
187210 let ( mut manifest, paths) =
188211 to_real_manifest ( manifest, embedded, source_id, package_root, config) ?;
189212 add_unused ( manifest. warnings_mut ( ) ) ;
213+ public_warn ( manifest. warnings_mut ( ) ) ;
190214 if manifest. targets ( ) . iter ( ) . all ( |t| t. is_custom_build ( ) ) {
191215 bail ! (
192216 "no targets specified in the manifest\n \
@@ -198,6 +222,7 @@ fn read_manifest_from_str(
198222 } else {
199223 let ( mut m, paths) = to_virtual_manifest ( manifest, source_id, package_root, config) ?;
200224 add_unused ( m. warnings_mut ( ) ) ;
225+ public_warn ( m. warnings_mut ( ) ) ;
201226 Ok ( ( EitherManifest :: Virtual ( m) , paths) )
202227 } ;
203228
@@ -678,7 +703,6 @@ pub fn to_real_manifest(
678703 nested_paths : & mut nested_paths,
679704 config,
680705 warnings : & mut warnings,
681- features : & features,
682706 platform : None ,
683707 root : package_root,
684708 } ;
@@ -1153,7 +1177,6 @@ fn to_virtual_manifest(
11531177 config,
11541178 warnings : & mut warnings,
11551179 platform : None ,
1156- features : & features,
11571180 root,
11581181 } ;
11591182 ( replace ( & me, & mut cx) ?, patch ( & me, & mut cx) ?)
@@ -1302,7 +1325,6 @@ struct Context<'a, 'b> {
13021325 warnings : & ' a mut Vec < String > ,
13031326 platform : Option < Platform > ,
13041327 root : & ' a Path ,
1305- features : & ' a Features ,
13061328}
13071329
13081330fn verify_lints ( lints : Option < manifest:: TomlLints > ) -> CargoResult < Option < manifest:: TomlLints > > {
@@ -1709,7 +1731,6 @@ pub(crate) fn to_dependency<P: ResolveToPath + Clone>(
17091731 warnings : & mut Vec < String > ,
17101732 platform : Option < Platform > ,
17111733 root : & Path ,
1712- features : & Features ,
17131734 kind : Option < DepKind > ,
17141735) -> CargoResult < Dependency > {
17151736 dep_to_dependency (
@@ -1723,7 +1744,6 @@ pub(crate) fn to_dependency<P: ResolveToPath + Clone>(
17231744 warnings,
17241745 platform,
17251746 root,
1726- features,
17271747 } ,
17281748 kind,
17291749 )
@@ -1944,8 +1964,6 @@ fn detailed_dep_to_dependency<P: ResolveToPath + Clone>(
19441964 }
19451965
19461966 if let Some ( p) = orig. public {
1947- cx. features . require ( Feature :: public_dependency ( ) ) ?;
1948-
19491967 if dep. kind ( ) != DepKind :: Normal {
19501968 bail ! ( "'public' specifier can only be used on regular dependencies, not {:?} dependencies" , dep. kind( ) ) ;
19511969 }
0 commit comments