1
+ #![ expect( clippy:: result_large_err) ] // TODO: FIXME
2
+
1
3
pub mod fs;
2
4
3
5
mod builtins;
@@ -11,6 +13,7 @@ use serde::{Deserialize, Serialize};
11
13
use serde_with:: { DefaultOnNull , serde_as} ;
12
14
use std:: {
13
15
collections:: { HashMap , HashSet , hash_map:: Entry } ,
16
+ fmt,
14
17
path:: { Path , PathBuf } ,
15
18
} ;
16
19
use util:: RegexDef ;
@@ -63,15 +66,16 @@ pub enum Error {
63
66
} ,
64
67
}
65
68
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 {
69
72
Error :: BadSpecifier { message, .. } => message. clone ( ) ,
70
73
Error :: FailedManifestHydration { message, .. } => message. clone ( ) ,
71
74
Error :: MissingPeerDependency { message, .. } => message. clone ( ) ,
72
75
Error :: UndeclaredDependency { message, .. } => message. clone ( ) ,
73
76
Error :: MissingDependency { message, .. } => message. clone ( ) ,
74
- }
77
+ } ;
78
+ write ! ( f, "{message}" )
75
79
}
76
80
}
77
81
@@ -82,6 +86,7 @@ pub enum Resolution {
82
86
}
83
87
84
88
pub struct ResolutionHost {
89
+ #[ allow( clippy:: type_complexity) ]
85
90
pub find_pnp_manifest : Box < dyn Fn ( & Path ) -> Result < Option < Manifest > , Error > > ,
86
91
}
87
92
@@ -172,13 +177,9 @@ pub struct Manifest {
172
177
fn parse_scoped_package_name ( specifier : & str ) -> Option < ( String , Option < String > ) > {
173
178
let mut segments = specifier. splitn ( 3 , '/' ) ;
174
179
175
- let Some ( scope) = segments. next ( ) else {
176
- return None ;
177
- } ;
180
+ let scope = segments. next ( ) ?;
178
181
179
- let Some ( name) = segments. next ( ) else {
180
- return None ;
181
- } ;
182
+ let name = segments. next ( ) ?;
182
183
183
184
let package_name = specifier[ ..scope. len ( ) + name. len ( ) + 1 ] . to_string ( ) ;
184
185
@@ -190,9 +191,7 @@ fn parse_scoped_package_name(specifier: &str) -> Option<(String, Option<String>)
190
191
fn parse_global_package_name ( specifier : & str ) -> Option < ( String , Option < String > ) > {
191
192
let mut segments = specifier. splitn ( 2 , '/' ) ;
192
193
193
- let Some ( name) = segments. next ( ) else {
194
- return None ;
195
- } ;
194
+ let name = segments. next ( ) ?;
196
195
197
196
let package_name = name. to_string ( ) ;
198
197
@@ -229,8 +228,7 @@ pub fn load_pnp_manifest<P: AsRef<Path>>(p: P) -> Result<Manifest, Error> {
229
228
let manifest_content =
230
229
std:: fs:: read_to_string ( p. as_ref ( ) ) . map_err ( |err| Error :: FailedManifestHydration {
231
230
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}"
234
232
) ,
235
233
manifest_path : p. as_ref ( ) . to_path_buf ( ) ,
236
234
} ) ?;
@@ -270,7 +268,7 @@ pub fn load_pnp_manifest<P: AsRef<Path>>(p: P) -> Result<Manifest, Error> {
270
268
271
269
let mut manifest: Manifest = serde_json:: from_str ( & json_string. to_owned ( ) )
272
270
. 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}" ) ,
274
272
manifest_path : p. as_ref ( ) . to_path_buf ( ) ,
275
273
} ) ?;
276
274
@@ -288,7 +286,7 @@ pub fn init_pnp_manifest<P: AsRef<Path>>(manifest: &mut Manifest, p: P) {
288
286
for ( reference, info) in ranges. iter_mut ( ) {
289
287
let package_location = manifest. manifest_dir . join ( info. package_location . clone ( ) ) ;
290
288
291
- let normalized_location = util:: normalize_path ( & package_location. to_string_lossy ( ) ) ;
289
+ let normalized_location = util:: normalize_path ( package_location. to_string_lossy ( ) ) ;
292
290
293
291
info. package_location = PathBuf :: from ( normalized_location) ;
294
292
@@ -366,7 +364,7 @@ pub fn find_broken_peer_dependencies(
366
364
_dependency : & str ,
367
365
_initial_package : & PackageLocator ,
368
366
) -> Vec < PackageLocator > {
369
- vec ! [ ] . to_vec ( )
367
+ [ ] . to_vec ( )
370
368
}
371
369
372
370
pub fn resolve_to_unqualified_via_manifest < P : AsRef < Path > > (
@@ -425,32 +423,30 @@ pub fn resolve_to_unqualified_via_manifest<P: AsRef<Path>>(
425
423
issuer_path = parent. as_ref( ) . to_string_lossy( ) ,
426
424
)
427
425
}
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
+ )
428
437
} 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
+ )
454
450
} ;
455
451
456
452
return Err ( Error :: UndeclaredDependency {
@@ -474,7 +470,7 @@ pub fn resolve_to_unqualified_via_manifest<P: AsRef<Path>>(
474
470
475
471
Ok ( Resolution :: Resolved ( dependency_pkg. package_location . clone ( ) , module_path) )
476
472
} else {
477
- let broken_ancestors = find_broken_peer_dependencies ( & specifier, parent_locator) ;
473
+ let broken_ancestors = find_broken_peer_dependencies ( specifier, parent_locator) ;
478
474
479
475
let message = if is_dependency_tree_root ( manifest, parent_locator) {
480
476
format ! (
@@ -523,7 +519,7 @@ pub fn resolve_to_unqualified_via_manifest<P: AsRef<Path>>(
523
519
dependency_name : ident,
524
520
issuer_locator : parent_locator. clone ( ) ,
525
521
issuer_path : parent. as_ref ( ) . to_path_buf ( ) ,
526
- broken_ancestors : vec ! [ ] . to_vec ( ) ,
522
+ broken_ancestors : [ ] . to_vec ( ) ,
527
523
} )
528
524
}
529
525
} else {
0 commit comments