diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-06-05 23:47:59 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-05 23:47:59 +0200 |
| commit | ff43249b0efd274322cbd53441ff15fcdb7096ba (patch) | |
| tree | 12b88e1283e15bc709000578948d56ef04eea717 /compiler/rustc_trait_selection/src/traits | |
| parent | 9ce0c7951c3f36d81809e43584c601536badb45f (diff) | |
| parent | c12575d3173eb6ba985482808a87e54f23ad328e (diff) | |
| download | rust-ff43249b0efd274322cbd53441ff15fcdb7096ba.tar.gz rust-ff43249b0efd274322cbd53441ff15fcdb7096ba.zip | |
Rollup merge of #112303 - Nilstrieb:as-deref, r=compiler-errors
Normalize in infcx instead of globally for `Option::as_deref` suggestion fixes #112293 The projection may contain inference variables. These inference variables are local to the local inference context. Using `tcx.normalize_erasing_regions` doesn't work here because this method is global and does not have access to the inference context. It's therefore unable to deal with the inference variables. We normalize in the local inference context instead, which knowns about the inference variables. The test looks a little different than the issue example, I made it more minimal and verified that it still ICEs on nightly. Also contains a drive-by fix to properly compare the types. r? `@compiler-errors`
Diffstat (limited to 'compiler/rustc_trait_selection/src/traits')
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 42038dbc3d8..80d0faca670 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -3592,8 +3592,9 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { // Extract `<U as Deref>::Target` assoc type and check that it is `T` && let Some(deref_target_did) = tcx.lang_items().deref_target() && let projection = tcx.mk_projection(deref_target_did, tcx.mk_substs(&[ty::GenericArg::from(found_ty)])) - && let Ok(deref_target) = tcx.try_normalize_erasing_regions(param_env, projection) - && deref_target == target_ty + && let InferOk { value: deref_target, obligations } = infcx.at(&ObligationCause::dummy(), param_env).normalize(projection) + && obligations.iter().all(|obligation| infcx.predicate_must_hold_modulo_regions(obligation)) + && infcx.can_eq(param_env, deref_target, target_ty) { let help = if let hir::Mutability::Mut = needs_mut && let Some(deref_mut_did) = tcx.lang_items().deref_mut_trait() |
