Simplify some nested if statements

This commit is contained in:
Michael Goulet 2024-09-11 13:32:53 -04:00
parent 5a2dd7d4f3
commit 954419aab0
36 changed files with 340 additions and 380 deletions

View File

@ -78,8 +78,7 @@ fn insert(&mut self, span: Span, hir_id: HirId, node: Node<'hir>) {
// Make sure that the DepNode of some node coincides with the HirId
// owner of that node.
if cfg!(debug_assertions) {
if hir_id.owner != self.owner {
if cfg!(debug_assertions) && hir_id.owner != self.owner {
span_bug!(
span,
"inconsistent HirId at `{:?}` for `{:?}`: \
@ -98,7 +97,6 @@ fn insert(&mut self, span: Span, hir_id: HirId, node: Node<'hir>) {
hir_id.owner,
)
}
}
self.nodes[hir_id.local_id] = ParentedNode { parent: self.parent_node, node };
}

View File

@ -447,15 +447,15 @@ fn check_decl_self_param(&self, fn_decl: &FnDecl, self_semantic: SelfSemantic) {
fn check_item_safety(&self, span: Span, safety: Safety) {
match self.extern_mod_safety {
Some(extern_safety) => {
if matches!(safety, Safety::Unsafe(_) | Safety::Safe(_)) {
if extern_safety == Safety::Default {
if matches!(safety, Safety::Unsafe(_) | Safety::Safe(_))
&& extern_safety == Safety::Default
{
self.dcx().emit_err(errors::InvalidSafetyOnExtern {
item_span: span,
block: Some(self.current_extern_span().shrink_to_lo()),
});
}
}
}
None => {
if matches!(safety, Safety::Safe(_)) {
self.dcx().emit_err(errors::InvalidSafetyOnItem { span });

View File

@ -2574,8 +2574,8 @@ struct ExpressionFinder<'tcx> {
}
impl<'hir> Visitor<'hir> for ExpressionFinder<'hir> {
fn visit_expr(&mut self, e: &'hir hir::Expr<'hir>) {
if e.span.contains(self.capture_span) {
if let hir::ExprKind::Closure(&hir::Closure {
if e.span.contains(self.capture_span)
&& let hir::ExprKind::Closure(&hir::Closure {
kind: hir::ClosureKind::Closure,
body,
fn_arg_span,
@ -2593,15 +2593,13 @@ fn visit_expr(&mut self, e: &'hir hir::Expr<'hir>) {
self.visit_expr(body);
self.in_closure = false;
}
}
if let hir::Expr { kind: hir::ExprKind::Path(path), .. } = e {
if let hir::QPath::Resolved(_, hir::Path { segments: [seg], .. }) = path
if let hir::Expr { kind: hir::ExprKind::Path(path), .. } = e
&& let hir::QPath::Resolved(_, hir::Path { segments: [seg], .. }) = path
&& seg.ident.name == kw::SelfLower
&& self.in_closure
{
self.closure_change_spans.push(e.span);
}
}
hir::intravisit::walk_expr(self, e);
}
@ -2609,8 +2607,7 @@ fn visit_local(&mut self, local: &'hir hir::LetStmt<'hir>) {
if let hir::Pat { kind: hir::PatKind::Binding(_, hir_id, _ident, _), .. } =
local.pat
&& let Some(init) = local.init
{
if let hir::Expr {
&& let hir::Expr {
kind:
hir::ExprKind::Closure(&hir::Closure {
kind: hir::ClosureKind::Closure,
@ -2622,7 +2619,7 @@ fn visit_local(&mut self, local: &'hir hir::LetStmt<'hir>) {
{
self.closure_local_id = Some(*hir_id);
}
}
hir::intravisit::walk_local(self, local);
}

View File

@ -2069,13 +2069,13 @@ fn check_parent_of_field<'a, 'tcx>(
// no move out from an earlier location) then this is an attempt at initialization
// of the union - we should error in that case.
let tcx = this.infcx.tcx;
if base.ty(this.body(), tcx).ty.is_union() {
if this.move_data.path_map[mpi].iter().any(|moi| {
if base.ty(this.body(), tcx).ty.is_union()
&& this.move_data.path_map[mpi].iter().any(|moi| {
this.move_data.moves[*moi].source.is_predecessor_of(location, this.body)
}) {
})
{
return;
}
}
this.report_use_of_moved_or_uninitialized(
location,

View File

@ -353,13 +353,13 @@ fn compute_drop_live_points_for(&mut self, local: Local) {
let location = self.cx.elements.to_location(drop_point);
debug_assert_eq!(self.cx.body.terminator_loc(location.block), location,);
if self.cx.initialized_at_terminator(location.block, mpi) {
if self.drop_live_at.insert(drop_point) {
if self.cx.initialized_at_terminator(location.block, mpi)
&& self.drop_live_at.insert(drop_point)
{
self.drop_locations.push(location);
self.stack.push(drop_point);
}
}
}
debug!("compute_drop_live_points_for: drop_locations={:?}", self.drop_locations);

View File

@ -92,13 +92,11 @@ fn prepare_lto(
dcx.emit_err(LtoDylib);
return Err(FatalError);
}
} else if *crate_type == CrateType::ProcMacro {
if !cgcx.opts.unstable_opts.dylib_lto {
} else if *crate_type == CrateType::ProcMacro && !cgcx.opts.unstable_opts.dylib_lto {
dcx.emit_err(LtoProcMacro);
return Err(FatalError);
}
}
}
if cgcx.opts.cg.prefer_dynamic && !cgcx.opts.unstable_opts.dylib_lto {
dcx.emit_err(DynamicLinkingWithLTO);

View File

@ -617,8 +617,8 @@ fn emit_error_with_label(
// purpose functions as they wouldn't have the right target features
// enabled. For that reason we also forbid #[inline(always)] as it can't be
// respected.
if !codegen_fn_attrs.target_features.is_empty() {
if codegen_fn_attrs.inline == InlineAttr::Always {
if !codegen_fn_attrs.target_features.is_empty() && codegen_fn_attrs.inline == InlineAttr::Always
{
if let Some(span) = inline_span {
tcx.dcx().span_err(
span,
@ -627,10 +627,8 @@ fn emit_error_with_label(
);
}
}
}
if !codegen_fn_attrs.no_sanitize.is_empty() {
if codegen_fn_attrs.inline == InlineAttr::Always {
if !codegen_fn_attrs.no_sanitize.is_empty() && codegen_fn_attrs.inline == InlineAttr::Always {
if let (Some(no_sanitize_span), Some(inline_span)) = (no_sanitize_span, inline_span) {
let hir_id = tcx.local_def_id_to_hir_id(did);
tcx.node_span_lint(
@ -644,7 +642,6 @@ fn emit_error_with_label(
)
}
}
}
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NAKED) {
codegen_fn_attrs.inline = InlineAttr::Never;

View File

@ -16,7 +16,7 @@
use rustc_target::abi::call::FnAbi;
use rustc_target::abi::{Align, HasDataLayout, Size, TargetDataLayout};
use rustc_trait_selection::traits::ObligationCtxt;
use tracing::{debug, trace};
use tracing::{debug, instrument, trace};
use super::{
err_inval, throw_inval, throw_ub, throw_ub_custom, Frame, FrameInfo, GlobalId, InterpErrorInfo,
@ -315,6 +315,7 @@ pub(super) fn resolve(
/// Check if the two things are equal in the current param_env, using an infctx to get proper
/// equality checks.
#[instrument(level = "trace", skip(self), ret)]
pub(super) fn eq_in_param_env<T>(&self, a: T, b: T) -> bool
where
T: PartialEq + TypeFoldable<TyCtxt<'tcx>> + ToTrace<'tcx>,
@ -330,15 +331,22 @@ pub(super) fn eq_in_param_env<T>(&self, a: T, b: T) -> bool
// equate the two trait refs after normalization
let a = ocx.normalize(&cause, self.param_env, a);
let b = ocx.normalize(&cause, self.param_env, b);
if ocx.eq(&cause, self.param_env, a, b).is_ok() {
if ocx.select_all_or_error().is_empty() {
// All good.
return true;
}
}
if let Err(terr) = ocx.eq(&cause, self.param_env, a, b) {
trace!(?terr);
return false;
}
let errors = ocx.select_all_or_error();
if !errors.is_empty() {
trace!(?errors);
return false;
}
// All good.
true
}
/// Walks up the callstack from the intrinsic's callsite, searching for the first callsite in a
/// frame which is not `#[track_caller]`. This matches the `caller_location` intrinsic,
/// and is primarily intended for the panic machinery.

View File

@ -222,11 +222,9 @@ fn tcx(&self) -> TyCtxt<'tcx> {
}
pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
if ppm.needs_analysis() {
if ex.tcx().analysis(()).is_err() {
if ppm.needs_analysis() && ex.tcx().analysis(()).is_err() {
FatalError.raise();
}
}
let (src, src_name) = get_source(sess);

View File

@ -186,8 +186,7 @@ fn maybe_check_static_with_link_section(tcx: TyCtxt<'_>, id: LocalDefId) {
if let Ok(alloc) = tcx.eval_static_initializer(id.to_def_id())
&& alloc.inner().provenance().ptrs().len() != 0
{
if attrs
&& attrs
.link_section
.map(|link_section| !link_section.as_str().starts_with(".init_array"))
.unwrap()
@ -198,7 +197,6 @@ fn maybe_check_static_with_link_section(tcx: TyCtxt<'_>, id: LocalDefId) {
tcx.dcx().span_err(tcx.def_span(id), msg);
}
}
}
fn report_forbidden_specialization(tcx: TyCtxt<'_>, impl_item: DefId, parent_impl: DefId) {
let span = tcx.def_span(impl_item);

View File

@ -53,8 +53,7 @@ fn enforce_trait_manually_implementable(
) -> Result<(), ErrorGuaranteed> {
let impl_header_span = tcx.def_span(impl_def_id);
if tcx.is_lang_item(trait_def_id, LangItem::Freeze) {
if !tcx.features().freeze_impls {
if tcx.is_lang_item(trait_def_id, LangItem::Freeze) && !tcx.features().freeze_impls {
feature_err(
&tcx.sess,
sym::freeze_impls,
@ -64,7 +63,6 @@ fn enforce_trait_manually_implementable(
.with_span_label(impl_header_span, format!("impl of `Freeze` not allowed"))
.emit();
}
}
// Disallow *all* explicit impls of traits marked `#[rustc_deny_explicit_impl]`
if trait_def.deny_explicit_impl {

View File

@ -827,8 +827,7 @@ fn suggest_moving_args_from_assoc_fn_to_trait_for_qualified_path(
if num_generic_args_supplied_to_trait + num_assoc_fn_excess_args
== num_trait_generics_except_self
{
if let Some(span) = self.gen_args.span_ext()
&& let Some(span) = self.gen_args.span_ext()
&& let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span)
{
let sugg = vec![
@ -843,7 +842,6 @@ fn suggest_moving_args_from_assoc_fn_to_trait_for_qualified_path(
}
}
}
}
fn suggest_moving_args_from_assoc_fn_to_trait_for_method_call(
&self,

View File

@ -732,13 +732,12 @@ fn do_check(&self, fcx: &FnCtxt<'a, 'tcx>) -> Result<CastKind, CastError> {
}
_ => return Err(CastError::NonScalar),
};
if let ty::Adt(adt_def, _) = *self.expr_ty.kind() {
if adt_def.did().krate != LOCAL_CRATE {
if adt_def.variants().iter().any(VariantDef::is_field_list_non_exhaustive) {
if let ty::Adt(adt_def, _) = *self.expr_ty.kind()
&& adt_def.did().krate != LOCAL_CRATE
&& adt_def.variants().iter().any(VariantDef::is_field_list_non_exhaustive)
{
return Err(CastError::ForeignNonExhaustiveAdt);
}
}
}
match (t_from, t_cast) {
// These types have invariants! can't cast into them.
(_, Int(CEnum) | FnPtr) => Err(CastError::NonScalar),

View File

@ -1780,8 +1780,7 @@ fn check_expr_struct_fields(
}
// Make sure the programmer specified correct number of fields.
if adt_kind == AdtKind::Union {
if hir_fields.len() != 1 {
if adt_kind == AdtKind::Union && hir_fields.len() != 1 {
struct_span_code_err!(
self.dcx(),
span,
@ -1790,7 +1789,6 @@ fn check_expr_struct_fields(
)
.emit();
}
}
// If check_expr_struct_fields hit an error, do not attempt to populate
// the fields with the base_expr. This could cause us to hit errors later

View File

@ -1252,12 +1252,12 @@ fn report_no_match_method_error(
&& suggested_bounds.contains(parent)
{
// We don't suggest `PartialEq` when we already suggest `Eq`.
} else if !suggested_bounds.contains(pred) {
if collect_type_param_suggestions(self_ty, *pred, &p) {
} else if !suggested_bounds.contains(pred)
&& collect_type_param_suggestions(self_ty, *pred, &p)
{
suggested = true;
suggested_bounds.insert(pred);
}
}
(
match parent_pred {
None => format!("`{p}`"),
@ -1267,15 +1267,14 @@ fn report_no_match_method_error(
if !suggested
&& !suggested_bounds.contains(pred)
&& !suggested_bounds.contains(parent_pred)
{
if collect_type_param_suggestions(
&& collect_type_param_suggestions(
self_ty,
*parent_pred,
&p,
) {
)
{
suggested_bounds.insert(pred);
}
}
format!("`{p}`\nwhich is required by `{parent_p}`")
}
},

View File

@ -429,11 +429,9 @@ fn check_missing_docs_attrs(
// Only check publicly-visible items, using the result from the privacy pass.
// It's an option so the crate root can also use this function (it doesn't
// have a `NodeId`).
if def_id != CRATE_DEF_ID {
if !cx.effective_visibilities.is_exported(def_id) {
if def_id != CRATE_DEF_ID && !cx.effective_visibilities.is_exported(def_id) {
return;
}
}
let attrs = cx.tcx.hir().attrs(cx.tcx.local_def_id_to_hir_id(def_id));
let has_doc = attrs.iter().any(has_doc);

View File

@ -444,11 +444,12 @@ pub fn eval_stability_allow_unstable(
// the `-Z force-unstable-if-unmarked` flag present (we're
// compiling a compiler crate), then let this missing feature
// annotation slide.
if feature == sym::rustc_private && issue == NonZero::new(27812) {
if self.sess.opts.unstable_opts.force_unstable_if_unmarked {
if feature == sym::rustc_private
&& issue == NonZero::new(27812)
&& self.sess.opts.unstable_opts.force_unstable_if_unmarked
{
return EvalResult::Allow;
}
}
if matches!(allow_unstable, AllowUnstable::Yes) {
return EvalResult::Allow;

View File

@ -448,8 +448,7 @@ pub fn get_bytes_strip_provenance(
bad: uninit_range,
}))
})?;
if !Prov::OFFSET_IS_ADDR {
if !self.provenance.range_empty(range, cx) {
if !Prov::OFFSET_IS_ADDR && !self.provenance.range_empty(range, cx) {
// Find the provenance.
let (offset, _prov) = self
.provenance
@ -464,7 +463,6 @@ pub fn get_bytes_strip_provenance(
bad: AllocRange::from(start..end),
})));
}
}
Ok(self.get_bytes_unchecked(range))
}

View File

@ -2606,8 +2606,7 @@ fn check_args_compatible_inner(
/// With `cfg(debug_assertions)`, assert that args are compatible with their generics,
/// and print out the args if not.
pub fn debug_assert_args_compatible(self, def_id: DefId, args: &'tcx [ty::GenericArg<'tcx>]) {
if cfg!(debug_assertions) {
if !self.check_args_compatible(def_id, args) {
if cfg!(debug_assertions) && !self.check_args_compatible(def_id, args) {
if let DefKind::AssocTy = self.def_kind(def_id)
&& let DefKind::Impl { of_trait: false } = self.def_kind(self.parent(def_id))
{
@ -2635,7 +2634,6 @@ pub fn debug_assert_args_compatible(self, def_id: DefId, args: &'tcx [ty::Generi
}
}
}
}
#[inline(always)]
pub(crate) fn check_and_mk_args(

View File

@ -1183,12 +1183,12 @@ pub fn fn_can_unwind(tcx: TyCtxt<'_>, fn_def_id: Option<DefId>, abi: SpecAbi) ->
//
// This is not part of `codegen_fn_attrs` as it can differ between crates
// and therefore cannot be computed in core.
if tcx.sess.opts.unstable_opts.panic_in_drop == PanicStrategy::Abort {
if tcx.is_lang_item(did, LangItem::DropInPlace) {
if tcx.sess.opts.unstable_opts.panic_in_drop == PanicStrategy::Abort
&& tcx.is_lang_item(did, LangItem::DropInPlace)
{
return false;
}
}
}
// Otherwise if this isn't special then unwinding is generally determined by
// the ABI of the itself. ABIs like `C` have variants which also

View File

@ -3361,12 +3361,10 @@ pub fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> DefIdMap<Symbol> {
// name.
//
// Any stable ordering would be fine here though.
if *v.get() != symbol {
if v.get().as_str() > symbol.as_str() {
if *v.get() != symbol && v.get().as_str() > symbol.as_str() {
v.insert(symbol);
}
}
}
Vacant(v) => {
v.insert(symbol);
}

View File

@ -268,10 +268,9 @@ pub(crate) fn mcdc_increment_depth_if_enabled(&mut self) {
pub(crate) fn mcdc_decrement_depth_if_enabled(&mut self) {
if let Some(coverage_info) = self.coverage_info.as_mut()
&& let Some(mcdc_info) = coverage_info.mcdc_info.as_mut()
&& mcdc_info.state.decision_ctx_stack.pop().is_none()
{
if mcdc_info.state.decision_ctx_stack.pop().is_none() {
bug!("Unexpected empty decision stack");
}
};
}
}

View File

@ -95,8 +95,8 @@ fn visit_statement(&mut self, stmt: &Statement<'tcx>, loc: Location) {
// Check for assignment to fields of a constant
// Assigning directly to a constant (e.g. `FOO = true;`) is a hard error,
// so emitting a lint would be redundant.
if !lhs.projection.is_empty() {
if let Some(def_id) = self.is_const_item_without_destructor(lhs.local)
if !lhs.projection.is_empty()
&& let Some(def_id) = self.is_const_item_without_destructor(lhs.local)
&& let Some((lint_root, span, item)) =
self.should_lint_const_item_usage(lhs, def_id, loc)
{
@ -107,7 +107,7 @@ fn visit_statement(&mut self, stmt: &Statement<'tcx>, loc: Location) {
errors::ConstMutate::Modify { konst: item },
);
}
}
// We are looking for MIR of the form:
//
// ```

View File

@ -168,8 +168,8 @@ pub(super) fn deduced_param_attrs<'tcx>(
// Codegen won't use this information for anything if all the function parameters are passed
// directly. Detect that and bail, for compilation speed.
let fn_ty = tcx.type_of(def_id).instantiate_identity();
if matches!(fn_ty.kind(), ty::FnDef(..)) {
if fn_ty
if matches!(fn_ty.kind(), ty::FnDef(..))
&& fn_ty
.fn_sig(tcx)
.inputs()
.skip_binder()
@ -179,7 +179,6 @@ pub(super) fn deduced_param_attrs<'tcx>(
{
return &[];
}
}
// Don't deduce any attributes for functions that have no MIR.
if !tcx.is_mir_available(def_id) {

View File

@ -378,11 +378,11 @@ fn check_binary_op(
if let (Some(l), Some(r)) = (l, r)
&& l.layout.ty.is_integral()
&& op.is_overflowing()
{
if self.use_ecx(|this| {
&& self.use_ecx(|this| {
let (_res, overflow) = this.ecx.binary_op(op, &l, &r)?.to_scalar_pair();
overflow.to_bool()
})? {
})?
{
self.report_assert_as_lint(
location,
AssertLintKind::ArithmeticOverflow,
@ -390,7 +390,7 @@ fn check_binary_op(
);
return None;
}
}
Some(())
}

View File

@ -504,12 +504,10 @@ fn compute_inlined_overlap<'tcx>(cgu1: &CodegenUnit<'tcx>, cgu2: &CodegenUnit<'t
let mut overlap = 0;
for (item, data) in src_cgu.items().iter() {
if data.inlined {
if dst_cgu.items().contains_key(item) {
if data.inlined && dst_cgu.items().contains_key(item) {
overlap += data.size_estimate;
}
}
}
overlap
}

View File

@ -185,14 +185,12 @@ fn finalize(self) -> (ty::UniverseIndex, I::CanonicalVars) {
for var in var_infos.iter_mut() {
// We simply put all regions from the input into the highest
// compressed universe, so we only deal with them at the end.
if !var.is_region() {
if is_existential == var.is_existential() {
if !var.is_region() && is_existential == var.is_existential() {
update_uv(var, orig_uv, is_existential)
}
}
}
}
}
// We uniquify regions and always put them into their own universe
let mut first_region = true;

View File

@ -671,13 +671,13 @@ pub(super) fn parse_angle_args(
err.emit();
continue;
}
if !self.token.kind.should_end_const_arg() {
if self.handle_ambiguous_unbraced_const_arg(&mut args)? {
if !self.token.kind.should_end_const_arg()
&& self.handle_ambiguous_unbraced_const_arg(&mut args)?
{
// We've managed to (partially) recover, so continue trying to parse
// arguments.
continue;
}
}
break;
}
}

View File

@ -174,17 +174,15 @@ fn annotate<F>(
// If the current node is a function, has const stability attributes and if it doesn not have an intrinsic ABI,
// check if the function/method is const or the parent impl block is const
if let (Some(const_span), Some(fn_sig)) = (const_span, fn_sig) {
if fn_sig.header.abi != Abi::RustIntrinsic && !fn_sig.header.is_const() {
if !self.in_trait_impl
|| (self.in_trait_impl && !self.tcx.is_const_fn_raw(def_id.to_def_id()))
if let (Some(const_span), Some(fn_sig)) = (const_span, fn_sig)
&& fn_sig.header.abi != Abi::RustIntrinsic
&& !fn_sig.header.is_const()
&& (!self.in_trait_impl || !self.tcx.is_const_fn_raw(def_id.to_def_id()))
{
self.tcx
.dcx()
.emit_err(errors::MissingConstErr { fn_sig_span: fn_sig.span, const_span });
}
}
}
// `impl const Trait for Type` items forward their const stability to their
// immediate children.

View File

@ -1233,8 +1233,8 @@ fn lookup_import_candidates_from_module<FilterFn>(
&& ns == namespace
&& in_module != parent_scope.module
&& !ident.span.normalize_to_macros_2_0().from_expansion()
&& filter_fn(res)
{
if filter_fn(res) {
// create the path
let mut segms = if lookup_ident.span.at_least_rust_2018() {
// crate-local absolute paths start with `crate::` in edition 2018
@ -1292,7 +1292,6 @@ fn lookup_import_candidates_from_module<FilterFn>(
});
}
}
}
// collect submodules to explore
if let Some(module) = name_binding.module() {

View File

@ -958,13 +958,13 @@ fn resolve_ident_in_module_unadjusted_ext(
});
}
if !restricted_shadowing && binding.expansion != LocalExpnId::ROOT {
if let NameBindingKind::Import { import, .. } = binding.kind
if !restricted_shadowing
&& binding.expansion != LocalExpnId::ROOT
&& let NameBindingKind::Import { import, .. } = binding.kind
&& matches!(import.kind, ImportKind::MacroExport)
{
self.macro_expanded_macro_export_errors.insert((path_span, binding.span));
}
}
self.record_use(ident, binding, used);
return Ok(binding);

View File

@ -4781,8 +4781,7 @@ fn resolve_and_cache_rustdoc_path(&mut self, path_str: &str, ns: Namespace) -> O
if let Some(res) = res
&& let Some(def_id) = res.opt_def_id()
&& !def_id.is_local()
{
if self.r.tcx.crate_types().contains(&CrateType::ProcMacro)
&& self.r.tcx.crate_types().contains(&CrateType::ProcMacro)
&& matches!(
self.r.tcx.sess.opts.resolve_doc_links,
ResolveDocLinks::ExportedMetadata
@ -4791,7 +4790,6 @@ fn resolve_and_cache_rustdoc_path(&mut self, path_str: &str, ns: Namespace) -> O
// Encoding foreign def ids in proc macro crate metadata will ICE.
return None;
}
}
res
});
self.r.doc_link_resolutions = doc_link_resolutions;

View File

@ -2255,8 +2255,8 @@ fn likely_rust_type(path: &[Segment]) -> Option<Symbol> {
fn let_binding_suggestion(&mut self, err: &mut Diag<'_>, ident_span: Span) -> bool {
if let Some(Expr { kind: ExprKind::Assign(lhs, ..), .. }) = self.diag_metadata.in_assignment
&& let ast::ExprKind::Path(None, ref path) = lhs.kind
&& !ident_span.from_expansion()
{
if !ident_span.from_expansion() {
let (span, text) = match path.segments.first() {
Some(seg) if let Some(name) = seg.ident.as_str().strip_prefix("let") => {
// a special case for #117894
@ -2274,7 +2274,6 @@ fn let_binding_suggestion(&mut self, err: &mut Diag<'_>, ident_span: Span) -> bo
);
return true;
}
}
false
}

View File

@ -513,12 +513,11 @@ fn assemble_async_fn_kind_helper_candidates(
// then there's nothing else to check.
if let Some(closure_kind) = self_ty.to_opt_closure_kind()
&& let Some(goal_kind) = target_kind_ty.to_opt_closure_kind()
&& closure_kind.extends(goal_kind)
{
if closure_kind.extends(goal_kind) {
candidates.vec.push(AsyncFnKindHelperCandidate);
}
}
}
/// Implements one of the `Fn()` family for a fn pointer.
fn assemble_fn_pointer_candidates(

View File

@ -1334,8 +1334,7 @@ fn insert_evaluation_cache(
return;
}
if self.can_use_global_caches(param_env) {
if !trait_pred.has_infer() {
if self.can_use_global_caches(param_env) && !trait_pred.has_infer() {
debug!(?trait_pred, ?result, "insert_evaluation_cache global");
// This may overwrite the cache with the same value
// FIXME: Due to #50507 this overwrites the different values
@ -1344,7 +1343,6 @@ fn insert_evaluation_cache(
self.tcx().evaluation_cache.insert((param_env, trait_pred), dep_node, result);
return;
}
}
debug!(?trait_pred, ?result, "insert_evaluation_cache");
self.infcx.evaluation_cache.insert((param_env, trait_pred), dep_node, result);
@ -1584,15 +1582,13 @@ fn insert_candidate_cache(
if self.can_use_global_caches(param_env) {
if let Err(Overflow(OverflowError::Canonical)) = candidate {
// Don't cache overflow globally; we only produce this in certain modes.
} else if !pred.has_infer() {
if !candidate.has_infer() {
} else if !pred.has_infer() && !candidate.has_infer() {
debug!(?pred, ?candidate, "insert_candidate_cache global");
// This may overwrite the cache with the same value.
tcx.selection_cache.insert((param_env, pred), dep_node, candidate);
return;
}
}
}
debug!(?pred, ?candidate, "insert_candidate_cache local");
self.infcx.selection_cache.insert((param_env, pred), dep_node, candidate);
@ -1980,11 +1976,11 @@ fn candidate_should_be_dropped_in_favor_of(
// impls have to be always applicable, meaning that the only allowed
// region constraints may be constraints also present on the default impl.
let tcx = self.tcx();
if other.evaluation.must_apply_modulo_regions() {
if tcx.specializes((other_def, victim_def)) {
if other.evaluation.must_apply_modulo_regions()
&& tcx.specializes((other_def, victim_def))
{
return DropVictim::Yes;
}
}
match tcx.impls_are_allowed_to_overlap(other_def, victim_def) {
// For #33140 the impl headers must be exactly equal, the trait must not have

View File

@ -143,13 +143,11 @@ fn visit_opaque_ty(&mut self, alias_ty: ty::AliasTy<'tcx>) {
match origin {
rustc_hir::OpaqueTyOrigin::FnReturn(_) | rustc_hir::OpaqueTyOrigin::AsyncFn(_) => {}
rustc_hir::OpaqueTyOrigin::TyAlias { in_assoc_ty, .. } => {
if !in_assoc_ty {
if !self.check_tait_defining_scope(alias_ty.def_id.expect_local()) {
if !in_assoc_ty && !self.check_tait_defining_scope(alias_ty.def_id.expect_local()) {
return;
}
}
}
}
self.opaques.push(alias_ty.def_id.expect_local());