Skip to content

Commit 9c43a84

Browse files
committed
chore: Update lints from epage/_rust template
1 parent b5a6b53 commit 9c43a84

File tree

6 files changed

+108
-44
lines changed

6 files changed

+108
-44
lines changed

Cargo.toml

+65-1
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,68 @@ default = []
5050
testing-colors = []
5151

5252
[lints.rust]
53-
rust_2018_idioms = "warn"
53+
rust_2018_idioms = { level = "warn", priority = -1 }
54+
unreachable_pub = "warn"
55+
unsafe_op_in_unsafe_fn = "warn"
56+
unused_lifetimes = "warn"
57+
unused_macro_rules = "warn"
58+
unused_qualifications = "warn"
59+
60+
[lints.clippy]
61+
bool_assert_comparison = "allow"
62+
branches_sharing_code = "allow"
63+
checked_conversions = "warn"
64+
collapsible_else_if = "allow"
65+
create_dir = "warn"
66+
dbg_macro = "warn"
67+
debug_assert_with_mut_call = "warn"
68+
doc_markdown = "warn"
69+
empty_enum = "warn"
70+
enum_glob_use = "warn"
71+
expl_impl_clone_on_copy = "warn"
72+
explicit_deref_methods = "warn"
73+
explicit_into_iter_loop = "warn"
74+
fallible_impl_from = "warn"
75+
filter_map_next = "warn"
76+
flat_map_option = "warn"
77+
float_cmp_const = "warn"
78+
fn_params_excessive_bools = "warn"
79+
from_iter_instead_of_collect = "warn"
80+
if_same_then_else = "allow"
81+
implicit_clone = "warn"
82+
imprecise_flops = "warn"
83+
inconsistent_struct_constructor = "warn"
84+
inefficient_to_string = "warn"
85+
infinite_loop = "warn"
86+
invalid_upcast_comparisons = "warn"
87+
large_digit_groups = "warn"
88+
large_stack_arrays = "warn"
89+
large_types_passed_by_value = "warn"
90+
let_and_return = "allow" # sometimes good to name what you are returning
91+
linkedlist = "warn"
92+
lossy_float_literal = "warn"
93+
macro_use_imports = "warn"
94+
mem_forget = "warn"
95+
mutex_integer = "warn"
96+
needless_continue = "warn"
97+
needless_for_each = "warn"
98+
negative_feature_names = "warn"
99+
path_buf_push_overwrite = "warn"
100+
ptr_as_ptr = "warn"
101+
rc_mutex = "warn"
102+
redundant_feature_names = "warn"
103+
ref_option_ref = "warn"
104+
rest_pat_in_fully_bound_structs = "warn"
105+
same_functions_in_if_condition = "warn"
106+
self_named_module_files = "warn"
107+
semicolon_if_nothing_returned = "warn"
108+
str_to_string = "warn"
109+
string_add = "warn"
110+
string_add_assign = "warn"
111+
string_lit_as_bytes = "warn"
112+
string_to_string = "warn"
113+
todo = "warn"
114+
trait_duplication_in_bounds = "warn"
115+
verbose_file_reads = "warn"
116+
wildcard_imports = "warn"
117+
zero_sized_map_values = "warn"

benches/simple.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fn create_snippet(renderer: Renderer) {
5050

5151
pub fn criterion_benchmark(c: &mut Criterion) {
5252
c.bench_function("format", |b| {
53-
b.iter(|| black_box(create_snippet(Renderer::plain())))
53+
b.iter(|| black_box(create_snippet(Renderer::plain())));
5454
});
5555
}
5656

src/renderer/display_list.rs

+32-32
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! display_list module stores the output model for the snippet.
1+
//! `display_list` module stores the output model for the snippet.
22
//!
33
//! `DisplayList` is a central structure in the crate, which contains
44
//! the structured list of lines to be displayed.
@@ -48,9 +48,9 @@ const WARNING_TXT: &str = "warning";
4848

4949
/// List of lines to be displayed.
5050
pub(crate) struct DisplayList<'a> {
51-
pub body: Vec<DisplaySet<'a>>,
52-
pub stylesheet: &'a Stylesheet,
53-
pub anonymized_line_numbers: bool,
51+
pub(crate) body: Vec<DisplaySet<'a>>,
52+
pub(crate) stylesheet: &'a Stylesheet,
53+
pub(crate) anonymized_line_numbers: bool,
5454
}
5555

5656
impl<'a> PartialEq for DisplayList<'a> {
@@ -147,8 +147,8 @@ impl<'a> DisplayList<'a> {
147147

148148
#[derive(Debug, PartialEq)]
149149
pub(crate) struct DisplaySet<'a> {
150-
pub display_lines: Vec<DisplayLine<'a>>,
151-
pub margin: Margin,
150+
pub(crate) display_lines: Vec<DisplayLine<'a>>,
151+
pub(crate) margin: Margin,
152152
}
153153

154154
impl<'a> DisplaySet<'a> {
@@ -493,15 +493,15 @@ impl<'a> DisplaySet<'a> {
493493

494494
/// Inline annotation which can be used in either Raw or Source line.
495495
#[derive(Debug, PartialEq)]
496-
pub struct Annotation<'a> {
497-
pub annotation_type: DisplayAnnotationType,
498-
pub id: Option<&'a str>,
499-
pub label: Vec<DisplayTextFragment<'a>>,
496+
pub(crate) struct Annotation<'a> {
497+
pub(crate) annotation_type: DisplayAnnotationType,
498+
pub(crate) id: Option<&'a str>,
499+
pub(crate) label: Vec<DisplayTextFragment<'a>>,
500500
}
501501

502502
/// A single line used in `DisplayList`.
503503
#[derive(Debug, PartialEq)]
504-
pub enum DisplayLine<'a> {
504+
pub(crate) enum DisplayLine<'a> {
505505
/// A line with `lineno` portion of the slice.
506506
Source {
507507
lineno: Option<usize>,
@@ -519,7 +519,7 @@ pub enum DisplayLine<'a> {
519519

520520
/// A source line.
521521
#[derive(Debug, PartialEq)]
522-
pub enum DisplaySourceLine<'a> {
522+
pub(crate) enum DisplaySourceLine<'a> {
523523
/// A line with the content of the Snippet.
524524
Content {
525525
text: &'a str,
@@ -530,17 +530,17 @@ pub enum DisplaySourceLine<'a> {
530530
}
531531

532532
#[derive(Debug, PartialEq)]
533-
pub struct DisplaySourceAnnotation<'a> {
534-
pub annotation: Annotation<'a>,
535-
pub range: (usize, usize),
536-
pub annotation_type: DisplayAnnotationType,
537-
pub annotation_part: DisplayAnnotationPart,
533+
pub(crate) struct DisplaySourceAnnotation<'a> {
534+
pub(crate) annotation: Annotation<'a>,
535+
pub(crate) range: (usize, usize),
536+
pub(crate) annotation_type: DisplayAnnotationType,
537+
pub(crate) annotation_part: DisplayAnnotationPart,
538538
}
539539

540540
/// Raw line - a line which does not have the `lineno` part and is not considered
541541
/// a part of the snippet.
542542
#[derive(Debug, PartialEq)]
543-
pub enum DisplayRawLine<'a> {
543+
pub(crate) enum DisplayRawLine<'a> {
544544
/// A line which provides information about the location of the given
545545
/// slice in the project structure.
546546
Origin {
@@ -566,23 +566,23 @@ pub enum DisplayRawLine<'a> {
566566

567567
/// An inline text fragment which any label is composed of.
568568
#[derive(Debug, PartialEq)]
569-
pub struct DisplayTextFragment<'a> {
570-
pub content: &'a str,
571-
pub style: DisplayTextStyle,
569+
pub(crate) struct DisplayTextFragment<'a> {
570+
pub(crate) content: &'a str,
571+
pub(crate) style: DisplayTextStyle,
572572
}
573573

574574
/// A style for the `DisplayTextFragment` which can be visually formatted.
575575
///
576576
/// This information may be used to emphasis parts of the label.
577577
#[derive(Debug, Clone, Copy, PartialEq)]
578-
pub enum DisplayTextStyle {
578+
pub(crate) enum DisplayTextStyle {
579579
Regular,
580580
Emphasis,
581581
}
582582

583583
/// An indicator of what part of the annotation a given `Annotation` is.
584584
#[derive(Debug, Clone, PartialEq)]
585-
pub enum DisplayAnnotationPart {
585+
pub(crate) enum DisplayAnnotationPart {
586586
/// A standalone, single-line annotation.
587587
Standalone,
588588
/// A continuation of a multi-line label of an annotation.
@@ -595,14 +595,14 @@ pub enum DisplayAnnotationPart {
595595

596596
/// A visual mark used in `inline_marks` field of the `DisplaySourceLine`.
597597
#[derive(Debug, Clone, PartialEq)]
598-
pub struct DisplayMark {
599-
pub mark_type: DisplayMarkType,
600-
pub annotation_type: DisplayAnnotationType,
598+
pub(crate) struct DisplayMark {
599+
pub(crate) mark_type: DisplayMarkType,
600+
pub(crate) annotation_type: DisplayAnnotationType,
601601
}
602602

603603
/// A type of the `DisplayMark`.
604604
#[derive(Debug, Clone, PartialEq)]
605-
pub enum DisplayMarkType {
605+
pub(crate) enum DisplayMarkType {
606606
/// A mark indicating a multiline annotation going through the current line.
607607
AnnotationThrough,
608608
/// A mark indicating a multiline annotation starting on the given line.
@@ -617,7 +617,7 @@ pub enum DisplayMarkType {
617617
/// * An underline for `Error` may be `^^^` while for `Warning` it could be `---`.
618618
/// * `ColorStylesheet` may use different colors for different annotations.
619619
#[derive(Debug, Clone, PartialEq)]
620-
pub enum DisplayAnnotationType {
620+
pub(crate) enum DisplayAnnotationType {
621621
None,
622622
Error,
623623
Warning,
@@ -642,7 +642,7 @@ impl From<snippet::Level> for DisplayAnnotationType {
642642
/// for multi-slice cases.
643643
// TODO: private
644644
#[derive(Debug, Clone, PartialEq)]
645-
pub enum DisplayHeaderType {
645+
pub(crate) enum DisplayHeaderType {
646646
/// Initial header is the first header in the snippet.
647647
Initial,
648648

@@ -728,9 +728,9 @@ fn format_message(
728728
}
729729

730730
if let Some(first) = sets.first_mut() {
731-
body.into_iter().for_each(|line| {
731+
for line in body {
732732
first.display_lines.insert(0, line);
733-
});
733+
}
734734
} else {
735735
sets.push(DisplaySet {
736736
display_lines: body,
@@ -1335,7 +1335,7 @@ const OUTPUT_REPLACEMENTS: &[(char, &str)] = &[
13351335
];
13361336

13371337
fn normalize_whitespace(str: &str) -> String {
1338-
let mut s = str.to_string();
1338+
let mut s = str.to_owned();
13391339
for (c, replacement) in OUTPUT_REPLACEMENTS {
13401340
s = s.replace(*c, replacement);
13411341
}

src/renderer/margin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const LONG_WHITESPACE: usize = 20;
55
const LONG_WHITESPACE_PADDING: usize = 4;
66

77
#[derive(Clone, Copy, Debug, PartialEq)]
8-
pub struct Margin {
8+
pub(crate) struct Margin {
99
/// The available whitespace in the left that can be consumed when centering.
1010
whitespace_left: usize,
1111
/// The column of the beginning of left-most span.
@@ -24,7 +24,7 @@ pub struct Margin {
2424
}
2525

2626
impl Margin {
27-
pub fn new(
27+
pub(crate) fn new(
2828
whitespace_left: usize,
2929
span_left: usize,
3030
span_right: usize,

tests/fixtures/deserialize.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ use annotate_snippets::renderer::DEFAULT_TERM_WIDTH;
55
use annotate_snippets::{Annotation, Level, Message, Renderer, Snippet};
66

77
#[derive(Deserialize)]
8-
pub struct Fixture<'a> {
8+
pub(crate) struct Fixture<'a> {
99
#[serde(default)]
10-
pub renderer: RendererDef,
10+
pub(crate) renderer: RendererDef,
1111
#[serde(borrow)]
12-
pub message: MessageDef<'a>,
12+
pub(crate) message: MessageDef<'a>,
1313
}
1414

1515
#[derive(Deserialize)]
@@ -88,7 +88,7 @@ impl<'a> From<SnippetDef<'a>> for Snippet<'a> {
8888
} = val;
8989
let mut snippet = Snippet::source(source).line_start(line_start).fold(fold);
9090
if let Some(origin) = origin {
91-
snippet = snippet.origin(origin)
91+
snippet = snippet.origin(origin);
9292
}
9393
snippet = snippet.annotations(annotations);
9494
snippet
@@ -127,11 +127,11 @@ impl<'a> From<AnnotationDef<'a>> for Annotation<'a> {
127127
}
128128

129129
#[derive(Serialize, Deserialize)]
130-
pub struct LabelDef<'a> {
130+
pub(crate) struct LabelDef<'a> {
131131
#[serde(with = "LevelDef")]
132-
pub level: Level,
132+
pub(crate) level: Level,
133133
#[serde(borrow)]
134-
pub label: &'a str,
134+
pub(crate) label: &'a str,
135135
}
136136

137137
#[allow(dead_code)]

tests/fixtures/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn main() {
1515

1616
fn setup(input_path: std::path::PathBuf) -> tryfn::Case {
1717
let name = input_path.file_name().unwrap().to_str().unwrap().to_owned();
18-
let expected = tryfn::Data::read_from(&input_path.with_extension("svg"), None);
18+
let expected = Data::read_from(&input_path.with_extension("svg"), None);
1919
tryfn::Case {
2020
name,
2121
fixture: input_path,

0 commit comments

Comments
 (0)