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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 4 additions & 6 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 33 additions & 8 deletions
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;
Lines changed: 19 additions & 0 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 3 additions & 4 deletions
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

Lines changed: 1 addition & 4 deletions
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

Lines changed: 1 addition & 6 deletions
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

Lines changed: 2 additions & 2 deletions
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

0 commit comments

Comments
 (0)