@@ -260,23 +260,42 @@ impl CheckAttrVisitor<'tcx> {
260260 }
261261 }
262262
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+
263273 fn check_doc_alias ( & self , attr : & Attribute , hir_id : HirId , target : Target ) -> bool {
264274 if let Some ( mi) = attr. meta ( ) {
265275 if let Some ( list) = mi. meta_item_list ( ) {
266276 for meta in list {
267277 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 ( ) )
274290 {
275291 self . tcx
276292 . sess
277293 . struct_span_err (
278294 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+ ) ,
280299 )
281300 . emit ( ) ;
282301 return false ;
@@ -312,6 +331,7 @@ impl CheckAttrVisitor<'tcx> {
312331 & format ! ( "`#[doc(alias = \" ...\" )]` isn't allowed on {}" , err) ,
313332 )
314333 . emit ( ) ;
334+ return false ;
315335 }
316336 }
317337 }
0 commit comments