@@ -52,9 +52,10 @@ use rustfix::diagnostics::Diagnostic;
5252use rustfix:: { self , CodeFix } ;
5353
5454use crate :: core:: compiler:: RustcTargetData ;
55- use crate :: core:: resolver:: features:: { FeatureOpts , FeatureResolver } ;
55+ use crate :: core:: resolver:: features:: { DiffMap , FeatureOpts , FeatureResolver } ;
5656use crate :: core:: resolver:: { HasDevUnits , Resolve , ResolveBehavior } ;
5757use crate :: core:: { Edition , MaybePackage , Workspace } ;
58+ use crate :: ops:: resolve:: WorkspaceResolve ;
5859use crate :: ops:: { self , CompileOptions } ;
5960use crate :: util:: diagnostic_server:: { Message , RustfixDiagnosticServer } ;
6061use crate :: util:: errors:: CargoResult ;
@@ -229,36 +230,40 @@ fn check_resolver_change(ws: &Workspace<'_>, opts: &FixOptions) -> CargoResult<(
229230 assert_eq ! ( ws. resolve_behavior( ) , ResolveBehavior :: V1 ) ;
230231 let specs = opts. compile_opts . spec . to_package_id_specs ( ws) ?;
231232 let target_data = RustcTargetData :: new ( ws, & opts. compile_opts . build_config . requested_kinds ) ?;
232- // HasDevUnits::No because that may uncover more differences.
233- // This is not the same as what `cargo fix` is doing, since it is doing
234- // `--all-targets` which includes dev dependencies.
235- let ws_resolve = ops:: resolve_ws_with_opts (
236- ws,
237- & target_data,
238- & opts. compile_opts . build_config . requested_kinds ,
239- & opts. compile_opts . cli_features ,
240- & specs,
241- HasDevUnits :: No ,
242- crate :: core:: resolver:: features:: ForceAllTargets :: No ,
243- ) ?;
233+ let resolve_differences = |has_dev_units| -> CargoResult < ( WorkspaceResolve < ' _ > , DiffMap ) > {
234+ let ws_resolve = ops:: resolve_ws_with_opts (
235+ ws,
236+ & target_data,
237+ & opts. compile_opts . build_config . requested_kinds ,
238+ & opts. compile_opts . cli_features ,
239+ & specs,
240+ has_dev_units,
241+ crate :: core:: resolver:: features:: ForceAllTargets :: No ,
242+ ) ?;
244243
245- let feature_opts = FeatureOpts :: new_behavior ( ResolveBehavior :: V2 , HasDevUnits :: No ) ;
246- let v2_features = FeatureResolver :: resolve (
247- ws,
248- & target_data,
249- & ws_resolve. targeted_resolve ,
250- & ws_resolve. pkg_set ,
251- & opts. compile_opts . cli_features ,
252- & specs,
253- & opts. compile_opts . build_config . requested_kinds ,
254- feature_opts,
255- ) ?;
244+ let feature_opts = FeatureOpts :: new_behavior ( ResolveBehavior :: V2 , has_dev_units ) ;
245+ let v2_features = FeatureResolver :: resolve (
246+ ws,
247+ & target_data,
248+ & ws_resolve. targeted_resolve ,
249+ & ws_resolve. pkg_set ,
250+ & opts. compile_opts . cli_features ,
251+ & specs,
252+ & opts. compile_opts . build_config . requested_kinds ,
253+ feature_opts,
254+ ) ?;
256255
257- let differences = v2_features. compare_legacy ( & ws_resolve. resolved_features ) ;
258- if differences. is_empty ( ) {
256+ let diffs = v2_features. compare_legacy ( & ws_resolve. resolved_features ) ;
257+ Ok ( ( ws_resolve, diffs) )
258+ } ;
259+ let ( _, without_dev_diffs) = resolve_differences ( HasDevUnits :: No ) ?;
260+ let ( ws_resolve, mut with_dev_diffs) = resolve_differences ( HasDevUnits :: Yes ) ?;
261+ if without_dev_diffs. is_empty ( ) && with_dev_diffs. is_empty ( ) {
259262 // Nothing is different, nothing to report.
260263 return Ok ( ( ) ) ;
261264 }
265+ // Only display unique changes with dev-dependencies.
266+ with_dev_diffs. retain ( |k, vals| without_dev_diffs. get ( k) != Some ( vals) ) ;
262267 let config = ws. config ( ) ;
263268 config. shell ( ) . note (
264269 "Switching to Edition 2021 will enable the use of the version 2 feature resolver in Cargo." ,
@@ -277,16 +282,28 @@ fn check_resolver_change(ws: &Workspace<'_>, opts: &FixOptions) -> CargoResult<(
277282 "When building the following dependencies, \
278283 the given features will no longer be used:\n "
279284 ) ;
280- for ( ( pkg_id, for_host) , removed) in differences {
281- drop_eprint ! ( config, " {}" , pkg_id) ;
282- if for_host {
283- drop_eprint ! ( config, " (as host dependency)" ) ;
285+ let show_diffs = |differences : DiffMap | {
286+ for ( ( pkg_id, for_host) , removed) in differences {
287+ drop_eprint ! ( config, " {}" , pkg_id) ;
288+ if for_host {
289+ drop_eprint ! ( config, " (as host dependency)" ) ;
290+ }
291+ drop_eprint ! ( config, " removed features: " ) ;
292+ let joined: Vec < _ > = removed. iter ( ) . map ( |s| s. as_str ( ) ) . collect ( ) ;
293+ drop_eprintln ! ( config, "{}" , joined. join( ", " ) ) ;
284294 }
285- drop_eprint ! ( config, ": " ) ;
286- let joined: Vec < _ > = removed. iter ( ) . map ( |s| s. as_str ( ) ) . collect ( ) ;
287- drop_eprintln ! ( config, "{}" , joined. join( ", " ) ) ;
295+ drop_eprint ! ( config, "\n " ) ;
296+ } ;
297+ if !without_dev_diffs. is_empty ( ) {
298+ show_diffs ( without_dev_diffs) ;
299+ }
300+ if !with_dev_diffs. is_empty ( ) {
301+ drop_eprintln ! (
302+ config,
303+ "The following differences only apply when building with dev-dependencies:\n "
304+ ) ;
305+ show_diffs ( with_dev_diffs) ;
288306 }
289- drop_eprint ! ( config, "\n " ) ;
290307 report_maybe_diesel ( config, & ws_resolve. targeted_resolve ) ?;
291308 Ok ( ( ) )
292309}
0 commit comments