Rollup merge of #138678 - durin42:rmeta-stability, r=fmease

rustc_resolve: fix instability in lib.rmeta contents

rust-lang/rust@23032f31c9 accidentally introduced some nondeterminism in the ordering of lib.rmeta files, which we caught in our bazel-based builds only recently due to being further behind than normal. In my testing, this fixes the issue.
This commit is contained in:
Matthias Krüger 2025-03-28 12:59:55 +01:00 committed by GitHub
commit bdc5adfe78
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 9 additions and 4 deletions

View File

@ -4300,6 +4300,7 @@ name = "rustc_resolve"
version = "0.0.0"
dependencies = [
"bitflags",
"itertools",
"pulldown-cmark 0.11.3",
"rustc_arena",
"rustc_ast",

View File

@ -6,6 +6,7 @@ edition = "2024"
[dependencies]
# tidy-alphabetical-start
bitflags = "2.4.1"
itertools = "0.12"
pulldown-cmark = { version = "0.11", features = ["html"], default-features = false }
rustc_arena = { path = "../rustc_arena" }
rustc_ast = { path = "../rustc_ast" }

View File

@ -1,13 +1,15 @@
use std::mem;
use std::ops::Range;
use itertools::Itertools;
use pulldown_cmark::{
BrokenLink, BrokenLinkCallback, CowStr, Event, LinkType, Options, Parser, Tag,
};
use rustc_ast as ast;
use rustc_ast::attr::AttributeExt;
use rustc_ast::util::comments::beautify_doc_string;
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::unord::UnordSet;
use rustc_middle::ty::TyCtxt;
use rustc_span::def_id::DefId;
use rustc_span::{DUMMY_SP, InnerSpan, Span, Symbol, kw, sym};
@ -422,7 +424,7 @@ fn parse_links<'md>(doc: &'md str) -> Vec<Box<str>> {
);
let mut links = Vec::new();
let mut refids = FxHashSet::default();
let mut refids = UnordSet::default();
while let Some(event) = event_iter.next() {
match event {
@ -454,7 +456,7 @@ fn parse_links<'md>(doc: &'md str) -> Vec<Box<str>> {
}
}
for (label, refdef) in event_iter.reference_definitions().iter() {
for (label, refdef) in event_iter.reference_definitions().iter().sorted_by_key(|x| x.0) {
if !refids.contains(label) {
links.push(preprocess_link(&refdef.dest));
}

View File

@ -1724,6 +1724,7 @@ pub(crate) fn markdown_links<'md, R>(
md: &'md str,
preprocess_link: impl Fn(MarkdownLink) -> Option<R>,
) -> Vec<R> {
use itertools::Itertools;
if md.is_empty() {
return vec![];
}
@ -1882,7 +1883,7 @@ pub(crate) fn markdown_links<'md, R>(
let mut links = Vec::new();
let mut refdefs = FxIndexMap::default();
for (label, refdef) in event_iter.reference_definitions().iter() {
for (label, refdef) in event_iter.reference_definitions().iter().sorted_by_key(|x| x.0) {
refdefs.insert(label.to_string(), (false, refdef.dest.to_string(), refdef.span.clone()));
}