@@ -9,8 +9,8 @@ use crate::AlreadyPrintedError;
9
9
use anyhow:: { anyhow, bail, Context as _} ;
10
10
use cargo_platform:: Platform ;
11
11
use 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 } ;
14
14
use itertools:: Itertools ;
15
15
use lazycell:: LazyCell ;
16
16
use pathdiff:: diff_paths;
@@ -105,61 +105,62 @@ fn read_manifest_from_str(
105
105
106
106
let mut unused = BTreeSet :: new ( ) ;
107
107
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
+ } ;
118
119
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 ( ) ) ,
153
144
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 ,
154
157
} ] ,
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
+ } ;
163
164
let add_unused = |warnings : & mut Warnings | {
164
165
for key in unused {
165
166
warnings. add_warning ( format ! ( "unused manifest key: {}" , key) ) ;
@@ -183,10 +184,33 @@ fn read_manifest_from_str(
183
184
}
184
185
}
185
186
}
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
+
186
209
return if manifest. project . is_some ( ) || manifest. package . is_some ( ) {
187
210
let ( mut manifest, paths) =
188
211
to_real_manifest ( manifest, embedded, source_id, package_root, config) ?;
189
212
add_unused ( manifest. warnings_mut ( ) ) ;
213
+ public_warn ( manifest. warnings_mut ( ) ) ;
190
214
if manifest. targets ( ) . iter ( ) . all ( |t| t. is_custom_build ( ) ) {
191
215
bail ! (
192
216
"no targets specified in the manifest\n \
@@ -198,6 +222,7 @@ fn read_manifest_from_str(
198
222
} else {
199
223
let ( mut m, paths) = to_virtual_manifest ( manifest, source_id, package_root, config) ?;
200
224
add_unused ( m. warnings_mut ( ) ) ;
225
+ public_warn ( m. warnings_mut ( ) ) ;
201
226
Ok ( ( EitherManifest :: Virtual ( m) , paths) )
202
227
} ;
203
228
@@ -678,7 +703,6 @@ pub fn to_real_manifest(
678
703
nested_paths : & mut nested_paths,
679
704
config,
680
705
warnings : & mut warnings,
681
- features : & features,
682
706
platform : None ,
683
707
root : package_root,
684
708
} ;
@@ -1153,7 +1177,6 @@ fn to_virtual_manifest(
1153
1177
config,
1154
1178
warnings : & mut warnings,
1155
1179
platform : None ,
1156
- features : & features,
1157
1180
root,
1158
1181
} ;
1159
1182
( replace ( & me, & mut cx) ?, patch ( & me, & mut cx) ?)
@@ -1302,7 +1325,6 @@ struct Context<'a, 'b> {
1302
1325
warnings : & ' a mut Vec < String > ,
1303
1326
platform : Option < Platform > ,
1304
1327
root : & ' a Path ,
1305
- features : & ' a Features ,
1306
1328
}
1307
1329
1308
1330
fn verify_lints ( lints : Option < manifest:: TomlLints > ) -> CargoResult < Option < manifest:: TomlLints > > {
@@ -1709,7 +1731,6 @@ pub(crate) fn to_dependency<P: ResolveToPath + Clone>(
1709
1731
warnings : & mut Vec < String > ,
1710
1732
platform : Option < Platform > ,
1711
1733
root : & Path ,
1712
- features : & Features ,
1713
1734
kind : Option < DepKind > ,
1714
1735
) -> CargoResult < Dependency > {
1715
1736
dep_to_dependency (
@@ -1723,7 +1744,6 @@ pub(crate) fn to_dependency<P: ResolveToPath + Clone>(
1723
1744
warnings,
1724
1745
platform,
1725
1746
root,
1726
- features,
1727
1747
} ,
1728
1748
kind,
1729
1749
)
@@ -1944,8 +1964,6 @@ fn detailed_dep_to_dependency<P: ResolveToPath + Clone>(
1944
1964
}
1945
1965
1946
1966
if let Some ( p) = orig. public {
1947
- cx. features . require ( Feature :: public_dependency ( ) ) ?;
1948
-
1949
1967
if dep. kind ( ) != DepKind :: Normal {
1950
1968
bail ! ( "'public' specifier can only be used on regular dependencies, not {:?} dependencies" , dep. kind( ) ) ;
1951
1969
}
0 commit comments