11use super :: * ;
2- use crate :: core:: { Shell , Verbosity } ;
2+ use crate :: core:: Shell ;
33
4+ use crate :: Config ;
45use dissimilar:: Chunk ;
56use itertools:: Itertools ;
67use std:: fmt;
@@ -76,8 +77,8 @@ pub enum DirtyReason {
7677}
7778
7879impl DirtyReason {
79- pub fn presentation ( & self ) -> DirtyReasonPrettyPresentation < ' _ > {
80- DirtyReasonPrettyPresentation ( self )
80+ pub fn presentation < ' a > ( & ' a self , unit : & ' a Unit , config : & ' a Config ) -> DirtyReasonPrettyPresentation < ' a > {
81+ DirtyReasonPrettyPresentation ( self , unit , config )
8182 }
8283}
8384
@@ -266,7 +267,7 @@ impl fmt::Display for DirtyReason {
266267
267268impl std:: error:: Error for DirtyReason { }
268269
269- pub struct DirtyReasonPrettyPresentation < ' a > ( & ' a DirtyReason ) ;
270+ pub struct DirtyReasonPrettyPresentation < ' a > ( & ' a DirtyReason , & ' a Unit , & ' a Config ) ;
270271
271272pub fn diffed ( a : & str , b : & str ) -> ( String , String ) {
272273 let mut s1 = String :: new ( ) ;
@@ -415,7 +416,14 @@ impl<'a> DirtyReasonPrettyPresentation<'a> {
415416 }
416417 }
417418
418- pub fn present_to ( & self , s : & mut Shell , unit : & Unit , root : & Path ) -> CargoResult < ( ) > {
419+ pub fn present_to ( & self , s : & mut Shell ) -> CargoResult < ( ) > {
420+ let unit = self . 1 ;
421+ let ws_roots = self . 2 . ws_roots . borrow ( ) ;
422+ let root: & Path = ws_roots
423+ . values ( )
424+ . next ( )
425+ . map_or_else ( || self . 2 . cwd ( ) , |it| it. inheritable ( ) . ws_root ( ) . as_ref ( ) ) ;
426+
419427 match & self . 0 {
420428 DirtyReason :: RustcChanged => s. dirty_because ( unit, "the toolchain changed" ) ,
421429 DirtyReason :: FeaturesChanged { old, new } => {
@@ -449,11 +457,9 @@ impl<'a> DirtyReasonPrettyPresentation<'a> {
449457 }
450458 DirtyReason :: LocalLengthsChanged => {
451459 s. dirty_because ( unit, "the local lengths changed" ) ?;
452- s. verbose ( |s| {
453- s. note (
460+ s. note (
454461 "This could happen because of added/removed `cargo:rerun-if` instructions in the build script" ,
455- )
456- } ) ?;
462+ ) ?;
457463
458464 Ok ( ( ) )
459465 }
@@ -537,20 +543,14 @@ impl<'a> DirtyReasonPrettyPresentation<'a> {
537543 ..
538544 } => {
539545 let file = stale. strip_prefix ( root) . unwrap_or ( & stale) ;
540- match s. verbosity ( ) {
541- Verbosity :: Verbose => s. dirty_because (
542- unit,
543- format ! (
544- "the file `{}` has changed({})" ,
545- file. display( ) ,
546- Self :: after( * reference_mtime, * stale_mtime, "last build" ) ,
547- ) ,
548- ) ,
549- _ => s. dirty_because (
550- unit,
551- format ! ( "the file `{}` has changed" , file. display( ) ) ,
546+ s. dirty_because (
547+ unit,
548+ format ! (
549+ "the file `{}` has changed ({})" ,
550+ file. display( ) ,
551+ Self :: after( * reference_mtime, * stale_mtime, "last build" ) ,
552552 ) ,
553- }
553+ )
554554 }
555555 StaleItem :: ChangedEnv {
556556 var,
@@ -571,14 +571,14 @@ impl<'a> DirtyReasonPrettyPresentation<'a> {
571571 max_mtime,
572572 ..
573573 } => {
574- let message = match ( dep_mtime, s . verbosity ( ) ) {
575- ( Some ( dep_mtime) , Verbosity :: Verbose ) => {
574+ let message = match dep_mtime {
575+ Some ( dep_mtime) => {
576576 format ! (
577577 "the dependency {name} was rebuilt ({})" ,
578578 Self :: after( * max_mtime, * dep_mtime, "last build" ) ,
579579 )
580580 }
581- ( None , _ ) | ( Some ( _ ) , _ ) => {
581+ None => {
582582 format ! ( "the dependency {name} was rebuilt" )
583583 }
584584 } ;
0 commit comments