@@ -220,6 +220,15 @@ impl Crate {
220
220
. unwrap_or ( false )
221
221
}
222
222
223
+ pub fn invalid_dependency_name_msg ( dep : & str ) -> String {
224
+ format ! (
225
+ "\" {dep}\" is an invalid dependency name (dependency \
226
+ names must start with a letter or underscore, contain only \
227
+ letters, numbers, hyphens, or underscores and have at most \
228
+ {MAX_NAME_LENGTH} characters)"
229
+ )
230
+ }
231
+
223
232
/// Validates the THIS parts of `features = ["THIS", "and/THIS", "dep:THIS", "dep?/THIS"]`.
224
233
/// 1. The name must be non-empty.
225
234
/// 2. The first character must be a Unicode XID start character, `_`, or a digit.
@@ -262,22 +271,12 @@ impl Crate {
262
271
if let Some ( ( dep, dep_feat) ) = name. split_once ( '/' ) {
263
272
let dep = dep. strip_suffix ( '?' ) . unwrap_or ( dep) ;
264
273
if !Crate :: valid_dependency_name ( dep) {
265
- return Err ( cargo_err ( & format_args ! (
266
- "\" {dep}\" is an invalid dependency name (dependency \
267
- names must start with a letter or underscore, contain only \
268
- letters, numbers, hyphens, or underscores and have at most \
269
- {MAX_NAME_LENGTH} characters)"
270
- ) ) ) ;
274
+ return Err ( cargo_err ( & Crate :: invalid_dependency_name_msg ( dep) ) ) ;
271
275
}
272
276
Crate :: valid_feature_name ( dep_feat)
273
277
} else if let Some ( ( _, dep) ) = name. split_once ( "dep:" ) {
274
278
if !Crate :: valid_dependency_name ( dep) {
275
- return Err ( cargo_err ( & format_args ! (
276
- "\" {dep}\" is an invalid dependency name (dependency \
277
- names must start with a letter or underscore, contain only \
278
- letters, numbers, hyphens, or underscores and have at most \
279
- {MAX_NAME_LENGTH} characters)"
280
- ) ) ) ;
279
+ return Err ( cargo_err ( & Crate :: invalid_dependency_name_msg ( dep) ) ) ;
281
280
}
282
281
return Ok ( ( ) ) ;
283
282
} else {
0 commit comments