use std::{self, borrow::Cow, iter};
use itertools::{multipeek, MultiPeek};
+use lazy_static::lazy_static;
+use regex::Regex;
use rustc_span::Span;
use crate::config::Config;
};
use crate::{ErrorKind, FormattingError};
+lazy_static! {
+ /// A regex matching reference doc links.
+ ///
+ /// ```markdown
+ /// /// An [example].
+ /// ///
+ /// /// [example]: this::is::a::link
+ /// ```
+ static ref REFERENCE_LINK_URL: Regex = Regex::new(r"^\[.+\]\s?:").unwrap();
+}
+
fn is_custom_comment(comment: &str) -> bool {
if !comment.starts_with("//") {
false
/// Returns `true` if the given string MAY include URLs or alike.
fn has_url(s: &str) -> bool {
// This function may return false positive, but should get its job done in most cases.
- s.contains("https://") || s.contains("http://") || s.contains("ftp://") || s.contains("file://")
+ s.contains("https://")
+ || s.contains("http://")
+ || s.contains("ftp://")
+ || s.contains("file://")
+ || REFERENCE_LINK_URL.is_match(s)
}
/// Given the span, rewrite the missing comment inside it if available.
--- /dev/null
+// rustfmt-wrap_comments: true
+
+pub mod a_long_name {
+ pub mod b_long_name {
+ pub mod c_long_name {
+ pub mod d_long_name {
+ pub mod e_long_name {
+ pub struct Bananas;
+ impl Bananas {
+ pub fn fantastic() {}
+ }
+
+ pub mod f_long_name {
+ pub struct Apples;
+ }
+ }
+ }
+ }
+ }
+}
+
+/// Check out [my other struct] ([`Bananas`]) and [the method it has].
+///
+/// [my other struct]: a_long_name::b_long_name::c_long_name::d_long_name::e_long_name::f_long_name::Apples
+/// [`Bananas`]: a_long_name::b_long_name::c_long_name::d_long_name::e_long_name::Bananas::fantastic()
+/// [the method it has]: a_long_name::b_long_name::c_long_name::d_long_name::e_long_name::Bananas::fantastic()
+pub struct A;