@@ -2,11 +2,11 @@ use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
2
2
use itertools:: Itertools ;
3
3
use rustc_errors:: Applicability ;
4
4
use rustc_lint:: LateContext ;
5
- use rustc_span:: { BytePos , Span } ;
5
+ use rustc_span:: BytePos ;
6
6
use std:: cmp:: Ordering ;
7
7
use std:: ops:: Range ;
8
8
9
- use super :: { DOC_LAZY_CONTINUATION , DOC_OVERINDENTED_LIST_ITEMS } ;
9
+ use super :: { DOC_LAZY_CONTINUATION , DOC_OVERINDENTED_LIST_ITEMS , Fragments } ;
10
10
11
11
fn map_container_to_text ( c : & super :: Container ) -> & ' static str {
12
12
match c {
@@ -19,29 +19,27 @@ fn map_container_to_text(c: &super::Container) -> &'static str {
19
19
pub ( super ) fn check (
20
20
cx : & LateContext < ' _ > ,
21
21
doc : & str ,
22
- range : Range < usize > ,
23
- mut span : Span ,
22
+ cooked_range : Range < usize > ,
23
+ fragments : & Fragments < ' _ > ,
24
24
containers : & [ super :: Container ] ,
25
25
) {
26
- if doc[ range. clone ( ) ] . contains ( '\t' ) {
27
- // We don't do tab stops correctly.
28
- return ;
29
- }
30
-
31
- // Blockquote
32
- let ccount = doc[ range. clone ( ) ] . chars ( ) . filter ( |c| * c == '>' ) . count ( ) ;
26
+ // Get blockquotes
27
+ let ccount = doc[ cooked_range. clone ( ) ] . chars ( ) . filter ( |c| * c == '>' ) . count ( ) ;
33
28
let blockquote_level = containers
34
29
. iter ( )
35
30
. filter ( |c| matches ! ( c, super :: Container :: Blockquote ) )
36
31
. count ( ) ;
37
- if ccount < blockquote_level {
32
+
33
+ if ccount < blockquote_level
34
+ && let Some ( mut span) = fragments. span ( cx, cooked_range. clone ( ) )
35
+ {
38
36
span_lint_and_then (
39
37
cx,
40
38
DOC_LAZY_CONTINUATION ,
41
39
span,
42
40
"doc quote line without `>` marker" ,
43
41
|diag| {
44
- let mut doc_start_range = & doc[ range ] ;
42
+ let mut doc_start_range = & doc[ cooked_range ] ;
45
43
let mut suggested = String :: new ( ) ;
46
44
for c in containers {
47
45
let text = map_container_to_text ( c) ;
@@ -78,7 +76,7 @@ pub(super) fn check(
78
76
}
79
77
80
78
// List
81
- let leading_spaces = doc[ range ] . chars ( ) . filter ( |c| * c == ' ' ) . count ( ) ;
79
+ let leading_spaces = doc[ cooked_range . clone ( ) ] . chars ( ) . filter ( |c| * c == ' ' ) . count ( ) ;
82
80
let list_indentation = containers
83
81
. iter ( )
84
82
. map ( |c| {
@@ -89,36 +87,41 @@ pub(super) fn check(
89
87
}
90
88
} )
91
89
. sum ( ) ;
92
- match leading_spaces. cmp ( & list_indentation) {
93
- Ordering :: Less => span_lint_and_then (
94
- cx,
95
- DOC_LAZY_CONTINUATION ,
96
- span,
97
- "doc list item without indentation" ,
98
- |diag| {
99
- // simpler suggestion style for indentation
100
- let indent = list_indentation - leading_spaces;
101
- diag. span_suggestion_verbose (
102
- span. shrink_to_hi ( ) ,
103
- "indent this line" ,
104
- std:: iter:: repeat_n ( " " , indent) . join ( "" ) ,
105
- Applicability :: MaybeIncorrect ,
106
- ) ;
107
- diag. help ( "if this is supposed to be its own paragraph, add a blank line" ) ;
108
- } ,
109
- ) ,
110
- Ordering :: Greater => {
111
- let sugg = std:: iter:: repeat_n ( " " , list_indentation) . join ( "" ) ;
112
- span_lint_and_sugg (
90
+
91
+ if leading_spaces != list_indentation
92
+ && let Some ( span) = fragments. span ( cx, cooked_range. clone ( ) )
93
+ {
94
+ if leading_spaces < list_indentation {
95
+ span_lint_and_then (
113
96
cx,
114
- DOC_OVERINDENTED_LIST_ITEMS ,
97
+ DOC_LAZY_CONTINUATION ,
115
98
span,
116
- "doc list item overindented" ,
117
- format ! ( "try using `{sugg}` ({list_indentation} spaces)" ) ,
118
- sugg,
119
- Applicability :: MaybeIncorrect ,
99
+ "doc list item without indentation" ,
100
+ |diag| {
101
+ // simpler suggestion style for indentation
102
+ let indent = list_indentation - leading_spaces;
103
+ diag. span_suggestion_verbose (
104
+ span. shrink_to_hi ( ) ,
105
+ "indent this line" ,
106
+ std:: iter:: repeat_n ( " " , indent) . join ( "" ) ,
107
+ Applicability :: MaybeIncorrect ,
108
+ ) ;
109
+ diag. help ( "if this is supposed to be its own paragraph, add a blank line" ) ;
110
+ } ,
120
111
) ;
121
- } ,
122
- Ordering :: Equal => { } ,
112
+
113
+ return ;
114
+ }
115
+
116
+ let sugg = std:: iter:: repeat_n ( " " , list_indentation) . join ( "" ) ;
117
+ span_lint_and_sugg (
118
+ cx,
119
+ DOC_OVERINDENTED_LIST_ITEMS ,
120
+ span,
121
+ "doc list item overindented" ,
122
+ format ! ( "try using `{sugg}` ({list_indentation} spaces)" ) ,
123
+ sugg,
124
+ Applicability :: MaybeIncorrect ,
125
+ ) ;
123
126
}
124
127
}
0 commit comments