Skip to content

Commit 436c0e1

Browse files
committed
Fix an ICE on rust-lang#96738
1 parent 30f3860 commit 436c0e1

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

compiler/rustc_typeck/src/check/method/suggest.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
367367

368368
if self.is_fn_ty(rcvr_ty, span) {
369369
if let SelfSource::MethodCall(expr) = source {
370-
let suggest = if let ty::FnDef(def_id, _) = rcvr_ty.kind() {
371-
let local_id = def_id.expect_local();
370+
let suggest = if let ty::FnDef(def_id, _) = rcvr_ty.kind() && let Some(local_id) = def_id.as_local() {
372371
let hir_id = tcx.hir().local_def_id_to_hir_id(local_id);
373372
let node = tcx.hir().get(hir_id);
374373
let fields = node.tuple_fields();

src/test/ui/typeck/issue-96738.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
Some.nonexistent_method(); //~ ERROR: no method named `nonexistent_method` found
3+
}

src/test/ui/typeck/issue-96738.stderr

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0599]: no method named `nonexistent_method` found for fn item `fn(_) -> Option<_> {Option::<_>::Some}` in the current scope
2+
--> $DIR/issue-96738.rs:2:10
3+
|
4+
LL | Some.nonexistent_method();
5+
| ---- ^^^^^^^^^^^^^^^^^^ method not found in `fn(_) -> Option<_> {Option::<_>::Some}`
6+
| |
7+
| this is a function, perhaps you wish to call it
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0599`.

0 commit comments

Comments
 (0)