Skip to content

Commit d169ee3

Browse files
committed
Recurse into function signatures in assert_assignable
Fixes rust-lang#1311
1 parent 43064b0 commit d169ee3

File tree

4 files changed

+75
-1
lines changed

4 files changed

+75
-1
lines changed

build_system/tests.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ struct TestCase {
2121
enum TestCaseCmd {
2222
Custom { func: &'static dyn Fn(&TestRunner<'_>) },
2323
BuildLib { source: &'static str, crate_types: &'static str },
24+
BuildBin { source: &'static str },
2425
BuildBinAndRun { source: &'static str, args: &'static [&'static str] },
2526
JitBin { source: &'static str, args: &'static str },
2627
}
@@ -39,6 +40,10 @@ impl TestCase {
3940
Self { config, cmd: TestCaseCmd::BuildLib { source, crate_types } }
4041
}
4142

43+
const fn build_bin(config: &'static str, source: &'static str) -> Self {
44+
Self { config, cmd: TestCaseCmd::BuildBin { source } }
45+
}
46+
4247
const fn build_bin_and_run(
4348
config: &'static str,
4449
source: &'static str,
@@ -92,6 +97,7 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[
9297
TestCase::build_bin_and_run("aot.float-minmax-pass", "example/float-minmax-pass.rs", &[]),
9398
TestCase::build_bin_and_run("aot.mod_bench", "example/mod_bench.rs", &[]),
9499
TestCase::build_bin_and_run("aot.issue-72793", "example/issue-72793.rs", &[]),
100+
TestCase::build_bin("aot.issue-59326", "example/issue-59326.rs"),
95101
];
96102

97103
// FIXME(rust-random/rand#1293): Newer rand versions fail to test on Windows. Update once this is
@@ -405,6 +411,13 @@ impl<'a> TestRunner<'a> {
405411
]);
406412
}
407413
}
414+
TestCaseCmd::BuildBin { source } => {
415+
if self.use_unstable_features {
416+
self.run_rustc([source]);
417+
} else {
418+
self.run_rustc([source, "--cfg", "no_unstable_features"]);
419+
}
420+
}
408421
TestCaseCmd::BuildBinAndRun { source, args } => {
409422
if self.use_unstable_features {
410423
self.run_rustc([source]);

config.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ aot.track-caller-attribute
4141
aot.float-minmax-pass
4242
aot.mod_bench
4343
aot.issue-72793
44+
aot.issue-59326
4445

4546
testsuite.extended_sysroot
4647
test.rust-random/rand

example/issue-59326.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Based on https://github.com/rust-lang/rust/blob/689511047a75a30825e367d4fd45c74604d0b15e/tests/ui/issues/issue-59326.rs#L1
2+
// check-pass
3+
trait Service {
4+
type S;
5+
}
6+
7+
trait Framing {
8+
type F;
9+
}
10+
11+
impl Framing for () {
12+
type F = ();
13+
}
14+
15+
trait HttpService<F: Framing>: Service<S = F::F> {}
16+
17+
type BoxService = Box<dyn HttpService<(), S = ()>>;
18+
19+
fn build_server<F: FnOnce() -> BoxService>(_: F) {}
20+
21+
fn make_server<F: Framing>() -> Box<dyn HttpService<F, S = F::F>> {
22+
unimplemented!()
23+
}
24+
25+
fn main() {
26+
build_server(|| make_server())
27+
}

src/value_and_place.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
33
use crate::prelude::*;
44

5+
use rustc_middle::ty::FnSig;
6+
57
use cranelift_codegen::entity::EntityRef;
68
use cranelift_codegen::ir::immediates::Offset32;
79

@@ -815,11 +817,42 @@ pub(crate) fn assert_assignable<'tcx>(
815817
ParamEnv::reveal_all(),
816818
from_ty.fn_sig(fx.tcx),
817819
);
820+
let FnSig {
821+
inputs_and_output: types_from,
822+
c_variadic: c_variadic_from,
823+
unsafety: unsafety_from,
824+
abi: abi_from,
825+
} = from_sig;
818826
let to_sig = fx
819827
.tcx
820828
.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), to_ty.fn_sig(fx.tcx));
829+
let FnSig {
830+
inputs_and_output: types_to,
831+
c_variadic: c_variadic_to,
832+
unsafety: unsafety_to,
833+
abi: abi_to,
834+
} = to_sig;
835+
let mut types_from = types_from.iter();
836+
let mut types_to = types_to.iter();
837+
loop {
838+
match (types_from.next(), types_to.next()) {
839+
(Some(a), Some(b)) => assert_assignable(fx, a, b, limit - 1),
840+
(None, None) => break,
841+
(Some(_), None) | (None, Some(_)) => panic!("{:#?}/{:#?}", from_ty, to_ty),
842+
}
843+
}
844+
assert_eq!(
845+
c_variadic_from, c_variadic_to,
846+
"Can't write fn ptr with incompatible sig {:?} to place with sig {:?}\n\n{:#?}",
847+
from_sig, to_sig, fx,
848+
);
849+
assert_eq!(
850+
unsafety_from, unsafety_to,
851+
"Can't write fn ptr with incompatible sig {:?} to place with sig {:?}\n\n{:#?}",
852+
from_sig, to_sig, fx,
853+
);
821854
assert_eq!(
822-
from_sig, to_sig,
855+
abi_from, abi_to,
823856
"Can't write fn ptr with incompatible sig {:?} to place with sig {:?}\n\n{:#?}",
824857
from_sig, to_sig, fx,
825858
);

0 commit comments

Comments
 (0)