Use proper type when applying deref adjustment in const · rust-lang/rust@c64038a (original) (raw)

File tree

3 files changed

lines changed

3 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -253,6 +253,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
253 253 return;
254 254 }
255 255
256 +let mut expr_ty = self.typeck_results.borrow().expr_ty_adjusted(expr);
257 +
256 258 for a in &adj {
257 259 match a.kind {
258 260 Adjust::NeverToAny => {
@@ -266,7 +268,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
266 268 None,
267 269 expr.span,
268 270 overloaded_deref.method_call(self.tcx),
269 -self.tcx.mk_args(&[a.target.into()]),
271 +self.tcx.mk_args(&[expr_ty.into()]),
270 272 );
271 273 }
272 274 Adjust::Deref(None) => {
@@ -283,6 +285,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
283 285 // No effects to enforce here.
284 286 }
285 287 }
288 +
289 + expr_ty = a.target;
286 290 }
287 291
288 292 let autoborrow_mut = adj.iter().any(|adj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
1 +//@ check-pass
2 +
3 +#![feature(const_deref)]
4 +#![feature(const_trait_impl)]
5 +
6 +use std::ops::Deref;
7 +
8 +struct Wrap<T>(T);
9 +struct Foo;
10 +
11 +impl Foo {
12 +const fn call(&self) {}
13 +}
14 +
15 +impl<T> const Deref for Wrap<T> {
16 +type Target = T;
17 +
18 +fn deref(&self) -> &Self::Target {
19 +&self.0
20 +}
21 +}
22 +
23 +const fn foo() {
24 +let x = Wrap(Foo);
25 + x.call();
26 +}
27 +
28 +fn main() {}