File tree Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Original file line number Diff line number Diff line change 33use std:: { self , borrow:: Cow , iter} ;
44
55use itertools:: { multipeek, MultiPeek } ;
6+ use lazy_static:: lazy_static;
7+ use regex:: Regex ;
68use rustc_span:: Span ;
79
810use crate :: config:: Config ;
@@ -15,6 +17,17 @@ use crate::utils::{
1517} ;
1618use crate :: { ErrorKind , FormattingError } ;
1719
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+
1831fn is_custom_comment ( comment : & str ) -> bool {
1932 if !comment. starts_with ( "//" ) {
2033 false
@@ -842,7 +855,11 @@ fn trim_custom_comment_prefix(s: &str) -> String {
842855/// Returns `true` if the given string MAY include URLs or alike.
843856fn has_url ( s : & str ) -> bool {
844857 // 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)
846863}
847864
848865/// 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+
3+ pub mod a_long_name {
4+ pub mod b_long_name {
5+ pub mod c_long_name {
6+ pub mod d_long_name {
7+ pub mod e_long_name {
8+ pub struct Bananas ;
9+ impl Bananas {
10+ pub fn fantastic ( ) { }
11+ }
12+
13+ pub mod f_long_name {
14+ pub struct Apples ;
15+ }
16+ }
17+ }
18+ }
19+ }
20+ }
21+
22+ /// Check out [my other struct] ([`Bananas`]) and [the method it has].
23+ ///
24+ /// [my other struct]: a_long_name::b_long_name::c_long_name::d_long_name::e_long_name::f_long_name::Apples
25+ /// [`Bananas`]: a_long_name::b_long_name::c_long_name::d_long_name::e_long_name::Bananas::fantastic()
26+ /// [the method it has]: a_long_name::b_long_name::c_long_name::d_long_name::e_long_name::Bananas::fantastic()
27+ pub struct A ;
You can’t perform that action at this time.
0 commit comments