Skip to content

Commit d9f3067

Browse files
committed
Detect type inference failure when auto-dereferencing a pointer
check::autoderef() returns a ty_err when it fails to infer the type. probe::probe() should respect this failure and fail together to prevent further corruption. Call stack: check::check_method_call() -> method::lookup() -> probe::probe() + confirm::confirm() Fixes #19692. Fixes #19583. Fixes #19297.
1 parent 95c2ed3 commit d9f3067

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/librustc_typeck/check/method/probe.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ pub fn probe<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
124124
// it ride, although it's really not great, and in fact could I
125125
// think cause spurious errors. Really though this part should
126126
// take place in the `fcx.infcx().probe` below.
127-
let steps = create_steps(fcx, span, self_ty);
127+
let steps = match create_steps(fcx, span, self_ty) {
128+
Some(steps) => steps,
129+
None => return Err(NoMatch(Vec::new())),
130+
};
128131

129132
// Create a list of simplified self types, if we can.
130133
let mut simplified_steps = Vec::new();
@@ -160,7 +163,7 @@ pub fn probe<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
160163
fn create_steps<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
161164
span: Span,
162165
self_ty: Ty<'tcx>)
163-
-> Vec<CandidateStep<'tcx>> {
166+
-> Option<Vec<CandidateStep<'tcx>>> {
164167
let mut steps = Vec::new();
165168

166169
let (fully_dereferenced_ty, dereferences, _) =
@@ -179,11 +182,11 @@ fn create_steps<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
179182
adjustment: AutoUnsizeLength(dereferences, len),
180183
});
181184
}
182-
_ => {
183-
}
185+
ty::ty_err => return None,
186+
_ => (),
184187
}
185188

186-
return steps;
189+
Some(steps)
187190
}
188191

189192
impl<'a,'tcx> ProbeContext<'a,'tcx> {

src/test/compile-fail/issue-19692.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct Homura;
12+
13+
fn akemi(homura: Homura) {
14+
let Some(ref madoka) = Some(homura.kaname()); //~ ERROR does not implement any method
15+
madoka.clone(); //~ ERROR the type of this value must be known
16+
}
17+
18+
fn main() { }

0 commit comments

Comments
 (0)