Auto merge of #98904 - matthiaskrgr:rollup-05owsx7, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #98738 (Clarify MIR semantics of checked binary operations) - #98782 (Improve spans for specialization error) - #98793 (Lint against executable files in the root directory) - #98814 (rustdoc: Censor certain complex unevaluated const exprs) - #98878 (add more `rustc_pass_by_value`) - #98879 (Fix "wrap closure in parenthesis" suggestion for `async` closure) - #98886 (incr.comp.: Make split-dwarf commandline options [TRACKED].) - #98898 (Add "no-div-regex" eslint rule) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
e1d1848cc6
27 changed files with 426 additions and 63 deletions
|
@ -149,7 +149,7 @@ impl<'cg, 'cx, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'cx, 'tcx> {
|
|||
fn visit_ascribe_user_ty(
|
||||
&mut self,
|
||||
_place: &Place<'tcx>,
|
||||
_variance: &ty::Variance,
|
||||
_variance: ty::Variance,
|
||||
_user_ty: &UserTypeProjection,
|
||||
_location: Location,
|
||||
) {
|
||||
|
|
|
@ -311,6 +311,7 @@ pub enum StatementKind<'tcx> {
|
|||
|
||||
/// Describes what kind of retag is to be performed.
|
||||
#[derive(Copy, Clone, TyEncodable, TyDecodable, Debug, PartialEq, Eq, Hash, HashStable)]
|
||||
#[rustc_pass_by_value]
|
||||
pub enum RetagKind {
|
||||
/// The initial retag when entering a function.
|
||||
FnEntry,
|
||||
|
@ -990,11 +991,19 @@ pub enum Rvalue<'tcx> {
|
|||
/// matching types and return a value of that type.
|
||||
BinaryOp(BinOp, Box<(Operand<'tcx>, Operand<'tcx>)>),
|
||||
|
||||
/// Same as `BinaryOp`, but yields `(T, bool)` instead of `T`. In addition to performing the
|
||||
/// same computation as the matching `BinaryOp`, checks if the infinite precison result would be
|
||||
/// unequal to the actual result and sets the `bool` if this is the case.
|
||||
/// Same as `BinaryOp`, but yields `(T, bool)` with a `bool` indicating an error condition.
|
||||
///
|
||||
/// This only supports addition, subtraction, multiplication, and shift operations on integers.
|
||||
/// When overflow checking is disabled, the error condition is false. Otherwise, the error
|
||||
/// condition is determined as described below.
|
||||
///
|
||||
/// For addition, subtraction, and multiplication on integers the error condition is set when
|
||||
/// the infinite precision result would be unequal to the actual result.
|
||||
///
|
||||
/// For shift operations on integers the error condition is set when the value of right-hand
|
||||
/// side is greater than or equal to the number of bits in the type of the left-hand side, or
|
||||
/// when the value of right-hand side is negative.
|
||||
///
|
||||
/// Other combinations of types and operators are unsupported.
|
||||
CheckedBinaryOp(BinOp, Box<(Operand<'tcx>, Operand<'tcx>)>),
|
||||
|
||||
/// Computes a value as described by the operation.
|
||||
|
|
|
@ -147,7 +147,7 @@ macro_rules! make_mir_visitor {
|
|||
fn visit_ascribe_user_ty(
|
||||
&mut self,
|
||||
place: & $($mutability)? Place<'tcx>,
|
||||
variance: & $($mutability)? ty::Variance,
|
||||
variance: $(& $mutability)? ty::Variance,
|
||||
user_ty: & $($mutability)? UserTypeProjection,
|
||||
location: Location,
|
||||
) {
|
||||
|
@ -164,7 +164,7 @@ macro_rules! make_mir_visitor {
|
|||
|
||||
fn visit_retag(
|
||||
&mut self,
|
||||
kind: & $($mutability)? RetagKind,
|
||||
kind: $(& $mutability)? RetagKind,
|
||||
place: & $($mutability)? Place<'tcx>,
|
||||
location: Location,
|
||||
) {
|
||||
|
@ -425,7 +425,7 @@ macro_rules! make_mir_visitor {
|
|||
self.visit_source_info(source_info);
|
||||
match kind {
|
||||
StatementKind::Assign(
|
||||
box(ref $($mutability)? place, ref $($mutability)? rvalue)
|
||||
box (place, rvalue)
|
||||
) => {
|
||||
self.visit_assign(place, rvalue, location);
|
||||
}
|
||||
|
@ -465,13 +465,13 @@ macro_rules! make_mir_visitor {
|
|||
);
|
||||
}
|
||||
StatementKind::Retag(kind, place) => {
|
||||
self.visit_retag(kind, place, location);
|
||||
self.visit_retag($(& $mutability)? *kind, place, location);
|
||||
}
|
||||
StatementKind::AscribeUserType(
|
||||
box(ref $($mutability)? place, ref $($mutability)? user_ty),
|
||||
box (place, user_ty),
|
||||
variance
|
||||
) => {
|
||||
self.visit_ascribe_user_ty(place, variance, user_ty, location);
|
||||
self.visit_ascribe_user_ty(place, $(& $mutability)? *variance, user_ty, location);
|
||||
}
|
||||
StatementKind::Coverage(coverage) => {
|
||||
self.visit_coverage(
|
||||
|
@ -480,9 +480,9 @@ macro_rules! make_mir_visitor {
|
|||
)
|
||||
}
|
||||
StatementKind::CopyNonOverlapping(box crate::mir::CopyNonOverlapping{
|
||||
ref $($mutability)? src,
|
||||
ref $($mutability)? dst,
|
||||
ref $($mutability)? count,
|
||||
src,
|
||||
dst,
|
||||
count,
|
||||
}) => {
|
||||
self.visit_operand(src, location);
|
||||
self.visit_operand(dst, location);
|
||||
|
@ -517,8 +517,7 @@ macro_rules! make_mir_visitor {
|
|||
TerminatorKind::GeneratorDrop |
|
||||
TerminatorKind::Unreachable |
|
||||
TerminatorKind::FalseEdge { .. } |
|
||||
TerminatorKind::FalseUnwind { .. } => {
|
||||
}
|
||||
TerminatorKind::FalseUnwind { .. } => {}
|
||||
|
||||
TerminatorKind::Return => {
|
||||
// `return` logically moves from the return place `_0`. Note that the place
|
||||
|
@ -830,7 +829,7 @@ macro_rules! make_mir_visitor {
|
|||
|
||||
fn super_ascribe_user_ty(&mut self,
|
||||
place: & $($mutability)? Place<'tcx>,
|
||||
_variance: & $($mutability)? ty::Variance,
|
||||
_variance: $(& $mutability)? ty::Variance,
|
||||
user_ty: & $($mutability)? UserTypeProjection,
|
||||
location: Location) {
|
||||
self.visit_place(
|
||||
|
@ -847,7 +846,7 @@ macro_rules! make_mir_visitor {
|
|||
}
|
||||
|
||||
fn super_retag(&mut self,
|
||||
_kind: & $($mutability)? RetagKind,
|
||||
_kind: $(& $mutability)? RetagKind,
|
||||
place: & $($mutability)? Place<'tcx>,
|
||||
location: Location) {
|
||||
self.visit_place(
|
||||
|
|
|
@ -2724,8 +2724,8 @@ pub(crate) mod dep_tracking {
|
|||
use super::{
|
||||
BranchProtection, CFGuard, CFProtection, CrateType, DebugInfo, ErrorOutputType,
|
||||
InstrumentCoverage, LdImpl, LinkerPluginLto, LocationDetail, LtoCli, OomStrategy, OptLevel,
|
||||
OutputType, OutputTypes, Passes, SourceFileHashAlgorithm, SwitchWithOptPath,
|
||||
SymbolManglingVersion, TrimmedDefPaths,
|
||||
OutputType, OutputTypes, Passes, SourceFileHashAlgorithm, SplitDwarfKind,
|
||||
SwitchWithOptPath, SymbolManglingVersion, TrimmedDefPaths,
|
||||
};
|
||||
use crate::lint;
|
||||
use crate::options::WasiExecModel;
|
||||
|
@ -2812,6 +2812,7 @@ pub(crate) mod dep_tracking {
|
|||
Edition,
|
||||
LinkerPluginLto,
|
||||
SplitDebuginfo,
|
||||
SplitDwarfKind,
|
||||
StackProtector,
|
||||
SwitchWithOptPath,
|
||||
SymbolManglingVersion,
|
||||
|
|
|
@ -1496,7 +1496,7 @@ options! {
|
|||
"control if mem::uninitialized and mem::zeroed panic on more UB"),
|
||||
strip: Strip = (Strip::None, parse_strip, [UNTRACKED],
|
||||
"tell the linker which information to strip (`none` (default), `debuginfo` or `symbols`)"),
|
||||
split_dwarf_kind: SplitDwarfKind = (SplitDwarfKind::Split, parse_split_dwarf_kind, [UNTRACKED],
|
||||
split_dwarf_kind: SplitDwarfKind = (SplitDwarfKind::Split, parse_split_dwarf_kind, [TRACKED],
|
||||
"split dwarf variant (only if -Csplit-debuginfo is enabled and on relevant platform)
|
||||
(default: `split`)
|
||||
|
||||
|
@ -1504,7 +1504,7 @@ options! {
|
|||
file which is ignored by the linker
|
||||
`single`: sections which do not require relocation are written into object file but ignored
|
||||
by the linker"),
|
||||
split_dwarf_inlining: bool = (true, parse_bool, [UNTRACKED],
|
||||
split_dwarf_inlining: bool = (true, parse_bool, [TRACKED],
|
||||
"provide minimal debug info in the object/executable to facilitate online \
|
||||
symbolication/stack traces in the absence of .dwo/.dwp files when using Split DWARF"),
|
||||
symbol_mangling_version: Option<SymbolManglingVersion> = (None,
|
||||
|
|
|
@ -599,6 +599,7 @@ impl UnifyKey for FloatVid {
|
|||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Decodable, Encodable, Hash)]
|
||||
#[rustc_pass_by_value]
|
||||
pub enum Variance {
|
||||
Covariant, // T<A> <: T<B> iff A <: B -- e.g., function return type
|
||||
Invariant, // T<A> <: T<B> iff B == A -- e.g., type of mutable cell
|
||||
|
|
|
@ -280,15 +280,36 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
callee_node: &hir::ExprKind<'_>,
|
||||
callee_span: Span,
|
||||
) {
|
||||
let hir_id = self.tcx.hir().get_parent_node(hir_id);
|
||||
let parent_node = self.tcx.hir().get(hir_id);
|
||||
let hir = self.tcx.hir();
|
||||
let parent_hir_id = hir.get_parent_node(hir_id);
|
||||
let parent_node = hir.get(parent_hir_id);
|
||||
if let (
|
||||
hir::Node::Expr(hir::Expr {
|
||||
kind: hir::ExprKind::Closure { fn_decl_span, .. }, ..
|
||||
kind: hir::ExprKind::Closure { fn_decl_span, body, .. },
|
||||
..
|
||||
}),
|
||||
hir::ExprKind::Block(..),
|
||||
) = (parent_node, callee_node)
|
||||
{
|
||||
let fn_decl_span = if hir.body(*body).generator_kind
|
||||
== Some(hir::GeneratorKind::Async(hir::AsyncGeneratorKind::Closure))
|
||||
{
|
||||
// Actually need to unwrap a few more layers of HIR to get to
|
||||
// the _real_ closure...
|
||||
let async_closure = hir.get_parent_node(hir.get_parent_node(parent_hir_id));
|
||||
if let hir::Node::Expr(hir::Expr {
|
||||
kind: hir::ExprKind::Closure { fn_decl_span, .. },
|
||||
..
|
||||
}) = hir.get(async_closure)
|
||||
{
|
||||
*fn_decl_span
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
*fn_decl_span
|
||||
};
|
||||
|
||||
let start = fn_decl_span.shrink_to_lo();
|
||||
let end = callee_span.shrink_to_hi();
|
||||
err.multipart_suggestion(
|
||||
|
|
|
@ -279,11 +279,16 @@ fn check_predicates<'tcx>(
|
|||
span: Span,
|
||||
) {
|
||||
let tcx = infcx.tcx;
|
||||
let impl1_predicates: Vec<_> = traits::elaborate_predicates(
|
||||
let instantiated = tcx.predicates_of(impl1_def_id).instantiate(tcx, impl1_substs);
|
||||
let impl1_predicates: Vec<_> = traits::elaborate_predicates_with_span(
|
||||
tcx,
|
||||
tcx.predicates_of(impl1_def_id).instantiate(tcx, impl1_substs).predicates.into_iter(),
|
||||
std::iter::zip(
|
||||
instantiated.predicates,
|
||||
// Don't drop predicates (unsound!) because `spans` is too short
|
||||
instantiated.spans.into_iter().chain(std::iter::repeat(span)),
|
||||
),
|
||||
)
|
||||
.map(|obligation| obligation.predicate)
|
||||
.map(|obligation| (obligation.predicate, obligation.cause.span))
|
||||
.collect();
|
||||
|
||||
let mut impl2_predicates = if impl2_node.is_from_trait() {
|
||||
|
@ -321,7 +326,7 @@ fn check_predicates<'tcx>(
|
|||
// which is sound because we forbid impls like the following
|
||||
//
|
||||
// impl<D: Debug> AlwaysApplicable for D { }
|
||||
let always_applicable_traits = impl1_predicates.iter().copied().filter(|&predicate| {
|
||||
let always_applicable_traits = impl1_predicates.iter().copied().filter(|&(predicate, _)| {
|
||||
matches!(
|
||||
trait_predicate_kind(tcx, predicate),
|
||||
Some(TraitSpecializationKind::AlwaysApplicable)
|
||||
|
@ -345,11 +350,11 @@ fn check_predicates<'tcx>(
|
|||
}
|
||||
}
|
||||
impl2_predicates.extend(
|
||||
traits::elaborate_predicates(tcx, always_applicable_traits)
|
||||
traits::elaborate_predicates_with_span(tcx, always_applicable_traits)
|
||||
.map(|obligation| obligation.predicate),
|
||||
);
|
||||
|
||||
for predicate in impl1_predicates {
|
||||
for (predicate, span) in impl1_predicates {
|
||||
if !impl2_predicates.contains(&predicate) {
|
||||
check_specialization_on(tcx, predicate, span)
|
||||
}
|
||||
|
@ -384,9 +389,17 @@ fn check_specialization_on<'tcx>(tcx: TyCtxt<'tcx>, predicate: ty::Predicate<'tc
|
|||
.emit();
|
||||
}
|
||||
}
|
||||
ty::PredicateKind::Projection(ty::ProjectionPredicate { projection_ty, term }) => {
|
||||
tcx.sess
|
||||
.struct_span_err(
|
||||
span,
|
||||
&format!("cannot specialize on associated type `{projection_ty} == {term}`",),
|
||||
)
|
||||
.emit();
|
||||
}
|
||||
_ => {
|
||||
tcx.sess
|
||||
.struct_span_err(span, &format!("cannot specialize on `{:?}`", predicate))
|
||||
.struct_span_err(span, &format!("cannot specialize on predicate `{}`", predicate))
|
||||
.emit();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue