-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Introduce Symbol::with_interner
.
#144287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Introduce Symbol::with_interner
.
#144287
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,26 +141,32 @@ pub fn unindent_doc_fragments(docs: &mut [DocFragment]) { | |
// In here, the `min_indent` is 1 (because non-sugared fragment are always counted with minimum | ||
// 1 whitespace), meaning that "hello!" will be considered a codeblock because it starts with 4 | ||
// (5 - 1) whitespaces. | ||
let Some(min_indent) = docs | ||
.iter() | ||
.map(|fragment| { | ||
fragment | ||
.doc | ||
.as_str() | ||
.lines() | ||
.filter(|line| line.chars().any(|c| !c.is_whitespace())) | ||
.map(|line| { | ||
// Compare against either space or tab, ignoring whether they are | ||
// mixed or not. | ||
let whitespace = line.chars().take_while(|c| *c == ' ' || *c == '\t').count(); | ||
whitespace | ||
+ (if fragment.kind == DocFragmentKind::SugaredDoc { 0 } else { add }) | ||
let Some(min_indent) = ({ | ||
Symbol::with_interner(|interner| { | ||
docs.iter() | ||
.map(|fragment| { | ||
interner | ||
.get_str(fragment.doc) | ||
.lines() | ||
.filter(|line| line.chars().any(|c| !c.is_whitespace())) | ||
.map(|line| { | ||
// Compare against either space or tab, ignoring whether they are | ||
// mixed or not. | ||
let whitespace = | ||
line.chars().take_while(|c| *c == ' ' || *c == '\t').count(); | ||
whitespace | ||
+ (if fragment.kind == DocFragmentKind::SugaredDoc { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: the formatting is bad, could you move the if expression to a local variable or something like that? |
||
0 | ||
} else { | ||
add | ||
}) | ||
}) | ||
.min() | ||
.unwrap_or(usize::MAX) | ||
}) | ||
.min() | ||
.unwrap_or(usize::MAX) | ||
}) | ||
.min() | ||
else { | ||
}) else { | ||
return; | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ use rustc_hir::def_id::DefId; | |
use rustc_index::IndexVec; | ||
use rustc_middle::ty::{self, TyCtxt}; | ||
use rustc_span::hygiene::MacroKind; | ||
use rustc_span::symbol::{Symbol, sym}; | ||
use rustc_span::symbol::{InternerInner, Symbol, sym}; | ||
use tracing::{debug, info}; | ||
|
||
use super::type_layout::document_type_layout; | ||
|
@@ -333,7 +333,12 @@ fn item_module(cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) -> i | |
} | ||
} | ||
|
||
fn cmp(i1: &clean::Item, i2: &clean::Item, tcx: TyCtxt<'_>) -> Ordering { | ||
fn cmp( | ||
i1: &clean::Item, | ||
i2: &clean::Item, | ||
interner: &InternerInner, | ||
tcx: TyCtxt<'_>, | ||
) -> Ordering { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, the interner is locked for very long time. |
||
let rty1 = reorder(i1.type_()); | ||
let rty2 = reorder(i2.type_()); | ||
if rty1 != rty2 { | ||
|
@@ -349,7 +354,9 @@ fn item_module(cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) -> i | |
return is_stable2.cmp(&is_stable1); | ||
} | ||
match (i1.name, i2.name) { | ||
(Some(name1), Some(name2)) => compare_names(name1.as_str(), name2.as_str()), | ||
(Some(name1), Some(name2)) => { | ||
compare_names(interner.get_str(name1), interner.get_str(name2)) | ||
} | ||
(Some(_), None) => Ordering::Greater, | ||
(None, Some(_)) => Ordering::Less, | ||
(None, None) => Ordering::Equal, | ||
|
@@ -360,7 +367,9 @@ fn item_module(cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) -> i | |
|
||
match cx.shared.module_sorting { | ||
ModuleSorting::Alphabetical => { | ||
not_stripped_items.sort_by(|(_, i1), (_, i2)| cmp(i1, i2, tcx)); | ||
Symbol::with_interner(|interner| { | ||
not_stripped_items.sort_by(|(_, i1), (_, i2)| cmp(i1, i2, interner, tcx)); | ||
}); | ||
} | ||
ModuleSorting::DeclarationOrder => {} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: the interner is locked for slightly longer than necessary.