Skip to content

Commit 6e5a6ff

Browse files
committed
Auto merge of rust-lang#94471 - matthiaskrgr:rollup-ffz65qt, r=matthiaskrgr
Rollup of 3 pull requests Successful merges: - rust-lang#94438 (Check method input expressions once) - rust-lang#94459 (Update cargo) - rust-lang#94470 (:arrow_up: rust-analyzer) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 6343edf + 6aab954 commit 6e5a6ff

File tree

10 files changed

+55
-26
lines changed

10 files changed

+55
-26
lines changed

Cargo.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ dependencies = [
318318

319319
[[package]]
320320
name = "cargo"
321-
version = "0.61.0"
321+
version = "0.62.0"
322322
dependencies = [
323323
"anyhow",
324324
"atty",

compiler/rustc_typeck/src/check/demand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
470470
return None;
471471
};
472472

473-
let self_ty = self.typeck_results.borrow().node_type(method_expr[0].hir_id);
473+
let self_ty = self.typeck_results.borrow().expr_ty(&method_expr[0]);
474474
let self_ty = format!("{:?}", self_ty);
475475
let name = method_path.ident.name;
476476
let is_as_ref_able = (self_ty.starts_with("&std::option::Option")

compiler/rustc_typeck/src/check/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15171517
}
15181518
} else {
15191519
self.check_expr_has_type_or_error(base_expr, adt_ty, |_| {
1520-
let base_ty = self.typeck_results.borrow().node_type(base_expr.hir_id);
1520+
let base_ty = self.typeck_results.borrow().expr_ty(*base_expr);
15211521
let same_adt = match (adt_ty.kind(), base_ty.kind()) {
15221522
(ty::Adt(adt, _), ty::Adt(base_adt, _)) if adt == base_adt => true,
15231523
_ => false,

compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs

-9
Original file line numberDiff line numberDiff line change
@@ -313,15 +313,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
313313
) => {
314314
// A reborrow has no effect before a dereference.
315315
}
316-
// Catch cases which have Deref(None)
317-
// having them slip to bug! causes ICE
318-
// see #94291 for more info
319-
(&[Adjustment { kind: Adjust::Deref(None), .. }], _) => {
320-
self.tcx.sess.delay_span_bug(
321-
DUMMY_SP,
322-
&format!("Can't compose Deref(None) expressions"),
323-
)
324-
}
325316
// FIXME: currently we never try to compose autoderefs
326317
// and ReifyFnPointer/UnsafeFnPointer, but we could.
327318
_ => bug!(

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
133133
let expected_arg_count = formal_input_tys.len();
134134

135135
// expected_count, arg_count, error_code, sugg_unit, sugg_tuple_wrap_args
136-
let mut error: Option<(usize, usize, &str, bool, Option<FnArgsAsTuple<'_>>)> = None;
136+
let mut arg_count_error: Option<(usize, usize, &str, bool, Option<FnArgsAsTuple<'_>>)> =
137+
None;
137138

138139
// If the arguments should be wrapped in a tuple (ex: closures), unwrap them here
139140
let (formal_input_tys, expected_input_tys) = if tuple_arguments == TupleArguments {
@@ -143,7 +144,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
143144
ty::Tuple(arg_types) => {
144145
// Argument length differs
145146
if arg_types.len() != provided_args.len() {
146-
error = Some((arg_types.len(), provided_args.len(), "E0057", false, None));
147+
arg_count_error =
148+
Some((arg_types.len(), provided_args.len(), "E0057", false, None));
147149
}
148150
let expected_input_tys = match expected_input_tys.get(0) {
149151
Some(&ty) => match ty.kind() {
@@ -174,7 +176,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
174176
if supplied_arg_count >= expected_arg_count {
175177
(formal_input_tys.to_vec(), expected_input_tys)
176178
} else {
177-
error = Some((expected_arg_count, supplied_arg_count, "E0060", false, None));
179+
arg_count_error =
180+
Some((expected_arg_count, supplied_arg_count, "E0060", false, None));
178181
(self.err_args(supplied_arg_count), vec![])
179182
}
180183
} else {
@@ -198,7 +201,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
198201

199202
let sugg_tuple_wrap_args = self.suggested_tuple_wrap(expected_input_tys, provided_args);
200203

201-
error = Some((
204+
arg_count_error = Some((
202205
expected_arg_count,
203206
supplied_arg_count,
204207
"E0061",
@@ -231,6 +234,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
231234
// This is more complicated than just checking type equality, as arguments could be coerced
232235
// This version writes those types back so further type checking uses the narrowed types
233236
let demand_compatible = |idx, final_arg_types: &mut Vec<Option<(Ty<'tcx>, Ty<'tcx>)>>| {
237+
// Do not check argument compatibility if the number of args do not match
238+
if arg_count_error.is_some() {
239+
return;
240+
}
241+
234242
let formal_input_ty: Ty<'tcx> = formal_input_tys[idx];
235243
let expected_input_ty: Ty<'tcx> = expected_input_tys[idx];
236244
let provided_arg = &provided_args[idx];
@@ -328,7 +336,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
328336
}
329337

330338
// If there was an error in parameter count, emit that here
331-
if let Some((expected_count, arg_count, err_code, sugg_unit, sugg_tuple_wrap_args)) = error
339+
if let Some((expected_count, arg_count, err_code, sugg_unit, sugg_tuple_wrap_args)) =
340+
arg_count_error
332341
{
333342
let (span, start_span, args, ctor_of) = match &call_expr.kind {
334343
hir::ExprKind::Call(

src/test/ui/mismatched_types/overloaded-calls-bad.rs

-1
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,4 @@ fn main() {
3030
//~^ ERROR this function takes 1 argument but 0 arguments were supplied
3131
let ans = s("burma", "shave");
3232
//~^ ERROR this function takes 1 argument but 2 arguments were supplied
33-
//~| ERROR mismatched types
3433
}

src/test/ui/mismatched_types/overloaded-calls-bad.stderr

+1-7
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ note: associated function defined here
1818
LL | extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output;
1919
| ^^^^^^^^
2020

21-
error[E0308]: mismatched types
22-
--> $DIR/overloaded-calls-bad.rs:31:17
23-
|
24-
LL | let ans = s("burma", "shave");
25-
| ^^^^^^^ expected `isize`, found `&str`
26-
2721
error[E0057]: this function takes 1 argument but 2 arguments were supplied
2822
--> $DIR/overloaded-calls-bad.rs:31:15
2923
|
@@ -38,7 +32,7 @@ note: associated function defined here
3832
LL | extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output;
3933
| ^^^^^^^^
4034

41-
error: aborting due to 4 previous errors
35+
error: aborting due to 3 previous errors
4236

4337
Some errors have detailed explanations: E0057, E0308.
4438
For more information about an error, try `rustc --explain E0057`.
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
fn test(t: (i32, i32)) {}
2+
3+
struct Foo;
4+
5+
impl Foo {
6+
fn qux(&self) -> i32 {
7+
0
8+
}
9+
}
10+
11+
fn bar() {
12+
let x = Foo;
13+
test(x.qux(), x.qux());
14+
//~^ ERROR this function takes 1 argument but 2 arguments were supplied
15+
}
16+
17+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0061]: this function takes 1 argument but 2 arguments were supplied
2+
--> $DIR/wrong_argument_ice-2.rs:13:5
3+
|
4+
LL | test(x.qux(), x.qux());
5+
| ^^^^ ------- ------- supplied 2 arguments
6+
|
7+
note: function defined here
8+
--> $DIR/wrong_argument_ice-2.rs:1:4
9+
|
10+
LL | fn test(t: (i32, i32)) {}
11+
| ^^^^ -------------
12+
help: use parentheses to construct a tuple
13+
|
14+
LL | test((x.qux(), x.qux()));
15+
| + +
16+
17+
error: aborting due to previous error
18+
19+
For more information about this error, try `rustc --explain E0061`.

0 commit comments

Comments
 (0)