Revert PR #114052 to fix invalid suggestion
This commit is contained in:
parent
aa864a7622
commit
1c73248b67
9 changed files with 73 additions and 61 deletions
|
@ -53,7 +53,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
|| self.suggest_no_capture_closure(err, expected, expr_ty)
|
||||
|| self.suggest_boxing_when_appropriate(err, expr.span, expr.hir_id, expected, expr_ty)
|
||||
|| self.suggest_block_to_brackets_peeling_refs(err, expr, expr_ty, expected)
|
||||
|| self.suggest_copied_cloned_or_as_ref(err, expr, expr_ty, expected, expected_ty_expr)
|
||||
|| self.suggest_copied_cloned_or_as_ref(err, expr, expr_ty, expected)
|
||||
|| self.suggest_clone_for_ref(err, expr, expr_ty, expected)
|
||||
|| self.suggest_into(err, expr, expr_ty, expected)
|
||||
|| self.suggest_floating_point_literal(err, expr, expected)
|
||||
|
|
|
@ -253,7 +253,7 @@ impl HelpUseLatestEdition {
|
|||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
pub enum OptionResultRefMismatch<'tcx> {
|
||||
pub enum OptionResultRefMismatch {
|
||||
#[suggestion(
|
||||
hir_typeck_option_result_copied,
|
||||
code = ".copied()",
|
||||
|
@ -276,19 +276,20 @@ pub enum OptionResultRefMismatch<'tcx> {
|
|||
span: Span,
|
||||
def_path: String,
|
||||
},
|
||||
#[suggestion(
|
||||
hir_typeck_option_result_asref,
|
||||
code = ".as_ref()",
|
||||
style = "verbose",
|
||||
applicability = "machine-applicable"
|
||||
)]
|
||||
AsRef {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
def_path: String,
|
||||
expected_ty: Ty<'tcx>,
|
||||
expr_ty: Ty<'tcx>,
|
||||
},
|
||||
// FIXME: #114050
|
||||
// #[suggestion(
|
||||
// hir_typeck_option_result_asref,
|
||||
// code = ".as_ref()",
|
||||
// style = "verbose",
|
||||
// applicability = "machine-applicable"
|
||||
// )]
|
||||
// AsRef {
|
||||
// #[primary_span]
|
||||
// span: Span,
|
||||
// def_path: String,
|
||||
// expected_ty: Ty<'tcx>,
|
||||
// expr_ty: Ty<'tcx>,
|
||||
// },
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
|
|
|
@ -1097,7 +1097,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
expr: &hir::Expr<'_>,
|
||||
expr_ty: Ty<'tcx>,
|
||||
expected_ty: Ty<'tcx>,
|
||||
expected_ty_expr: Option<&'tcx hir::Expr<'tcx>>,
|
||||
) -> bool {
|
||||
let ty::Adt(adt_def, args) = expr_ty.kind() else {
|
||||
return false;
|
||||
|
@ -1115,7 +1114,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
{
|
||||
let expr_inner_ty = args.type_at(0);
|
||||
let expected_inner_ty = expected_args.type_at(0);
|
||||
if let &ty::Ref(_, ty, mutability) = expr_inner_ty.kind()
|
||||
if let &ty::Ref(_, ty, _mutability) = expr_inner_ty.kind()
|
||||
&& self.can_eq(self.param_env, ty, expected_inner_ty)
|
||||
{
|
||||
let def_path = self.tcx.def_path_str(adt_def.did());
|
||||
|
@ -1124,14 +1123,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
errors::OptionResultRefMismatch::Copied {
|
||||
span, def_path
|
||||
}
|
||||
} else if let Some(expected_ty_expr) = expected_ty_expr
|
||||
// FIXME: suggest changes to both expressions to convert both to
|
||||
// Option/Result<&T>
|
||||
&& mutability.is_not()
|
||||
{
|
||||
errors::OptionResultRefMismatch::AsRef {
|
||||
span: expected_ty_expr.span.shrink_to_hi(), expected_ty, expr_ty, def_path
|
||||
}
|
||||
} else if let Some(clone_did) = self.tcx.lang_items().clone_trait()
|
||||
&& rustc_trait_selection::traits::type_known_to_meet_bound_modulo_regions(
|
||||
self,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue