Skip to content

Commit 1aa0964

Browse files
Drop RefCell from IdMap in markdown rendering
1 parent c250b5f commit 1aa0964

File tree

6 files changed

+22
-31
lines changed

6 files changed

+22
-31
lines changed

src/librustdoc/externalfiles.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ use crate::syntax::feature_gate::UnstableFeatures;
66
use crate::syntax::edition::Edition;
77
use crate::html::markdown::{IdMap, ErrorCodes, Markdown, Playground};
88

9-
use std::cell::RefCell;
10-
119
#[derive(Clone, Debug)]
1210
pub struct ExternalHtml {
1311
/// Content that will be included inline in the <head> section of a
@@ -35,7 +33,7 @@ impl ExternalHtml {
3533
.and_then(|(ih, bc)|
3634
load_external_files(md_before_content, diag)
3735
.map(|m_bc| (ih,
38-
format!("{}{}", bc, Markdown(&m_bc, &[], RefCell::new(id_map),
36+
format!("{}{}", bc, Markdown(&m_bc, &[], id_map,
3937
codes, edition, playground).to_string())))
4038
)
4139
.and_then(|(ih, bc)|
@@ -45,7 +43,7 @@ impl ExternalHtml {
4543
.and_then(|(ih, bc, ac)|
4644
load_external_files(md_after_content, diag)
4745
.map(|m_ac| (ih, bc,
48-
format!("{}{}", ac, Markdown(&m_ac, &[], RefCell::new(id_map),
46+
format!("{}{}", ac, Markdown(&m_ac, &[], id_map,
4947
codes, edition, playground).to_string())))
5048
)
5149
.map(|(ih, bc, ac)|

src/librustdoc/html/markdown.rs

+7-12
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@
99
//!
1010
//! use syntax::edition::Edition;
1111
//! use rustdoc::html::markdown::{IdMap, Markdown, ErrorCodes};
12-
//! use std::cell::RefCell;
1312
//!
1413
//! let s = "My *markdown* _text_";
1514
//! let mut id_map = IdMap::new();
16-
//! let md = Markdown(s, &[], RefCell::new(&mut id_map),
17-
//! ErrorCodes::Yes, Edition::Edition2015, None);
15+
//! let md = Markdown(s, &[], &mut id_map, ErrorCodes::Yes, Edition::Edition2015, &None);
1816
//! let html = md.to_string();
1917
//! // ... something using html
2018
//! ```
@@ -51,7 +49,7 @@ pub struct Markdown<'a>(
5149
/// A list of link replacements.
5250
pub &'a [(String, String)],
5351
/// The current list of used header IDs.
54-
pub RefCell<&'a mut IdMap>,
52+
pub &'a mut IdMap,
5553
/// Whether to allow the use of explicit error codes in doctest lang strings.
5654
pub ErrorCodes,
5755
/// Default edition to use when parsing doctests (to add a `fn main`).
@@ -61,15 +59,15 @@ pub struct Markdown<'a>(
6159
/// A tuple struct like `Markdown` that renders the markdown with a table of contents.
6260
pub struct MarkdownWithToc<'a>(
6361
pub &'a str,
64-
pub RefCell<&'a mut IdMap>,
62+
pub &'a mut IdMap,
6563
pub ErrorCodes,
6664
pub Edition,
6765
pub &'a Option<Playground>,
6866
);
6967
/// A tuple struct like `Markdown` that renders the markdown escaping HTML tags.
7068
pub struct MarkdownHtml<'a>(
7169
pub &'a str,
72-
pub RefCell<&'a mut IdMap>,
70+
pub &'a mut IdMap,
7371
pub ErrorCodes,
7472
pub Edition,
7573
pub &'a Option<Playground>,
@@ -690,8 +688,7 @@ impl LangString {
690688

691689
impl Markdown<'_> {
692690
pub fn to_string(self) -> String {
693-
let Markdown(md, links, ids, codes, edition, playground) = self;
694-
let mut ids = ids.borrow_mut();
691+
let Markdown(md, links, mut ids, codes, edition, playground) = self;
695692

696693
// This is actually common enough to special-case
697694
if md.is_empty() { return String::new(); }
@@ -719,8 +716,7 @@ impl Markdown<'_> {
719716

720717
impl MarkdownWithToc<'_> {
721718
pub fn to_string(self) -> String {
722-
let MarkdownWithToc(md, ref ids, codes, edition, playground) = self;
723-
let mut ids = ids.borrow_mut();
719+
let MarkdownWithToc(md, mut ids, codes, edition, playground) = self;
724720

725721
let p = Parser::new_ext(md, opts());
726722

@@ -741,8 +737,7 @@ impl MarkdownWithToc<'_> {
741737

742738
impl MarkdownHtml<'_> {
743739
pub fn to_string(self) -> String {
744-
let MarkdownHtml(md, ref ids, codes, edition, playground) = self;
745-
let mut ids = ids.borrow_mut();
740+
let MarkdownHtml(md, mut ids, codes, edition, playground) = self;
746741

747742
// This is actually common enough to special-case
748743
if md.is_empty() { return String::new(); }

src/librustdoc/html/markdown/tests.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ fn test_lang_string_parse() {
7373
fn test_header() {
7474
fn t(input: &str, expect: &str) {
7575
let mut map = IdMap::new();
76-
let output = Markdown(input, &[], RefCell::new(&mut map),
77-
ErrorCodes::Yes, DEFAULT_EDITION).to_string();
76+
let output = Markdown(
77+
input, &[], &mut map, ErrorCodes::Yes, DEFAULT_EDITION, &None).to_string();
7878
assert_eq!(output, expect, "original: {}", input);
7979
}
8080

@@ -96,8 +96,8 @@ fn test_header() {
9696
fn test_header_ids_multiple_blocks() {
9797
let mut map = IdMap::new();
9898
fn t(map: &mut IdMap, input: &str, expect: &str) {
99-
let output = Markdown(input, &[], RefCell::new(map),
100-
ErrorCodes::Yes, DEFAULT_EDITION).to_string();
99+
let output = Markdown(input, &[], map,
100+
ErrorCodes::Yes, DEFAULT_EDITION, &None).to_string();
101101
assert_eq!(output, expect, "original: {}", input);
102102
}
103103

@@ -134,8 +134,8 @@ fn test_plain_summary_line() {
134134
fn test_markdown_html_escape() {
135135
fn t(input: &str, expect: &str) {
136136
let mut idmap = IdMap::new();
137-
let output = MarkdownHtml(input, RefCell::new(&mut idmap),
138-
ErrorCodes::Yes, DEFAULT_EDITION).to_string();
137+
let output = MarkdownHtml(input, &mut idmap,
138+
ErrorCodes::Yes, DEFAULT_EDITION, &None).to_string();
139139
assert_eq!(output, expect, "original: {}", input);
140140
}
141141

src/librustdoc/html/render.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -2595,7 +2595,7 @@ fn render_markdown(w: &mut fmt::Formatter<'_>,
25952595
write!(w, "<div class='docblock{}'>{}{}</div>",
25962596
if is_hidden { " hidden" } else { "" },
25972597
prefix,
2598-
Markdown(md_text, &links, RefCell::new(&mut ids),
2598+
Markdown(md_text, &links, &mut ids,
25992599
cx.codes, cx.edition, &cx.playground).to_string())
26002600
}
26012601

@@ -2961,8 +2961,7 @@ fn short_stability(item: &clean::Item, cx: &Context) -> Vec<String> {
29612961

29622962
if let Some(note) = note {
29632963
let mut ids = cx.id_map.borrow_mut();
2964-
let html = MarkdownHtml(
2965-
&note, RefCell::new(&mut ids), error_codes, cx.edition, &cx.playground);
2964+
let html = MarkdownHtml(&note, &mut ids, error_codes, cx.edition, &cx.playground);
29662965
message.push_str(&format!(": {}", html.to_string()));
29672966
}
29682967
stability.push(format!("<div class='stab deprecated'>{}</div>", message));
@@ -3013,7 +3012,7 @@ fn short_stability(item: &clean::Item, cx: &Context) -> Vec<String> {
30133012
message,
30143013
MarkdownHtml(
30153014
&unstable_reason,
3016-
RefCell::new(&mut ids),
3015+
&mut ids,
30173016
error_codes,
30183017
cx.edition,
30193018
&cx.playground,
@@ -4247,7 +4246,7 @@ fn render_impl(w: &mut fmt::Formatter<'_>, cx: &Context, i: &Impl, link: AssocIt
42474246
if let Some(ref dox) = cx.shared.maybe_collapsed_doc_value(&i.impl_item) {
42484247
let mut ids = cx.id_map.borrow_mut();
42494248
write!(w, "<div class='docblock'>{}</div>",
4250-
Markdown(&*dox, &i.impl_item.links(), RefCell::new(&mut ids),
4249+
Markdown(&*dox, &i.impl_item.links(), &mut ids,
42514250
cx.codes, cx.edition, &cx.playground).to_string())?;
42524251
}
42534252
}

src/librustdoc/markdown.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::fs::File;
22
use std::io::prelude::*;
33
use std::path::PathBuf;
4-
use std::cell::RefCell;
54

65
use errors;
76
use testing;
@@ -83,9 +82,9 @@ pub fn render(
8382
let mut ids = IdMap::new();
8483
let error_codes = ErrorCodes::from(UnstableFeatures::from_environment().is_nightly_build());
8584
let text = if !options.markdown_no_toc {
86-
MarkdownWithToc(text, RefCell::new(&mut ids), error_codes, edition, &playground).to_string()
85+
MarkdownWithToc(text, &mut ids, error_codes, edition, &playground).to_string()
8786
} else {
88-
Markdown(text, &[], RefCell::new(&mut ids), error_codes, edition, &playground).to_string()
87+
Markdown(text, &[], &mut ids, error_codes, edition, &playground).to_string()
8988
};
9089

9190
let err = write!(

src/tools/error_index_generator/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl Formatter for HTMLFormatter {
100100
url: String::from("https://play.rust-lang.org/"),
101101
};
102102
write!(output, "{}",
103-
Markdown(desc, &[], RefCell::new(&mut id_map),
103+
Markdown(desc, &[], &mut id_map,
104104
ErrorCodes::Yes, DEFAULT_EDITION, &Some(playground)).to_string())?
105105
},
106106
None => write!(output, "<p>No description.</p>\n")?,

0 commit comments

Comments
 (0)