Skip to content

Commit b3f1b95

Browse files
authored
Rollup merge of #72061 - lcnr:const-inference-test, r=eddyb
add regression tests for stalled_on const vars closes #70180 Afaict this has been fixed sometime after #70213 `trait_ref_type_vars` correctly adds const infers and I did not find any remaining `FIXME`s which correspond to this issue. https://github.com/rust-lang/rust/blob/7c59a81a5fcbaaca311f744cd7c68d99bfbb05d3/src/librustc_trait_selection/traits/fulfill.rs#L555-L557 Added both examples from the issue as regression tests and renamed `trait_ref_type_vars` -> `trait_ref_infer_vars`. r? @eddyb
2 parents f93bb2a + a8c152d commit b3f1b95

File tree

3 files changed

+74
-4
lines changed

3 files changed

+74
-4
lines changed

src/librustc_trait_selection/traits/fulfill.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
357357
// trait selection is because we don't have enough
358358
// information about the types in the trait.
359359
pending_obligation.stalled_on =
360-
trait_ref_type_vars(self.selcx, data.to_poly_trait_ref());
360+
trait_ref_infer_vars(self.selcx, data.to_poly_trait_ref());
361361

362362
debug!(
363363
"process_predicate: pending obligation {:?} now stalled on {:?}",
@@ -435,7 +435,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
435435
Ok(None) => {
436436
let tcx = self.selcx.tcx();
437437
pending_obligation.stalled_on =
438-
trait_ref_type_vars(self.selcx, data.to_poly_trait_ref(tcx));
438+
trait_ref_infer_vars(self.selcx, data.to_poly_trait_ref(tcx));
439439
ProcessResult::Unchanged
440440
}
441441
Ok(Some(os)) => ProcessResult::Changed(mk_pending(infcx, os)),
@@ -603,8 +603,8 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
603603
}
604604
}
605605

606-
/// Returns the set of type inference variables contained in a trait ref.
607-
fn trait_ref_type_vars<'a, 'tcx>(
606+
/// Returns the set of inference variables contained in a trait ref.
607+
fn trait_ref_infer_vars<'a, 'tcx>(
608608
selcx: &mut SelectionContext<'a, 'tcx>,
609609
trait_ref: ty::PolyTraitRef<'tcx>,
610610
) -> Vec<TyOrConstInferVar<'tcx>> {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// build-pass
2+
#![feature(const_generics)]
3+
#![allow(incomplete_features)]
4+
5+
pub fn works() {
6+
let array/*: [_; _]*/ = default_array();
7+
let _: [_; 4] = array;
8+
Foo::foo(&array);
9+
}
10+
11+
pub fn didnt_work() {
12+
let array/*: [_; _]*/ = default_array();
13+
Foo::foo(&array);
14+
let _: [_; 4] = array;
15+
}
16+
17+
trait Foo {
18+
fn foo(&self) {}
19+
}
20+
21+
impl Foo for [i32; 4] {}
22+
impl Foo for [i64; 8] {}
23+
24+
// Only needed because `[_; _]` is not valid type syntax.
25+
fn default_array<T, const N: usize>() -> [T; N]
26+
where
27+
[T; N]: Default,
28+
{
29+
Default::default()
30+
}
31+
32+
fn main() {
33+
works();
34+
didnt_work();
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// build-pass
2+
#![feature(const_generics)]
3+
#![allow(incomplete_features)]
4+
5+
fn works() {
6+
let array/*: [u8; _]*/ = default_byte_array();
7+
let _: [_; 4] = array;
8+
Foo::foo(&array);
9+
}
10+
11+
fn didnt_work() {
12+
let array/*: [u8; _]*/ = default_byte_array();
13+
Foo::foo(&array);
14+
let _: [_; 4] = array;
15+
}
16+
17+
trait Foo<T> {
18+
fn foo(&self) {}
19+
}
20+
21+
impl Foo<i32> for [u8; 4] {}
22+
impl Foo<i64> for [u8; 8] {}
23+
24+
// Only needed because `[u8; _]` is not valid type syntax.
25+
fn default_byte_array<const N: usize>() -> [u8; N]
26+
where
27+
[u8; N]: Default,
28+
{
29+
Default::default()
30+
}
31+
32+
fn main() {
33+
works();
34+
didnt_work();
35+
}

0 commit comments

Comments
 (0)