Skip to content

Commit 61189b6

Browse files
authored
Rollup merge of #105310 - compiler-errors:issue-105288, r=eholk
Be more careful about unresolved exprs in suggestion Fixes #105288
2 parents 0a07ffe + f4c76b1 commit 61189b6

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -1482,25 +1482,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14821482
ident_name: Symbol,
14831483
}
14841484

1485+
// FIXME: This really should be taking scoping, etc into account.
14851486
impl<'v> Visitor<'v> for LetVisitor<'v> {
14861487
fn visit_stmt(&mut self, ex: &'v hir::Stmt<'v>) {
1487-
if let hir::StmtKind::Local(hir::Local { pat, init, .. }) = &ex.kind {
1488-
if let Binding(_, _, ident, ..) = pat.kind &&
1489-
ident.name == self.ident_name {
1490-
self.result = *init;
1491-
}
1488+
if let hir::StmtKind::Local(hir::Local { pat, init, .. }) = &ex.kind
1489+
&& let Binding(_, _, ident, ..) = pat.kind
1490+
&& ident.name == self.ident_name
1491+
{
1492+
self.result = *init;
1493+
} else {
1494+
hir::intravisit::walk_stmt(self, ex);
14921495
}
1493-
hir::intravisit::walk_stmt(self, ex);
14941496
}
14951497
}
14961498

14971499
let mut visitor = LetVisitor { result: None, ident_name: seg1.ident.name };
14981500
visitor.visit_body(&body);
14991501

15001502
let parent = self.tcx.hir().get_parent_node(seg1.hir_id);
1501-
if let Some(Node::Expr(call_expr)) = self.tcx.hir().find(parent) &&
1502-
let Some(expr) = visitor.result {
1503-
let self_ty = self.node_ty(expr.hir_id);
1503+
if let Some(Node::Expr(call_expr)) = self.tcx.hir().find(parent)
1504+
&& let Some(expr) = visitor.result
1505+
&& let Some(self_ty) = self.node_ty_opt(expr.hir_id)
1506+
{
15041507
let probe = self.lookup_probe(
15051508
seg2.ident,
15061509
self_ty,
@@ -1513,7 +1516,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15131516
sm.span_extend_while(seg1.ident.span.shrink_to_hi(), |c| c == ':').unwrap(),
15141517
"you may have meant to call an instance method",
15151518
".".to_string(),
1516-
Applicability::MaybeIncorrect
1519+
Applicability::MaybeIncorrect,
15171520
);
15181521
}
15191522
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
let page_size = page_size::get();
3+
//~^ ERROR failed to resolve: use of undeclared crate or module `page_size`
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0433]: failed to resolve: use of undeclared crate or module `page_size`
2+
--> $DIR/path-to-method-sugg-unresolved-expr.rs:2:21
3+
|
4+
LL | let page_size = page_size::get();
5+
| ^^^^^^^^^ use of undeclared crate or module `page_size`
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0433`.

0 commit comments

Comments
 (0)