Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #85199

Merged
merged 34 commits into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f6dd332
shrinking the deprecated method span
Rustin170506 May 7, 2021
7c5bc20
Address comments
Rustin170506 May 8, 2021
0778e8d
change k to key and v to v in std::env mod
shirshak55 May 10, 2021
41779f6
Fix typo in variable name
LingMan May 10, 2021
f740923
Use .name_str() to format primitive types in error messages
FabianWolff May 11, 2021
001f0dd
rustdoc: Show basic type layout information
camelid Mar 22, 2021
5859c5d
Remove FIXME
camelid Apr 8, 2021
20b30ac
Include a warning in the layout docs that layout is unstable
camelid Apr 8, 2021
9859e2b
Add test for memory layout information
camelid Apr 13, 2021
48da66f
Show memory layout for type aliases
camelid Apr 13, 2021
12ee920
Only show type layout info if `--show-type-layout` is passed
camelid Apr 13, 2021
9615d6d
Enable `--show-type-layout` for the rustc API docs
camelid Apr 13, 2021
db3a06d
Fix a few small things
camelid Apr 13, 2021
8048c70
Add `tcx` local variable
camelid Apr 14, 2021
bcbc727
Apply suggestions from code review
camelid Apr 23, 2021
61a8479
Make test more specific
camelid Apr 23, 2021
879a914
Add test case for zero-sized types
camelid Apr 27, 2021
8b9298b
Add note to docs when layout cannot be computed
camelid Apr 28, 2021
9b89d01
Enable `--show-type-layout` for the rustdoc API docs
camelid May 9, 2021
d43701c
Disable layout docs for type aliases for now
camelid May 9, 2021
f510e41
rustdoc: remove explicit boolean comparisons.
jsha May 9, 2021
d5a24b0
Move rustdoc-gui rust libraries into their own folder and prepare the…
GuillaumeGomez May 2, 2021
1b0976c
Update toggle-docs GUI test to last version
GuillaumeGomez May 11, 2021
6b94990
Make rustdoc-gui test suite able to run with different sub directories
GuillaumeGomez May 11, 2021
bea112b
Revert "Auto merge of #84797 - richkadel:cover-unreachable-statements…
richkadel May 11, 2021
69a4ae2
Add explanatory comment to the issue-84976.rs test case
FabianWolff May 11, 2021
40be1d3
Rollup merge of #83501 - camelid:rustdoc-layout, r=jyn514,GuillaumeGomez
JohnTitor May 11, 2021
649b385
Rollup merge of #85018 - hi-rustin:rustin-patch-84637, r=estebank
JohnTitor May 11, 2021
4ab3050
Rollup merge of #85124 - jsha:trust-the-bool, r=GuillaumeGomez
JohnTitor May 11, 2021
6ec4f91
Rollup merge of #85136 - shirshak55:master, r=dtolnay
JohnTitor May 11, 2021
9ad5c4d
Rollup merge of #85162 - LingMan:patch-1, r=varkor
JohnTitor May 11, 2021
c4c654f
Rollup merge of #85187 - FabianWolff:issue-84976, r=jackh726
JohnTitor May 11, 2021
8f3c2cc
Rollup merge of #85191 - GuillaumeGomez:improve-rustdoc-gui-tester, r…
JohnTitor May 11, 2021
e27f20a
Rollup merge of #85196 - richkadel:reverts-cover-unreachable-statemen…
JohnTitor May 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions compiler/rustc_middle/src/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,13 @@ impl<'tcx> TyCtxt<'tcx> {
/// If `id` is `Some(_)`, this function will also check if the item at `def_id` has been
/// deprecated. If the item is indeed deprecated, we will emit a deprecation lint attached to
/// `id`.
pub fn eval_stability(self, def_id: DefId, id: Option<HirId>, span: Span) -> EvalResult {
pub fn eval_stability(
self,
def_id: DefId,
id: Option<HirId>,
span: Span,
method_span: Option<Span>,
) -> EvalResult {
// Deprecated attributes apply in-crate and cross-crate.
if let Some(id) = id {
if let Some(depr_entry) = self.lookup_deprecation_entry(def_id) {
Expand All @@ -300,6 +306,7 @@ impl<'tcx> TyCtxt<'tcx> {
let path = &with_no_trimmed_paths(|| self.def_path_str(def_id));
let kind = self.def_kind(def_id).descr(def_id);
let (message, lint) = deprecation_message(&depr_entry.attr, kind, path);
let span = method_span.unwrap_or(span);
late_report_deprecation(
self,
&message,
Expand Down Expand Up @@ -382,8 +389,14 @@ impl<'tcx> TyCtxt<'tcx> {
///
/// This function will also check if the item is deprecated.
/// If so, and `id` is not `None`, a deprecated lint attached to `id` will be emitted.
pub fn check_stability(self, def_id: DefId, id: Option<HirId>, span: Span) {
self.check_optional_stability(def_id, id, span, |span, def_id| {
pub fn check_stability(
self,
def_id: DefId,
id: Option<HirId>,
span: Span,
method_span: Option<Span>,
) {
self.check_optional_stability(def_id, id, span, method_span, |span, def_id| {
// The API could be uncallable for other reasons, for example when a private module
// was referenced.
self.sess.delay_span_bug(span, &format!("encountered unmarked API: {:?}", def_id));
Expand All @@ -399,14 +412,15 @@ impl<'tcx> TyCtxt<'tcx> {
def_id: DefId,
id: Option<HirId>,
span: Span,
method_span: Option<Span>,
unmarked: impl FnOnce(Span, DefId),
) {
let soft_handler = |lint, span, msg: &_| {
self.struct_span_lint_hir(lint, id.unwrap_or(hir::CRATE_HIR_ID), span, |lint| {
lint.build(msg).emit()
})
};
match self.eval_stability(def_id, id, span) {
match self.eval_stability(def_id, id, span, method_span) {
EvalResult::Allow => {}
EvalResult::Deny { feature, reason, issue, is_soft } => {
report_unstable(self.sess, feature, reason, issue, is_soft, span, soft_handler)
Expand Down
17 changes: 15 additions & 2 deletions compiler/rustc_middle/src/ty/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,23 @@ impl<'tcx> fmt::Display for TypeError<'tcx> {
)
}),
IntMismatch(ref values) => {
write!(f, "expected `{:?}`, found `{:?}`", values.expected, values.found)
let expected = match values.expected {
ty::IntVarValue::IntType(ty) => ty.name_str(),
ty::IntVarValue::UintType(ty) => ty.name_str(),
};
let found = match values.found {
ty::IntVarValue::IntType(ty) => ty.name_str(),
ty::IntVarValue::UintType(ty) => ty.name_str(),
};
write!(f, "expected `{}`, found `{}`", expected, found)
}
FloatMismatch(ref values) => {
write!(f, "expected `{:?}`, found `{:?}`", values.expected, values.found)
write!(
f,
"expected `{}`, found `{}`",
values.expected.name_str(),
values.found.name_str()
)
}
VariadicMismatch(ref values) => write!(
f,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/transform/const_goto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl<'tcx> MirPass<'tcx> for ConstGoto {
// if we applied optimizations, we potentially have some cfg to cleanup to
// make it easier for further passes
if should_simplify {
simplify_cfg(tcx, body);
simplify_cfg(body);
simplify_locals(body, tcx);
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/transform/deduplicate_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl<'tcx> MirPass<'tcx> for DeduplicateBlocks {
if has_opts_to_apply {
let mut opt_applier = OptApplier { tcx, duplicates };
opt_applier.visit_body(body);
simplify_cfg(tcx, body);
simplify_cfg(body);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/transform/early_otherwise_branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch {
// Since this optimization adds new basic blocks and invalidates others,
// clean up the cfg to make it nicer for other passes
if should_cleanup {
simplify_cfg(tcx, body);
simplify_cfg(body);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir/src/transform/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ fn create_generator_drop_shim<'tcx>(

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

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

Expand Down Expand Up @@ -1137,7 +1137,7 @@ fn create_generator_resume_function<'tcx>(

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

dump_mir(tcx, None, "generator_resume", &0, body, |_, _| Ok(()));
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/transform/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl<'tcx> MirPass<'tcx> for Inline {
if inline(tcx, body) {
debug!("running simplify cfg on {:?}", body.source);
CfgSimplifier::new(body).simplify();
remove_dead_blocks(tcx, body);
remove_dead_blocks(body);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/transform/match_branches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl<'tcx> MirPass<'tcx> for MatchBranchSimplification {
}

if should_cleanup {
simplify_cfg(tcx, body);
simplify_cfg(body);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ impl<'tcx> MirPass<'tcx> for MultipleReturnTerminators {
}
}

simplify::remove_dead_blocks(tcx, body)
simplify::remove_dead_blocks(body)
}
}
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/transform/remove_unneeded_drops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl<'tcx> MirPass<'tcx> for RemoveUnneededDrops {
// if we applied optimizations, we potentially have some cfg to cleanup to
// make it easier for further passes
if should_simplify {
simplify_cfg(tcx, body);
simplify_cfg(body);
}
}
}
42 changes: 5 additions & 37 deletions compiler/rustc_mir/src/transform/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

use crate::transform::MirPass;
use rustc_index::vec::{Idx, IndexVec};
use rustc_middle::mir::coverage::*;
use rustc_middle::mir::visit::{MutVisitor, MutatingUseContext, PlaceContext, Visitor};
use rustc_middle::mir::*;
use rustc_middle::ty::TyCtxt;
Expand All @@ -47,9 +46,9 @@ impl SimplifyCfg {
}
}

pub fn simplify_cfg(tcx: TyCtxt<'tcx>, body: &mut Body<'_>) {
pub fn simplify_cfg(body: &mut Body<'_>) {
CfgSimplifier::new(body).simplify();
remove_dead_blocks(tcx, body);
remove_dead_blocks(body);

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

fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
fn run_pass(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
debug!("SimplifyCfg({:?}) - simplifying {:?}", self.label, body.source);
simplify_cfg(tcx, body);
simplify_cfg(body);
}
}

Expand Down Expand Up @@ -287,7 +286,7 @@ impl<'a, 'tcx> CfgSimplifier<'a, 'tcx> {
}
}

pub fn remove_dead_blocks(tcx: TyCtxt<'tcx>, body: &mut Body<'_>) {
pub fn remove_dead_blocks(body: &mut Body<'_>) {
let reachable = traversal::reachable_as_bitset(body);
let num_blocks = body.basic_blocks().len();
if num_blocks == reachable.count() {
Expand All @@ -307,11 +306,6 @@ pub fn remove_dead_blocks(tcx: TyCtxt<'tcx>, body: &mut Body<'_>) {
}
used_blocks += 1;
}

if tcx.sess.instrument_coverage() {
save_unreachable_coverage(basic_blocks, used_blocks);
}

basic_blocks.raw.truncate(used_blocks);

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

fn save_unreachable_coverage(
basic_blocks: &mut IndexVec<BasicBlock, BasicBlockData<'_>>,
first_dead_block: usize,
) {
// retain coverage info for dead blocks, so coverage reports will still
// report `0` executions for the uncovered code regions.
let mut dropped_coverage = Vec::new();
for dead_block in first_dead_block..basic_blocks.len() {
for statement in basic_blocks[BasicBlock::new(dead_block)].statements.iter() {
if let StatementKind::Coverage(coverage) = &statement.kind {
if let Some(code_region) = &coverage.code_region {
dropped_coverage.push((statement.source_info, code_region.clone()));
}
}
}
}
for (source_info, code_region) in dropped_coverage {
basic_blocks[START_BLOCK].statements.push(Statement {
source_info,
kind: StatementKind::Coverage(box Coverage {
kind: CoverageKind::Unreachable,
code_region: Some(code_region),
}),
})
}
}
pub struct SimplifyLocals;

impl<'tcx> MirPass<'tcx> for SimplifyLocals {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/transform/simplify_try.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ impl<'tcx> MirPass<'tcx> for SimplifyBranchSame {

if did_remove_blocks {
// We have dead blocks now, so remove those.
simplify::remove_dead_blocks(tcx, body);
simplify::remove_dead_blocks(body);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/transform/unreachable_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl MirPass<'_> for UnreachablePropagation {
}

if replaced {
simplify::remove_dead_blocks(tcx, body);
simplify::remove_dead_blocks(body);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_passes/src/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ impl Visitor<'tcx> for Checker<'tcx> {
None => return,
};
let def_id = DefId { krate: cnum, index: CRATE_DEF_INDEX };
self.tcx.check_stability(def_id, Some(item.hir_id()), item.span);
self.tcx.check_stability(def_id, Some(item.hir_id()), item.span, None);
}

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

fn visit_path(&mut self, path: &'tcx hir::Path<'tcx>, id: hir::HirId) {
if let Some(def_id) = path.res.opt_def_id() {
self.tcx.check_stability(def_id, Some(id), path.span)
self.tcx.check_stability(def_id, Some(id), path.span, None)
}
intravisit::walk_path(self, path)
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,9 +621,9 @@ mod parse {
true
}

crate fn parse_linker_flavor(slote: &mut Option<LinkerFlavor>, v: Option<&str>) -> bool {
crate fn parse_linker_flavor(slot: &mut Option<LinkerFlavor>, v: Option<&str>) -> bool {
match v.and_then(LinkerFlavor::from_str) {
Some(lf) => *slote = Some(lf),
Some(lf) => *slot = Some(lf),
_ => return false,
}
true
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_typeck/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
param.def_id,
Some(arg.id()),
arg.span(),
None,
|_, _| {
// Default generic parameters may not be marked
// with stability attributes, i.e. when the
Expand Down Expand Up @@ -1059,7 +1060,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
.span_label(binding.span, "private associated type")
.emit();
}
tcx.check_stability(assoc_ty.def_id, Some(hir_ref_id), binding.span);
tcx.check_stability(assoc_ty.def_id, Some(hir_ref_id), binding.span, None);

if !speculative {
dup_bindings
Expand Down Expand Up @@ -1666,7 +1667,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
.find(|vd| tcx.hygienic_eq(assoc_ident, vd.ident, adt_def.did));
if let Some(variant_def) = variant_def {
if permit_variants {
tcx.check_stability(variant_def.def_id, Some(hir_ref_id), span);
tcx.check_stability(variant_def.def_id, Some(hir_ref_id), span, None);
self.prohibit_generics(slice::from_ref(assoc_segment));
return Ok((qself_ty, DefKind::Variant, variant_def.def_id));
} else {
Expand Down Expand Up @@ -1786,7 +1787,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
.span_label(span, &format!("private {}", kind))
.emit();
}
tcx.check_stability(item.def_id, Some(hir_ref_id), span);
tcx.check_stability(item.def_id, Some(hir_ref_id), span, None);

if let Some(variant_def_id) = variant_resolution {
tcx.struct_span_lint_hir(AMBIGUOUS_ASSOCIATED_ITEMS, hir_ref_id, span, |lint| {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_typeck/src/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// struct-like enums (yet...), but it's definitely not
// a bug to have constructed one.
if adt_kind != AdtKind::Enum {
tcx.check_stability(v_field.did, Some(expr_id), field.span);
tcx.check_stability(v_field.did, Some(expr_id), field.span, None);
}

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

self.tcx.check_stability(field.did, Some(expr.hir_id), expr.span);
self.tcx.check_stability(field.did, Some(expr.hir_id), expr.span, None);
return field_ty;
}
private_candidate = Some((base_def.did, field_ty));
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_typeck/src/check/method/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.insert(*import_id);
}

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

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

let def_kind = pick.item.kind.as_def_kind();
debug!("resolve_ufcs: def_kind={:?}, def_id={:?}", def_kind, pick.item.def_id);
tcx.check_stability(pick.item.def_id, Some(expr_id), span);
tcx.check_stability(pick.item.def_id, Some(expr_id), span, Some(method_name.span));
Ok((def_kind, pick.item.def_id))
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
if let Some(uc) = unstable_candidates {
applicable_candidates.retain(|&(p, _)| {
if let stability::EvalResult::Deny { feature, .. } =
self.tcx.eval_stability(p.item.def_id, None, self.span)
self.tcx.eval_stability(p.item.def_id, None, self.span, None)
{
uc.push((p, feature));
return false;
Expand Down
Loading