Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit e84902d

Browse files
committed
Auto merge of rust-lang#133047 - matthiaskrgr:rollup-9se1vth, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - rust-lang#128197 (Skip locking span interner for some syntax context checks) - rust-lang#133040 ([rustdoc] Fix handling of footnote reference in footnote definition) - rust-lang#133043 (rustdoc-search: case-sensitive only when capitals are used) - rust-lang#133046 (Clippy subtree update) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 90ab8ea + d6a9ded commit e84902d

File tree

100 files changed

+1269
-325
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+1269
-325
lines changed

compiler/rustc_span/src/lib.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -559,12 +559,6 @@ impl Span {
559559
!self.is_dummy() && sm.is_span_accessible(self)
560560
}
561561

562-
/// Returns `true` if this span comes from any kind of macro, desugaring or inlining.
563-
#[inline]
564-
pub fn from_expansion(self) -> bool {
565-
!self.ctxt().is_root()
566-
}
567-
568562
/// Returns `true` if `span` originates in a derive-macro's expansion.
569563
pub fn in_derive_expansion(self) -> bool {
570564
matches!(self.ctxt().outer_expn_data().kind, ExpnKind::Macro(MacroKind::Derive, _))

compiler/rustc_span/src/span_encoding.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,13 @@ impl Span {
303303
}
304304
}
305305

306+
/// Returns `true` if this span comes from any kind of macro, desugaring or inlining.
307+
#[inline]
308+
pub fn from_expansion(self) -> bool {
309+
// If the span is fully inferred then ctxt > MAX_CTXT
310+
self.inline_ctxt().map_or(true, |ctxt| !ctxt.is_root())
311+
}
312+
306313
/// Returns `true` if this is a dummy span with any hygienic context.
307314
#[inline]
308315
pub fn is_dummy(self) -> bool {
@@ -370,9 +377,10 @@ impl Span {
370377
pub fn eq_ctxt(self, other: Span) -> bool {
371378
match (self.inline_ctxt(), other.inline_ctxt()) {
372379
(Ok(ctxt1), Ok(ctxt2)) => ctxt1 == ctxt2,
373-
(Ok(ctxt), Err(index)) | (Err(index), Ok(ctxt)) => {
374-
with_span_interner(|interner| ctxt == interner.spans[index].ctxt)
375-
}
380+
// If `inline_ctxt` returns `Ok` the context is <= MAX_CTXT.
381+
// If it returns `Err` the span is fully interned and the context is > MAX_CTXT.
382+
// As these do not overlap an `Ok` and `Err` result cannot have an equal context.
383+
(Ok(_), Err(_)) | (Err(_), Ok(_)) => false,
376384
(Err(index1), Err(index2)) => with_span_interner(|interner| {
377385
interner.spans[index1].ctxt == interner.spans[index2].ctxt
378386
}),

src/librustdoc/html/markdown/footnotes.rs

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Markdown footnote handling.
22
use std::fmt::Write as _;
33

4-
use pulldown_cmark::{Event, Tag, TagEnd, html};
4+
use pulldown_cmark::{CowStr, Event, Tag, TagEnd, html};
55
use rustc_data_structures::fx::FxIndexMap;
66

77
use super::SpannedEvent;
@@ -21,7 +21,7 @@ struct FootnoteDef<'a> {
2121
id: usize,
2222
}
2323

24-
impl<'a, 'b, I> Footnotes<'a, 'b, I> {
24+
impl<'a, 'b, I: Iterator<Item = SpannedEvent<'a>>> Footnotes<'a, 'b, I> {
2525
pub(super) fn new(iter: I, existing_footnotes: &'b mut usize) -> Self {
2626
Footnotes { inner: iter, footnotes: FxIndexMap::default(), existing_footnotes }
2727
}
@@ -34,31 +34,50 @@ impl<'a, 'b, I> Footnotes<'a, 'b, I> {
3434
// Don't allow changing the ID of existing entrys, but allow changing the contents.
3535
(content, *id)
3636
}
37+
38+
fn handle_footnote_reference(&mut self, reference: &CowStr<'a>) -> Event<'a> {
39+
// When we see a reference (to a footnote we may not know) the definition of,
40+
// reserve a number for it, and emit a link to that number.
41+
let (_, id) = self.get_entry(reference);
42+
let reference = format!(
43+
"<sup id=\"fnref{0}\"><a href=\"#fn{0}\">{1}</a></sup>",
44+
id,
45+
// Although the ID count is for the whole page, the footnote reference
46+
// are local to the item so we make this ID "local" when displayed.
47+
id - *self.existing_footnotes
48+
);
49+
Event::Html(reference.into())
50+
}
51+
52+
fn collect_footnote_def(&mut self) -> Vec<Event<'a>> {
53+
let mut content = Vec::new();
54+
while let Some((event, _)) = self.inner.next() {
55+
match event {
56+
Event::End(TagEnd::FootnoteDefinition) => break,
57+
Event::FootnoteReference(ref reference) => {
58+
content.push(self.handle_footnote_reference(reference));
59+
}
60+
event => content.push(event),
61+
}
62+
}
63+
content
64+
}
3765
}
3866

3967
impl<'a, 'b, I: Iterator<Item = SpannedEvent<'a>>> Iterator for Footnotes<'a, 'b, I> {
4068
type Item = SpannedEvent<'a>;
4169

4270
fn next(&mut self) -> Option<Self::Item> {
4371
loop {
44-
match self.inner.next() {
72+
let next = self.inner.next();
73+
match next {
4574
Some((Event::FootnoteReference(ref reference), range)) => {
46-
// When we see a reference (to a footnote we may not know) the definition of,
47-
// reserve a number for it, and emit a link to that number.
48-
let (_, id) = self.get_entry(reference);
49-
let reference = format!(
50-
"<sup id=\"fnref{0}\"><a href=\"#fn{0}\">{1}</a></sup>",
51-
id,
52-
// Although the ID count is for the whole page, the footnote reference
53-
// are local to the item so we make this ID "local" when displayed.
54-
id - *self.existing_footnotes
55-
);
56-
return Some((Event::Html(reference.into()), range));
75+
return Some((self.handle_footnote_reference(reference), range));
5776
}
5877
Some((Event::Start(Tag::FootnoteDefinition(def)), _)) => {
5978
// When we see a footnote definition, collect the assocated content, and store
6079
// that for rendering later.
61-
let content = collect_footnote_def(&mut self.inner);
80+
let content = self.collect_footnote_def();
6281
let (entry_content, _) = self.get_entry(&def);
6382
*entry_content = content;
6483
}
@@ -80,17 +99,6 @@ impl<'a, 'b, I: Iterator<Item = SpannedEvent<'a>>> Iterator for Footnotes<'a, 'b
8099
}
81100
}
82101

83-
fn collect_footnote_def<'a>(events: impl Iterator<Item = SpannedEvent<'a>>) -> Vec<Event<'a>> {
84-
let mut content = Vec::new();
85-
for (event, _) in events {
86-
if let Event::End(TagEnd::FootnoteDefinition) = event {
87-
break;
88-
}
89-
content.push(event);
90-
}
91-
content
92-
}
93-
94102
fn render_footnotes_defs(mut footnotes: Vec<FootnoteDef<'_>>) -> String {
95103
let mut ret = String::from("<div class=\"footnotes\"><hr><ol>");
96104

src/librustdoc/html/static/js/search.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2667,6 +2667,7 @@ class DocSearch {
26672667
const sortResults = async(results, typeInfo, preferredCrate) => {
26682668
const userQuery = parsedQuery.userQuery;
26692669
const normalizedUserQuery = parsedQuery.userQuery.toLowerCase();
2670+
const isMixedCase = normalizedUserQuery !== userQuery;
26702671
const result_list = [];
26712672
for (const result of results.values()) {
26722673
result.item = this.searchIndex[result.id];
@@ -2678,10 +2679,12 @@ class DocSearch {
26782679
let a, b;
26792680

26802681
// sort by exact case-sensitive match
2681-
a = (aaa.item.name !== userQuery);
2682-
b = (bbb.item.name !== userQuery);
2683-
if (a !== b) {
2684-
return a - b;
2682+
if (isMixedCase) {
2683+
a = (aaa.item.name !== userQuery);
2684+
b = (bbb.item.name !== userQuery);
2685+
if (a !== b) {
2686+
return a - b;
2687+
}
26852688
}
26862689

26872690
// sort by exact match with regard to the last word (mismatch goes later)

src/tools/clippy/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6071,6 +6071,7 @@ Released 2018-09-13
60716071
[`unnecessary_literal_bound`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_literal_bound
60726072
[`unnecessary_literal_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_literal_unwrap
60736073
[`unnecessary_map_on_constructor`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_on_constructor
6074+
[`unnecessary_map_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_or
60746075
[`unnecessary_min_or_max`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_min_or_max
60756076
[`unnecessary_mut_passed`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_mut_passed
60766077
[`unnecessary_operation`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_operation

src/tools/clippy/clippy_dev/src/setup/vscode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ fn delete_vs_task_file(path: &Path) -> bool {
8484
/// It may fail silently.
8585
fn try_delete_vs_directory_if_empty() {
8686
let path = Path::new(VSCODE_DIR);
87-
if path.read_dir().map_or(false, |mut iter| iter.next().is_none()) {
87+
if path.read_dir().is_ok_and(|mut iter| iter.next().is_none()) {
8888
// The directory is empty. We just try to delete it but allow a silence
8989
// fail as an empty `.vscode` directory is still valid
9090
let _silence_result = fs::remove_dir(path);

src/tools/clippy/clippy_lints/src/attrs/useless_attribute.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub(super) fn check(cx: &EarlyContext<'_>, item: &Item, attrs: &[Attribute]) {
1616
return;
1717
}
1818
if let Some(lint_list) = &attr.meta_item_list() {
19-
if attr.ident().map_or(false, |ident| is_lint_level(ident.name, attr.id)) {
19+
if attr.ident().is_some_and(|ident| is_lint_level(ident.name, attr.id)) {
2020
for lint in lint_list {
2121
match item.kind {
2222
ItemKind::Use(..) => {

src/tools/clippy/clippy_lints/src/attrs/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fn is_relevant_block(cx: &LateContext<'_>, typeck_results: &ty::TypeckResults<'_
5050
block
5151
.expr
5252
.as_ref()
53-
.map_or(false, |e| is_relevant_expr(cx, typeck_results, e)),
53+
.is_some_and(|e| is_relevant_expr(cx, typeck_results, e)),
5454
|stmt| match &stmt.kind {
5555
StmtKind::Let(_) => true,
5656
StmtKind::Expr(expr) | StmtKind::Semi(expr) => is_relevant_expr(cx, typeck_results, expr),
@@ -60,7 +60,7 @@ fn is_relevant_block(cx: &LateContext<'_>, typeck_results: &ty::TypeckResults<'_
6060
}
6161

6262
fn is_relevant_expr(cx: &LateContext<'_>, typeck_results: &ty::TypeckResults<'_>, expr: &Expr<'_>) -> bool {
63-
if macro_backtrace(expr.span).last().map_or(false, |macro_call| {
63+
if macro_backtrace(expr.span).last().is_some_and(|macro_call| {
6464
is_panic(cx, macro_call.def_id) || cx.tcx.item_name(macro_call.def_id) == sym::unreachable
6565
}) {
6666
return false;

src/tools/clippy/clippy_lints/src/bool_assert_comparison.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ fn is_impl_not_trait_with_bool_out<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -
6060
trait_id,
6161
)
6262
})
63-
.map_or(false, |assoc_item| {
64-
let proj = Ty::new_projection_from_args(cx.tcx, assoc_item.def_id, cx.tcx.mk_args_trait(ty, []));
63+
.is_some_and(|assoc_item| {
64+
let proj = Ty::new_projection(cx.tcx, assoc_item.def_id, cx.tcx.mk_args_trait(ty, []));
6565
let nty = cx.tcx.normalize_erasing_regions(cx.param_env, proj);
6666

6767
nty.is_bool()

src/tools/clippy/clippy_lints/src/booleans.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,5 +667,5 @@ fn implements_ord(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
667667
let ty = cx.typeck_results().expr_ty(expr);
668668
cx.tcx
669669
.get_diagnostic_item(sym::Ord)
670-
.map_or(false, |id| implements_trait(cx, ty, id, &[]))
670+
.is_some_and(|id| implements_trait(cx, ty, id, &[]))
671671
}

0 commit comments

Comments
 (0)