Auto merge of #106090 - WaffleLapkin:dereffffffffff, r=Nilstrieb
Remove some `ref` patterns from the compiler Previous PR: https://github.com/rust-lang/rust/pull/105368 r? `@Nilstrieb`
This commit is contained in:
commit
56ee85274e
53 changed files with 524 additions and 587 deletions
|
@ -531,9 +531,7 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
|
|||
DefKind::Fn => {} // entirely within check_item_body
|
||||
DefKind::Impl => {
|
||||
let it = tcx.hir().item(id);
|
||||
let hir::ItemKind::Impl(ref impl_) = it.kind else {
|
||||
return;
|
||||
};
|
||||
let hir::ItemKind::Impl(impl_) = it.kind else { return };
|
||||
debug!("ItemKind::Impl {} with id {:?}", it.ident, it.owner_id);
|
||||
if let Some(impl_trait_ref) = tcx.impl_trait_ref(it.owner_id) {
|
||||
check_impl_items_against_trait(
|
||||
|
@ -548,15 +546,15 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
|
|||
}
|
||||
DefKind::Trait => {
|
||||
let it = tcx.hir().item(id);
|
||||
let hir::ItemKind::Trait(_, _, _, _, ref items) = it.kind else {
|
||||
let hir::ItemKind::Trait(_, _, _, _, items) = it.kind else {
|
||||
return;
|
||||
};
|
||||
check_on_unimplemented(tcx, it);
|
||||
|
||||
for item in items.iter() {
|
||||
let item = tcx.hir().trait_item(item.id);
|
||||
match item.kind {
|
||||
hir::TraitItemKind::Fn(ref sig, _) => {
|
||||
match &item.kind {
|
||||
hir::TraitItemKind::Fn(sig, _) => {
|
||||
let abi = sig.header.abi;
|
||||
fn_maybe_err(tcx, item.ident.span, abi);
|
||||
}
|
||||
|
@ -652,8 +650,8 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
|
|||
}
|
||||
|
||||
let item = tcx.hir().foreign_item(item.id);
|
||||
match item.kind {
|
||||
hir::ForeignItemKind::Fn(ref fn_decl, _, _) => {
|
||||
match &item.kind {
|
||||
hir::ForeignItemKind::Fn(fn_decl, _, _) => {
|
||||
require_c_abi_if_c_variadic(tcx, fn_decl, abi, item.span);
|
||||
}
|
||||
hir::ForeignItemKind::Static(..) => {
|
||||
|
|
|
@ -47,42 +47,22 @@ pub(super) fn compare_impl_method<'tcx>(
|
|||
|
||||
let impl_m_span = tcx.def_span(impl_m.def_id);
|
||||
|
||||
if let Err(_) = compare_self_type(tcx, impl_m, impl_m_span, trait_m, impl_trait_ref) {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Err(_) = compare_number_of_generics(tcx, impl_m, trait_m, trait_item_span, false) {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Err(_) = compare_generic_param_kinds(tcx, impl_m, trait_m, false) {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Err(_) =
|
||||
compare_number_of_method_arguments(tcx, impl_m, impl_m_span, trait_m, trait_item_span)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if let Err(_) = compare_synthetic_generics(tcx, impl_m, trait_m) {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Err(_) = compare_asyncness(tcx, impl_m, impl_m_span, trait_m, trait_item_span) {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Err(_) = compare_method_predicate_entailment(
|
||||
tcx,
|
||||
impl_m,
|
||||
impl_m_span,
|
||||
trait_m,
|
||||
impl_trait_ref,
|
||||
CheckImpliedWfMode::Check,
|
||||
) {
|
||||
return;
|
||||
}
|
||||
let _: Result<_, ErrorGuaranteed> = try {
|
||||
compare_self_type(tcx, impl_m, impl_m_span, trait_m, impl_trait_ref)?;
|
||||
compare_number_of_generics(tcx, impl_m, trait_m, trait_item_span, false)?;
|
||||
compare_generic_param_kinds(tcx, impl_m, trait_m, false)?;
|
||||
compare_number_of_method_arguments(tcx, impl_m, impl_m_span, trait_m, trait_item_span)?;
|
||||
compare_synthetic_generics(tcx, impl_m, trait_m)?;
|
||||
compare_asyncness(tcx, impl_m, impl_m_span, trait_m, trait_item_span)?;
|
||||
compare_method_predicate_entailment(
|
||||
tcx,
|
||||
impl_m,
|
||||
impl_m_span,
|
||||
trait_m,
|
||||
impl_trait_ref,
|
||||
CheckImpliedWfMode::Check,
|
||||
)?;
|
||||
};
|
||||
}
|
||||
|
||||
/// This function is best explained by example. Consider a trait:
|
||||
|
@ -936,16 +916,14 @@ fn report_trait_method_mismatch<'tcx>(
|
|||
// When the `impl` receiver is an arbitrary self type, like `self: Box<Self>`, the
|
||||
// span points only at the type `Box<Self`>, but we want to cover the whole
|
||||
// argument pattern and type.
|
||||
let span = match tcx.hir().expect_impl_item(impl_m.def_id.expect_local()).kind {
|
||||
ImplItemKind::Fn(ref sig, body) => tcx
|
||||
.hir()
|
||||
.body_param_names(body)
|
||||
.zip(sig.decl.inputs.iter())
|
||||
.map(|(param, ty)| param.span.to(ty.span))
|
||||
.next()
|
||||
.unwrap_or(impl_err_span),
|
||||
_ => bug!("{:?} is not a method", impl_m),
|
||||
};
|
||||
let ImplItemKind::Fn(ref sig, body) = tcx.hir().expect_impl_item(impl_m.def_id.expect_local()).kind else { bug!("{impl_m:?} is not a method") };
|
||||
let span = tcx
|
||||
.hir()
|
||||
.body_param_names(body)
|
||||
.zip(sig.decl.inputs.iter())
|
||||
.map(|(param, ty)| param.span.to(ty.span))
|
||||
.next()
|
||||
.unwrap_or(impl_err_span);
|
||||
|
||||
diag.span_suggestion(
|
||||
span,
|
||||
|
@ -958,22 +936,21 @@ fn report_trait_method_mismatch<'tcx>(
|
|||
if trait_sig.inputs().len() == *i {
|
||||
// Suggestion to change output type. We do not suggest in `async` functions
|
||||
// to avoid complex logic or incorrect output.
|
||||
match tcx.hir().expect_impl_item(impl_m.def_id.expect_local()).kind {
|
||||
ImplItemKind::Fn(ref sig, _) if !sig.header.asyncness.is_async() => {
|
||||
let msg = "change the output type to match the trait";
|
||||
let ap = Applicability::MachineApplicable;
|
||||
match sig.decl.output {
|
||||
hir::FnRetTy::DefaultReturn(sp) => {
|
||||
let sugg = format!("-> {} ", trait_sig.output());
|
||||
diag.span_suggestion_verbose(sp, msg, sugg, ap);
|
||||
}
|
||||
hir::FnRetTy::Return(hir_ty) => {
|
||||
let sugg = trait_sig.output();
|
||||
diag.span_suggestion(hir_ty.span, msg, sugg, ap);
|
||||
}
|
||||
};
|
||||
}
|
||||
_ => {}
|
||||
if let ImplItemKind::Fn(sig, _) = &tcx.hir().expect_impl_item(impl_m.def_id.expect_local()).kind
|
||||
&& !sig.header.asyncness.is_async()
|
||||
{
|
||||
let msg = "change the output type to match the trait";
|
||||
let ap = Applicability::MachineApplicable;
|
||||
match sig.decl.output {
|
||||
hir::FnRetTy::DefaultReturn(sp) => {
|
||||
let sugg = format!("-> {} ", trait_sig.output());
|
||||
diag.span_suggestion_verbose(sp, msg, sugg, ap);
|
||||
}
|
||||
hir::FnRetTy::Return(hir_ty) => {
|
||||
let sugg = trait_sig.output();
|
||||
diag.span_suggestion(hir_ty.span, msg, sugg, ap);
|
||||
}
|
||||
};
|
||||
};
|
||||
} else if let Some(trait_ty) = trait_sig.inputs().get(*i) {
|
||||
diag.span_suggestion(
|
||||
|
@ -1100,25 +1077,18 @@ fn extract_spans_for_error_reporting<'tcx>(
|
|||
trait_m: &ty::AssocItem,
|
||||
) -> (Span, Option<Span>) {
|
||||
let tcx = infcx.tcx;
|
||||
let mut impl_args = match tcx.hir().expect_impl_item(impl_m.def_id.expect_local()).kind {
|
||||
ImplItemKind::Fn(ref sig, _) => {
|
||||
sig.decl.inputs.iter().map(|t| t.span).chain(iter::once(sig.decl.output.span()))
|
||||
}
|
||||
_ => bug!("{:?} is not a method", impl_m),
|
||||
let mut impl_args = {
|
||||
let ImplItemKind::Fn(sig, _) = &tcx.hir().expect_impl_item(impl_m.def_id.expect_local()).kind else { bug!("{:?} is not a method", impl_m) };
|
||||
sig.decl.inputs.iter().map(|t| t.span).chain(iter::once(sig.decl.output.span()))
|
||||
};
|
||||
let trait_args =
|
||||
trait_m.def_id.as_local().map(|def_id| match tcx.hir().expect_trait_item(def_id).kind {
|
||||
TraitItemKind::Fn(ref sig, _) => {
|
||||
sig.decl.inputs.iter().map(|t| t.span).chain(iter::once(sig.decl.output.span()))
|
||||
}
|
||||
_ => bug!("{:?} is not a TraitItemKind::Fn", trait_m),
|
||||
});
|
||||
|
||||
let trait_args = trait_m.def_id.as_local().map(|def_id| {
|
||||
let TraitItemKind::Fn(sig, _) = &tcx.hir().expect_trait_item(def_id).kind else { bug!("{:?} is not a TraitItemKind::Fn", trait_m) };
|
||||
sig.decl.inputs.iter().map(|t| t.span).chain(iter::once(sig.decl.output.span()))
|
||||
});
|
||||
|
||||
match terr {
|
||||
TypeError::ArgumentMutability(i) => {
|
||||
(impl_args.nth(i).unwrap(), trait_args.and_then(|mut args| args.nth(i)))
|
||||
}
|
||||
TypeError::ArgumentSorts(ExpectedFound { .. }, i) => {
|
||||
TypeError::ArgumentMutability(i) | TypeError::ArgumentSorts(ExpectedFound { .. }, i) => {
|
||||
(impl_args.nth(i).unwrap(), trait_args.and_then(|mut args| args.nth(i)))
|
||||
}
|
||||
_ => (cause.span(), tcx.hir().span_if_local(trait_m.def_id)),
|
||||
|
@ -1178,8 +1148,7 @@ fn compare_self_type<'tcx>(
|
|||
} else {
|
||||
err.note_trait_signature(trait_m.name, trait_m.signature(tcx));
|
||||
}
|
||||
let reported = err.emit();
|
||||
return Err(reported);
|
||||
return Err(err.emit());
|
||||
}
|
||||
|
||||
(true, false) => {
|
||||
|
@ -1198,8 +1167,8 @@ fn compare_self_type<'tcx>(
|
|||
} else {
|
||||
err.note_trait_signature(trait_m.name, trait_m.signature(tcx));
|
||||
}
|
||||
let reported = err.emit();
|
||||
return Err(reported);
|
||||
|
||||
return Err(err.emit());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1381,41 +1350,39 @@ fn compare_number_of_method_arguments<'tcx>(
|
|||
let trait_m_fty = tcx.fn_sig(trait_m.def_id);
|
||||
let trait_number_args = trait_m_fty.inputs().skip_binder().len();
|
||||
let impl_number_args = impl_m_fty.inputs().skip_binder().len();
|
||||
|
||||
if trait_number_args != impl_number_args {
|
||||
let trait_span = if let Some(def_id) = trait_m.def_id.as_local() {
|
||||
match tcx.hir().expect_trait_item(def_id).kind {
|
||||
TraitItemKind::Fn(ref trait_m_sig, _) => {
|
||||
let pos = if trait_number_args > 0 { trait_number_args - 1 } else { 0 };
|
||||
if let Some(arg) = trait_m_sig.decl.inputs.get(pos) {
|
||||
Some(if pos == 0 {
|
||||
arg.span
|
||||
} else {
|
||||
arg.span.with_lo(trait_m_sig.decl.inputs[0].span.lo())
|
||||
})
|
||||
} else {
|
||||
trait_item_span
|
||||
}
|
||||
}
|
||||
_ => bug!("{:?} is not a method", impl_m),
|
||||
}
|
||||
} else {
|
||||
trait_item_span
|
||||
};
|
||||
let impl_span = match tcx.hir().expect_impl_item(impl_m.def_id.expect_local()).kind {
|
||||
ImplItemKind::Fn(ref impl_m_sig, _) => {
|
||||
let pos = if impl_number_args > 0 { impl_number_args - 1 } else { 0 };
|
||||
if let Some(arg) = impl_m_sig.decl.inputs.get(pos) {
|
||||
let trait_span = trait_m
|
||||
.def_id
|
||||
.as_local()
|
||||
.and_then(|def_id| {
|
||||
let TraitItemKind::Fn(trait_m_sig, _) = &tcx.hir().expect_trait_item(def_id).kind else { bug!("{:?} is not a method", impl_m) };
|
||||
let pos = trait_number_args.saturating_sub(1);
|
||||
trait_m_sig.decl.inputs.get(pos).map(|arg| {
|
||||
if pos == 0 {
|
||||
arg.span
|
||||
} else {
|
||||
arg.span.with_lo(impl_m_sig.decl.inputs[0].span.lo())
|
||||
arg.span.with_lo(trait_m_sig.decl.inputs[0].span.lo())
|
||||
}
|
||||
})
|
||||
})
|
||||
.or(trait_item_span);
|
||||
|
||||
let ImplItemKind::Fn(impl_m_sig, _) = &tcx.hir().expect_impl_item(impl_m.def_id.expect_local()).kind else { bug!("{:?} is not a method", impl_m) };
|
||||
let pos = impl_number_args.saturating_sub(1);
|
||||
let impl_span = impl_m_sig
|
||||
.decl
|
||||
.inputs
|
||||
.get(pos)
|
||||
.map(|arg| {
|
||||
if pos == 0 {
|
||||
arg.span
|
||||
} else {
|
||||
impl_m_span
|
||||
arg.span.with_lo(impl_m_sig.decl.inputs[0].span.lo())
|
||||
}
|
||||
}
|
||||
_ => bug!("{:?} is not a method", impl_m),
|
||||
};
|
||||
})
|
||||
.unwrap_or(impl_m_span);
|
||||
|
||||
let mut err = struct_span_err!(
|
||||
tcx.sess,
|
||||
impl_span,
|
||||
|
@ -1426,6 +1393,7 @@ fn compare_number_of_method_arguments<'tcx>(
|
|||
tcx.def_path_str(trait_m.def_id),
|
||||
trait_number_args
|
||||
);
|
||||
|
||||
if let Some(trait_span) = trait_span {
|
||||
err.span_label(
|
||||
trait_span,
|
||||
|
@ -1437,6 +1405,7 @@ fn compare_number_of_method_arguments<'tcx>(
|
|||
} else {
|
||||
err.note_trait_signature(trait_m.name, trait_m.signature(tcx));
|
||||
}
|
||||
|
||||
err.span_label(
|
||||
impl_span,
|
||||
format!(
|
||||
|
@ -1445,8 +1414,8 @@ fn compare_number_of_method_arguments<'tcx>(
|
|||
impl_number_args
|
||||
),
|
||||
);
|
||||
let reported = err.emit();
|
||||
return Err(reported);
|
||||
|
||||
return Err(err.emit());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -1493,7 +1462,7 @@ fn compare_synthetic_generics<'tcx>(
|
|||
// explicit generics
|
||||
(true, false) => {
|
||||
err.span_label(impl_span, "expected generic parameter, found `impl Trait`");
|
||||
(|| {
|
||||
let _: Option<_> = try {
|
||||
// try taking the name from the trait impl
|
||||
// FIXME: this is obviously suboptimal since the name can already be used
|
||||
// as another generic argument
|
||||
|
@ -1526,26 +1495,23 @@ fn compare_synthetic_generics<'tcx>(
|
|||
],
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
Some(())
|
||||
})();
|
||||
};
|
||||
}
|
||||
// The case where the trait method uses `impl Trait`, but the impl method uses
|
||||
// explicit generics.
|
||||
(false, true) => {
|
||||
err.span_label(impl_span, "expected `impl Trait`, found generic parameter");
|
||||
(|| {
|
||||
let _: Option<_> = try {
|
||||
let impl_m = impl_m.def_id.as_local()?;
|
||||
let impl_m = tcx.hir().expect_impl_item(impl_m);
|
||||
let input_tys = match impl_m.kind {
|
||||
hir::ImplItemKind::Fn(ref sig, _) => sig.decl.inputs,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let hir::ImplItemKind::Fn(sig, _) = &impl_m.kind else { unreachable!() };
|
||||
let input_tys = sig.decl.inputs;
|
||||
|
||||
struct Visitor(Option<Span>, hir::def_id::LocalDefId);
|
||||
impl<'v> intravisit::Visitor<'v> for Visitor {
|
||||
fn visit_ty(&mut self, ty: &'v hir::Ty<'v>) {
|
||||
intravisit::walk_ty(self, ty);
|
||||
if let hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) =
|
||||
ty.kind
|
||||
if let hir::TyKind::Path(hir::QPath::Resolved(None, path)) = ty.kind
|
||||
&& let Res::Def(DefKind::TyParam, def_id) = path.res
|
||||
&& def_id == self.1.to_def_id()
|
||||
{
|
||||
|
@ -1553,6 +1519,7 @@ fn compare_synthetic_generics<'tcx>(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut visitor = Visitor(None, impl_def_id);
|
||||
for ty in input_tys {
|
||||
intravisit::Visitor::visit_ty(&mut visitor, ty);
|
||||
|
@ -1573,13 +1540,11 @@ fn compare_synthetic_generics<'tcx>(
|
|||
],
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
Some(())
|
||||
})();
|
||||
};
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
let reported = err.emit();
|
||||
error_found = Some(reported);
|
||||
error_found = Some(err.emit());
|
||||
}
|
||||
}
|
||||
if let Some(reported) = error_found { Err(reported) } else { Ok(()) }
|
||||
|
@ -1739,10 +1704,8 @@ pub(super) fn compare_impl_const_raw(
|
|||
);
|
||||
|
||||
// Locate the Span containing just the type of the offending impl
|
||||
match tcx.hir().expect_impl_item(impl_const_item_def).kind {
|
||||
ImplItemKind::Const(ref ty, _) => cause.span = ty.span,
|
||||
_ => bug!("{:?} is not a impl const", impl_const_item),
|
||||
}
|
||||
let ImplItemKind::Const(ty, _) = tcx.hir().expect_impl_item(impl_const_item_def).kind else { bug!("{impl_const_item:?} is not a impl const") };
|
||||
cause.span = ty.span;
|
||||
|
||||
let mut diag = struct_span_err!(
|
||||
tcx.sess,
|
||||
|
@ -1754,10 +1717,8 @@ pub(super) fn compare_impl_const_raw(
|
|||
|
||||
let trait_c_span = trait_const_item_def.as_local().map(|trait_c_def_id| {
|
||||
// Add a label to the Span containing just the type of the const
|
||||
match tcx.hir().expect_trait_item(trait_c_def_id).kind {
|
||||
TraitItemKind::Const(ref ty, _) => ty.span,
|
||||
_ => bug!("{:?} is not a trait const", trait_const_item),
|
||||
}
|
||||
let TraitItemKind::Const(ty, _) = tcx.hir().expect_trait_item(trait_c_def_id).kind else { bug!("{trait_const_item:?} is not a trait const") };
|
||||
ty.span
|
||||
});
|
||||
|
||||
infcx.err_ctxt().note_type_err(
|
||||
|
@ -1799,7 +1760,7 @@ pub(super) fn compare_impl_ty<'tcx>(
|
|||
) {
|
||||
debug!("compare_impl_type(impl_trait_ref={:?})", impl_trait_ref);
|
||||
|
||||
let _: Result<(), ErrorGuaranteed> = (|| {
|
||||
let _: Result<(), ErrorGuaranteed> = try {
|
||||
compare_number_of_generics(tcx, impl_ty, trait_ty, trait_item_span, false)?;
|
||||
|
||||
compare_generic_param_kinds(tcx, impl_ty, trait_ty, false)?;
|
||||
|
@ -1807,8 +1768,8 @@ pub(super) fn compare_impl_ty<'tcx>(
|
|||
let sp = tcx.def_span(impl_ty.def_id);
|
||||
compare_type_predicate_entailment(tcx, impl_ty, sp, trait_ty, impl_trait_ref)?;
|
||||
|
||||
check_type_bounds(tcx, trait_ty, impl_ty, impl_ty_span, impl_trait_ref)
|
||||
})();
|
||||
check_type_bounds(tcx, trait_ty, impl_ty, impl_ty_span, impl_trait_ref)?;
|
||||
};
|
||||
}
|
||||
|
||||
/// The equivalent of [compare_method_predicate_entailment], but for associated types
|
||||
|
|
|
@ -351,7 +351,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
|
|||
}
|
||||
|
||||
match *op {
|
||||
hir::InlineAsmOperand::In { reg, ref expr } => {
|
||||
hir::InlineAsmOperand::In { reg, expr } => {
|
||||
self.check_asm_operand_type(
|
||||
idx,
|
||||
reg,
|
||||
|
@ -362,7 +362,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
|
|||
&target_features,
|
||||
);
|
||||
}
|
||||
hir::InlineAsmOperand::Out { reg, late: _, ref expr } => {
|
||||
hir::InlineAsmOperand::Out { reg, late: _, expr } => {
|
||||
if let Some(expr) = expr {
|
||||
self.check_asm_operand_type(
|
||||
idx,
|
||||
|
@ -375,7 +375,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
|
|||
);
|
||||
}
|
||||
}
|
||||
hir::InlineAsmOperand::InOut { reg, late: _, ref expr } => {
|
||||
hir::InlineAsmOperand::InOut { reg, late: _, expr } => {
|
||||
self.check_asm_operand_type(
|
||||
idx,
|
||||
reg,
|
||||
|
@ -386,7 +386,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
|
|||
&target_features,
|
||||
);
|
||||
}
|
||||
hir::InlineAsmOperand::SplitInOut { reg, late: _, ref in_expr, ref out_expr } => {
|
||||
hir::InlineAsmOperand::SplitInOut { reg, late: _, in_expr, out_expr } => {
|
||||
let in_ty = self.check_asm_operand_type(
|
||||
idx,
|
||||
reg,
|
||||
|
|
|
@ -180,7 +180,7 @@ fn resolve_arm<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, arm: &'tcx hir
|
|||
|
||||
visitor.terminating_scopes.insert(arm.body.hir_id.local_id);
|
||||
|
||||
if let Some(hir::Guard::If(ref expr)) = arm.guard {
|
||||
if let Some(hir::Guard::If(expr)) = arm.guard {
|
||||
visitor.terminating_scopes.insert(expr.hir_id.local_id);
|
||||
}
|
||||
|
||||
|
@ -242,8 +242,8 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h
|
|||
// This ensures fixed size stacks.
|
||||
hir::ExprKind::Binary(
|
||||
source_map::Spanned { node: hir::BinOpKind::And | hir::BinOpKind::Or, .. },
|
||||
ref l,
|
||||
ref r,
|
||||
l,
|
||||
r,
|
||||
) => {
|
||||
// expr is a short circuiting operator (|| or &&). As its
|
||||
// functionality can't be overridden by traits, it always
|
||||
|
@ -288,20 +288,20 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h
|
|||
terminating(r.hir_id.local_id);
|
||||
}
|
||||
}
|
||||
hir::ExprKind::If(_, ref then, Some(ref otherwise)) => {
|
||||
hir::ExprKind::If(_, then, Some(otherwise)) => {
|
||||
terminating(then.hir_id.local_id);
|
||||
terminating(otherwise.hir_id.local_id);
|
||||
}
|
||||
|
||||
hir::ExprKind::If(_, ref then, None) => {
|
||||
hir::ExprKind::If(_, then, None) => {
|
||||
terminating(then.hir_id.local_id);
|
||||
}
|
||||
|
||||
hir::ExprKind::Loop(ref body, _, _, _) => {
|
||||
hir::ExprKind::Loop(body, _, _, _) => {
|
||||
terminating(body.hir_id.local_id);
|
||||
}
|
||||
|
||||
hir::ExprKind::DropTemps(ref expr) => {
|
||||
hir::ExprKind::DropTemps(expr) => {
|
||||
// `DropTemps(expr)` does not denote a conditional scope.
|
||||
// Rather, we want to achieve the same behavior as `{ let _t = expr; _t }`.
|
||||
terminating(expr.hir_id.local_id);
|
||||
|
@ -396,7 +396,7 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h
|
|||
let body = visitor.tcx.hir().body(body);
|
||||
visitor.visit_body(body);
|
||||
}
|
||||
hir::ExprKind::AssignOp(_, ref left_expr, ref right_expr) => {
|
||||
hir::ExprKind::AssignOp(_, left_expr, right_expr) => {
|
||||
debug!(
|
||||
"resolve_expr - enabling pessimistic_yield, was previously {}",
|
||||
prev_pessimistic
|
||||
|
@ -447,7 +447,7 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h
|
|||
}
|
||||
}
|
||||
|
||||
hir::ExprKind::If(ref cond, ref then, Some(ref otherwise)) => {
|
||||
hir::ExprKind::If(cond, then, Some(otherwise)) => {
|
||||
let expr_cx = visitor.cx;
|
||||
visitor.enter_scope(Scope { id: then.hir_id.local_id, data: ScopeData::IfThen });
|
||||
visitor.cx.var_parent = visitor.cx.parent;
|
||||
|
@ -457,7 +457,7 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h
|
|||
visitor.visit_expr(otherwise);
|
||||
}
|
||||
|
||||
hir::ExprKind::If(ref cond, ref then, None) => {
|
||||
hir::ExprKind::If(cond, then, None) => {
|
||||
let expr_cx = visitor.cx;
|
||||
visitor.enter_scope(Scope { id: then.hir_id.local_id, data: ScopeData::IfThen });
|
||||
visitor.cx.var_parent = visitor.cx.parent;
|
||||
|
@ -641,21 +641,21 @@ fn resolve_local<'tcx>(
|
|||
match pat.kind {
|
||||
PatKind::Binding(hir::BindingAnnotation(hir::ByRef::Yes, _), ..) => true,
|
||||
|
||||
PatKind::Struct(_, ref field_pats, _) => {
|
||||
PatKind::Struct(_, field_pats, _) => {
|
||||
field_pats.iter().any(|fp| is_binding_pat(&fp.pat))
|
||||
}
|
||||
|
||||
PatKind::Slice(ref pats1, ref pats2, ref pats3) => {
|
||||
PatKind::Slice(pats1, pats2, pats3) => {
|
||||
pats1.iter().any(|p| is_binding_pat(&p))
|
||||
|| pats2.iter().any(|p| is_binding_pat(&p))
|
||||
|| pats3.iter().any(|p| is_binding_pat(&p))
|
||||
}
|
||||
|
||||
PatKind::Or(ref subpats)
|
||||
| PatKind::TupleStruct(_, ref subpats, _)
|
||||
| PatKind::Tuple(ref subpats, _) => subpats.iter().any(|p| is_binding_pat(&p)),
|
||||
PatKind::Or(subpats)
|
||||
| PatKind::TupleStruct(_, subpats, _)
|
||||
| PatKind::Tuple(subpats, _) => subpats.iter().any(|p| is_binding_pat(&p)),
|
||||
|
||||
PatKind::Box(ref subpat) => is_binding_pat(&subpat),
|
||||
PatKind::Box(subpat) => is_binding_pat(&subpat),
|
||||
|
||||
PatKind::Ref(_, _)
|
||||
| PatKind::Binding(hir::BindingAnnotation(hir::ByRef::No, _), ..)
|
||||
|
@ -704,11 +704,11 @@ fn resolve_local<'tcx>(
|
|||
record_rvalue_scope_if_borrow_expr(visitor, &subexpr, blk_id);
|
||||
}
|
||||
}
|
||||
hir::ExprKind::Cast(ref subexpr, _) => {
|
||||
hir::ExprKind::Cast(subexpr, _) => {
|
||||
record_rvalue_scope_if_borrow_expr(visitor, &subexpr, blk_id)
|
||||
}
|
||||
hir::ExprKind::Block(ref block, _) => {
|
||||
if let Some(ref subexpr) = block.expr {
|
||||
hir::ExprKind::Block(block, _) => {
|
||||
if let Some(subexpr) = block.expr {
|
||||
record_rvalue_scope_if_borrow_expr(visitor, &subexpr, blk_id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -178,7 +178,7 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) {
|
|||
//
|
||||
// won't be allowed unless there's an *explicit* implementation of `Send`
|
||||
// for `T`
|
||||
hir::ItemKind::Impl(ref impl_) => {
|
||||
hir::ItemKind::Impl(impl_) => {
|
||||
let is_auto = tcx
|
||||
.impl_trait_ref(def_id)
|
||||
.map_or(false, |trait_ref| tcx.trait_is_auto(trait_ref.skip_binder().def_id));
|
||||
|
@ -224,15 +224,15 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) {
|
|||
hir::ItemKind::Const(ty, ..) => {
|
||||
check_item_type(tcx, def_id, ty.span, false);
|
||||
}
|
||||
hir::ItemKind::Struct(_, ref ast_generics) => {
|
||||
hir::ItemKind::Struct(_, ast_generics) => {
|
||||
check_type_defn(tcx, item, false);
|
||||
check_variances_for_type_defn(tcx, item, ast_generics);
|
||||
}
|
||||
hir::ItemKind::Union(_, ref ast_generics) => {
|
||||
hir::ItemKind::Union(_, ast_generics) => {
|
||||
check_type_defn(tcx, item, true);
|
||||
check_variances_for_type_defn(tcx, item, ast_generics);
|
||||
}
|
||||
hir::ItemKind::Enum(_, ref ast_generics) => {
|
||||
hir::ItemKind::Enum(_, ast_generics) => {
|
||||
check_type_defn(tcx, item, true);
|
||||
check_variances_for_type_defn(tcx, item, ast_generics);
|
||||
}
|
||||
|
@ -1247,8 +1247,8 @@ fn check_impl<'tcx>(
|
|||
constness: hir::Constness,
|
||||
) {
|
||||
enter_wf_checking_ctxt(tcx, item.span, item.owner_id.def_id, |wfcx| {
|
||||
match *ast_trait_ref {
|
||||
Some(ref ast_trait_ref) => {
|
||||
match ast_trait_ref {
|
||||
Some(ast_trait_ref) => {
|
||||
// `#[rustc_reservation_impl]` impls are not real impls and
|
||||
// therefore don't need to be WF (the trait's `Self: Trait` predicate
|
||||
// won't hold).
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue