mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
Rollup merge of #106055 - compiler-errors:too-many-calls, r=estebank
Check arg expressions properly on error in `confirm_builtin_call` Makes sure we don't regress diagnostic output when we have an expr error nested inside of a bad fn call: https://github.com/rust-lang/rust/pull/105973#issuecomment-1363152232 Fixes #106030 Fixes #105244
This commit is contained in:
commit
de99a87926
@ -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
|
||||
@ -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.
|
||||
|
13
src/test/ui/suggestions/fn-to-method-deeply-nested.rs
Normal file
13
src/test/ui/suggestions/fn-to-method-deeply-nested.rs
Normal file
@ -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
src/test/ui/suggestions/fn-to-method-deeply-nested.stderr
Normal file
39
src/test/ui/suggestions/fn-to-method-deeply-nested.stderr
Normal file
@ -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
src/test/ui/typeck/check-args-on-fn-err-2.rs
Normal file
5
src/test/ui/typeck/check-args-on-fn-err-2.rs
Normal file
@ -0,0 +1,5 @@
|
||||
fn main() {
|
||||
a((), 1i32 == 2u32);
|
||||
//~^ ERROR cannot find function `a` in this scope
|
||||
//~| ERROR mismatched types
|
||||
}
|
23
src/test/ui/typeck/check-args-on-fn-err-2.stderr
Normal file
23
src/test/ui/typeck/check-args-on-fn-err-2.stderr
Normal file
@ -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
src/test/ui/typeck/check-args-on-fn-err.rs
Normal file
6
src/test/ui/typeck/check-args-on-fn-err.rs
Normal file
@ -0,0 +1,6 @@
|
||||
fn main() {
|
||||
unknown(1, |glyf| {
|
||||
//~^ ERROR: cannot find function `unknown` in this scope
|
||||
let actual = glyf;
|
||||
});
|
||||
}
|
9
src/test/ui/typeck/check-args-on-fn-err.stderr
Normal file
9
src/test/ui/typeck/check-args-on-fn-err.stderr
Normal file
@ -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`.
|
Loading…
Reference in New Issue
Block a user