@@ -131,46 +131,48 @@ pub fn normalize_lib(
131
131
edition : Edition ,
132
132
warnings : & mut Vec < String > ,
133
133
) -> CargoResult < Option < TomlLibTarget > > {
134
- let inferred = inferred_lib ( package_root) ;
135
- let lib = original_lib. cloned ( ) . or_else ( || {
136
- inferred. as_ref ( ) . map ( |lib| TomlTarget {
137
- path : Some ( PathValue ( lib. clone ( ) ) ) ,
138
- ..TomlTarget :: new ( )
139
- } )
140
- } ) ;
141
- let Some ( mut lib) = lib else { return Ok ( None ) } ;
142
- lib. name
143
- . get_or_insert_with ( || package_name. replace ( "-" , "_" ) ) ;
144
-
145
- // Check early to improve error messages
146
- validate_lib_name ( & lib, warnings) ?;
147
-
148
- validate_proc_macro ( & lib, "library" , edition, warnings) ?;
149
- validate_crate_types ( & lib, "library" , edition, warnings) ?;
150
-
151
- if lib. path . is_none ( ) {
152
- if let Some ( inferred) = inferred {
153
- lib. path = Some ( PathValue ( inferred) ) ;
154
- } else {
155
- let name = name_or_panic ( & lib) ;
156
- let legacy_path = Path :: new ( "src" ) . join ( format ! ( "{name}.rs" ) ) ;
157
- if edition == Edition :: Edition2015 && package_root. join ( & legacy_path) . exists ( ) {
158
- warnings. push ( format ! (
159
- "path `{}` was erroneously implicitly accepted for library `{name}`,\n \
160
- please rename the file to `src/lib.rs` or set lib.path in Cargo.toml",
161
- legacy_path. display( ) ,
162
- ) ) ;
163
- lib. path = Some ( PathValue ( legacy_path) ) ;
134
+ {
135
+ let inferred = inferred_lib ( package_root) ;
136
+ let lib = original_lib. cloned ( ) . or_else ( || {
137
+ inferred. as_ref ( ) . map ( |lib| TomlTarget {
138
+ path : Some ( PathValue ( lib. clone ( ) ) ) ,
139
+ ..TomlTarget :: new ( )
140
+ } )
141
+ } ) ;
142
+ let Some ( mut lib) = lib else { return Ok ( None ) } ;
143
+ lib. name
144
+ . get_or_insert_with ( || package_name. replace ( "-" , "_" ) ) ;
145
+
146
+ // Check early to improve error messages
147
+ validate_lib_name ( & lib, warnings) ?;
148
+
149
+ validate_proc_macro ( & lib, "library" , edition, warnings) ?;
150
+ validate_crate_types ( & lib, "library" , edition, warnings) ?;
151
+
152
+ if lib. path . is_none ( ) {
153
+ if let Some ( inferred) = inferred {
154
+ lib. path = Some ( PathValue ( inferred) ) ;
164
155
} else {
165
- anyhow:: bail!(
166
- "can't find library `{name}`, \
156
+ let name = name_or_panic ( & lib) ;
157
+ let legacy_path = Path :: new ( "src" ) . join ( format ! ( "{name}.rs" ) ) ;
158
+ if edition == Edition :: Edition2015 && package_root. join ( & legacy_path) . exists ( ) {
159
+ warnings. push ( format ! (
160
+ "path `{}` was erroneously implicitly accepted for library `{name}`,\n \
161
+ please rename the file to `src/lib.rs` or set lib.path in Cargo.toml",
162
+ legacy_path. display( ) ,
163
+ ) ) ;
164
+ lib. path = Some ( PathValue ( legacy_path) ) ;
165
+ } else {
166
+ anyhow:: bail!(
167
+ "can't find library `{name}`, \
167
168
rename file to `src/lib.rs` or specify lib.path",
168
- )
169
+ )
170
+ }
169
171
}
170
172
}
171
- }
172
173
173
- Ok ( Some ( lib) )
174
+ Ok ( Some ( lib) )
175
+ }
174
176
}
175
177
176
178
#[ tracing:: instrument( skip_all) ]
0 commit comments