Skip to content

Commit 890803d

Browse files
committed
Auto merge of rust-lang#85199 - JohnTitor:rollup-gz5m06c, r=JohnTitor
Rollup of 8 pull requests Successful merges: - rust-lang#83501 (rustdoc: Add unstable CLI option to show basic type layout information) - rust-lang#85018 (shrinking the deprecated method span) - rust-lang#85124 (rustdoc: remove explicit boolean comparisons.) - rust-lang#85136 (Change param name (k to key and v to value) in std::env module) - rust-lang#85162 (Fix typo in variable name) - rust-lang#85187 (Use .name_str() to format primitive types in error messages) - rust-lang#85191 (Improve rustdoc gui tester) - rust-lang#85196 (Revert "Auto merge of rust-lang#84797 - richkadel:cover-unreachable-statements…) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 5c02926 + e27f20a commit 890803d

File tree

65 files changed

+552
-314
lines changed

Some content is hidden

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

65 files changed

+552
-314
lines changed

compiler/rustc_middle/src/middle/stability.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,13 @@ impl<'tcx> TyCtxt<'tcx> {
281281
/// If `id` is `Some(_)`, this function will also check if the item at `def_id` has been
282282
/// deprecated. If the item is indeed deprecated, we will emit a deprecation lint attached to
283283
/// `id`.
284-
pub fn eval_stability(self, def_id: DefId, id: Option<HirId>, span: Span) -> EvalResult {
284+
pub fn eval_stability(
285+
self,
286+
def_id: DefId,
287+
id: Option<HirId>,
288+
span: Span,
289+
method_span: Option<Span>,
290+
) -> EvalResult {
285291
// Deprecated attributes apply in-crate and cross-crate.
286292
if let Some(id) = id {
287293
if let Some(depr_entry) = self.lookup_deprecation_entry(def_id) {
@@ -300,6 +306,7 @@ impl<'tcx> TyCtxt<'tcx> {
300306
let path = &with_no_trimmed_paths(|| self.def_path_str(def_id));
301307
let kind = self.def_kind(def_id).descr(def_id);
302308
let (message, lint) = deprecation_message(&depr_entry.attr, kind, path);
309+
let span = method_span.unwrap_or(span);
303310
late_report_deprecation(
304311
self,
305312
&message,
@@ -382,8 +389,14 @@ impl<'tcx> TyCtxt<'tcx> {
382389
///
383390
/// This function will also check if the item is deprecated.
384391
/// If so, and `id` is not `None`, a deprecated lint attached to `id` will be emitted.
385-
pub fn check_stability(self, def_id: DefId, id: Option<HirId>, span: Span) {
386-
self.check_optional_stability(def_id, id, span, |span, def_id| {
392+
pub fn check_stability(
393+
self,
394+
def_id: DefId,
395+
id: Option<HirId>,
396+
span: Span,
397+
method_span: Option<Span>,
398+
) {
399+
self.check_optional_stability(def_id, id, span, method_span, |span, def_id| {
387400
// The API could be uncallable for other reasons, for example when a private module
388401
// was referenced.
389402
self.sess.delay_span_bug(span, &format!("encountered unmarked API: {:?}", def_id));
@@ -399,14 +412,15 @@ impl<'tcx> TyCtxt<'tcx> {
399412
def_id: DefId,
400413
id: Option<HirId>,
401414
span: Span,
415+
method_span: Option<Span>,
402416
unmarked: impl FnOnce(Span, DefId),
403417
) {
404418
let soft_handler = |lint, span, msg: &_| {
405419
self.struct_span_lint_hir(lint, id.unwrap_or(hir::CRATE_HIR_ID), span, |lint| {
406420
lint.build(msg).emit()
407421
})
408422
};
409-
match self.eval_stability(def_id, id, span) {
423+
match self.eval_stability(def_id, id, span, method_span) {
410424
EvalResult::Allow => {}
411425
EvalResult::Deny { feature, reason, issue, is_soft } => {
412426
report_unstable(self.sess, feature, reason, issue, is_soft, span, soft_handler)

compiler/rustc_middle/src/ty/error.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,23 @@ impl<'tcx> fmt::Display for TypeError<'tcx> {
159159
)
160160
}),
161161
IntMismatch(ref values) => {
162-
write!(f, "expected `{:?}`, found `{:?}`", values.expected, values.found)
162+
let expected = match values.expected {
163+
ty::IntVarValue::IntType(ty) => ty.name_str(),
164+
ty::IntVarValue::UintType(ty) => ty.name_str(),
165+
};
166+
let found = match values.found {
167+
ty::IntVarValue::IntType(ty) => ty.name_str(),
168+
ty::IntVarValue::UintType(ty) => ty.name_str(),
169+
};
170+
write!(f, "expected `{}`, found `{}`", expected, found)
163171
}
164172
FloatMismatch(ref values) => {
165-
write!(f, "expected `{:?}`, found `{:?}`", values.expected, values.found)
173+
write!(
174+
f,
175+
"expected `{}`, found `{}`",
176+
values.expected.name_str(),
177+
values.found.name_str()
178+
)
166179
}
167180
VariadicMismatch(ref values) => write!(
168181
f,

compiler/rustc_mir/src/transform/const_goto.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl<'tcx> MirPass<'tcx> for ConstGoto {
4747
// if we applied optimizations, we potentially have some cfg to cleanup to
4848
// make it easier for further passes
4949
if should_simplify {
50-
simplify_cfg(tcx, body);
50+
simplify_cfg(body);
5151
simplify_locals(body, tcx);
5252
}
5353
}

compiler/rustc_mir/src/transform/deduplicate_blocks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl<'tcx> MirPass<'tcx> for DeduplicateBlocks {
2626
if has_opts_to_apply {
2727
let mut opt_applier = OptApplier { tcx, duplicates };
2828
opt_applier.visit_body(body);
29-
simplify_cfg(tcx, body);
29+
simplify_cfg(body);
3030
}
3131
}
3232
}

compiler/rustc_mir/src/transform/early_otherwise_branch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch {
164164
// Since this optimization adds new basic blocks and invalidates others,
165165
// clean up the cfg to make it nicer for other passes
166166
if should_cleanup {
167-
simplify_cfg(tcx, body);
167+
simplify_cfg(body);
168168
}
169169
}
170170
}

compiler/rustc_mir/src/transform/generator.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ fn create_generator_drop_shim<'tcx>(
964964

965965
// Make sure we remove dead blocks to remove
966966
// unrelated code from the resume part of the function
967-
simplify::remove_dead_blocks(tcx, &mut body);
967+
simplify::remove_dead_blocks(&mut body);
968968

969969
dump_mir(tcx, None, "generator_drop", &0, &body, |_, _| Ok(()));
970970

@@ -1137,7 +1137,7 @@ fn create_generator_resume_function<'tcx>(
11371137

11381138
// Make sure we remove dead blocks to remove
11391139
// unrelated code from the drop part of the function
1140-
simplify::remove_dead_blocks(tcx, body);
1140+
simplify::remove_dead_blocks(body);
11411141

11421142
dump_mir(tcx, None, "generator_resume", &0, body, |_, _| Ok(()));
11431143
}

compiler/rustc_mir/src/transform/inline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl<'tcx> MirPass<'tcx> for Inline {
5757
if inline(tcx, body) {
5858
debug!("running simplify cfg on {:?}", body.source);
5959
CfgSimplifier::new(body).simplify();
60-
remove_dead_blocks(tcx, body);
60+
remove_dead_blocks(body);
6161
}
6262
}
6363
}

compiler/rustc_mir/src/transform/match_branches.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl<'tcx> MirPass<'tcx> for MatchBranchSimplification {
167167
}
168168

169169
if should_cleanup {
170-
simplify_cfg(tcx, body);
170+
simplify_cfg(body);
171171
}
172172
}
173173
}

compiler/rustc_mir/src/transform/multiple_return_terminators.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ impl<'tcx> MirPass<'tcx> for MultipleReturnTerminators {
3838
}
3939
}
4040

41-
simplify::remove_dead_blocks(tcx, body)
41+
simplify::remove_dead_blocks(body)
4242
}
4343
}

compiler/rustc_mir/src/transform/remove_unneeded_drops.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl<'tcx> MirPass<'tcx> for RemoveUnneededDrops {
3636
// if we applied optimizations, we potentially have some cfg to cleanup to
3737
// make it easier for further passes
3838
if should_simplify {
39-
simplify_cfg(tcx, body);
39+
simplify_cfg(body);
4040
}
4141
}
4242
}

compiler/rustc_mir/src/transform/simplify.rs

+5-37
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
3030
use crate::transform::MirPass;
3131
use rustc_index::vec::{Idx, IndexVec};
32-
use rustc_middle::mir::coverage::*;
3332
use rustc_middle::mir::visit::{MutVisitor, MutatingUseContext, PlaceContext, Visitor};
3433
use rustc_middle::mir::*;
3534
use rustc_middle::ty::TyCtxt;
@@ -47,9 +46,9 @@ impl SimplifyCfg {
4746
}
4847
}
4948

50-
pub fn simplify_cfg(tcx: TyCtxt<'tcx>, body: &mut Body<'_>) {
49+
pub fn simplify_cfg(body: &mut Body<'_>) {
5150
CfgSimplifier::new(body).simplify();
52-
remove_dead_blocks(tcx, body);
51+
remove_dead_blocks(body);
5352

5453
// FIXME: Should probably be moved into some kind of pass manager
5554
body.basic_blocks_mut().raw.shrink_to_fit();
@@ -60,9 +59,9 @@ impl<'tcx> MirPass<'tcx> for SimplifyCfg {
6059
Cow::Borrowed(&self.label)
6160
}
6261

63-
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
62+
fn run_pass(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
6463
debug!("SimplifyCfg({:?}) - simplifying {:?}", self.label, body.source);
65-
simplify_cfg(tcx, body);
64+
simplify_cfg(body);
6665
}
6766
}
6867

@@ -287,7 +286,7 @@ impl<'a, 'tcx> CfgSimplifier<'a, 'tcx> {
287286
}
288287
}
289288

290-
pub fn remove_dead_blocks(tcx: TyCtxt<'tcx>, body: &mut Body<'_>) {
289+
pub fn remove_dead_blocks(body: &mut Body<'_>) {
291290
let reachable = traversal::reachable_as_bitset(body);
292291
let num_blocks = body.basic_blocks().len();
293292
if num_blocks == reachable.count() {
@@ -307,11 +306,6 @@ pub fn remove_dead_blocks(tcx: TyCtxt<'tcx>, body: &mut Body<'_>) {
307306
}
308307
used_blocks += 1;
309308
}
310-
311-
if tcx.sess.instrument_coverage() {
312-
save_unreachable_coverage(basic_blocks, used_blocks);
313-
}
314-
315309
basic_blocks.raw.truncate(used_blocks);
316310

317311
for block in basic_blocks {
@@ -321,32 +315,6 @@ pub fn remove_dead_blocks(tcx: TyCtxt<'tcx>, body: &mut Body<'_>) {
321315
}
322316
}
323317

324-
fn save_unreachable_coverage(
325-
basic_blocks: &mut IndexVec<BasicBlock, BasicBlockData<'_>>,
326-
first_dead_block: usize,
327-
) {
328-
// retain coverage info for dead blocks, so coverage reports will still
329-
// report `0` executions for the uncovered code regions.
330-
let mut dropped_coverage = Vec::new();
331-
for dead_block in first_dead_block..basic_blocks.len() {
332-
for statement in basic_blocks[BasicBlock::new(dead_block)].statements.iter() {
333-
if let StatementKind::Coverage(coverage) = &statement.kind {
334-
if let Some(code_region) = &coverage.code_region {
335-
dropped_coverage.push((statement.source_info, code_region.clone()));
336-
}
337-
}
338-
}
339-
}
340-
for (source_info, code_region) in dropped_coverage {
341-
basic_blocks[START_BLOCK].statements.push(Statement {
342-
source_info,
343-
kind: StatementKind::Coverage(box Coverage {
344-
kind: CoverageKind::Unreachable,
345-
code_region: Some(code_region),
346-
}),
347-
})
348-
}
349-
}
350318
pub struct SimplifyLocals;
351319

352320
impl<'tcx> MirPass<'tcx> for SimplifyLocals {

compiler/rustc_mir/src/transform/simplify_try.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ impl<'tcx> MirPass<'tcx> for SimplifyBranchSame {
558558

559559
if did_remove_blocks {
560560
// We have dead blocks now, so remove those.
561-
simplify::remove_dead_blocks(tcx, body);
561+
simplify::remove_dead_blocks(body);
562562
}
563563
}
564564
}

compiler/rustc_mir/src/transform/unreachable_prop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl MirPass<'_> for UnreachablePropagation {
6060
}
6161

6262
if replaced {
63-
simplify::remove_dead_blocks(tcx, body);
63+
simplify::remove_dead_blocks(body);
6464
}
6565
}
6666
}

compiler/rustc_passes/src/stability.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ impl Visitor<'tcx> for Checker<'tcx> {
739739
None => return,
740740
};
741741
let def_id = DefId { krate: cnum, index: CRATE_DEF_INDEX };
742-
self.tcx.check_stability(def_id, Some(item.hir_id()), item.span);
742+
self.tcx.check_stability(def_id, Some(item.hir_id()), item.span, None);
743743
}
744744

745745
// For implementations of traits, check the stability of each item
@@ -783,7 +783,7 @@ impl Visitor<'tcx> for Checker<'tcx> {
783783
.map(|item| item.def_id);
784784
if let Some(def_id) = trait_item_def_id {
785785
// Pass `None` to skip deprecation warnings.
786-
self.tcx.check_stability(def_id, None, impl_item.span);
786+
self.tcx.check_stability(def_id, None, impl_item.span, None);
787787
}
788788
}
789789
}
@@ -832,7 +832,7 @@ impl Visitor<'tcx> for Checker<'tcx> {
832832

833833
fn visit_path(&mut self, path: &'tcx hir::Path<'tcx>, id: hir::HirId) {
834834
if let Some(def_id) = path.res.opt_def_id() {
835-
self.tcx.check_stability(def_id, Some(id), path.span)
835+
self.tcx.check_stability(def_id, Some(id), path.span, None)
836836
}
837837
intravisit::walk_path(self, path)
838838
}

compiler/rustc_session/src/options.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -621,9 +621,9 @@ mod parse {
621621
true
622622
}
623623

624-
crate fn parse_linker_flavor(slote: &mut Option<LinkerFlavor>, v: Option<&str>) -> bool {
624+
crate fn parse_linker_flavor(slot: &mut Option<LinkerFlavor>, v: Option<&str>) -> bool {
625625
match v.and_then(LinkerFlavor::from_str) {
626-
Some(lf) => *slote = Some(lf),
626+
Some(lf) => *slot = Some(lf),
627627
_ => return false,
628628
}
629629
true

compiler/rustc_typeck/src/astconv/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
432432
param.def_id,
433433
Some(arg.id()),
434434
arg.span(),
435+
None,
435436
|_, _| {
436437
// Default generic parameters may not be marked
437438
// with stability attributes, i.e. when the
@@ -1059,7 +1060,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
10591060
.span_label(binding.span, "private associated type")
10601061
.emit();
10611062
}
1062-
tcx.check_stability(assoc_ty.def_id, Some(hir_ref_id), binding.span);
1063+
tcx.check_stability(assoc_ty.def_id, Some(hir_ref_id), binding.span, None);
10631064

10641065
if !speculative {
10651066
dup_bindings
@@ -1666,7 +1667,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
16661667
.find(|vd| tcx.hygienic_eq(assoc_ident, vd.ident, adt_def.did));
16671668
if let Some(variant_def) = variant_def {
16681669
if permit_variants {
1669-
tcx.check_stability(variant_def.def_id, Some(hir_ref_id), span);
1670+
tcx.check_stability(variant_def.def_id, Some(hir_ref_id), span, None);
16701671
self.prohibit_generics(slice::from_ref(assoc_segment));
16711672
return Ok((qself_ty, DefKind::Variant, variant_def.def_id));
16721673
} else {
@@ -1786,7 +1787,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
17861787
.span_label(span, &format!("private {}", kind))
17871788
.emit();
17881789
}
1789-
tcx.check_stability(item.def_id, Some(hir_ref_id), span);
1790+
tcx.check_stability(item.def_id, Some(hir_ref_id), span, None);
17901791

17911792
if let Some(variant_def_id) = variant_resolution {
17921793
tcx.struct_span_lint_hir(AMBIGUOUS_ASSOCIATED_ITEMS, hir_ref_id, span, |lint| {

compiler/rustc_typeck/src/check/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12301230
// struct-like enums (yet...), but it's definitely not
12311231
// a bug to have constructed one.
12321232
if adt_kind != AdtKind::Enum {
1233-
tcx.check_stability(v_field.did, Some(expr_id), field.span);
1233+
tcx.check_stability(v_field.did, Some(expr_id), field.span, None);
12341234
}
12351235

12361236
self.field_ty(field.span, v_field, substs)
@@ -1571,7 +1571,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15711571
self.apply_adjustments(base, adjustments);
15721572
self.register_predicates(autoderef.into_obligations());
15731573

1574-
self.tcx.check_stability(field.did, Some(expr.hir_id), expr.span);
1574+
self.tcx.check_stability(field.did, Some(expr.hir_id), expr.span, None);
15751575
return field_ty;
15761576
}
15771577
private_candidate = Some((base_def.did, field_ty));

compiler/rustc_typeck/src/check/method/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
205205
.insert(*import_id);
206206
}
207207

208-
self.tcx.check_stability(pick.item.def_id, Some(call_expr.hir_id), span);
208+
self.tcx.check_stability(pick.item.def_id, Some(call_expr.hir_id), span, None);
209209

210210
let result =
211211
self.confirm_method(span, self_expr, call_expr, self_ty, pick.clone(), segment);
@@ -445,7 +445,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
445445
// them as well. It's ok to use the variant's id as a ctor id since an
446446
// error will be reported on any use of such resolution anyway.
447447
let ctor_def_id = variant_def.ctor_def_id.unwrap_or(variant_def.def_id);
448-
tcx.check_stability(ctor_def_id, Some(expr_id), span);
448+
tcx.check_stability(ctor_def_id, Some(expr_id), span, Some(method_name.span));
449449
return Ok((
450450
DefKind::Ctor(CtorOf::Variant, variant_def.ctor_kind),
451451
ctor_def_id,
@@ -475,7 +475,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
475475

476476
let def_kind = pick.item.kind.as_def_kind();
477477
debug!("resolve_ufcs: def_kind={:?}, def_id={:?}", def_kind, pick.item.def_id);
478-
tcx.check_stability(pick.item.def_id, Some(expr_id), span);
478+
tcx.check_stability(pick.item.def_id, Some(expr_id), span, Some(method_name.span));
479479
Ok((def_kind, pick.item.def_id))
480480
}
481481

compiler/rustc_typeck/src/check/method/probe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
12861286
if let Some(uc) = unstable_candidates {
12871287
applicable_candidates.retain(|&(p, _)| {
12881288
if let stability::EvalResult::Deny { feature, .. } =
1289-
self.tcx.eval_stability(p.item.def_id, None, self.span)
1289+
self.tcx.eval_stability(p.item.def_id, None, self.span, None)
12901290
{
12911291
uc.push((p, feature));
12921292
return false;

0 commit comments

Comments
 (0)