@@ -252,23 +252,42 @@ impl CheckAttrVisitor<'tcx> {
252
252
}
253
253
}
254
254
255
+ fn doc_alias_str_error ( & self , meta : & NestedMetaItem ) {
256
+ self . tcx
257
+ . sess
258
+ . struct_span_err (
259
+ meta. span ( ) ,
260
+ "doc alias attribute expects a string: #[doc(alias = \" 0\" )]" ,
261
+ )
262
+ . emit ( ) ;
263
+ }
264
+
255
265
fn check_doc_alias ( & self , attr : & Attribute , hir_id : HirId , target : Target ) -> bool {
256
266
if let Some ( mi) = attr. meta ( ) {
257
267
if let Some ( list) = mi. meta_item_list ( ) {
258
268
for meta in list {
259
269
if meta. has_name ( sym:: alias) {
260
- if !meta. is_value_str ( )
261
- || meta
262
- . value_str ( )
263
- . map ( |s| s. to_string ( ) )
264
- . unwrap_or_else ( String :: new)
265
- . is_empty ( )
270
+ if !meta. is_value_str ( ) {
271
+ self . doc_alias_str_error ( meta) ;
272
+ return false ;
273
+ }
274
+ let doc_alias =
275
+ meta. value_str ( ) . map ( |s| s. to_string ( ) ) . unwrap_or_else ( String :: new) ;
276
+ if doc_alias. is_empty ( ) {
277
+ self . doc_alias_str_error ( meta) ;
278
+ return false ;
279
+ }
280
+ if let Some ( c) =
281
+ doc_alias. chars ( ) . find ( |& c| c == '"' || c == '\'' || c. is_whitespace ( ) )
266
282
{
267
283
self . tcx
268
284
. sess
269
285
. struct_span_err (
270
286
meta. span ( ) ,
271
- "doc alias attribute expects a string: #[doc(alias = \" 0\" )]" ,
287
+ & format ! (
288
+ "{:?} character isn't allowed in `#[doc(alias = \" ...\" )]`" ,
289
+ c,
290
+ ) ,
272
291
)
273
292
. emit ( ) ;
274
293
return false ;
@@ -304,6 +323,7 @@ impl CheckAttrVisitor<'tcx> {
304
323
& format ! ( "`#[doc(alias = \" ...\" )]` isn't allowed on {}" , err) ,
305
324
)
306
325
. emit ( ) ;
326
+ return false ;
307
327
}
308
328
}
309
329
}
0 commit comments