Skip to content

Commit fea103d

Browse files
committed
Auto merge of #8150 - flip1995:clippy_utils_test, r=xFrednet
Test clippy_utils in CI r? `@xFrednet` Since you did the last refactor of the `str_utils` functions in #7873 changelog: Make sure tests in `clippy_utils` are passing by testing it in CI
2 parents 7905130 + eb47398 commit fea103d

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

.github/workflows/clippy.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ jobs:
5858
run: cargo test --features deny-warnings,internal-lints,metadata-collector-lint
5959
working-directory: clippy_lints
6060

61+
- name: Test clippy_utils
62+
run: cargo test --features deny-warnings,internal-lints,metadata-collector-lint
63+
working-directory: clippy_utils
64+
6165
- name: Test rustc_tools_util
6266
run: cargo test --features deny-warnings
6367
working-directory: rustc_tools_util

.github/workflows/clippy_bors.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ jobs:
121121
run: cargo test --features deny-warnings,internal-lints,metadata-collector-lint
122122
working-directory: clippy_lints
123123

124+
- name: Test clippy_utils
125+
run: cargo test --features deny-warnings,internal-lints,metadata-collector-lint
126+
working-directory: clippy_utils
127+
124128
- name: Test rustc_tools_util
125129
run: cargo test --features deny-warnings
126130
working-directory: rustc_tools_util

clippy_utils/src/lib.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,18 +156,18 @@ pub fn differing_macro_contexts(lhs: Span, rhs: Span) -> bool {
156156
/// instead.
157157
///
158158
/// Examples:
159-
/// ```ignore
159+
/// ```
160160
/// let abc = 1;
161161
/// // ^ output
162162
/// let def = abc;
163-
/// dbg!(def)
163+
/// dbg!(def);
164164
/// // ^^^ input
165165
///
166166
/// // or...
167167
/// let abc = 1;
168168
/// let def = abc + 2;
169169
/// // ^^^^^^^ output
170-
/// dbg!(def)
170+
/// dbg!(def);
171171
/// // ^^^ input
172172
/// ```
173173
pub fn expr_or_init<'a, 'b, 'tcx: 'b>(cx: &LateContext<'tcx>, mut expr: &'a Expr<'b>) -> &'a Expr<'b> {
@@ -1136,7 +1136,7 @@ pub fn find_macro_calls(names: &[&str], body: &Body<'_>) -> Vec<Span> {
11361136

11371137
/// Extends the span to the beginning of the spans line, incl. whitespaces.
11381138
///
1139-
/// ```rust,ignore
1139+
/// ```rust
11401140
/// let x = ();
11411141
/// // ^^
11421142
/// // will be converted to
@@ -1337,7 +1337,7 @@ pub fn is_adjusted(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
13371337
cx.typeck_results().adjustments().get(e.hir_id).is_some()
13381338
}
13391339

1340-
/// Returns the pre-expansion span if is this comes from an expansion of the
1340+
/// Returns the pre-expansion span if this comes from an expansion of the
13411341
/// macro `name`.
13421342
/// See also [`is_direct_expn_of`].
13431343
#[must_use]
@@ -1364,7 +1364,8 @@ pub fn is_expn_of(mut span: Span, name: &str) -> Option<Span> {
13641364
/// of the macro `name`.
13651365
/// The difference with [`is_expn_of`] is that in
13661366
/// ```rust
1367-
/// # macro_rules! foo { ($e:tt) => { $e } }; macro_rules! bar { ($e:expr) => { $e } }
1367+
/// # macro_rules! foo { ($name:tt!$args:tt) => { $name!$args } }
1368+
/// # macro_rules! bar { ($e:expr) => { $e } }
13681369
/// foo!(bar!(42));
13691370
/// ```
13701371
/// `42` is considered expanded from `foo!` and `bar!` by `is_expn_of` but only
@@ -1905,7 +1906,9 @@ pub fn is_no_core_crate(cx: &LateContext<'_>) -> bool {
19051906

19061907
/// Check if parent of a hir node is a trait implementation block.
19071908
/// For example, `f` in
1908-
/// ```rust,ignore
1909+
/// ```rust
1910+
/// # struct S;
1911+
/// # trait Trait { fn f(); }
19091912
/// impl Trait for S {
19101913
/// fn f() {}
19111914
/// }

clippy_utils/src/str_utils.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ impl StrIndex {
1515
/// Returns the index of the character after the first camel-case component of `s`.
1616
///
1717
/// ```
18+
/// # use clippy_utils::str_utils::{camel_case_until, StrIndex};
1819
/// assert_eq!(camel_case_until("AbcDef"), StrIndex::new(6, 6));
1920
/// assert_eq!(camel_case_until("ABCD"), StrIndex::new(0, 0));
2021
/// assert_eq!(camel_case_until("AbcDD"), StrIndex::new(3, 3));
@@ -55,9 +56,10 @@ pub fn camel_case_until(s: &str) -> StrIndex {
5556
}
5657
}
5758

58-
/// Returns index of the last camel-case component of `s`.
59+
/// Returns index of the first camel-case component of `s`.
5960
///
6061
/// ```
62+
/// # use clippy_utils::str_utils::{camel_case_start, StrIndex};
6163
/// assert_eq!(camel_case_start("AbcDef"), StrIndex::new(0, 0));
6264
/// assert_eq!(camel_case_start("abcDef"), StrIndex::new(3, 3));
6365
/// assert_eq!(camel_case_start("ABCD"), StrIndex::new(4, 4));
@@ -69,9 +71,9 @@ pub fn camel_case_start(s: &str) -> StrIndex {
6971
let char_count = s.chars().count();
7072
let range = 0..char_count;
7173
let mut iter = range.rev().zip(s.char_indices().rev());
72-
if let Some((char_index, (_, first))) = iter.next() {
74+
if let Some((_, (_, first))) = iter.next() {
7375
if !first.is_lowercase() {
74-
return StrIndex::new(char_index, s.len());
76+
return StrIndex::new(char_count, s.len());
7577
}
7678
} else {
7779
return StrIndex::new(char_count, s.len());
@@ -116,6 +118,7 @@ impl StrCount {
116118
/// Returns the number of chars that match from the start
117119
///
118120
/// ```
121+
/// # use clippy_utils::str_utils::{count_match_start, StrCount};
119122
/// assert_eq!(count_match_start("hello_mouse", "hello_penguin"), StrCount::new(6, 6));
120123
/// assert_eq!(count_match_start("hello_clippy", "bye_bugs"), StrCount::new(0, 0));
121124
/// assert_eq!(count_match_start("hello_world", "hello_world"), StrCount::new(11, 11));
@@ -141,6 +144,7 @@ pub fn count_match_start(str1: &str, str2: &str) -> StrCount {
141144
/// Returns the number of chars and bytes that match from the end
142145
///
143146
/// ```
147+
/// # use clippy_utils::str_utils::{count_match_end, StrCount};
144148
/// assert_eq!(count_match_end("hello_cat", "bye_cat"), StrCount::new(4, 4));
145149
/// assert_eq!(count_match_end("if_item_thing", "enum_value"), StrCount::new(0, 0));
146150
/// assert_eq!(count_match_end("Clippy", "Clippy"), StrCount::new(6, 6));

0 commit comments

Comments
 (0)