Skip to content

Commit 47e6684

Browse files
authored
Rollup merge of #136314 - compiler-errors:const-deref-adj, r=fee1-dead
Use proper type when applying deref adjustment in const When applying a deref adjustment to some type `Wrap<T>` which derefs to `T`, we were checking that `T: ~const Deref`, not `Wrap<T>: ~const Deref` like we should have been. r? project-const-traits Fixes #136273 Fixes #135210 -- I just deleted the test since the regression test is uninteresting
2 parents 4b310be + c64038a commit 47e6684

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
253253
return;
254254
}
255255

256+
let mut expr_ty = self.typeck_results.borrow().expr_ty_adjusted(expr);
257+
256258
for a in &adj {
257259
match a.kind {
258260
Adjust::NeverToAny => {
@@ -266,7 +268,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
266268
None,
267269
expr.span,
268270
overloaded_deref.method_call(self.tcx),
269-
self.tcx.mk_args(&[a.target.into()]),
271+
self.tcx.mk_args(&[expr_ty.into()]),
270272
);
271273
}
272274
Adjust::Deref(None) => {
@@ -283,6 +285,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
283285
// No effects to enforce here.
284286
}
285287
}
288+
289+
expr_ty = a.target;
286290
}
287291

288292
let autoborrow_mut = adj.iter().any(|adj| {

tests/crashes/135210.rs

-8
This file was deleted.
Original file line numberDiff line numberDiff 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() {}

0 commit comments

Comments
 (0)