@@ -260,23 +260,42 @@ impl CheckAttrVisitor<'tcx> {
260
260
}
261
261
}
262
262
263
+ fn doc_alias_str_error ( & self , meta : & NestedMetaItem ) {
264
+ self . tcx
265
+ . sess
266
+ . struct_span_err (
267
+ meta. span ( ) ,
268
+ "doc alias attribute expects a string: #[doc(alias = \" 0\" )]" ,
269
+ )
270
+ . emit ( ) ;
271
+ }
272
+
263
273
fn check_doc_alias ( & self , attr : & Attribute , hir_id : HirId , target : Target ) -> bool {
264
274
if let Some ( mi) = attr. meta ( ) {
265
275
if let Some ( list) = mi. meta_item_list ( ) {
266
276
for meta in list {
267
277
if meta. has_name ( sym:: alias) {
268
- if !meta. is_value_str ( )
269
- || meta
270
- . value_str ( )
271
- . map ( |s| s. to_string ( ) )
272
- . unwrap_or_else ( String :: new)
273
- . is_empty ( )
278
+ if !meta. is_value_str ( ) {
279
+ self . doc_alias_str_error ( meta) ;
280
+ return false ;
281
+ }
282
+ let doc_alias =
283
+ meta. value_str ( ) . map ( |s| s. to_string ( ) ) . unwrap_or_else ( String :: new) ;
284
+ if doc_alias. is_empty ( ) {
285
+ self . doc_alias_str_error ( meta) ;
286
+ return false ;
287
+ }
288
+ if let Some ( c) =
289
+ doc_alias. chars ( ) . find ( |& c| c == '"' || c == '\'' || c. is_whitespace ( ) )
274
290
{
275
291
self . tcx
276
292
. sess
277
293
. struct_span_err (
278
294
meta. span ( ) ,
279
- "doc alias attribute expects a string: #[doc(alias = \" 0\" )]" ,
295
+ & format ! (
296
+ "{:?} character isn't allowed in `#[doc(alias = \" ...\" )]`" ,
297
+ c,
298
+ ) ,
280
299
)
281
300
. emit ( ) ;
282
301
return false ;
@@ -312,6 +331,7 @@ impl CheckAttrVisitor<'tcx> {
312
331
& format ! ( "`#[doc(alias = \" ...\" )]` isn't allowed on {}" , err) ,
313
332
)
314
333
. emit ( ) ;
334
+ return false ;
315
335
}
316
336
}
317
337
}
0 commit comments