diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index 8e647ad3c6a4d..1035d983b716c 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -253,6 +253,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return; } + let mut expr_ty = self.typeck_results.borrow().expr_ty_adjusted(expr); + for a in &adj { match a.kind { Adjust::NeverToAny => { @@ -266,7 +268,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { None, expr.span, overloaded_deref.method_call(self.tcx), - self.tcx.mk_args(&[a.target.into()]), + self.tcx.mk_args(&[expr_ty.into()]), ); } Adjust::Deref(None) => { @@ -283,6 +285,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // No effects to enforce here. } } + + expr_ty = a.target; } let autoborrow_mut = adj.iter().any(|adj| { diff --git a/tests/crashes/135210.rs b/tests/crashes/135210.rs deleted file mode 100644 index acb61e21090d2..0000000000000 --- a/tests/crashes/135210.rs +++ /dev/null @@ -1,8 +0,0 @@ -//@ known-bug: #135210 - -#![feature(const_trait_impl)] -const _: fn(&String) = |s| { - &*s as &str; -}; - -fn main() {} diff --git a/tests/ui/traits/const-traits/enforce-deref-on-adjust.rs b/tests/ui/traits/const-traits/enforce-deref-on-adjust.rs new file mode 100644 index 0000000000000..d5240b7e18ddb --- /dev/null +++ b/tests/ui/traits/const-traits/enforce-deref-on-adjust.rs @@ -0,0 +1,28 @@ +//@ check-pass + +#![feature(const_deref)] +#![feature(const_trait_impl)] + +use std::ops::Deref; + +struct Wrap(T); +struct Foo; + +impl Foo { + const fn call(&self) {} +} + +impl const Deref for Wrap { + type Target = T; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +const fn foo() { + let x = Wrap(Foo); + x.call(); +} + +fn main() {}