Skip to content

Commit 3064d6e

Browse files
authored
Rollup merge of #94596 - compiler-errors:delay-adjustment-duplicate, r=estebank
Delay bug in expr adjustment when check_expr is called multiple times Instead of including slightly more complicated logic in `check_argument_types` to fix the bug (#94516) I introduced in #94438, and inevitably have this bug appear once again when some other diagnostic is written that causes `check_expr` to be called an expression during a (bad) code path, just delay the bug in adjustment logic. I am open to other implementations that don't delay the bug here. Fixes #94516
2 parents f27466d + 8af683d commit 3064d6e

File tree

6 files changed

+50
-11
lines changed

6 files changed

+50
-11
lines changed

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

+8-5
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
315315
}
316316
// FIXME: currently we never try to compose autoderefs
317317
// and ReifyFnPointer/UnsafeFnPointer, but we could.
318-
_ => bug!(
319-
"while adjusting {:?}, can't compose {:?} and {:?}",
320-
expr,
321-
entry.get(),
322-
adj
318+
_ => self.tcx.sess.delay_span_bug(
319+
expr.span,
320+
&format!(
321+
"while adjusting {:?}, can't compose {:?} and {:?}",
322+
expr,
323+
entry.get(),
324+
adj
325+
),
323326
),
324327
};
325328
*entry.get_mut() = adj;

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

-5
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
234234
// This is more complicated than just checking type equality, as arguments could be coerced
235235
// This version writes those types back so further type checking uses the narrowed types
236236
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-
242237
let formal_input_ty: Ty<'tcx> = formal_input_tys[idx];
243238
let expected_input_ty: Ty<'tcx> = expected_input_tys[idx];
244239
let provided_arg = &provided_args[idx];

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

+1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ 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
3334
}

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ 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+
2127
error[E0057]: this function takes 1 argument but 2 arguments were supplied
2228
--> $DIR/overloaded-calls-bad.rs:31:15
2329
|
@@ -32,7 +38,7 @@ note: associated function defined here
3238
LL | extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output;
3339
| ^^^^^^^^
3440

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

3743
Some errors have detailed explanations: E0057, E0308.
3844
For more information about an error, try `rustc --explain E0057`.
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
struct Process;
2+
3+
pub type Group = (Vec<String>, Vec<Process>);
4+
5+
fn test(process: &Process, groups: Vec<Group>) -> Vec<Group> {
6+
let new_group = vec![String::new()];
7+
8+
if groups.capacity() == 0 {
9+
groups.push(new_group, vec![process]);
10+
//~^ ERROR this function takes 1 argument but 2 arguments were supplied
11+
return groups;
12+
}
13+
14+
todo!()
15+
}
16+
17+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0061]: this function takes 1 argument but 2 arguments were supplied
2+
--> $DIR/wrong_argument_ice-3.rs:9:16
3+
|
4+
LL | groups.push(new_group, vec![process]);
5+
| ^^^^ --------- ------------- supplied 2 arguments
6+
| |
7+
| expected 1 argument
8+
|
9+
note: associated function defined here
10+
--> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
11+
|
12+
LL | pub fn push(&mut self, value: T) {
13+
| ^^^^
14+
15+
error: aborting due to previous error
16+
17+
For more information about this error, try `rustc --explain E0061`.

0 commit comments

Comments
 (0)