@@ -252,23 +252,42 @@ impl CheckAttrVisitor<'tcx> {
252252 }
253253 }
254254
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+
255265 fn check_doc_alias ( & self , attr : & Attribute , hir_id : HirId , target : Target ) -> bool {
256266 if let Some ( mi) = attr. meta ( ) {
257267 if let Some ( list) = mi. meta_item_list ( ) {
258268 for meta in list {
259269 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 ( ) )
266282 {
267283 self . tcx
268284 . sess
269285 . struct_span_err (
270286 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+ ) ,
272291 )
273292 . emit ( ) ;
274293 return false ;
@@ -304,6 +323,7 @@ impl CheckAttrVisitor<'tcx> {
304323 & format ! ( "`#[doc(alias = \" ...\" )]` isn't allowed on {}" , err) ,
305324 )
306325 . emit ( ) ;
326+ return false ;
307327 }
308328 }
309329 }
0 commit comments