Skip to content

Commit

Permalink
fix typos, more Self
Browse files Browse the repository at this point in the history
typos in comments, remove references to crate-info, Self type in
ordered_json and sorted_template
  • Loading branch information
EtomicBomb committed Aug 8, 2024
1 parent 4b418cd commit b4f057f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
20 changes: 8 additions & 12 deletions src/librustdoc/html/render/ordered_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use itertools::Itertools as _;
use serde::{Deserialize, Serialize};
use serde_json::Value;

/// Prerenedered json.
/// Prerendered json.
///
/// Both the Display and serde_json::to_string implementations write the serialized json
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
Expand All @@ -16,25 +16,21 @@ pub(crate) struct OrderedJson(String);
impl OrderedJson {
/// If you pass in an array, it will not be sorted.
pub(crate) fn serialize<T: Serialize>(item: T) -> Result<Self, serde_json::Error> {
Ok(OrderedJson(serde_json::to_string(&item)?))
Ok(Self(serde_json::to_string(&item)?))
}

/// Serializes and sorts
pub(crate) fn array_sorted<T: Borrow<OrderedJson>, I: IntoIterator<Item = T>>(
items: I,
) -> Self {
pub(crate) fn array_sorted<T: Borrow<Self>, I: IntoIterator<Item = T>>(items: I) -> Self {
let items = items
.into_iter()
.sorted_unstable_by(|a, b| a.borrow().cmp(&b.borrow()))
.format_with(",", |item, f| f(item.borrow()));
OrderedJson(format!("[{}]", items))
Self(format!("[{}]", items))
}

pub(crate) fn array_unsorted<T: Borrow<OrderedJson>, I: IntoIterator<Item = T>>(
items: I,
) -> Self {
pub(crate) fn array_unsorted<T: Borrow<Self>, I: IntoIterator<Item = T>>(items: I) -> Self {
let items = items.into_iter().format_with(",", |item, f| f(item.borrow()));
OrderedJson(format!("[{items}]"))
Self(format!("[{items}]"))
}
}

Expand All @@ -48,7 +44,7 @@ impl From<Value> for OrderedJson {
fn from(value: Value) -> Self {
let serialized =
serde_json::to_string(&value).expect("Serializing a Value to String should never fail");
OrderedJson(serialized)
Self(serialized)
}
}

Expand All @@ -69,7 +65,7 @@ pub(crate) struct EscapedJson(OrderedJson);

impl From<OrderedJson> for EscapedJson {
fn from(json: OrderedJson) -> Self {
EscapedJson(json)
Self(json)
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/html/render/sorted_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct Offset {

impl<F> SortedTemplate<F> {
/// Generate this template from arbitary text.
/// Will insert wherever the substring `magic` can be found.
/// Will insert wherever the substring `delimiter` can be found.
/// Errors if it does not appear exactly once.
pub(crate) fn from_template(template: &str, delimiter: &str) -> Result<Self, Error> {
let mut split = template.split(delimiter);
Expand All @@ -45,7 +45,7 @@ impl<F> SortedTemplate<F> {
pub(crate) fn from_before_after<S: ToString, T: ToString>(before: S, after: T) -> Self {
let before = before.to_string();
let after = after.to_string();
SortedTemplate { format: PhantomData, before, after, fragments: Default::default() }
Self { format: PhantomData, before, after, fragments: Default::default() }
}
}

Expand Down Expand Up @@ -100,7 +100,7 @@ impl<F: FileFormat> FromStr for SortedTemplate<F> {
.ok_or(Error("invalid fragment length: expected to find separator here"))?;
fragments.insert(fragment.to_string());
}
Ok(SortedTemplate {
Ok(Self {
format: PhantomData,
before: before.to_string(),
after: s.to_string(),
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/render/write_shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use crate::html::static_files::{self, suffix_path};
use crate::visit::DocVisitor;
use crate::{try_err, try_none};

/// Write crate-info.json cross-crate information, static files, invocation-specific files, etc. to disk
/// Write cross-crate information files, static files, invocation-specific files, etc. to disk
pub(crate) fn write_shared(
cx: &mut Context<'_>,
krate: &Crate,
Expand Down Expand Up @@ -184,7 +184,7 @@ fn write_search_desc(
Ok(())
}

/// Written to `crate-info.json`. Contains pre-rendered contents to insert into the CCI template
/// Contains pre-rendered contents to insert into the CCI template
#[derive(Serialize, Deserialize, Clone, Debug)]
struct CrateInfo {
src_files_js: PartsAndLocations<SourcesPart>,
Expand Down

0 comments on commit b4f057f

Please sign in to comment.