File tree 2 files changed +46
-1
lines changed
2 files changed +46
-1
lines changed Original file line number Diff line number Diff line change 3
3
use std:: { self , borrow:: Cow , iter} ;
4
4
5
5
use itertools:: { multipeek, MultiPeek } ;
6
+ use lazy_static:: lazy_static;
7
+ use regex:: Regex ;
6
8
use rustc_span:: Span ;
7
9
8
10
use crate :: config:: Config ;
@@ -15,6 +17,17 @@ use crate::utils::{
15
17
} ;
16
18
use crate :: { ErrorKind , FormattingError } ;
17
19
20
+ lazy_static ! {
21
+ /// A regex matching reference doc links.
22
+ ///
23
+ /// ```markdown
24
+ /// /// An [example].
25
+ /// ///
26
+ /// /// [example]: this::is::a::link
27
+ /// ```
28
+ static ref REFERENCE_LINK_URL : Regex = Regex :: new( r"^\[.+\]\s?:" ) . unwrap( ) ;
29
+ }
30
+
18
31
fn is_custom_comment ( comment : & str ) -> bool {
19
32
if !comment. starts_with ( "//" ) {
20
33
false
@@ -842,7 +855,11 @@ fn trim_custom_comment_prefix(s: &str) -> String {
842
855
/// Returns `true` if the given string MAY include URLs or alike.
843
856
fn has_url ( s : & str ) -> bool {
844
857
// This function may return false positive, but should get its job done in most cases.
845
- s. contains ( "https://" ) || s. contains ( "http://" ) || s. contains ( "ftp://" ) || s. contains ( "file://" )
858
+ s. contains ( "https://" )
859
+ || s. contains ( "http://" )
860
+ || s. contains ( "ftp://" )
861
+ || s. contains ( "file://" )
862
+ || REFERENCE_LINK_URL . is_match ( s)
846
863
}
847
864
848
865
/// Given the span, rewrite the missing comment inside it if available.
Original file line number Diff line number Diff line change
1
+ // rustfmt-wrap_comments: true
2
+ // format_code_in_doc_comments: true
3
+
4
+ pub mod a_long_name {
5
+ pub mod b_long_name {
6
+ pub mod c_long_name {
7
+ pub mod d_long_name {
8
+ pub mod e_long_name {
9
+ pub struct Bananas ;
10
+ impl Bananas {
11
+ pub fn fantastic ( ) { }
12
+ }
13
+
14
+ pub mod f_long_name {
15
+ pub struct Apples ;
16
+ }
17
+ }
18
+ }
19
+ }
20
+ }
21
+ }
22
+
23
+ /// Check out [my other struct] ([`Bananas`]) and [the method it has].
24
+ ///
25
+ /// [my other struct]: a_long_name::b_long_name::c_long_name::d_long_name::e_long_name::f_long_name::Apples
26
+ /// [`Bananas`]: a_long_name::b_long_name::c_long_name::d_long_name::e_long_name::Bananas::fantastic()
27
+ /// [the method it has]: a_long_name::b_long_name::c_long_name::d_long_name::e_long_name::Bananas::fantastic()
28
+ pub struct A ;
You can’t perform that action at this time.
0 commit comments