Skip to content

Commit 3c5da6e

Browse files
authored
Rollup merge of #84953 - GuillaumeGomez:remove-unneeded-with_default_session_globals, r=jyn514
Remove unneeded call to with_default_session_globals in rustdoc highlight This was the origin of the `Span` bug in #84176. cc `````@Aaron1011````` r? `````@jyn514`````
2 parents eec3ae3 + 3c489a3 commit 3c5da6e

File tree

2 files changed

+33
-31
lines changed

2 files changed

+33
-31
lines changed

src/librustdoc/html/highlight.rs

+17-20
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use std::iter::Peekable;
1313
use rustc_lexer::{LiteralKind, TokenKind};
1414
use rustc_span::edition::Edition;
1515
use rustc_span::symbol::Symbol;
16-
use rustc_span::with_default_session_globals;
1716

1817
use super::format::Buffer;
1918

@@ -238,28 +237,26 @@ impl<'a> Classifier<'a> {
238237
/// possibly giving it an HTML span with a class specifying what flavor of
239238
/// token is used.
240239
fn highlight(mut self, sink: &mut dyn FnMut(Highlight<'a>)) {
241-
with_default_session_globals(|| {
242-
loop {
243-
if self
244-
.tokens
245-
.peek()
246-
.map(|t| matches!(t.0, TokenKind::Colon | TokenKind::Ident))
247-
.unwrap_or(false)
248-
{
249-
let tokens = self.get_full_ident_path();
250-
for (token, start, end) in tokens {
251-
let text = &self.src[start..end];
252-
self.advance(token, text, sink);
253-
self.byte_pos += text.len() as u32;
254-
}
255-
}
256-
if let Some((token, text)) = self.next() {
240+
loop {
241+
if self
242+
.tokens
243+
.peek()
244+
.map(|t| matches!(t.0, TokenKind::Colon | TokenKind::Ident))
245+
.unwrap_or(false)
246+
{
247+
let tokens = self.get_full_ident_path();
248+
for (token, start, end) in tokens {
249+
let text = &self.src[start..end];
257250
self.advance(token, text, sink);
258-
} else {
259-
break;
251+
self.byte_pos += text.len() as u32;
260252
}
261253
}
262-
})
254+
if let Some((token, text)) = self.next() {
255+
self.advance(token, text, sink);
256+
} else {
257+
break;
258+
}
259+
}
263260
}
264261

265262
/// Single step of highlighting. This will classify `token`, but maybe also

src/librustdoc/html/highlight/tests.rs

+16-11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use super::write_code;
22
use crate::html::format::Buffer;
33
use expect_test::expect_file;
44
use rustc_span::edition::Edition;
5+
use rustc_span::with_default_session_globals;
56

67
const STYLE: &str = r#"
78
<style>
@@ -17,21 +18,25 @@ const STYLE: &str = r#"
1718

1819
#[test]
1920
fn test_html_highlighting() {
20-
let src = include_str!("fixtures/sample.rs");
21-
let html = {
22-
let mut out = Buffer::new();
23-
write_code(&mut out, src, Edition::Edition2018);
24-
format!("{}<pre><code>{}</code></pre>\n", STYLE, out.into_inner())
25-
};
26-
expect_file!["fixtures/sample.html"].assert_eq(&html);
21+
with_default_session_globals(|| {
22+
let src = include_str!("fixtures/sample.rs");
23+
let html = {
24+
let mut out = Buffer::new();
25+
write_code(&mut out, src, Edition::Edition2018);
26+
format!("{}<pre><code>{}</code></pre>\n", STYLE, out.into_inner())
27+
};
28+
expect_file!["fixtures/sample.html"].assert_eq(&html);
29+
});
2730
}
2831

2932
#[test]
3033
fn test_dos_backline() {
31-
let src = "pub fn foo() {\r\n\
34+
with_default_session_globals(|| {
35+
let src = "pub fn foo() {\r\n\
3236
println!(\"foo\");\r\n\
3337
}\r\n";
34-
let mut html = Buffer::new();
35-
write_code(&mut html, src, Edition::Edition2018);
36-
expect_file!["fixtures/dos_line.html"].assert_eq(&html.into_inner());
38+
let mut html = Buffer::new();
39+
write_code(&mut html, src, Edition::Edition2018);
40+
expect_file!["fixtures/dos_line.html"].assert_eq(&html.into_inner());
41+
});
3742
}

0 commit comments

Comments
 (0)