Skip to content

Commit

Permalink
Auto merge of #111848 - Dylan-DPC:rollup-7jqydzg, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 6 pull requests

Successful merges:

 - #111501 (MIR drive-by cleanups)
 - #111609 (Mark internal functions and traits unsafe to reflect preconditions)
 - #111612 (Give better error when collecting into `&[T]`)
 - #111756 (Rename `{drop,forget}_{copy,ref}` lints to more consistent naming)
 - #111843 (move lcnr to only review types stuff)
 - #111844 (Migrate GUI colors test to original CSS color format)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed May 22, 2023
2 parents cfcde24 + ec372a1 commit 8b4b208
Show file tree
Hide file tree
Showing 98 changed files with 376 additions and 372 deletions.
8 changes: 4 additions & 4 deletions compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -521,18 +521,18 @@ lint_opaque_hidden_inferred_bound = opaque type `{$ty}` does not satisfy its ass
lint_opaque_hidden_inferred_bound_sugg = add this bound
lint_drop_ref = calls to `std::mem::drop` with a reference instead of an owned value does nothing
lint_dropping_references = calls to `std::mem::drop` with a reference instead of an owned value does nothing
.label = argument has type `{$arg_ty}`
.note = use `let _ = ...` to ignore the expression or result
lint_drop_copy = calls to `std::mem::drop` with a value that implements `Copy` does nothing
lint_dropping_copy_types = calls to `std::mem::drop` with a value that implements `Copy` does nothing
.label = argument has type `{$arg_ty}`
.note = use `let _ = ...` to ignore the expression or result
lint_forget_ref = calls to `std::mem::forget` with a reference instead of an owned value does nothing
lint_forgetting_references = calls to `std::mem::forget` with a reference instead of an owned value does nothing
.label = argument has type `{$arg_ty}`
.note = use `let _ = ...` to ignore the expression or result
lint_forget_copy = calls to `std::mem::forget` with a value that implements `Copy` does nothing
lint_forgetting_copy_types = calls to `std::mem::forget` with a value that implements `Copy` does nothing
.label = argument has type `{$arg_ty}`
.note = use `let _ = ...` to ignore the expression or result
26 changes: 13 additions & 13 deletions compiler/rustc_lint/src/drop_forget_useless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
};

declare_lint! {
/// The `drop_ref` lint checks for calls to `std::mem::drop` with a reference
/// The `dropping_references` lint checks for calls to `std::mem::drop` with a reference
/// instead of an owned value.
///
/// ### Example
Expand All @@ -29,13 +29,13 @@ declare_lint! {
/// reference itself, which is a no-op. It will not call the `drop` method (from
/// the `Drop` trait implementation) on the underlying referenced value, which
/// is likely what was intended.
pub DROP_REF,
pub DROPPING_REFERENCES,
Warn,
"calls to `std::mem::drop` with a reference instead of an owned value"
}

declare_lint! {
/// The `forget_ref` lint checks for calls to `std::mem::forget` with a reference
/// The `forgetting_references` lint checks for calls to `std::mem::forget` with a reference
/// instead of an owned value.
///
/// ### Example
Expand All @@ -52,13 +52,13 @@ declare_lint! {
/// Calling `forget` on a reference will only forget the
/// reference itself, which is a no-op. It will not forget the underlying
/// referenced value, which is likely what was intended.
pub FORGET_REF,
pub FORGETTING_REFERENCES,
Warn,
"calls to `std::mem::forget` with a reference instead of an owned value"
}

declare_lint! {
/// The `drop_copy` lint checks for calls to `std::mem::drop` with a value
/// The `dropping_copy_types` lint checks for calls to `std::mem::drop` with a value
/// that derives the Copy trait.
///
/// ### Example
Expand All @@ -76,13 +76,13 @@ declare_lint! {
/// Calling `std::mem::drop` [does nothing for types that
/// implement Copy](https://doc.rust-lang.org/std/mem/fn.drop.html), since the
/// value will be copied and moved into the function on invocation.
pub DROP_COPY,
pub DROPPING_COPY_TYPES,
Warn,
"calls to `std::mem::drop` with a value that implements Copy"
}

declare_lint! {
/// The `forget_copy` lint checks for calls to `std::mem::forget` with a value
/// The `forgetting_copy_types` lint checks for calls to `std::mem::forget` with a value
/// that derives the Copy trait.
///
/// ### Example
Expand All @@ -104,12 +104,12 @@ declare_lint! {
/// An alternative, but also valid, explanation is that Copy types do not
/// implement the Drop trait, which means they have no destructors. Without a
/// destructor, there is nothing for `std::mem::forget` to ignore.
pub FORGET_COPY,
pub FORGETTING_COPY_TYPES,
Warn,
"calls to `std::mem::forget` with a value that implements Copy"
}

declare_lint_pass!(DropForgetUseless => [DROP_REF, FORGET_REF, DROP_COPY, FORGET_COPY]);
declare_lint_pass!(DropForgetUseless => [DROPPING_REFERENCES, FORGETTING_REFERENCES, DROPPING_COPY_TYPES, FORGETTING_COPY_TYPES]);

impl<'tcx> LateLintPass<'tcx> for DropForgetUseless {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
Expand All @@ -123,16 +123,16 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetUseless {
let drop_is_single_call_in_arm = is_single_call_in_arm(cx, arg, expr);
match fn_name {
sym::mem_drop if arg_ty.is_ref() && !drop_is_single_call_in_arm => {
cx.emit_spanned_lint(DROP_REF, expr.span, DropRefDiag { arg_ty, label: arg.span });
cx.emit_spanned_lint(DROPPING_REFERENCES, expr.span, DropRefDiag { arg_ty, label: arg.span });
},
sym::mem_forget if arg_ty.is_ref() => {
cx.emit_spanned_lint(FORGET_REF, expr.span, ForgetRefDiag { arg_ty, label: arg.span });
cx.emit_spanned_lint(FORGETTING_REFERENCES, expr.span, ForgetRefDiag { arg_ty, label: arg.span });
},
sym::mem_drop if is_copy && !drop_is_single_call_in_arm => {
cx.emit_spanned_lint(DROP_COPY, expr.span, DropCopyDiag { arg_ty, label: arg.span });
cx.emit_spanned_lint(DROPPING_COPY_TYPES, expr.span, DropCopyDiag { arg_ty, label: arg.span });
}
sym::mem_forget if is_copy => {
cx.emit_spanned_lint(FORGET_COPY, expr.span, ForgetCopyDiag { arg_ty, label: arg.span });
cx.emit_spanned_lint(FORGETTING_COPY_TYPES, expr.span, ForgetCopyDiag { arg_ty, label: arg.span });
}
_ => return,
};
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,9 +662,9 @@ pub struct ForLoopsOverFalliblesSuggestion<'a> {
pub end_span: Span,
}

// drop_ref.rs
// drop_forget_useless.rs
#[derive(LintDiagnostic)]
#[diag(lint_drop_ref)]
#[diag(lint_dropping_references)]
#[note]
pub struct DropRefDiag<'a> {
pub arg_ty: Ty<'a>,
Expand All @@ -673,7 +673,7 @@ pub struct DropRefDiag<'a> {
}

#[derive(LintDiagnostic)]
#[diag(lint_drop_copy)]
#[diag(lint_dropping_copy_types)]
#[note]
pub struct DropCopyDiag<'a> {
pub arg_ty: Ty<'a>,
Expand All @@ -682,7 +682,7 @@ pub struct DropCopyDiag<'a> {
}

#[derive(LintDiagnostic)]
#[diag(lint_forget_ref)]
#[diag(lint_forgetting_references)]
#[note]
pub struct ForgetRefDiag<'a> {
pub arg_ty: Ty<'a>,
Expand All @@ -691,7 +691,7 @@ pub struct ForgetRefDiag<'a> {
}

#[derive(LintDiagnostic)]
#[diag(lint_forget_copy)]
#[diag(lint_forgetting_copy_types)]
#[note]
pub struct ForgetCopyDiag<'a> {
pub arg_ty: Ty<'a>,
Expand Down
23 changes: 23 additions & 0 deletions compiler/rustc_middle/src/mir/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,29 @@ pub enum TerminatorKind<'tcx> {
},
}

impl TerminatorKind<'_> {
/// Returns a simple string representation of a `TerminatorKind` variant, independent of any
/// values it might hold (e.g. `TerminatorKind::Call` always returns `"Call"`).
pub const fn name(&self) -> &'static str {
match self {
TerminatorKind::Goto { .. } => "Goto",
TerminatorKind::SwitchInt { .. } => "SwitchInt",
TerminatorKind::Resume => "Resume",
TerminatorKind::Terminate => "Terminate",
TerminatorKind::Return => "Return",
TerminatorKind::Unreachable => "Unreachable",
TerminatorKind::Drop { .. } => "Drop",
TerminatorKind::Call { .. } => "Call",
TerminatorKind::Assert { .. } => "Assert",
TerminatorKind::Yield { .. } => "Yield",
TerminatorKind::GeneratorDrop => "GeneratorDrop",
TerminatorKind::FalseEdge { .. } => "FalseEdge",
TerminatorKind::FalseUnwind { .. } => "FalseUnwind",
TerminatorKind::InlineAsm { .. } => "InlineAsm",
}
}
}

/// Action to be taken when a stack unwind happens.
#[derive(Copy, Clone, Debug, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable)]
#[derive(TypeFoldable, TypeVisitable)]
Expand Down
27 changes: 15 additions & 12 deletions compiler/rustc_mir_build/src/build/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,24 +644,27 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
};

if let Some(destination) = destination {
if let Some(value) = value {
match (destination, value) {
(Some(destination), Some(value)) => {
debug!("stmt_expr Break val block_context.push(SubExpr)");
self.block_context.push(BlockFrame::SubExpr);
unpack!(block = self.expr_into_dest(destination, block, value));
self.block_context.pop();
} else {
}
(Some(destination), None) => {
self.cfg.push_assign_unit(block, source_info, destination, self.tcx)
}
} else {
assert!(value.is_none(), "`return` and `break` should have a destination");
if self.tcx.sess.instrument_coverage() {
(None, Some(_)) => {
panic!("`return`, `become` and `break` with value and must have a destination")
}
(None, None) if self.tcx.sess.instrument_coverage() => {
// Unlike `break` and `return`, which push an `Assign` statement to MIR, from which
// a Coverage code region can be generated, `continue` needs no `Assign`; but
// without one, the `InstrumentCoverage` MIR pass cannot generate a code region for
// `continue`. Coverage will be missing unless we add a dummy `Assign` to MIR.
self.add_dummy_assignment(span, block, source_info);
}
(None, None) => {}
}

let region_scope = self.scopes.breakable_scopes[break_index].region_scope;
Expand All @@ -671,12 +674,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
} else {
self.scopes.breakable_scopes[break_index].continue_drops.as_mut().unwrap()
};
let mut drop_idx = ROOT_NODE;
for scope in &self.scopes.scopes[scope_index + 1..] {
for drop in &scope.drops {
drop_idx = drops.add_drop(*drop, drop_idx);
}
}

let drop_idx = self.scopes.scopes[scope_index + 1..]
.iter()
.flat_map(|scope| &scope.drops)
.fold(ROOT_NODE, |drop_idx, &drop| drops.add_drop(drop, drop_idx));

drops.add_entry(block, drop_idx);

// `build_drop_trees` doesn't have access to our source_info, so we
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_mir_build/src/thir/cx/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ impl<'tcx> Cx<'tcx> {
ExprKind::Pointer { cast: PointerCast::Unsize, source: self.thir.exprs.push(expr) }
}
Adjust::Pointer(cast) => ExprKind::Pointer { cast, source: self.thir.exprs.push(expr) },
Adjust::NeverToAny if adjustment.target.is_never() => return expr,
Adjust::NeverToAny => ExprKind::NeverToAny { source: self.thir.exprs.push(expr) },
Adjust::Deref(None) => {
adjust_span(&mut expr);
Expand Down
27 changes: 3 additions & 24 deletions compiler/rustc_mir_transform/src/coverage/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ use rustc_middle::mir::spanview::{self, SpanViewable};

use rustc_data_structures::fx::FxHashMap;
use rustc_middle::mir::coverage::*;
use rustc_middle::mir::{self, BasicBlock, TerminatorKind};
use rustc_middle::mir::{self, BasicBlock};
use rustc_middle::ty::TyCtxt;
use rustc_span::Span;

Expand Down Expand Up @@ -796,36 +796,15 @@ fn bcb_to_string_sections<'tcx>(
}
let non_term_blocks = bcb_data.basic_blocks[0..len - 1]
.iter()
.map(|&bb| format!("{:?}: {}", bb, term_type(&mir_body[bb].terminator().kind)))
.map(|&bb| format!("{:?}: {}", bb, mir_body[bb].terminator().kind.name()))
.collect::<Vec<_>>();
if non_term_blocks.len() > 0 {
sections.push(non_term_blocks.join("\n"));
}
sections.push(format!(
"{:?}: {}",
bcb_data.basic_blocks.last().unwrap(),
term_type(&bcb_data.terminator(mir_body).kind)
bcb_data.terminator(mir_body).kind.name(),
));
sections
}

/// Returns a simple string representation of a `TerminatorKind` variant, independent of any
/// values it might hold.
pub(super) fn term_type(kind: &TerminatorKind<'_>) -> &'static str {
match kind {
TerminatorKind::Goto { .. } => "Goto",
TerminatorKind::SwitchInt { .. } => "SwitchInt",
TerminatorKind::Resume => "Resume",
TerminatorKind::Terminate => "Terminate",
TerminatorKind::Return => "Return",
TerminatorKind::Unreachable => "Unreachable",
TerminatorKind::Drop { .. } => "Drop",
TerminatorKind::Call { .. } => "Call",
TerminatorKind::Assert { .. } => "Assert",
TerminatorKind::Yield { .. } => "Yield",
TerminatorKind::GeneratorDrop => "GeneratorDrop",
TerminatorKind::FalseEdge { .. } => "FalseEdge",
TerminatorKind::FalseUnwind { .. } => "FalseUnwind",
TerminatorKind::InlineAsm { .. } => "InlineAsm",
}
}
3 changes: 1 addition & 2 deletions compiler/rustc_mir_transform/src/coverage/spans.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use super::debug::term_type;
use super::graph::{BasicCoverageBlock, BasicCoverageBlockData, CoverageGraph, START_BCB};

use itertools::Itertools;
Expand Down Expand Up @@ -40,7 +39,7 @@ impl CoverageStatement {
"{}: @{}.{}: {:?}",
source_range_no_file(tcx, span),
bb.index(),
term_type(&term.kind),
term.kind.name(),
term.kind
)
}
Expand Down
11 changes: 5 additions & 6 deletions compiler/rustc_mir_transform/src/coverage/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
//! to: `rustc_span::create_default_session_globals_then(|| { test_here(); })`.

use super::counters;
use super::debug;
use super::graph;
use super::spans;

Expand Down Expand Up @@ -188,12 +187,12 @@ fn debug_basic_blocks(mir_body: &Body<'_>) -> String {
| TerminatorKind::Goto { target }
| TerminatorKind::InlineAsm { destination: Some(target), .. }
| TerminatorKind::Yield { resume: target, .. } => {
format!("{}{:?}:{} -> {:?}", sp, bb, debug::term_type(kind), target)
format!("{}{:?}:{} -> {:?}", sp, bb, kind.name(), target)
}
TerminatorKind::SwitchInt { targets, .. } => {
format!("{}{:?}:{} -> {:?}", sp, bb, debug::term_type(kind), targets)
format!("{}{:?}:{} -> {:?}", sp, bb, kind.name(), targets)
}
_ => format!("{}{:?}:{}", sp, bb, debug::term_type(kind)),
_ => format!("{}{:?}:{}", sp, bb, kind.name()),
}
})
.collect::<Vec<_>>()
Expand All @@ -215,7 +214,7 @@ fn print_mir_graphviz(name: &str, mir_body: &Body<'_>) {
" {:?} [label=\"{:?}: {}\"];\n{}",
bb,
bb,
debug::term_type(&data.terminator().kind),
data.terminator().kind.name(),
mir_body
.basic_blocks
.successors(bb)
Expand Down Expand Up @@ -244,7 +243,7 @@ fn print_coverage_graphviz(
" {:?} [label=\"{:?}: {}\"];\n{}",
bcb,
bcb,
debug::term_type(&bcb_data.terminator(mir_body).kind),
bcb_data.terminator(mir_body).kind.name(),
basic_coverage_blocks
.successors(bcb)
.map(|successor| { format!(" {:?} -> {:?};", bcb, successor) })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,14 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
}
}
}

// `&[{integral}]` - `FromIterator` needs that.
if let ty::Ref(_, ref_ty, rustc_ast::Mutability::Not) = self_ty.kind()
&& let ty::Slice(sty) = ref_ty.kind()
&& sty.is_integral()
{
flags.push((sym::_Self, Some("&[{integral}]".to_owned())));
}
});

if let Ok(Some(command)) = OnUnimplementedDirective::of_item(self.tcx, def_id) {
Expand Down
Loading

0 comments on commit 8b4b208

Please sign in to comment.