@@ -220,6 +220,15 @@ impl Crate {
220220 . unwrap_or ( false )
221221 }
222222
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+
223232 /// Validates the THIS parts of `features = ["THIS", "and/THIS", "dep:THIS", "dep?/THIS"]`.
224233 /// 1. The name must be non-empty.
225234 /// 2. The first character must be a Unicode XID start character, `_`, or a digit.
@@ -262,22 +271,12 @@ impl Crate {
262271 if let Some ( ( dep, dep_feat) ) = name. split_once ( '/' ) {
263272 let dep = dep. strip_suffix ( '?' ) . unwrap_or ( dep) ;
264273 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) ) ) ;
271275 }
272276 Crate :: valid_feature_name ( dep_feat)
273277 } else if let Some ( ( _, dep) ) = name. split_once ( "dep:" ) {
274278 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) ) ) ;
281280 }
282281 return Ok ( ( ) ) ;
283282 } else {
0 commit comments