mirror of https://github.com/rust-lang/rust.git
Simplify some nested if statements
This commit is contained in:
parent
5a2dd7d4f3
commit
954419aab0
|
@ -78,26 +78,24 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
|
||||||
|
|
||||||
// Make sure that the DepNode of some node coincides with the HirId
|
// Make sure that the DepNode of some node coincides with the HirId
|
||||||
// owner of that node.
|
// owner of that node.
|
||||||
if cfg!(debug_assertions) {
|
if cfg!(debug_assertions) && hir_id.owner != self.owner {
|
||||||
if hir_id.owner != self.owner {
|
span_bug!(
|
||||||
span_bug!(
|
span,
|
||||||
span,
|
"inconsistent HirId at `{:?}` for `{:?}`: \
|
||||||
"inconsistent HirId at `{:?}` for `{:?}`: \
|
|
||||||
current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?})",
|
current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?})",
|
||||||
self.tcx.sess.source_map().span_to_diagnostic_string(span),
|
self.tcx.sess.source_map().span_to_diagnostic_string(span),
|
||||||
node,
|
node,
|
||||||
self.tcx
|
self.tcx
|
||||||
.definitions_untracked()
|
.definitions_untracked()
|
||||||
.def_path(self.owner.def_id)
|
.def_path(self.owner.def_id)
|
||||||
.to_string_no_crate_verbose(),
|
.to_string_no_crate_verbose(),
|
||||||
self.owner,
|
self.owner,
|
||||||
self.tcx
|
self.tcx
|
||||||
.definitions_untracked()
|
.definitions_untracked()
|
||||||
.def_path(hir_id.owner.def_id)
|
.def_path(hir_id.owner.def_id)
|
||||||
.to_string_no_crate_verbose(),
|
.to_string_no_crate_verbose(),
|
||||||
hir_id.owner,
|
hir_id.owner,
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.nodes[hir_id.local_id] = ParentedNode { parent: self.parent_node, node };
|
self.nodes[hir_id.local_id] = ParentedNode { parent: self.parent_node, node };
|
||||||
|
|
|
@ -447,13 +447,13 @@ impl<'a> AstValidator<'a> {
|
||||||
fn check_item_safety(&self, span: Span, safety: Safety) {
|
fn check_item_safety(&self, span: Span, safety: Safety) {
|
||||||
match self.extern_mod_safety {
|
match self.extern_mod_safety {
|
||||||
Some(extern_safety) => {
|
Some(extern_safety) => {
|
||||||
if matches!(safety, Safety::Unsafe(_) | Safety::Safe(_)) {
|
if matches!(safety, Safety::Unsafe(_) | Safety::Safe(_))
|
||||||
if extern_safety == Safety::Default {
|
&& extern_safety == Safety::Default
|
||||||
self.dcx().emit_err(errors::InvalidSafetyOnExtern {
|
{
|
||||||
item_span: span,
|
self.dcx().emit_err(errors::InvalidSafetyOnExtern {
|
||||||
block: Some(self.current_extern_span().shrink_to_lo()),
|
item_span: span,
|
||||||
});
|
block: Some(self.current_extern_span().shrink_to_lo()),
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
|
|
|
@ -2574,33 +2574,31 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||||
}
|
}
|
||||||
impl<'hir> Visitor<'hir> for ExpressionFinder<'hir> {
|
impl<'hir> Visitor<'hir> for ExpressionFinder<'hir> {
|
||||||
fn visit_expr(&mut self, e: &'hir hir::Expr<'hir>) {
|
fn visit_expr(&mut self, e: &'hir hir::Expr<'hir>) {
|
||||||
if e.span.contains(self.capture_span) {
|
if e.span.contains(self.capture_span)
|
||||||
if let hir::ExprKind::Closure(&hir::Closure {
|
&& let hir::ExprKind::Closure(&hir::Closure {
|
||||||
kind: hir::ClosureKind::Closure,
|
kind: hir::ClosureKind::Closure,
|
||||||
body,
|
body,
|
||||||
fn_arg_span,
|
fn_arg_span,
|
||||||
fn_decl: hir::FnDecl { inputs, .. },
|
fn_decl: hir::FnDecl { inputs, .. },
|
||||||
..
|
..
|
||||||
}) = e.kind
|
}) = e.kind
|
||||||
&& let hir::Node::Expr(body) = self.tcx.hir_node(body.hir_id)
|
&& let hir::Node::Expr(body) = self.tcx.hir_node(body.hir_id)
|
||||||
{
|
{
|
||||||
self.suggest_arg = "this: &Self".to_string();
|
self.suggest_arg = "this: &Self".to_string();
|
||||||
if inputs.len() > 0 {
|
if inputs.len() > 0 {
|
||||||
self.suggest_arg.push_str(", ");
|
self.suggest_arg.push_str(", ");
|
||||||
}
|
|
||||||
self.in_closure = true;
|
|
||||||
self.closure_arg_span = fn_arg_span;
|
|
||||||
self.visit_expr(body);
|
|
||||||
self.in_closure = false;
|
|
||||||
}
|
}
|
||||||
|
self.in_closure = true;
|
||||||
|
self.closure_arg_span = fn_arg_span;
|
||||||
|
self.visit_expr(body);
|
||||||
|
self.in_closure = false;
|
||||||
}
|
}
|
||||||
if let hir::Expr { kind: hir::ExprKind::Path(path), .. } = e {
|
if let hir::Expr { kind: hir::ExprKind::Path(path), .. } = e
|
||||||
if let hir::QPath::Resolved(_, hir::Path { segments: [seg], .. }) = path
|
&& let hir::QPath::Resolved(_, hir::Path { segments: [seg], .. }) = path
|
||||||
&& seg.ident.name == kw::SelfLower
|
&& seg.ident.name == kw::SelfLower
|
||||||
&& self.in_closure
|
&& self.in_closure
|
||||||
{
|
{
|
||||||
self.closure_change_spans.push(e.span);
|
self.closure_change_spans.push(e.span);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
hir::intravisit::walk_expr(self, e);
|
hir::intravisit::walk_expr(self, e);
|
||||||
}
|
}
|
||||||
|
@ -2609,8 +2607,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||||
if let hir::Pat { kind: hir::PatKind::Binding(_, hir_id, _ident, _), .. } =
|
if let hir::Pat { kind: hir::PatKind::Binding(_, hir_id, _ident, _), .. } =
|
||||||
local.pat
|
local.pat
|
||||||
&& let Some(init) = local.init
|
&& let Some(init) = local.init
|
||||||
{
|
&& let hir::Expr {
|
||||||
if let hir::Expr {
|
|
||||||
kind:
|
kind:
|
||||||
hir::ExprKind::Closure(&hir::Closure {
|
hir::ExprKind::Closure(&hir::Closure {
|
||||||
kind: hir::ClosureKind::Closure,
|
kind: hir::ClosureKind::Closure,
|
||||||
|
@ -2618,11 +2615,11 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||||
}),
|
}),
|
||||||
..
|
..
|
||||||
} = init
|
} = init
|
||||||
&& init.span.contains(self.capture_span)
|
&& init.span.contains(self.capture_span)
|
||||||
{
|
{
|
||||||
self.closure_local_id = Some(*hir_id);
|
self.closure_local_id = Some(*hir_id);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hir::intravisit::walk_local(self, local);
|
hir::intravisit::walk_local(self, local);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2069,12 +2069,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
|
||||||
// no move out from an earlier location) then this is an attempt at initialization
|
// no move out from an earlier location) then this is an attempt at initialization
|
||||||
// of the union - we should error in that case.
|
// of the union - we should error in that case.
|
||||||
let tcx = this.infcx.tcx;
|
let tcx = this.infcx.tcx;
|
||||||
if base.ty(this.body(), tcx).ty.is_union() {
|
if base.ty(this.body(), tcx).ty.is_union()
|
||||||
if this.move_data.path_map[mpi].iter().any(|moi| {
|
&& this.move_data.path_map[mpi].iter().any(|moi| {
|
||||||
this.move_data.moves[*moi].source.is_predecessor_of(location, this.body)
|
this.move_data.moves[*moi].source.is_predecessor_of(location, this.body)
|
||||||
}) {
|
})
|
||||||
return;
|
{
|
||||||
}
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.report_use_of_moved_or_uninitialized(
|
this.report_use_of_moved_or_uninitialized(
|
||||||
|
|
|
@ -353,11 +353,11 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
|
||||||
let location = self.cx.elements.to_location(drop_point);
|
let location = self.cx.elements.to_location(drop_point);
|
||||||
debug_assert_eq!(self.cx.body.terminator_loc(location.block), location,);
|
debug_assert_eq!(self.cx.body.terminator_loc(location.block), location,);
|
||||||
|
|
||||||
if self.cx.initialized_at_terminator(location.block, mpi) {
|
if self.cx.initialized_at_terminator(location.block, mpi)
|
||||||
if self.drop_live_at.insert(drop_point) {
|
&& self.drop_live_at.insert(drop_point)
|
||||||
self.drop_locations.push(location);
|
{
|
||||||
self.stack.push(drop_point);
|
self.drop_locations.push(location);
|
||||||
}
|
self.stack.push(drop_point);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,11 +92,9 @@ fn prepare_lto(
|
||||||
dcx.emit_err(LtoDylib);
|
dcx.emit_err(LtoDylib);
|
||||||
return Err(FatalError);
|
return Err(FatalError);
|
||||||
}
|
}
|
||||||
} else if *crate_type == CrateType::ProcMacro {
|
} else if *crate_type == CrateType::ProcMacro && !cgcx.opts.unstable_opts.dylib_lto {
|
||||||
if !cgcx.opts.unstable_opts.dylib_lto {
|
dcx.emit_err(LtoProcMacro);
|
||||||
dcx.emit_err(LtoProcMacro);
|
return Err(FatalError);
|
||||||
return Err(FatalError);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -617,32 +617,29 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
|
||||||
// purpose functions as they wouldn't have the right target features
|
// 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
|
// enabled. For that reason we also forbid #[inline(always)] as it can't be
|
||||||
// respected.
|
// respected.
|
||||||
if !codegen_fn_attrs.target_features.is_empty() {
|
if !codegen_fn_attrs.target_features.is_empty() && codegen_fn_attrs.inline == InlineAttr::Always
|
||||||
if codegen_fn_attrs.inline == InlineAttr::Always {
|
{
|
||||||
if let Some(span) = inline_span {
|
if let Some(span) = inline_span {
|
||||||
tcx.dcx().span_err(
|
tcx.dcx().span_err(
|
||||||
span,
|
span,
|
||||||
"cannot use `#[inline(always)]` with \
|
"cannot use `#[inline(always)]` with \
|
||||||
`#[target_feature]`",
|
`#[target_feature]`",
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !codegen_fn_attrs.no_sanitize.is_empty() {
|
if !codegen_fn_attrs.no_sanitize.is_empty() && codegen_fn_attrs.inline == InlineAttr::Always {
|
||||||
if codegen_fn_attrs.inline == InlineAttr::Always {
|
if let (Some(no_sanitize_span), Some(inline_span)) = (no_sanitize_span, inline_span) {
|
||||||
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);
|
||||||
let hir_id = tcx.local_def_id_to_hir_id(did);
|
tcx.node_span_lint(
|
||||||
tcx.node_span_lint(
|
lint::builtin::INLINE_NO_SANITIZE,
|
||||||
lint::builtin::INLINE_NO_SANITIZE,
|
hir_id,
|
||||||
hir_id,
|
no_sanitize_span,
|
||||||
no_sanitize_span,
|
|lint| {
|
||||||
|lint| {
|
lint.primary_message("`no_sanitize` will have no effect after inlining");
|
||||||
lint.primary_message("`no_sanitize` will have no effect after inlining");
|
lint.span_note(inline_span, "inlining requested here");
|
||||||
lint.span_note(inline_span, "inlining requested here");
|
},
|
||||||
},
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ use rustc_span::Span;
|
||||||
use rustc_target::abi::call::FnAbi;
|
use rustc_target::abi::call::FnAbi;
|
||||||
use rustc_target::abi::{Align, HasDataLayout, Size, TargetDataLayout};
|
use rustc_target::abi::{Align, HasDataLayout, Size, TargetDataLayout};
|
||||||
use rustc_trait_selection::traits::ObligationCtxt;
|
use rustc_trait_selection::traits::ObligationCtxt;
|
||||||
use tracing::{debug, trace};
|
use tracing::{debug, instrument, trace};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
err_inval, throw_inval, throw_ub, throw_ub_custom, Frame, FrameInfo, GlobalId, InterpErrorInfo,
|
err_inval, throw_inval, throw_ub, throw_ub_custom, Frame, FrameInfo, GlobalId, InterpErrorInfo,
|
||||||
|
@ -315,6 +315,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
||||||
|
|
||||||
/// Check if the two things are equal in the current param_env, using an infctx to get proper
|
/// Check if the two things are equal in the current param_env, using an infctx to get proper
|
||||||
/// equality checks.
|
/// equality checks.
|
||||||
|
#[instrument(level = "trace", skip(self), ret)]
|
||||||
pub(super) fn eq_in_param_env<T>(&self, a: T, b: T) -> bool
|
pub(super) fn eq_in_param_env<T>(&self, a: T, b: T) -> bool
|
||||||
where
|
where
|
||||||
T: PartialEq + TypeFoldable<TyCtxt<'tcx>> + ToTrace<'tcx>,
|
T: PartialEq + TypeFoldable<TyCtxt<'tcx>> + ToTrace<'tcx>,
|
||||||
|
@ -330,13 +331,20 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
||||||
// equate the two trait refs after normalization
|
// equate the two trait refs after normalization
|
||||||
let a = ocx.normalize(&cause, self.param_env, a);
|
let a = ocx.normalize(&cause, self.param_env, a);
|
||||||
let b = ocx.normalize(&cause, self.param_env, b);
|
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() {
|
if let Err(terr) = ocx.eq(&cause, self.param_env, a, b) {
|
||||||
// All good.
|
trace!(?terr);
|
||||||
return true;
|
return false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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
|
/// Walks up the callstack from the intrinsic's callsite, searching for the first callsite in a
|
||||||
|
|
|
@ -222,10 +222,8 @@ impl<'tcx> PrintExtra<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
|
pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
|
||||||
if ppm.needs_analysis() {
|
if ppm.needs_analysis() && ex.tcx().analysis(()).is_err() {
|
||||||
if ex.tcx().analysis(()).is_err() {
|
FatalError.raise();
|
||||||
FatalError.raise();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let (src, src_name) = get_source(sess);
|
let (src, src_name) = get_source(sess);
|
||||||
|
|
|
@ -186,17 +186,15 @@ fn maybe_check_static_with_link_section(tcx: TyCtxt<'_>, id: LocalDefId) {
|
||||||
|
|
||||||
if let Ok(alloc) = tcx.eval_static_initializer(id.to_def_id())
|
if let Ok(alloc) = tcx.eval_static_initializer(id.to_def_id())
|
||||||
&& alloc.inner().provenance().ptrs().len() != 0
|
&& alloc.inner().provenance().ptrs().len() != 0
|
||||||
{
|
&& attrs
|
||||||
if attrs
|
|
||||||
.link_section
|
.link_section
|
||||||
.map(|link_section| !link_section.as_str().starts_with(".init_array"))
|
.map(|link_section| !link_section.as_str().starts_with(".init_array"))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
{
|
{
|
||||||
let msg = "statics with a custom `#[link_section]` must be a \
|
let msg = "statics with a custom `#[link_section]` must be a \
|
||||||
simple list of bytes on the wasm target with no \
|
simple list of bytes on the wasm target with no \
|
||||||
extra levels of indirection such as references";
|
extra levels of indirection such as references";
|
||||||
tcx.dcx().span_err(tcx.def_span(id), msg);
|
tcx.dcx().span_err(tcx.def_span(id), msg);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,17 +53,15 @@ fn enforce_trait_manually_implementable(
|
||||||
) -> Result<(), ErrorGuaranteed> {
|
) -> Result<(), ErrorGuaranteed> {
|
||||||
let impl_header_span = tcx.def_span(impl_def_id);
|
let impl_header_span = tcx.def_span(impl_def_id);
|
||||||
|
|
||||||
if tcx.is_lang_item(trait_def_id, LangItem::Freeze) {
|
if tcx.is_lang_item(trait_def_id, LangItem::Freeze) && !tcx.features().freeze_impls {
|
||||||
if !tcx.features().freeze_impls {
|
feature_err(
|
||||||
feature_err(
|
&tcx.sess,
|
||||||
&tcx.sess,
|
sym::freeze_impls,
|
||||||
sym::freeze_impls,
|
impl_header_span,
|
||||||
impl_header_span,
|
"explicit impls for the `Freeze` trait are not permitted",
|
||||||
"explicit impls for the `Freeze` trait are not permitted",
|
)
|
||||||
)
|
.with_span_label(impl_header_span, format!("impl of `Freeze` not allowed"))
|
||||||
.with_span_label(impl_header_span, format!("impl of `Freeze` not allowed"))
|
.emit();
|
||||||
.emit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disallow *all* explicit impls of traits marked `#[rustc_deny_explicit_impl]`
|
// Disallow *all* explicit impls of traits marked `#[rustc_deny_explicit_impl]`
|
||||||
|
|
|
@ -827,20 +827,18 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
||||||
|
|
||||||
if num_generic_args_supplied_to_trait + num_assoc_fn_excess_args
|
if num_generic_args_supplied_to_trait + num_assoc_fn_excess_args
|
||||||
== num_trait_generics_except_self
|
== num_trait_generics_except_self
|
||||||
|
&& let Some(span) = self.gen_args.span_ext()
|
||||||
|
&& let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span)
|
||||||
{
|
{
|
||||||
if let Some(span) = self.gen_args.span_ext()
|
let sugg = vec![
|
||||||
&& let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span)
|
(
|
||||||
{
|
self.path_segment.ident.span,
|
||||||
let sugg = vec![
|
format!("{}::{}", snippet, self.path_segment.ident),
|
||||||
(
|
),
|
||||||
self.path_segment.ident.span,
|
(span.with_lo(self.path_segment.ident.span.hi()), "".to_owned()),
|
||||||
format!("{}::{}", snippet, self.path_segment.ident),
|
];
|
||||||
),
|
|
||||||
(span.with_lo(self.path_segment.ident.span.hi()), "".to_owned()),
|
|
||||||
];
|
|
||||||
|
|
||||||
err.multipart_suggestion(msg, sugg, Applicability::MaybeIncorrect);
|
err.multipart_suggestion(msg, sugg, Applicability::MaybeIncorrect);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -732,12 +732,11 @@ impl<'a, 'tcx> CastCheck<'tcx> {
|
||||||
}
|
}
|
||||||
_ => return Err(CastError::NonScalar),
|
_ => return Err(CastError::NonScalar),
|
||||||
};
|
};
|
||||||
if let ty::Adt(adt_def, _) = *self.expr_ty.kind() {
|
if let ty::Adt(adt_def, _) = *self.expr_ty.kind()
|
||||||
if adt_def.did().krate != LOCAL_CRATE {
|
&& adt_def.did().krate != LOCAL_CRATE
|
||||||
if adt_def.variants().iter().any(VariantDef::is_field_list_non_exhaustive) {
|
&& adt_def.variants().iter().any(VariantDef::is_field_list_non_exhaustive)
|
||||||
return Err(CastError::ForeignNonExhaustiveAdt);
|
{
|
||||||
}
|
return Err(CastError::ForeignNonExhaustiveAdt);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
match (t_from, t_cast) {
|
match (t_from, t_cast) {
|
||||||
// These types have invariants! can't cast into them.
|
// These types have invariants! can't cast into them.
|
||||||
|
|
|
@ -1780,16 +1780,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the programmer specified correct number of fields.
|
// Make sure the programmer specified correct number of fields.
|
||||||
if adt_kind == AdtKind::Union {
|
if adt_kind == AdtKind::Union && hir_fields.len() != 1 {
|
||||||
if hir_fields.len() != 1 {
|
struct_span_code_err!(
|
||||||
struct_span_code_err!(
|
self.dcx(),
|
||||||
self.dcx(),
|
span,
|
||||||
span,
|
E0784,
|
||||||
E0784,
|
"union expressions should have exactly one field",
|
||||||
"union expressions should have exactly one field",
|
)
|
||||||
)
|
.emit();
|
||||||
.emit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If check_expr_struct_fields hit an error, do not attempt to populate
|
// If check_expr_struct_fields hit an error, do not attempt to populate
|
||||||
|
|
|
@ -1252,11 +1252,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
&& suggested_bounds.contains(parent)
|
&& suggested_bounds.contains(parent)
|
||||||
{
|
{
|
||||||
// We don't suggest `PartialEq` when we already suggest `Eq`.
|
// We don't suggest `PartialEq` when we already suggest `Eq`.
|
||||||
} else if !suggested_bounds.contains(pred) {
|
} else if !suggested_bounds.contains(pred)
|
||||||
if collect_type_param_suggestions(self_ty, *pred, &p) {
|
&& collect_type_param_suggestions(self_ty, *pred, &p)
|
||||||
suggested = true;
|
{
|
||||||
suggested_bounds.insert(pred);
|
suggested = true;
|
||||||
}
|
suggested_bounds.insert(pred);
|
||||||
}
|
}
|
||||||
(
|
(
|
||||||
match parent_pred {
|
match parent_pred {
|
||||||
|
@ -1267,14 +1267,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
if !suggested
|
if !suggested
|
||||||
&& !suggested_bounds.contains(pred)
|
&& !suggested_bounds.contains(pred)
|
||||||
&& !suggested_bounds.contains(parent_pred)
|
&& !suggested_bounds.contains(parent_pred)
|
||||||
{
|
&& collect_type_param_suggestions(
|
||||||
if collect_type_param_suggestions(
|
|
||||||
self_ty,
|
self_ty,
|
||||||
*parent_pred,
|
*parent_pred,
|
||||||
&p,
|
&p,
|
||||||
) {
|
)
|
||||||
suggested_bounds.insert(pred);
|
{
|
||||||
}
|
suggested_bounds.insert(pred);
|
||||||
}
|
}
|
||||||
format!("`{p}`\nwhich is required by `{parent_p}`")
|
format!("`{p}`\nwhich is required by `{parent_p}`")
|
||||||
}
|
}
|
||||||
|
|
|
@ -429,10 +429,8 @@ impl MissingDoc {
|
||||||
// Only check publicly-visible items, using the result from the privacy pass.
|
// 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
|
// It's an option so the crate root can also use this function (it doesn't
|
||||||
// have a `NodeId`).
|
// have a `NodeId`).
|
||||||
if def_id != CRATE_DEF_ID {
|
if def_id != CRATE_DEF_ID && !cx.effective_visibilities.is_exported(def_id) {
|
||||||
if !cx.effective_visibilities.is_exported(def_id) {
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let attrs = cx.tcx.hir().attrs(cx.tcx.local_def_id_to_hir_id(def_id));
|
let attrs = cx.tcx.hir().attrs(cx.tcx.local_def_id_to_hir_id(def_id));
|
||||||
|
|
|
@ -444,10 +444,11 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
// the `-Z force-unstable-if-unmarked` flag present (we're
|
// the `-Z force-unstable-if-unmarked` flag present (we're
|
||||||
// compiling a compiler crate), then let this missing feature
|
// compiling a compiler crate), then let this missing feature
|
||||||
// annotation slide.
|
// annotation slide.
|
||||||
if feature == sym::rustc_private && issue == NonZero::new(27812) {
|
if feature == sym::rustc_private
|
||||||
if self.sess.opts.unstable_opts.force_unstable_if_unmarked {
|
&& issue == NonZero::new(27812)
|
||||||
return EvalResult::Allow;
|
&& self.sess.opts.unstable_opts.force_unstable_if_unmarked
|
||||||
}
|
{
|
||||||
|
return EvalResult::Allow;
|
||||||
}
|
}
|
||||||
|
|
||||||
if matches!(allow_unstable, AllowUnstable::Yes) {
|
if matches!(allow_unstable, AllowUnstable::Yes) {
|
||||||
|
|
|
@ -448,22 +448,20 @@ impl<Prov: Provenance, Extra, Bytes: AllocBytes> Allocation<Prov, Extra, Bytes>
|
||||||
bad: uninit_range,
|
bad: uninit_range,
|
||||||
}))
|
}))
|
||||||
})?;
|
})?;
|
||||||
if !Prov::OFFSET_IS_ADDR {
|
if !Prov::OFFSET_IS_ADDR && !self.provenance.range_empty(range, cx) {
|
||||||
if !self.provenance.range_empty(range, cx) {
|
// Find the provenance.
|
||||||
// Find the provenance.
|
let (offset, _prov) = self
|
||||||
let (offset, _prov) = self
|
.provenance
|
||||||
.provenance
|
.range_get_ptrs(range, cx)
|
||||||
.range_get_ptrs(range, cx)
|
.first()
|
||||||
.first()
|
.copied()
|
||||||
.copied()
|
.expect("there must be provenance somewhere here");
|
||||||
.expect("there must be provenance somewhere here");
|
let start = offset.max(range.start); // the pointer might begin before `range`!
|
||||||
let start = offset.max(range.start); // the pointer might begin before `range`!
|
let end = (offset + cx.pointer_size()).min(range.end()); // the pointer might end after `range`!
|
||||||
let end = (offset + cx.pointer_size()).min(range.end()); // the pointer might end after `range`!
|
return Err(AllocError::ReadPointerAsInt(Some(BadBytesAccess {
|
||||||
return Err(AllocError::ReadPointerAsInt(Some(BadBytesAccess {
|
access: range,
|
||||||
access: range,
|
bad: AllocRange::from(start..end),
|
||||||
bad: AllocRange::from(start..end),
|
})));
|
||||||
})));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Ok(self.get_bytes_unchecked(range))
|
Ok(self.get_bytes_unchecked(range))
|
||||||
}
|
}
|
||||||
|
|
|
@ -2606,33 +2606,31 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
/// With `cfg(debug_assertions)`, assert that args are compatible with their generics,
|
/// With `cfg(debug_assertions)`, assert that args are compatible with their generics,
|
||||||
/// and print out the args if not.
|
/// and print out the args if not.
|
||||||
pub fn debug_assert_args_compatible(self, def_id: DefId, args: &'tcx [ty::GenericArg<'tcx>]) {
|
pub fn debug_assert_args_compatible(self, def_id: DefId, args: &'tcx [ty::GenericArg<'tcx>]) {
|
||||||
if cfg!(debug_assertions) {
|
if cfg!(debug_assertions) && !self.check_args_compatible(def_id, args) {
|
||||||
if !self.check_args_compatible(def_id, args) {
|
if let DefKind::AssocTy = self.def_kind(def_id)
|
||||||
if let DefKind::AssocTy = self.def_kind(def_id)
|
&& let DefKind::Impl { of_trait: false } = self.def_kind(self.parent(def_id))
|
||||||
&& let DefKind::Impl { of_trait: false } = self.def_kind(self.parent(def_id))
|
{
|
||||||
{
|
bug!(
|
||||||
bug!(
|
"args not compatible with generics for {}: args={:#?}, generics={:#?}",
|
||||||
"args not compatible with generics for {}: args={:#?}, generics={:#?}",
|
self.def_path_str(def_id),
|
||||||
self.def_path_str(def_id),
|
args,
|
||||||
args,
|
// Make `[Self, GAT_ARGS...]` (this could be simplified)
|
||||||
// Make `[Self, GAT_ARGS...]` (this could be simplified)
|
self.mk_args_from_iter(
|
||||||
self.mk_args_from_iter(
|
[self.types.self_param.into()].into_iter().chain(
|
||||||
[self.types.self_param.into()].into_iter().chain(
|
self.generics_of(def_id)
|
||||||
self.generics_of(def_id)
|
.own_args(ty::GenericArgs::identity_for_item(self, def_id))
|
||||||
.own_args(ty::GenericArgs::identity_for_item(self, def_id))
|
.iter()
|
||||||
.iter()
|
.copied()
|
||||||
.copied()
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
);
|
)
|
||||||
} else {
|
);
|
||||||
bug!(
|
} else {
|
||||||
"args not compatible with generics for {}: args={:#?}, generics={:#?}",
|
bug!(
|
||||||
self.def_path_str(def_id),
|
"args not compatible with generics for {}: args={:#?}, generics={:#?}",
|
||||||
args,
|
self.def_path_str(def_id),
|
||||||
ty::GenericArgs::identity_for_item(self, def_id)
|
args,
|
||||||
);
|
ty::GenericArgs::identity_for_item(self, def_id)
|
||||||
}
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1183,10 +1183,10 @@ 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
|
// This is not part of `codegen_fn_attrs` as it can differ between crates
|
||||||
// and therefore cannot be computed in core.
|
// and therefore cannot be computed in core.
|
||||||
if tcx.sess.opts.unstable_opts.panic_in_drop == PanicStrategy::Abort {
|
if tcx.sess.opts.unstable_opts.panic_in_drop == PanicStrategy::Abort
|
||||||
if tcx.is_lang_item(did, LangItem::DropInPlace) {
|
&& tcx.is_lang_item(did, LangItem::DropInPlace)
|
||||||
return false;
|
{
|
||||||
}
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3361,10 +3361,8 @@ pub fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> DefIdMap<Symbol> {
|
||||||
// name.
|
// name.
|
||||||
//
|
//
|
||||||
// Any stable ordering would be fine here though.
|
// Any stable ordering would be fine here though.
|
||||||
if *v.get() != symbol {
|
if *v.get() != symbol && v.get().as_str() > symbol.as_str() {
|
||||||
if v.get().as_str() > symbol.as_str() {
|
v.insert(symbol);
|
||||||
v.insert(symbol);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Vacant(v) => {
|
Vacant(v) => {
|
||||||
|
|
|
@ -268,10 +268,9 @@ impl Builder<'_, '_> {
|
||||||
pub(crate) fn mcdc_decrement_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()
|
if let Some(coverage_info) = self.coverage_info.as_mut()
|
||||||
&& let Some(mcdc_info) = coverage_info.mcdc_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");
|
||||||
bug!("Unexpected empty decision stack");
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,19 +95,19 @@ impl<'tcx> Visitor<'tcx> for ConstMutationChecker<'_, 'tcx> {
|
||||||
// Check for assignment to fields of a constant
|
// Check for assignment to fields of a constant
|
||||||
// Assigning directly to a constant (e.g. `FOO = true;`) is a hard error,
|
// Assigning directly to a constant (e.g. `FOO = true;`) is a hard error,
|
||||||
// so emitting a lint would be redundant.
|
// so emitting a lint would be redundant.
|
||||||
if !lhs.projection.is_empty() {
|
if !lhs.projection.is_empty()
|
||||||
if let Some(def_id) = self.is_const_item_without_destructor(lhs.local)
|
&& let Some(def_id) = self.is_const_item_without_destructor(lhs.local)
|
||||||
&& let Some((lint_root, span, item)) =
|
&& let Some((lint_root, span, item)) =
|
||||||
self.should_lint_const_item_usage(lhs, def_id, loc)
|
self.should_lint_const_item_usage(lhs, def_id, loc)
|
||||||
{
|
{
|
||||||
self.tcx.emit_node_span_lint(
|
self.tcx.emit_node_span_lint(
|
||||||
CONST_ITEM_MUTATION,
|
CONST_ITEM_MUTATION,
|
||||||
lint_root,
|
lint_root,
|
||||||
span,
|
span,
|
||||||
errors::ConstMutate::Modify { konst: item },
|
errors::ConstMutate::Modify { konst: item },
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We are looking for MIR of the form:
|
// We are looking for MIR of the form:
|
||||||
//
|
//
|
||||||
// ```
|
// ```
|
||||||
|
|
|
@ -168,17 +168,16 @@ pub(super) fn deduced_param_attrs<'tcx>(
|
||||||
// Codegen won't use this information for anything if all the function parameters are passed
|
// Codegen won't use this information for anything if all the function parameters are passed
|
||||||
// directly. Detect that and bail, for compilation speed.
|
// directly. Detect that and bail, for compilation speed.
|
||||||
let fn_ty = tcx.type_of(def_id).instantiate_identity();
|
let fn_ty = tcx.type_of(def_id).instantiate_identity();
|
||||||
if matches!(fn_ty.kind(), ty::FnDef(..)) {
|
if matches!(fn_ty.kind(), ty::FnDef(..))
|
||||||
if fn_ty
|
&& fn_ty
|
||||||
.fn_sig(tcx)
|
.fn_sig(tcx)
|
||||||
.inputs()
|
.inputs()
|
||||||
.skip_binder()
|
.skip_binder()
|
||||||
.iter()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
.all(type_will_always_be_passed_directly)
|
.all(type_will_always_be_passed_directly)
|
||||||
{
|
{
|
||||||
return &[];
|
return &[];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't deduce any attributes for functions that have no MIR.
|
// Don't deduce any attributes for functions that have no MIR.
|
||||||
|
|
|
@ -378,19 +378,19 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
||||||
if let (Some(l), Some(r)) = (l, r)
|
if let (Some(l), Some(r)) = (l, r)
|
||||||
&& l.layout.ty.is_integral()
|
&& l.layout.ty.is_integral()
|
||||||
&& op.is_overflowing()
|
&& op.is_overflowing()
|
||||||
{
|
&& self.use_ecx(|this| {
|
||||||
if self.use_ecx(|this| {
|
|
||||||
let (_res, overflow) = this.ecx.binary_op(op, &l, &r)?.to_scalar_pair();
|
let (_res, overflow) = this.ecx.binary_op(op, &l, &r)?.to_scalar_pair();
|
||||||
overflow.to_bool()
|
overflow.to_bool()
|
||||||
})? {
|
})?
|
||||||
self.report_assert_as_lint(
|
{
|
||||||
location,
|
self.report_assert_as_lint(
|
||||||
AssertLintKind::ArithmeticOverflow,
|
location,
|
||||||
AssertKind::Overflow(op, l.to_const_int(), r.to_const_int()),
|
AssertLintKind::ArithmeticOverflow,
|
||||||
);
|
AssertKind::Overflow(op, l.to_const_int(), r.to_const_int()),
|
||||||
return None;
|
);
|
||||||
}
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(())
|
Some(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -504,10 +504,8 @@ fn compute_inlined_overlap<'tcx>(cgu1: &CodegenUnit<'tcx>, cgu2: &CodegenUnit<'t
|
||||||
|
|
||||||
let mut overlap = 0;
|
let mut overlap = 0;
|
||||||
for (item, data) in src_cgu.items().iter() {
|
for (item, data) in src_cgu.items().iter() {
|
||||||
if data.inlined {
|
if data.inlined && dst_cgu.items().contains_key(item) {
|
||||||
if dst_cgu.items().contains_key(item) {
|
overlap += data.size_estimate;
|
||||||
overlap += data.size_estimate;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
overlap
|
overlap
|
||||||
|
|
|
@ -185,10 +185,8 @@ impl<'a, D: SolverDelegate<Interner = I>, I: Interner> Canonicalizer<'a, D, I> {
|
||||||
for var in var_infos.iter_mut() {
|
for var in var_infos.iter_mut() {
|
||||||
// We simply put all regions from the input into the highest
|
// We simply put all regions from the input into the highest
|
||||||
// compressed universe, so we only deal with them at the end.
|
// compressed universe, so we only deal with them at the end.
|
||||||
if !var.is_region() {
|
if !var.is_region() && is_existential == var.is_existential() {
|
||||||
if is_existential == var.is_existential() {
|
update_uv(var, orig_uv, is_existential)
|
||||||
update_uv(var, orig_uv, is_existential)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -671,12 +671,12 @@ impl<'a> Parser<'a> {
|
||||||
err.emit();
|
err.emit();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if !self.token.kind.should_end_const_arg() {
|
if !self.token.kind.should_end_const_arg()
|
||||||
if self.handle_ambiguous_unbraced_const_arg(&mut args)? {
|
&& self.handle_ambiguous_unbraced_const_arg(&mut args)?
|
||||||
// We've managed to (partially) recover, so continue trying to parse
|
{
|
||||||
// arguments.
|
// We've managed to (partially) recover, so continue trying to parse
|
||||||
continue;
|
// arguments.
|
||||||
}
|
continue;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -174,16 +174,14 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
|
||||||
|
|
||||||
// If the current node is a function, has const stability attributes and if it doesn not have an intrinsic ABI,
|
// 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
|
// 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 let (Some(const_span), Some(fn_sig)) = (const_span, fn_sig)
|
||||||
if fn_sig.header.abi != Abi::RustIntrinsic && !fn_sig.header.is_const() {
|
&& fn_sig.header.abi != Abi::RustIntrinsic
|
||||||
if !self.in_trait_impl
|
&& !fn_sig.header.is_const()
|
||||||
|| (self.in_trait_impl && !self.tcx.is_const_fn_raw(def_id.to_def_id()))
|
&& (!self.in_trait_impl || !self.tcx.is_const_fn_raw(def_id.to_def_id()))
|
||||||
{
|
{
|
||||||
self.tcx
|
self.tcx
|
||||||
.dcx()
|
.dcx()
|
||||||
.emit_err(errors::MissingConstErr { fn_sig_span: fn_sig.span, const_span });
|
.emit_err(errors::MissingConstErr { fn_sig_span: fn_sig.span, const_span });
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// `impl const Trait for Type` items forward their const stability to their
|
// `impl const Trait for Type` items forward their const stability to their
|
||||||
|
|
|
@ -1233,64 +1233,63 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
&& ns == namespace
|
&& ns == namespace
|
||||||
&& in_module != parent_scope.module
|
&& in_module != parent_scope.module
|
||||||
&& !ident.span.normalize_to_macros_2_0().from_expansion()
|
&& !ident.span.normalize_to_macros_2_0().from_expansion()
|
||||||
|
&& filter_fn(res)
|
||||||
{
|
{
|
||||||
if filter_fn(res) {
|
// create the path
|
||||||
// create the path
|
let mut segms = if lookup_ident.span.at_least_rust_2018() {
|
||||||
let mut segms = if lookup_ident.span.at_least_rust_2018() {
|
// crate-local absolute paths start with `crate::` in edition 2018
|
||||||
// crate-local absolute paths start with `crate::` in edition 2018
|
// FIXME: may also be stabilized for Rust 2015 (Issues #45477, #44660)
|
||||||
// FIXME: may also be stabilized for Rust 2015 (Issues #45477, #44660)
|
crate_path.clone()
|
||||||
crate_path.clone()
|
} else {
|
||||||
|
ThinVec::new()
|
||||||
|
};
|
||||||
|
segms.append(&mut path_segments.clone());
|
||||||
|
|
||||||
|
segms.push(ast::PathSegment::from_ident(ident));
|
||||||
|
let path = Path { span: name_binding.span, segments: segms, tokens: None };
|
||||||
|
|
||||||
|
if child_accessible {
|
||||||
|
// Remove invisible match if exists
|
||||||
|
if let Some(idx) = candidates
|
||||||
|
.iter()
|
||||||
|
.position(|v: &ImportSuggestion| v.did == did && !v.accessible)
|
||||||
|
{
|
||||||
|
candidates.remove(idx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if candidates.iter().all(|v: &ImportSuggestion| v.did != did) {
|
||||||
|
// See if we're recommending TryFrom, TryInto, or FromIterator and add
|
||||||
|
// a note about editions
|
||||||
|
let note = if let Some(did) = did {
|
||||||
|
let requires_note = !did.is_local()
|
||||||
|
&& this.tcx.get_attrs(did, sym::rustc_diagnostic_item).any(
|
||||||
|
|attr| {
|
||||||
|
[sym::TryInto, sym::TryFrom, sym::FromIterator]
|
||||||
|
.map(|x| Some(x))
|
||||||
|
.contains(&attr.value_str())
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
requires_note.then(|| {
|
||||||
|
format!(
|
||||||
|
"'{}' is included in the prelude starting in Edition 2021",
|
||||||
|
path_names_to_string(&path)
|
||||||
|
)
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
ThinVec::new()
|
None
|
||||||
};
|
};
|
||||||
segms.append(&mut path_segments.clone());
|
|
||||||
|
|
||||||
segms.push(ast::PathSegment::from_ident(ident));
|
candidates.push(ImportSuggestion {
|
||||||
let path = Path { span: name_binding.span, segments: segms, tokens: None };
|
did,
|
||||||
|
descr: res.descr(),
|
||||||
if child_accessible {
|
path,
|
||||||
// Remove invisible match if exists
|
accessible: child_accessible,
|
||||||
if let Some(idx) = candidates
|
doc_visible: child_doc_visible,
|
||||||
.iter()
|
note,
|
||||||
.position(|v: &ImportSuggestion| v.did == did && !v.accessible)
|
via_import,
|
||||||
{
|
});
|
||||||
candidates.remove(idx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if candidates.iter().all(|v: &ImportSuggestion| v.did != did) {
|
|
||||||
// See if we're recommending TryFrom, TryInto, or FromIterator and add
|
|
||||||
// a note about editions
|
|
||||||
let note = if let Some(did) = did {
|
|
||||||
let requires_note = !did.is_local()
|
|
||||||
&& this.tcx.get_attrs(did, sym::rustc_diagnostic_item).any(
|
|
||||||
|attr| {
|
|
||||||
[sym::TryInto, sym::TryFrom, sym::FromIterator]
|
|
||||||
.map(|x| Some(x))
|
|
||||||
.contains(&attr.value_str())
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
requires_note.then(|| {
|
|
||||||
format!(
|
|
||||||
"'{}' is included in the prelude starting in Edition 2021",
|
|
||||||
path_names_to_string(&path)
|
|
||||||
)
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
candidates.push(ImportSuggestion {
|
|
||||||
did,
|
|
||||||
descr: res.descr(),
|
|
||||||
path,
|
|
||||||
accessible: child_accessible,
|
|
||||||
doc_visible: child_doc_visible,
|
|
||||||
note,
|
|
||||||
via_import,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -958,12 +958,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if !restricted_shadowing && binding.expansion != LocalExpnId::ROOT {
|
if !restricted_shadowing
|
||||||
if let NameBindingKind::Import { import, .. } = binding.kind
|
&& binding.expansion != LocalExpnId::ROOT
|
||||||
&& matches!(import.kind, ImportKind::MacroExport)
|
&& let NameBindingKind::Import { import, .. } = binding.kind
|
||||||
{
|
&& matches!(import.kind, ImportKind::MacroExport)
|
||||||
self.macro_expanded_macro_export_errors.insert((path_span, binding.span));
|
{
|
||||||
}
|
self.macro_expanded_macro_export_errors.insert((path_span, binding.span));
|
||||||
}
|
}
|
||||||
|
|
||||||
self.record_use(ident, binding, used);
|
self.record_use(ident, binding, used);
|
||||||
|
|
|
@ -4781,16 +4781,14 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
if let Some(res) = res
|
if let Some(res) = res
|
||||||
&& let Some(def_id) = res.opt_def_id()
|
&& let Some(def_id) = res.opt_def_id()
|
||||||
&& !def_id.is_local()
|
&& !def_id.is_local()
|
||||||
|
&& self.r.tcx.crate_types().contains(&CrateType::ProcMacro)
|
||||||
|
&& matches!(
|
||||||
|
self.r.tcx.sess.opts.resolve_doc_links,
|
||||||
|
ResolveDocLinks::ExportedMetadata
|
||||||
|
)
|
||||||
{
|
{
|
||||||
if self.r.tcx.crate_types().contains(&CrateType::ProcMacro)
|
// Encoding foreign def ids in proc macro crate metadata will ICE.
|
||||||
&& matches!(
|
return None;
|
||||||
self.r.tcx.sess.opts.resolve_doc_links,
|
|
||||||
ResolveDocLinks::ExportedMetadata
|
|
||||||
)
|
|
||||||
{
|
|
||||||
// Encoding foreign def ids in proc macro crate metadata will ICE.
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
res
|
res
|
||||||
});
|
});
|
||||||
|
|
|
@ -2255,25 +2255,24 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
||||||
fn let_binding_suggestion(&mut self, err: &mut Diag<'_>, ident_span: Span) -> bool {
|
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
|
if let Some(Expr { kind: ExprKind::Assign(lhs, ..), .. }) = self.diag_metadata.in_assignment
|
||||||
&& let ast::ExprKind::Path(None, ref path) = lhs.kind
|
&& 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() {
|
||||||
let (span, text) = match path.segments.first() {
|
Some(seg) if let Some(name) = seg.ident.as_str().strip_prefix("let") => {
|
||||||
Some(seg) if let Some(name) = seg.ident.as_str().strip_prefix("let") => {
|
// a special case for #117894
|
||||||
// a special case for #117894
|
let name = name.strip_prefix('_').unwrap_or(name);
|
||||||
let name = name.strip_prefix('_').unwrap_or(name);
|
(ident_span, format!("let {name}"))
|
||||||
(ident_span, format!("let {name}"))
|
}
|
||||||
}
|
_ => (ident_span.shrink_to_lo(), "let ".to_string()),
|
||||||
_ => (ident_span.shrink_to_lo(), "let ".to_string()),
|
};
|
||||||
};
|
|
||||||
|
|
||||||
err.span_suggestion_verbose(
|
err.span_suggestion_verbose(
|
||||||
span,
|
span,
|
||||||
"you might have meant to introduce a new binding",
|
"you might have meant to introduce a new binding",
|
||||||
text,
|
text,
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
|
@ -513,10 +513,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
// then there's nothing else to check.
|
// then there's nothing else to check.
|
||||||
if let Some(closure_kind) = self_ty.to_opt_closure_kind()
|
if let Some(closure_kind) = self_ty.to_opt_closure_kind()
|
||||||
&& let Some(goal_kind) = target_kind_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);
|
||||||
candidates.vec.push(AsyncFnKindHelperCandidate);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1334,16 +1334,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.can_use_global_caches(param_env) {
|
if self.can_use_global_caches(param_env) && !trait_pred.has_infer() {
|
||||||
if !trait_pred.has_infer() {
|
debug!(?trait_pred, ?result, "insert_evaluation_cache global");
|
||||||
debug!(?trait_pred, ?result, "insert_evaluation_cache global");
|
// This may overwrite the cache with the same value
|
||||||
// This may overwrite the cache with the same value
|
// FIXME: Due to #50507 this overwrites the different values
|
||||||
// FIXME: Due to #50507 this overwrites the different values
|
// This should be changed to use HashMapExt::insert_same
|
||||||
// This should be changed to use HashMapExt::insert_same
|
// when that is fixed
|
||||||
// when that is fixed
|
self.tcx().evaluation_cache.insert((param_env, trait_pred), dep_node, result);
|
||||||
self.tcx().evaluation_cache.insert((param_env, trait_pred), dep_node, result);
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!(?trait_pred, ?result, "insert_evaluation_cache");
|
debug!(?trait_pred, ?result, "insert_evaluation_cache");
|
||||||
|
@ -1584,13 +1582,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
if self.can_use_global_caches(param_env) {
|
if self.can_use_global_caches(param_env) {
|
||||||
if let Err(Overflow(OverflowError::Canonical)) = candidate {
|
if let Err(Overflow(OverflowError::Canonical)) = candidate {
|
||||||
// Don't cache overflow globally; we only produce this in certain modes.
|
// Don't cache overflow globally; we only produce this in certain modes.
|
||||||
} else if !pred.has_infer() {
|
} else if !pred.has_infer() && !candidate.has_infer() {
|
||||||
if !candidate.has_infer() {
|
debug!(?pred, ?candidate, "insert_candidate_cache global");
|
||||||
debug!(?pred, ?candidate, "insert_candidate_cache global");
|
// This may overwrite the cache with the same value.
|
||||||
// This may overwrite the cache with the same value.
|
tcx.selection_cache.insert((param_env, pred), dep_node, candidate);
|
||||||
tcx.selection_cache.insert((param_env, pred), dep_node, candidate);
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1980,10 +1976,10 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
|
||||||
// impls have to be always applicable, meaning that the only allowed
|
// impls have to be always applicable, meaning that the only allowed
|
||||||
// region constraints may be constraints also present on the default impl.
|
// region constraints may be constraints also present on the default impl.
|
||||||
let tcx = self.tcx();
|
let tcx = self.tcx();
|
||||||
if other.evaluation.must_apply_modulo_regions() {
|
if other.evaluation.must_apply_modulo_regions()
|
||||||
if tcx.specializes((other_def, victim_def)) {
|
&& tcx.specializes((other_def, victim_def))
|
||||||
return DropVictim::Yes;
|
{
|
||||||
}
|
return DropVictim::Yes;
|
||||||
}
|
}
|
||||||
|
|
||||||
match tcx.impls_are_allowed_to_overlap(other_def, victim_def) {
|
match tcx.impls_are_allowed_to_overlap(other_def, victim_def) {
|
||||||
|
|
|
@ -143,10 +143,8 @@ impl<'tcx> OpaqueTypeCollector<'tcx> {
|
||||||
match origin {
|
match origin {
|
||||||
rustc_hir::OpaqueTyOrigin::FnReturn(_) | rustc_hir::OpaqueTyOrigin::AsyncFn(_) => {}
|
rustc_hir::OpaqueTyOrigin::FnReturn(_) | rustc_hir::OpaqueTyOrigin::AsyncFn(_) => {}
|
||||||
rustc_hir::OpaqueTyOrigin::TyAlias { in_assoc_ty, .. } => {
|
rustc_hir::OpaqueTyOrigin::TyAlias { in_assoc_ty, .. } => {
|
||||||
if !in_assoc_ty {
|
if !in_assoc_ty && !self.check_tait_defining_scope(alias_ty.def_id.expect_local()) {
|
||||||
if !self.check_tait_defining_scope(alias_ty.def_id.expect_local()) {
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue