1+ #![ expect( clippy:: result_large_err) ] // TODO: FIXME
2+
13pub mod fs;
24
35mod builtins;
@@ -11,6 +13,7 @@ use serde::{Deserialize, Serialize};
1113use serde_with:: { DefaultOnNull , serde_as} ;
1214use std:: {
1315 collections:: { HashMap , HashSet , hash_map:: Entry } ,
16+ fmt,
1417 path:: { Path , PathBuf } ,
1518} ;
1619use util:: RegexDef ;
@@ -63,15 +66,16 @@ pub enum Error {
6366 } ,
6467}
6568
66- impl ToString for Error {
67- fn to_string ( & self ) -> String {
68- match & self {
69+ impl fmt :: Display for Error {
70+ fn fmt ( & self , f : & mut fmt :: Formatter < ' _ > ) -> fmt :: Result {
71+ let message = match & self {
6972 Error :: BadSpecifier { message, .. } => message. clone ( ) ,
7073 Error :: FailedManifestHydration { message, .. } => message. clone ( ) ,
7174 Error :: MissingPeerDependency { message, .. } => message. clone ( ) ,
7275 Error :: UndeclaredDependency { message, .. } => message. clone ( ) ,
7376 Error :: MissingDependency { message, .. } => message. clone ( ) ,
74- }
77+ } ;
78+ write ! ( f, "{message}" )
7579 }
7680}
7781
@@ -82,6 +86,7 @@ pub enum Resolution {
8286}
8387
8488pub struct ResolutionHost {
89+ #[ allow( clippy:: type_complexity) ]
8590 pub find_pnp_manifest : Box < dyn Fn ( & Path ) -> Result < Option < Manifest > , Error > > ,
8691}
8792
@@ -172,13 +177,9 @@ pub struct Manifest {
172177fn parse_scoped_package_name ( specifier : & str ) -> Option < ( String , Option < String > ) > {
173178 let mut segments = specifier. splitn ( 3 , '/' ) ;
174179
175- let Some ( scope) = segments. next ( ) else {
176- return None ;
177- } ;
180+ let scope = segments. next ( ) ?;
178181
179- let Some ( name) = segments. next ( ) else {
180- return None ;
181- } ;
182+ let name = segments. next ( ) ?;
182183
183184 let package_name = specifier[ ..scope. len ( ) + name. len ( ) + 1 ] . to_string ( ) ;
184185
@@ -190,9 +191,7 @@ fn parse_scoped_package_name(specifier: &str) -> Option<(String, Option<String>)
190191fn parse_global_package_name ( specifier : & str ) -> Option < ( String , Option < String > ) > {
191192 let mut segments = specifier. splitn ( 2 , '/' ) ;
192193
193- let Some ( name) = segments. next ( ) else {
194- return None ;
195- } ;
194+ let name = segments. next ( ) ?;
196195
197196 let package_name = name. to_string ( ) ;
198197
@@ -229,8 +228,7 @@ pub fn load_pnp_manifest<P: AsRef<Path>>(p: P) -> Result<Manifest, Error> {
229228 let manifest_content =
230229 std:: fs:: read_to_string ( p. as_ref ( ) ) . map_err ( |err| Error :: FailedManifestHydration {
231230 message : format ! (
232- "We failed to read the content of the manifest.\n \n Original error: {}" ,
233- err. to_string( )
231+ "We failed to read the content of the manifest.\n \n Original error: {err}"
234232 ) ,
235233 manifest_path : p. as_ref ( ) . to_path_buf ( ) ,
236234 } ) ?;
@@ -270,7 +268,7 @@ pub fn load_pnp_manifest<P: AsRef<Path>>(p: P) -> Result<Manifest, Error> {
270268
271269 let mut manifest: Manifest = serde_json:: from_str ( & json_string. to_owned ( ) )
272270 . map_err ( |err| Error :: FailedManifestHydration {
273- message : format ! ( "We failed to parse the PnP data payload as proper JSON; Did you manually edit the file?\n \n Original error: {}" , err . to_string ( ) ) ,
271+ message : format ! ( "We failed to parse the PnP data payload as proper JSON; Did you manually edit the file?\n \n Original error: {err}" ) ,
274272 manifest_path : p. as_ref ( ) . to_path_buf ( ) ,
275273 } ) ?;
276274
@@ -288,7 +286,7 @@ pub fn init_pnp_manifest<P: AsRef<Path>>(manifest: &mut Manifest, p: P) {
288286 for ( reference, info) in ranges. iter_mut ( ) {
289287 let package_location = manifest. manifest_dir . join ( info. package_location . clone ( ) ) ;
290288
291- let normalized_location = util:: normalize_path ( & package_location. to_string_lossy ( ) ) ;
289+ let normalized_location = util:: normalize_path ( package_location. to_string_lossy ( ) ) ;
292290
293291 info. package_location = PathBuf :: from ( normalized_location) ;
294292
@@ -366,7 +364,7 @@ pub fn find_broken_peer_dependencies(
366364 _dependency : & str ,
367365 _initial_package : & PackageLocator ,
368366) -> Vec < PackageLocator > {
369- vec ! [ ] . to_vec ( )
367+ [ ] . to_vec ( )
370368}
371369
372370pub fn resolve_to_unqualified_via_manifest < P : AsRef < Path > > (
@@ -425,32 +423,30 @@ pub fn resolve_to_unqualified_via_manifest<P: AsRef<Path>>(
425423 issuer_path = parent. as_ref( ) . to_string_lossy( ) ,
426424 )
427425 }
426+ } else if is_dependency_tree_root ( manifest, parent_locator) {
427+ format ! (
428+ "Your application tried to access {dependency_name}, but it isn't declared in your dependencies; this makes the require call ambiguous and unsound.\n \n Required package: {dependency_name}{via}\n Required by: {issuer_path}" ,
429+ dependency_name = & ident,
430+ via = if ident != specifier {
431+ format!( " (via \" {}\" )" , & specifier)
432+ } else {
433+ String :: from( "" )
434+ } ,
435+ issuer_path = parent. as_ref( ) . to_string_lossy( ) ,
436+ )
428437 } else {
429- if is_dependency_tree_root ( manifest, parent_locator) {
430- format ! (
431- "Your application tried to access {dependency_name}, but it isn't declared in your dependencies; this makes the require call ambiguous and unsound.\n \n Required package: {dependency_name}{via}\n Required by: {issuer_path}" ,
432- dependency_name = & ident,
433- via = if ident != specifier {
434- format!( " (via \" {}\" )" , & specifier)
435- } else {
436- String :: from( "" )
437- } ,
438- issuer_path = parent. as_ref( ) . to_string_lossy( ) ,
439- )
440- } else {
441- format ! (
442- "{issuer_locator_name} tried to access {dependency_name}, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.\n \n Required package: {dependency_name}{via}\n Required by: {issuer_locator_name}@{issuer_locator_reference} (via {issuer_path})" ,
443- issuer_locator_name = & parent_locator. name,
444- issuer_locator_reference = & parent_locator. reference,
445- dependency_name = & ident,
446- via = if ident != specifier {
447- format!( " (via \" {}\" )" , & specifier)
448- } else {
449- String :: from( "" )
450- } ,
451- issuer_path = parent. as_ref( ) . to_string_lossy( ) ,
452- )
453- }
438+ format ! (
439+ "{issuer_locator_name} tried to access {dependency_name}, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.\n \n Required package: {dependency_name}{via}\n Required by: {issuer_locator_name}@{issuer_locator_reference} (via {issuer_path})" ,
440+ issuer_locator_name = & parent_locator. name,
441+ issuer_locator_reference = & parent_locator. reference,
442+ dependency_name = & ident,
443+ via = if ident != specifier {
444+ format!( " (via \" {}\" )" , & specifier)
445+ } else {
446+ String :: from( "" )
447+ } ,
448+ issuer_path = parent. as_ref( ) . to_string_lossy( ) ,
449+ )
454450 } ;
455451
456452 return Err ( Error :: UndeclaredDependency {
@@ -474,7 +470,7 @@ pub fn resolve_to_unqualified_via_manifest<P: AsRef<Path>>(
474470
475471 Ok ( Resolution :: Resolved ( dependency_pkg. package_location . clone ( ) , module_path) )
476472 } else {
477- let broken_ancestors = find_broken_peer_dependencies ( & specifier, parent_locator) ;
473+ let broken_ancestors = find_broken_peer_dependencies ( specifier, parent_locator) ;
478474
479475 let message = if is_dependency_tree_root ( manifest, parent_locator) {
480476 format ! (
@@ -523,7 +519,7 @@ pub fn resolve_to_unqualified_via_manifest<P: AsRef<Path>>(
523519 dependency_name : ident,
524520 issuer_locator : parent_locator. clone ( ) ,
525521 issuer_path : parent. as_ref ( ) . to_path_buf ( ) ,
526- broken_ancestors : vec ! [ ] . to_vec ( ) ,
522+ broken_ancestors : [ ] . to_vec ( ) ,
527523 } )
528524 }
529525 } else {
0 commit comments