Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check arg expressions properly on error in confirm_builtin_call #106055

Merged
merged 3 commits into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion compiler/rustc_hir_typeck/src/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
ty::FnPtr(sig) => (sig, None),
_ => {
for arg in arg_exprs {
self.check_expr(arg);
}

if let hir::ExprKind::Path(hir::QPath::Resolved(_, path)) = &callee_expr.kind
&& let [segment] = path.segments
&& let Some(mut diag) = self
Expand Down Expand Up @@ -486,7 +490,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expected: Expectation<'tcx>,
) -> Option<Ty<'tcx>> {
if let [callee_expr, rest @ ..] = arg_exprs {
let callee_ty = self.check_expr(callee_expr);
let callee_ty = self.typeck_results.borrow().expr_ty_adjusted_opt(callee_expr)?;

// First, do a probe with `IsSuggestion(true)` to avoid emitting
// any strange errors. If it's successful, then we'll do a true
// method lookup.
Expand Down
13 changes: 13 additions & 0 deletions src/test/ui/suggestions/fn-to-method-deeply-nested.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
fn main() -> Result<(), ()> {
a(b(c(d(e(
//~^ ERROR cannot find function `a` in this scope
//~| ERROR cannot find function `b` in this scope
//~| ERROR cannot find function `c` in this scope
//~| ERROR cannot find function `d` in this scope
//~| ERROR cannot find function `e` in this scope
z????????????????????????????????????????????????????????????????????????????????????????
?????????????????????????????????????????????????????????????????????????????????????????
??????????????????????????????????????????????????????????????????
//~^^^ ERROR cannot find value `z` in this scope
)))))
}
39 changes: 39 additions & 0 deletions src/test/ui/suggestions/fn-to-method-deeply-nested.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
error[E0425]: cannot find value `z` in this scope
--> $DIR/fn-to-method-deeply-nested.rs:8:9
|
LL | z????????????????????????????????????????????????????????????????????????????????????????
| ^ not found in this scope

error[E0425]: cannot find function `e` in this scope
--> $DIR/fn-to-method-deeply-nested.rs:2:13
|
LL | a(b(c(d(e(
| ^ not found in this scope

error[E0425]: cannot find function `d` in this scope
--> $DIR/fn-to-method-deeply-nested.rs:2:11
|
LL | a(b(c(d(e(
| ^ not found in this scope

error[E0425]: cannot find function `c` in this scope
--> $DIR/fn-to-method-deeply-nested.rs:2:9
|
LL | a(b(c(d(e(
| ^ not found in this scope

error[E0425]: cannot find function `b` in this scope
--> $DIR/fn-to-method-deeply-nested.rs:2:7
|
LL | a(b(c(d(e(
| ^ not found in this scope

error[E0425]: cannot find function `a` in this scope
--> $DIR/fn-to-method-deeply-nested.rs:2:5
|
LL | a(b(c(d(e(
| ^ not found in this scope

error: aborting due to 6 previous errors

For more information about this error, try `rustc --explain E0425`.
5 changes: 5 additions & 0 deletions src/test/ui/typeck/check-args-on-fn-err-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fn main() {
a((), 1i32 == 2u32);
//~^ ERROR cannot find function `a` in this scope
//~| ERROR mismatched types
}
23 changes: 23 additions & 0 deletions src/test/ui/typeck/check-args-on-fn-err-2.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
error[E0308]: mismatched types
--> $DIR/check-args-on-fn-err-2.rs:2:19
|
LL | a((), 1i32 == 2u32);
| ---- ^^^^ expected `i32`, found `u32`
| |
| expected because this is `i32`
|
help: change the type of the numeric literal from `u32` to `i32`
|
LL | a((), 1i32 == 2i32);
| ~~~

error[E0425]: cannot find function `a` in this scope
--> $DIR/check-args-on-fn-err-2.rs:2:5
|
LL | a((), 1i32 == 2u32);
| ^ not found in this scope

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0308, E0425.
For more information about an error, try `rustc --explain E0308`.
6 changes: 6 additions & 0 deletions src/test/ui/typeck/check-args-on-fn-err.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn main() {
unknown(1, |glyf| {
//~^ ERROR: cannot find function `unknown` in this scope
let actual = glyf;
});
}
9 changes: 9 additions & 0 deletions src/test/ui/typeck/check-args-on-fn-err.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0425]: cannot find function `unknown` in this scope
--> $DIR/check-args-on-fn-err.rs:2:5
|
LL | unknown(1, |glyf| {
| ^^^^^^^ not found in this scope

error: aborting due to previous error

For more information about this error, try `rustc --explain E0425`.