Skip to content

Commit 1279b3b

Browse files
committed
Auto merge of rust-lang#81304 - jonas-schievink:rollup-d9kuugm, r=jonas-schievink
Rollup of 15 pull requests Successful merges: - rust-lang#79841 (More clear documentation for NonNull<T>) - rust-lang#81072 (PlaceRef::ty: use method call syntax) - rust-lang#81130 (Edit rustc_middle::dep_graph module documentation) - rust-lang#81170 (Avoid hash_slice in VecDeque's Hash implementation) - rust-lang#81243 (mir: Improve size_of handling when arg is unsized) - rust-lang#81245 (Update cargo) - rust-lang#81249 (Lower closure prototype after its body.) - rust-lang#81252 (Add more self-profile info to rustc_resolve) - rust-lang#81275 (Fix <unknown> queries and add more timing info to render_html) - rust-lang#81281 (Inline methods of Path and OsString) - rust-lang#81283 (Note library tracking issue template in tracking issue template.) - rust-lang#81285 (Remove special casing of rustdoc in rustc_lint) - rust-lang#81288 (rustdoc: Fix visibility of trait and impl items) - rust-lang#81298 (replace RefCell with Cell in FnCtxt) - rust-lang#81301 (Fix small typo) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4d0dd02 + ebeb6b8 commit 1279b3b

File tree

37 files changed

+434
-112
lines changed

37 files changed

+434
-112
lines changed

.github/ISSUE_TEMPLATE/tracking_issue.md

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ title: Tracking Issue for XXX
55
labels: C-tracking-issue
66
---
77
<!--
8+
NOTE: For library features, please use the "Library Tracking Issue" template instead.
9+
810
Thank you for creating a tracking issue! 📜 Tracking issues are for tracking a
911
feature from implementation to stabilisation. Make sure to include the relevant
1012
RFC for the feature if it has one. Otherwise provide a short summary of the

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ dependencies = [
427427
"remove_dir_all",
428428
"serde_json",
429429
"tar",
430+
"toml",
430431
"url 2.1.1",
431432
]
432433

compiler/rustc_ast_lowering/src/expr.rs

+18-13
Original file line numberDiff line numberDiff line change
@@ -776,10 +776,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
776776
body: &Expr,
777777
fn_decl_span: Span,
778778
) -> hir::ExprKind<'hir> {
779-
// Lower outside new scope to preserve `is_in_loop_condition`.
780-
let fn_decl = self.lower_fn_decl(decl, None, false, None);
781-
782-
self.with_new_scopes(move |this| {
779+
let (body_id, generator_option) = self.with_new_scopes(move |this| {
783780
let prev = this.current_item;
784781
this.current_item = Some(fn_decl_span);
785782
let mut generator_kind = None;
@@ -791,8 +788,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
791788
let generator_option =
792789
this.generator_movability_for_fn(&decl, fn_decl_span, generator_kind, movability);
793790
this.current_item = prev;
794-
hir::ExprKind::Closure(capture_clause, fn_decl, body_id, fn_decl_span, generator_option)
795-
})
791+
(body_id, generator_option)
792+
});
793+
794+
// Lower outside new scope to preserve `is_in_loop_condition`.
795+
let fn_decl = self.lower_fn_decl(decl, None, false, None);
796+
797+
hir::ExprKind::Closure(capture_clause, fn_decl, body_id, fn_decl_span, generator_option)
796798
}
797799

798800
fn generator_movability_for_fn(
@@ -838,12 +840,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
838840
) -> hir::ExprKind<'hir> {
839841
let outer_decl =
840842
FnDecl { inputs: decl.inputs.clone(), output: FnRetTy::Default(fn_decl_span) };
841-
// We need to lower the declaration outside the new scope, because we
842-
// have to conserve the state of being inside a loop condition for the
843-
// closure argument types.
844-
let fn_decl = self.lower_fn_decl(&outer_decl, None, false, None);
845843

846-
self.with_new_scopes(move |this| {
844+
let body_id = self.with_new_scopes(|this| {
847845
// FIXME(cramertj): allow `async` non-`move` closures with arguments.
848846
if capture_clause == CaptureBy::Ref && !decl.inputs.is_empty() {
849847
struct_span_err!(
@@ -874,8 +872,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
874872
);
875873
this.expr(fn_decl_span, async_body, ThinVec::new())
876874
});
877-
hir::ExprKind::Closure(capture_clause, fn_decl, body_id, fn_decl_span, None)
878-
})
875+
body_id
876+
});
877+
878+
// We need to lower the declaration outside the new scope, because we
879+
// have to conserve the state of being inside a loop condition for the
880+
// closure argument types.
881+
let fn_decl = self.lower_fn_decl(&outer_decl, None, false, None);
882+
883+
hir::ExprKind::Closure(capture_clause, fn_decl, body_id, fn_decl_span, None)
879884
}
880885

881886
/// Destructure the LHS of complex assignments.

compiler/rustc_codegen_ssa/src/mir/analyze.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
119119
)
120120
);
121121
if is_consume {
122-
let base_ty = mir::PlaceRef::ty(&place_base, self.fx.mir, cx.tcx());
122+
let base_ty = place_base.ty(self.fx.mir, cx.tcx());
123123
let base_ty = self.fx.monomorphize(base_ty);
124124

125125
// ZSTs don't require any actual memory access.

compiler/rustc_codegen_ssa/src/mir/place.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
506506

507507
pub fn monomorphized_place_ty(&self, place_ref: mir::PlaceRef<'tcx>) -> Ty<'tcx> {
508508
let tcx = self.cx.tcx();
509-
let place_ty = mir::PlaceRef::ty(&place_ref, self.mir, tcx);
509+
let place_ty = place_ref.ty(self.mir, tcx);
510510
self.monomorphize(place_ty.ty)
511511
}
512512
}

compiler/rustc_interface/src/passes.rs

-7
Original file line numberDiff line numberDiff line change
@@ -1017,13 +1017,6 @@ pub fn start_codegen<'tcx>(
10171017
tcx.sess.time("assert_dep_graph", || rustc_incremental::assert_dep_graph(tcx));
10181018
tcx.sess.time("serialize_dep_graph", || rustc_incremental::save_dep_graph(tcx));
10191019

1020-
// We assume that no queries are run past here. If there are new queries
1021-
// after this point, they'll show up as "<unknown>" in self-profiling data.
1022-
{
1023-
let _prof_timer = tcx.prof.generic_activity("self_profile_alloc_query_strings");
1024-
tcx.alloc_self_profile_query_strings();
1025-
}
1026-
10271020
info!("Post-codegen\n{:?}", tcx.debug_stats());
10281021

10291022
if tcx.sess.opts.output_types.contains_key(&OutputType::Mir) {

compiler/rustc_interface/src/queries.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -417,9 +417,19 @@ impl Compiler {
417417
let queries = Queries::new(&self);
418418
let ret = f(&queries);
419419

420-
if self.session().opts.debugging_opts.query_stats {
421-
if let Ok(gcx) = queries.global_ctxt() {
422-
gcx.peek_mut().print_stats();
420+
// NOTE: intentionally does not compute the global context if it hasn't been built yet,
421+
// since that likely means there was a parse error.
422+
if let Some(Ok(gcx)) = &mut *queries.global_ctxt.result.borrow_mut() {
423+
// We assume that no queries are run past here. If there are new queries
424+
// after this point, they'll show up as "<unknown>" in self-profiling data.
425+
{
426+
let _prof_timer =
427+
queries.session().prof.generic_activity("self_profile_alloc_query_strings");
428+
gcx.enter(|tcx| tcx.alloc_self_profile_query_strings());
429+
}
430+
431+
if self.session().opts.debugging_opts.query_stats {
432+
gcx.print_stats();
423433
}
424434
}
425435

compiler/rustc_lint/src/early.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -379,17 +379,9 @@ pub fn check_ast_crate<T: EarlyLintPass>(
379379
// All of the buffered lints should have been emitted at this point.
380380
// If not, that means that we somehow buffered a lint for a node id
381381
// that was not lint-checked (perhaps it doesn't exist?). This is a bug.
382-
//
383-
// Rustdoc runs everybody-loops before the early lints and removes
384-
// function bodies, so it's totally possible for linted
385-
// node ids to not exist (e.g., macros defined within functions for the
386-
// unused_macro lint) anymore. So we only run this check
387-
// when we're not in rustdoc mode. (see issue #47639)
388-
if !sess.opts.actually_rustdoc {
389-
for (_id, lints) in buffered.map {
390-
for early_lint in lints {
391-
sess.delay_span_bug(early_lint.span, "failed to process buffered lint here");
392-
}
382+
for (_id, lints) in buffered.map {
383+
for early_lint in lints {
384+
sess.delay_span_bug(early_lint.span, "failed to process buffered lint here");
393385
}
394386
}
395387
}

compiler/rustc_middle/src/dep_graph/dep_node.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
//! This module defines the `DepNode` type which the compiler uses to represent
2-
//! nodes in the dependency graph.
1+
//! Nodes in the dependency graph.
32
//!
4-
//! A `DepNode` consists of a `DepKind` (which
5-
//! specifies the kind of thing it represents, like a piece of HIR, MIR, etc)
6-
//! and a `Fingerprint`, a 128-bit hash value the exact meaning of which
3+
//! A node in the [dependency graph] is represented by a [`DepNode`].
4+
//! A `DepNode` consists of a [`DepKind`] (which
5+
//! specifies the kind of thing it represents, like a piece of HIR, MIR, etc.)
6+
//! and a [`Fingerprint`], a 128-bit hash value, the exact meaning of which
77
//! depends on the node's `DepKind`. Together, the kind and the fingerprint
88
//! fully identify a dependency node, even across multiple compilation sessions.
99
//! In other words, the value of the fingerprint does not depend on anything
1010
//! that is specific to a given compilation session, like an unpredictable
11-
//! interning key (e.g., NodeId, DefId, Symbol) or the numeric value of a
11+
//! interning key (e.g., `NodeId`, `DefId`, `Symbol`) or the numeric value of a
1212
//! pointer. The concept behind this could be compared to how git commit hashes
13-
//! uniquely identify a given commit and has a few advantages:
13+
//! uniquely identify a given commit. The fingerprinting approach has
14+
//! a few advantages:
1415
//!
1516
//! * A `DepNode` can simply be serialized to disk and loaded in another session
1617
//! without the need to do any "rebasing" (like we have to do for Spans and
@@ -51,6 +52,8 @@
5152
//! than a zeroed out fingerprint. More generally speaking, it relieves the
5253
//! user of the `DepNode` API of having to know how to compute the expected
5354
//! fingerprint for a given set of node parameters.
55+
//!
56+
//! [dependency graph]: https://rustc-dev-guide.rust-lang.org/query.html
5457
5558
use crate::ty::TyCtxt;
5659

compiler/rustc_middle/src/mir/interpret/error.rs

+3
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ pub enum InvalidProgramInfo<'tcx> {
127127
Layout(layout::LayoutError<'tcx>),
128128
/// An invalid transmute happened.
129129
TransmuteSizeDiff(Ty<'tcx>, Ty<'tcx>),
130+
/// SizeOf of unsized type was requested.
131+
SizeOfUnsizedType(Ty<'tcx>),
130132
}
131133

132134
impl fmt::Display for InvalidProgramInfo<'_> {
@@ -144,6 +146,7 @@ impl fmt::Display for InvalidProgramInfo<'_> {
144146
"transmuting `{}` to `{}` is not possible, because these types do not have the same size",
145147
from_ty, to_ty
146148
),
149+
SizeOfUnsizedType(ty) => write!(f, "size_of called on unsized type `{}`", ty),
147150
}
148151
}
149152
}

compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
289289
);
290290
}
291291

292-
let ty = PlaceRef::ty(&used_place, self.body, self.infcx.tcx).ty;
292+
let ty = used_place.ty(self.body, self.infcx.tcx).ty;
293293
let needs_note = match ty.kind() {
294294
ty::Closure(id, _) => {
295295
let tables = self.infcx.tcx.typeck(id.expect_local());
@@ -728,6 +728,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
728728
// Define a small closure that we can use to check if the type of a place
729729
// is a union.
730730
let union_ty = |place_base| {
731+
// Need to use fn call syntax `PlaceRef::ty` to determine the type of `place_base`;
732+
// using a type annotation in the closure argument instead leads to a lifetime error.
731733
let ty = PlaceRef::ty(&place_base, self.body, self.infcx.tcx).ty;
732734
ty.ty_adt_def().filter(|adt| adt.is_union()).map(|_| ty)
733735
};

compiler/rustc_mir/src/borrow_check/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1743,7 +1743,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
17431743
if let Some((place_base, ProjectionElem::Subslice { from, to, from_end: false })) =
17441744
place_span.0.last_projection()
17451745
{
1746-
let place_ty = PlaceRef::ty(&place_base, self.body(), self.infcx.tcx);
1746+
let place_ty = place_base.ty(self.body(), self.infcx.tcx);
17471747
if let ty::Array(..) = place_ty.ty.kind() {
17481748
self.check_if_subslice_element_is_moved(
17491749
location,
@@ -1854,7 +1854,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
18541854
// assigning to `P.f` requires `P` itself
18551855
// be already initialized
18561856
let tcx = self.infcx.tcx;
1857-
let base_ty = PlaceRef::ty(&place_base, self.body(), tcx).ty;
1857+
let base_ty = place_base.ty(self.body(), tcx).ty;
18581858
match base_ty.kind() {
18591859
ty::Adt(def, _) if def.has_dtor(tcx) => {
18601860
self.check_if_path_or_subpath_is_moved(
@@ -1951,7 +1951,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
19511951
// no move out from an earlier location) then this is an attempt at initialization
19521952
// of the union - we should error in that case.
19531953
let tcx = this.infcx.tcx;
1954-
if let ty::Adt(def, _) = PlaceRef::ty(&base, this.body(), tcx).ty.kind() {
1954+
if let ty::Adt(def, _) = base.ty(this.body(), tcx).ty.kind() {
19551955
if def.is_union() {
19561956
if this.move_data.path_map[mpi].iter().any(|moi| {
19571957
this.move_data.moves[*moi].source.is_predecessor_of(location, this.body)
@@ -2173,7 +2173,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
21732173
Some((place_base, elem)) => {
21742174
match elem {
21752175
ProjectionElem::Deref => {
2176-
let base_ty = PlaceRef::ty(&place_base, self.body(), self.infcx.tcx).ty;
2176+
let base_ty = place_base.ty(self.body(), self.infcx.tcx).ty;
21772177

21782178
// Check the kind of deref to decide
21792179
match base_ty.kind() {

compiler/rustc_mir/src/borrow_check/prefixes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl<'cx, 'tcx> Iterator for Prefixes<'cx, 'tcx> {
117117
// derefs, except we stop at the deref of a shared
118118
// reference.
119119

120-
let ty = PlaceRef::ty(&cursor_base, self.body, self.tcx).ty;
120+
let ty = cursor_base.ty(self.body, self.tcx).ty;
121121
match ty.kind() {
122122
ty::RawPtr(_) | ty::Ref(_ /*rgn*/, _ /*ty*/, hir::Mutability::Not) => {
123123
// don't continue traversing over derefs of raw pointers or shared

compiler/rustc_mir/src/interpret/step.rs

+1
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
270270
self.frame().current_span(),
271271
&format!("SizeOf nullary MIR operator called for unsized type {}", ty),
272272
);
273+
throw_inval!(SizeOfUnsizedType(ty));
273274
}
274275
self.write_scalar(Scalar::from_machine_usize(layout.size.bytes(), self), dest)?;
275276
}

compiler/rustc_resolve/src/lib.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -1465,16 +1465,14 @@ impl<'a> Resolver<'a> {
14651465

14661466
/// Entry point to crate resolution.
14671467
pub fn resolve_crate(&mut self, krate: &Crate) {
1468-
let _prof_timer = self.session.prof.generic_activity("resolve_crate");
1469-
1470-
ImportResolver { r: self }.finalize_imports();
1471-
self.finalize_macro_resolutions();
1472-
1473-
self.late_resolve_crate(krate);
1474-
1475-
self.check_unused(krate);
1476-
self.report_errors(krate);
1477-
self.crate_loader.postprocess(krate);
1468+
self.session.time("resolve_crate", || {
1469+
self.session.time("finalize_imports", || ImportResolver { r: self }.finalize_imports());
1470+
self.session.time("finalize_macro_resolutions", || self.finalize_macro_resolutions());
1471+
self.session.time("late_resolve_crate", || self.late_resolve_crate(krate));
1472+
self.session.time("resolve_check_unused", || self.check_unused(krate));
1473+
self.session.time("resolve_report_errors", || self.report_errors(krate));
1474+
self.session.time("resolve_postprocess", || self.crate_loader.postprocess(krate));
1475+
});
14781476
}
14791477

14801478
pub fn traits_in_scope(

compiler/rustc_typeck/src/check/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub(super) fn check_fn<'a, 'tcx>(
6666
// Create the function context. This is either derived from scratch or,
6767
// in the case of closures, based on the outer context.
6868
let mut fcx = FnCtxt::new(inherited, param_env, body.value.hir_id);
69-
*fcx.ps.borrow_mut() = UnsafetyState::function(fn_sig.unsafety, fn_id);
69+
fcx.ps.set(UnsafetyState::function(fn_sig.unsafety, fn_id));
7070

7171
let tcx = fcx.tcx;
7272
let sess = tcx.sess;

compiler/rustc_typeck/src/check/coercion.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1472,22 +1472,22 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
14721472
fn_output = Some(&fn_decl.output); // `impl Trait` return type
14731473
}
14741474
}
1475-
if let (Some(sp), Some(fn_output)) = (fcx.ret_coercion_span.borrow().as_ref(), fn_output) {
1476-
self.add_impl_trait_explanation(&mut err, cause, fcx, expected, *sp, fn_output);
1475+
if let (Some(sp), Some(fn_output)) = (fcx.ret_coercion_span.get(), fn_output) {
1476+
self.add_impl_trait_explanation(&mut err, cause, fcx, expected, sp, fn_output);
14771477
}
14781478

1479-
if let Some(sp) = fcx.ret_coercion_span.borrow().as_ref() {
1479+
if let Some(sp) = fcx.ret_coercion_span.get() {
14801480
// If the closure has an explicit return type annotation,
14811481
// then a type error may occur at the first return expression we
14821482
// see in the closure (if it conflicts with the declared
14831483
// return type). Skip adding a note in this case, since it
14841484
// would be incorrect.
1485-
if !err.span.primary_spans().iter().any(|span| span == sp) {
1485+
if !err.span.primary_spans().iter().any(|&span| span == sp) {
14861486
let hir = fcx.tcx.hir();
14871487
let body_owner = hir.body_owned_by(hir.enclosing_body_owner(fcx.body_id));
14881488
if fcx.tcx.is_closure(hir.body_owner_def_id(body_owner).to_def_id()) {
14891489
err.span_note(
1490-
*sp,
1490+
sp,
14911491
&format!(
14921492
"return type inferred to be `{}` here",
14931493
fcx.resolve_vars_if_possible(expected)

compiler/rustc_typeck/src/check/expr.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -680,14 +680,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
680680
if self.ret_coercion.is_none() {
681681
self.tcx.sess.emit_err(ReturnStmtOutsideOfFnBody { span: expr.span });
682682
} else if let Some(ref e) = expr_opt {
683-
if self.ret_coercion_span.borrow().is_none() {
684-
*self.ret_coercion_span.borrow_mut() = Some(e.span);
683+
if self.ret_coercion_span.get().is_none() {
684+
self.ret_coercion_span.set(Some(e.span));
685685
}
686686
self.check_return_expr(e);
687687
} else {
688688
let mut coercion = self.ret_coercion.as_ref().unwrap().borrow_mut();
689-
if self.ret_coercion_span.borrow().is_none() {
690-
*self.ret_coercion_span.borrow_mut() = Some(expr.span);
689+
if self.ret_coercion_span.get().is_none() {
690+
self.ret_coercion_span.set(Some(expr.span));
691691
}
692692
let cause = self.cause(expr.span, ObligationCauseCode::ReturnNoExpression);
693693
if let Some((fn_decl, _)) = self.get_fn_decl(expr.hir_id) {

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use rustc_span::{self, MultiSpan, Span};
2323
use rustc_trait_selection::traits::{self, ObligationCauseCode, StatementAsExpression};
2424

2525
use crate::structured_errors::StructuredDiagnostic;
26-
use std::mem::replace;
2726
use std::slice;
2827

2928
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
@@ -589,11 +588,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
589588
blk: &'tcx hir::Block<'tcx>,
590589
expected: Expectation<'tcx>,
591590
) -> Ty<'tcx> {
592-
let prev = {
593-
let mut fcx_ps = self.ps.borrow_mut();
594-
let unsafety_state = fcx_ps.recurse(blk);
595-
replace(&mut *fcx_ps, unsafety_state)
596-
};
591+
let prev = self.ps.replace(self.ps.get().recurse(blk));
597592

598593
// In some cases, blocks have just one exit, but other blocks
599594
// can be targeted by multiple breaks. This can happen both
@@ -709,7 +704,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
709704

710705
self.write_ty(blk.hir_id, ty);
711706

712-
*self.ps.borrow_mut() = prev;
707+
self.ps.set(prev);
713708
ty
714709
}
715710

0 commit comments

Comments
 (0)