Skip to content

Commit 74864fa

Browse files
committed
Auto merge of rust-lang#110481 - matthiaskrgr:rollup-phkkgm9, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#109981 (Set commit information environment variables when building tools) - rust-lang#110348 (Add list of supported disambiguators and suffixes for intra-doc links in the rustdoc book) - rust-lang#110409 (Don't use `serde_json` to serialize a simple JSON object) - rust-lang#110442 (Avoid including dry run steps in the build metrics) - rust-lang#110450 (rustdoc: Fix invalid handling of nested items with `--document-private-items`) - rust-lang#110461 (Use `Item::expect_*` and `ImplItem::expect_*` more) - rust-lang#110465 (Assure everyone that `has_type_flags` is fast) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3860251 + 5606653 commit 74864fa

File tree

27 files changed

+244
-70
lines changed

27 files changed

+244
-70
lines changed

Cargo.lock

-1
Original file line numberDiff line numberDiff line change
@@ -3181,7 +3181,6 @@ dependencies = [
31813181
"rustc_index",
31823182
"rustc_macros",
31833183
"rustc_serialize",
3184-
"serde_json",
31853184
"smallvec",
31863185
"stable_deref_trait",
31873186
"stacker",

compiler/rustc_ast_lowering/src/item.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,10 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
138138
// Evaluate with the lifetimes in `params` in-scope.
139139
// This is used to track which lifetimes have already been defined,
140140
// and which need to be replicated when lowering an async fn.
141-
match parent_hir.node().expect_item().kind {
142-
hir::ItemKind::Impl(hir::Impl { of_trait, .. }) => {
143-
lctx.is_in_trait_impl = of_trait.is_some();
144-
}
145-
_ => {}
146-
};
141+
142+
if let hir::ItemKind::Impl(impl_) = parent_hir.node().expect_item().kind {
143+
lctx.is_in_trait_impl = impl_.of_trait.is_some();
144+
}
147145

148146
match ctxt {
149147
AssocCtxt::Trait => hir::OwnerNode::TraitItem(lctx.lower_trait_item(item)),

compiler/rustc_data_structures/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ rustc-hash = "1.1.0"
2121
rustc_index = { path = "../rustc_index", package = "rustc_index" }
2222
rustc_macros = { path = "../rustc_macros" }
2323
rustc_serialize = { path = "../rustc_serialize" }
24-
serde_json = "1.0.59"
2524
smallvec = { version = "1.8.1", features = [
2625
"const_generics",
2726
"union",

compiler/rustc_data_structures/src/profiling.rs

+33-8
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ use crate::fx::FxHashMap;
8787
use std::borrow::Borrow;
8888
use std::collections::hash_map::Entry;
8989
use std::error::Error;
90+
use std::fmt::Display;
9091
use std::fs;
9192
use std::intrinsics::unlikely;
9293
use std::path::Path;
@@ -97,7 +98,6 @@ use std::time::{Duration, Instant};
9798
pub use measureme::EventId;
9899
use measureme::{EventIdBuilder, Profiler, SerializableString, StringId};
99100
use parking_lot::RwLock;
100-
use serde_json::json;
101101
use smallvec::SmallVec;
102102

103103
bitflags::bitflags! {
@@ -763,6 +763,31 @@ impl Drop for VerboseTimingGuard<'_> {
763763
}
764764
}
765765

766+
struct JsonTimePassesEntry<'a> {
767+
pass: &'a str,
768+
time: f64,
769+
start_rss: Option<usize>,
770+
end_rss: Option<usize>,
771+
}
772+
773+
impl Display for JsonTimePassesEntry<'_> {
774+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
775+
let Self { pass: what, time, start_rss, end_rss } = self;
776+
write!(f, r#"{{"pass":"{what}","time":{time},"rss_start":"#).unwrap();
777+
match start_rss {
778+
Some(rss) => write!(f, "{rss}")?,
779+
None => write!(f, "null")?,
780+
}
781+
write!(f, r#","rss_end":"#)?;
782+
match end_rss {
783+
Some(rss) => write!(f, "{rss}")?,
784+
None => write!(f, "null")?,
785+
}
786+
write!(f, "}}")?;
787+
Ok(())
788+
}
789+
}
790+
766791
pub fn print_time_passes_entry(
767792
what: &str,
768793
dur: Duration,
@@ -772,13 +797,10 @@ pub fn print_time_passes_entry(
772797
) {
773798
match format {
774799
TimePassesFormat::Json => {
775-
let json = json!({
776-
"pass": what,
777-
"time": dur.as_secs_f64(),
778-
"rss_start": start_rss,
779-
"rss_end": end_rss,
780-
});
781-
eprintln!("time: {json}");
800+
let entry =
801+
JsonTimePassesEntry { pass: what, time: dur.as_secs_f64(), start_rss, end_rss };
802+
803+
eprintln!(r#"time: {entry}"#);
782804
return;
783805
}
784806
TimePassesFormat::Text => (),
@@ -894,3 +916,6 @@ cfg_if! {
894916
}
895917
}
896918
}
919+
920+
#[cfg(test)]
921+
mod tests;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use super::JsonTimePassesEntry;
2+
3+
#[test]
4+
fn with_rss() {
5+
let entry =
6+
JsonTimePassesEntry { pass: "typeck", time: 56.1, start_rss: Some(10), end_rss: Some(20) };
7+
8+
assert_eq!(entry.to_string(), r#"{"pass":"typeck","time":56.1,"rss_start":10,"rss_end":20}"#)
9+
}
10+
11+
#[test]
12+
fn no_rss() {
13+
let entry = JsonTimePassesEntry { pass: "typeck", time: 56.1, start_rss: None, end_rss: None };
14+
15+
assert_eq!(
16+
entry.to_string(),
17+
r#"{"pass":"typeck","time":56.1,"rss_start":null,"rss_end":null}"#
18+
)
19+
}

compiler/rustc_hir/src/hir.rs

-2
Original file line numberDiff line numberDiff line change
@@ -3146,7 +3146,6 @@ impl<'hir> Item<'hir> {
31463146
(ty, gen)
31473147
}
31483148

3149-
/// An opaque `impl Trait` type alias, e.g., `type Foo = impl Bar;`.
31503149
/// Expect an [`ItemKind::OpaqueTy`] or panic.
31513150
#[track_caller]
31523151
pub fn expect_opaque_ty(&self) -> &OpaqueTy<'hir> {
@@ -3168,7 +3167,6 @@ impl<'hir> Item<'hir> {
31683167
(data, gen)
31693168
}
31703169

3171-
/// A union definition, e.g., `union Foo<A, B> {x: A, y: B}`.
31723170
/// Expect an [`ItemKind::Union`] or panic.
31733171
#[track_caller]
31743172
pub fn expect_union(&self) -> (&VariantData<'hir>, &'hir Generics<'hir>) {

compiler/rustc_hir_analysis/src/coherence/builtin.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,9 @@ fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
7474

7575
debug!("visit_implementation_of_copy: self_type={:?} (free)", self_type);
7676

77-
let span = match tcx.hir().expect_item(impl_did).kind {
78-
ItemKind::Impl(hir::Impl { polarity: hir::ImplPolarity::Negative(_), .. }) => return,
79-
ItemKind::Impl(impl_) => impl_.self_ty.span,
80-
_ => bug!("expected Copy impl item"),
77+
let span = match tcx.hir().expect_item(impl_did).expect_impl() {
78+
hir::Impl { polarity: hir::ImplPolarity::Negative(_), .. } => return,
79+
hir::Impl { self_ty, .. } => self_ty.span,
8180
};
8281

8382
let cause = traits::ObligationCause::misc(span, impl_did);

compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -462,10 +462,7 @@ fn foo(&self) -> Self::T { String::new() }
462462
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = *proj_ty.self_ty().kind() {
463463
let opaque_local_def_id = def_id.as_local();
464464
let opaque_hir_ty = if let Some(opaque_local_def_id) = opaque_local_def_id {
465-
match &tcx.hir().expect_item(opaque_local_def_id).kind {
466-
hir::ItemKind::OpaqueTy(opaque_hir_ty) => opaque_hir_ty,
467-
_ => bug!("The HirId comes from a `ty::Opaque`"),
468-
}
465+
tcx.hir().expect_item(opaque_local_def_id).expect_opaque_ty()
469466
} else {
470467
return false;
471468
};

compiler/rustc_infer/src/infer/opaque_types.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -392,12 +392,7 @@ impl<'tcx> InferCtxt<'tcx> {
392392
/// defining scope.
393393
#[instrument(skip(self), level = "trace", ret)]
394394
fn opaque_type_origin_unchecked(&self, def_id: LocalDefId) -> OpaqueTyOrigin {
395-
match self.tcx.hir().expect_item(def_id).kind {
396-
hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) => origin,
397-
ref itemkind => {
398-
bug!("weird opaque type: {:?}, {:#?}", def_id, itemkind)
399-
}
400-
}
395+
self.tcx.hir().expect_item(def_id).expect_opaque_ty().origin
401396
}
402397
}
403398

compiler/rustc_metadata/src/rmeta/encoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1469,8 +1469,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14691469

14701470
match impl_item.kind {
14711471
ty::AssocKind::Fn => {
1472-
let ast_item = self.tcx.hir().expect_impl_item(def_id.expect_local());
1473-
let hir::ImplItemKind::Fn(ref sig, body) = ast_item.kind else { bug!() };
1472+
let (sig, body) =
1473+
self.tcx.hir().expect_impl_item(def_id.expect_local()).expect_fn();
14741474
self.tables.asyncness.set_some(def_id.index, sig.header.asyncness);
14751475
record_array!(self.tables.fn_arg_names[def_id] <- self.tcx.hir().body_param_names(body));
14761476
// Can be inside `impl const Trait`, so using sig.header.constness is not reliable

compiler/rustc_middle/src/ty/visit.rs

+8
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ pub trait TypeVisitableExt<'tcx>: TypeVisitable<TyCtxt<'tcx>> {
3333
}
3434

3535
fn has_type_flags(&self, flags: TypeFlags) -> bool {
36+
// N.B. Even though this uses a visitor, the visitor does not actually
37+
// recurse through the whole `TypeVisitable` implementor type.
38+
//
39+
// Instead it stops on the first "level", visiting types, regions,
40+
// consts and predicates just fetches their type flags.
41+
//
42+
// Thus this is a lot faster than it might seem and should be
43+
// optimized to a simple field access.
3644
let res =
3745
self.visit_with(&mut HasTypeFlagsVisitor { flags }).break_value() == Some(FoundFlags);
3846
trace!(?self, ?flags, ?res, "has_type_flags");

src/bootstrap/builder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2030,7 +2030,7 @@ impl<'a> Builder<'a> {
20302030
}
20312031

20322032
#[cfg(feature = "build-metrics")]
2033-
self.metrics.enter_step(&step);
2033+
self.metrics.enter_step(&step, self);
20342034

20352035
let (out, dur) = {
20362036
let start = Instant::now();
@@ -2056,7 +2056,7 @@ impl<'a> Builder<'a> {
20562056
}
20572057

20582058
#[cfg(feature = "build-metrics")]
2059-
self.metrics.exit_step();
2059+
self.metrics.exit_step(self);
20602060

20612061
{
20622062
let mut stack = self.stack.borrow_mut();

src/bootstrap/metrics.rs

+19-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! As this module requires additional dependencies not present during local builds, it's cfg'd
55
//! away whenever the `build.metrics` config option is not set to `true`.
66
7-
use crate::builder::Step;
7+
use crate::builder::{Builder, Step};
88
use crate::util::t;
99
use crate::Build;
1010
use serde_derive::{Deserialize, Serialize};
@@ -33,7 +33,12 @@ impl BuildMetrics {
3333
BuildMetrics { state }
3434
}
3535

36-
pub(crate) fn enter_step<S: Step>(&self, step: &S) {
36+
pub(crate) fn enter_step<S: Step>(&self, step: &S, builder: &Builder<'_>) {
37+
// Do not record dry runs, as they'd be duplicates of the actual steps.
38+
if builder.config.dry_run() {
39+
return;
40+
}
41+
3742
let mut state = self.state.borrow_mut();
3843

3944
// Consider all the stats gathered so far as the parent's.
@@ -56,7 +61,12 @@ impl BuildMetrics {
5661
});
5762
}
5863

59-
pub(crate) fn exit_step(&self) {
64+
pub(crate) fn exit_step(&self, builder: &Builder<'_>) {
65+
// Do not record dry runs, as they'd be duplicates of the actual steps.
66+
if builder.config.dry_run() {
67+
return;
68+
}
69+
6070
let mut state = self.state.borrow_mut();
6171

6272
self.collect_stats(&mut *state);
@@ -74,7 +84,12 @@ impl BuildMetrics {
7484
}
7585
}
7686

77-
pub(crate) fn record_test(&self, name: &str, outcome: TestOutcome) {
87+
pub(crate) fn record_test(&self, name: &str, outcome: TestOutcome, builder: &Builder<'_>) {
88+
// Do not record dry runs, as they'd be duplicates of the actual steps.
89+
if builder.config.dry_run() {
90+
return;
91+
}
92+
7893
let mut state = self.state.borrow_mut();
7994
state
8095
.running_steps

src/bootstrap/render_tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ impl<'a> Renderer<'a> {
124124
ignore_reason: reason.map(|s| s.to_string()),
125125
},
126126
},
127+
self.builder,
127128
);
128129

129130
if self.builder.config.verbose_tests {

src/bootstrap/test.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1804,6 +1804,10 @@ note: if you're sure you want to do this, please open an issue as to why. In the
18041804

18051805
cmd.arg("--channel").arg(&builder.config.channel);
18061806

1807+
if !builder.config.omit_git_hash {
1808+
cmd.arg("--git-hash");
1809+
}
1810+
18071811
if let Some(commit) = builder.config.download_rustc_commit() {
18081812
cmd.env("FAKE_DOWNLOAD_RUSTC_PREFIX", format!("/rustc/{commit}"));
18091813
}

src/bootstrap/tool.rs

+6
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,12 @@ pub fn prepare_tool_cargo(
194194
cargo.env("CFG_VERSION", builder.rust_version());
195195
cargo.env("CFG_RELEASE_NUM", &builder.version);
196196
cargo.env("DOC_RUST_LANG_ORG_CHANNEL", builder.doc_rust_lang_org_channel());
197+
if let Some(ref ver_date) = builder.rust_info().commit_date() {
198+
cargo.env("CFG_VER_DATE", ver_date);
199+
}
200+
if let Some(ref ver_hash) = builder.rust_info().sha() {
201+
cargo.env("CFG_VER_HASH", ver_hash);
202+
}
197203

198204
let info = GitInfo::new(builder.config.omit_git_hash, &dir);
199205
if let Some(sha) = info.sha() {

src/doc/rustdoc/src/write-documentation/linking-to-items-by-name.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,16 @@ fn Foo() {}
8888
```
8989

9090
These prefixes will be stripped when displayed in the documentation, so `[struct@Foo]` will be
91-
rendered as `Foo`.
91+
rendered as `Foo`. The following prefixes are available: `struct`, `enum`, `trait`, `union`,
92+
`mod`, `module`, `const`, `constant`, `fn`, `function`, `method`, `derive`, `type`, `value`,
93+
`macro`, `prim` or `primitive`.
9294

9395
You can also disambiguate for functions by adding `()` after the function name,
94-
or for macros by adding `!` after the macro name:
96+
or for macros by adding `!` after the macro name. The macro `!` can be followed by `()`, `{}`,
97+
or `[]`. Example:
9598

9699
```rust
97-
/// This is different from [`foo!`]
100+
/// This is different from [`foo!()`].
98101
fn foo() {}
99102

100103
/// This is different from [`foo()`]

src/librustdoc/passes/collect_intra_doc_links.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,7 @@ impl Disambiguator {
14191419
if let Some(idx) = link.find('@') {
14201420
let (prefix, rest) = link.split_at(idx);
14211421
let d = match prefix {
1422+
// If you update this list, please also update the relevant rustdoc book section!
14221423
"struct" => Kind(DefKind::Struct),
14231424
"enum" => Kind(DefKind::Enum),
14241425
"trait" => Kind(DefKind::Trait),
@@ -1437,6 +1438,7 @@ impl Disambiguator {
14371438
Ok(Some((d, &rest[1..], &rest[1..])))
14381439
} else {
14391440
let suffixes = [
1441+
// If you update this list, please also update the relevant rustdoc book section!
14401442
("!()", DefKind::Macro(MacroKind::Bang)),
14411443
("!{}", DefKind::Macro(MacroKind::Bang)),
14421444
("![]", DefKind::Macro(MacroKind::Bang)),

0 commit comments

Comments
 (0)