Fix a few nursery rule violations (#2548)

This commit is contained in:
Charlie Marsh
2023-02-03 11:59:29 -05:00
committed by GitHub
parent 38addbe50d
commit 85ca6cde49
42 changed files with 140 additions and 145 deletions

View File

@@ -57,8 +57,12 @@ impl<'a> From<&'a Stylist<'a>> for Generator<'a> {
}
impl<'a> Generator<'a> {
pub fn new(indent: &'a Indentation, quote: &'a Quote, line_ending: &'a LineEnding) -> Self {
Generator {
pub const fn new(
indent: &'a Indentation,
quote: &'a Quote,
line_ending: &'a LineEnding,
) -> Self {
Self {
// Style preferences.
indent,
quote,

View File

@@ -93,8 +93,8 @@ fn truncate(location: Location, index: &Index, contents: &str) -> usize {
}
impl<'a> Locator<'a> {
pub fn new(contents: &'a str) -> Self {
Locator {
pub const fn new(contents: &'a str) -> Self {
Self {
contents,
index: OnceCell::new(),
}
@@ -140,11 +140,11 @@ impl<'a> Locator<'a> {
)
}
pub fn len(&self) -> usize {
pub const fn len(&self) -> usize {
self.contents.len()
}
pub fn is_empty(&self) -> bool {
pub const fn is_empty(&self) -> bool {
self.contents.is_empty()
}
}

View File

@@ -97,7 +97,7 @@ impl From<&Quote> for char {
pub struct Indentation(String);
impl Indentation {
pub fn new(indentation: String) -> Self {
pub const fn new(indentation: String) -> Self {
Self(indentation)
}
}
@@ -142,7 +142,7 @@ impl Default for LineEnding {
}
impl LineEnding {
pub fn as_str(&self) -> &'static str {
pub const fn as_str(&self) -> &'static str {
match self {
LineEnding::CrLf => "\r\n",
LineEnding::Lf => "\n",