Skip to content

Commit

Permalink
Rollup merge of rust-lang#72061 - lcnr:const-inference-test, r=eddyb
Browse files Browse the repository at this point in the history
add regression tests for stalled_on const vars

closes rust-lang#70180

Afaict this has been fixed sometime after rust-lang#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
  • Loading branch information
Dylan-DPC authored May 25, 2020
2 parents f93bb2a + a8c152d commit b3f1b95
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/librustc_trait_selection/traits/fulfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
// trait selection is because we don't have enough
// information about the types in the trait.
pending_obligation.stalled_on =
trait_ref_type_vars(self.selcx, data.to_poly_trait_ref());
trait_ref_infer_vars(self.selcx, data.to_poly_trait_ref());

debug!(
"process_predicate: pending obligation {:?} now stalled on {:?}",
Expand Down Expand Up @@ -435,7 +435,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
Ok(None) => {
let tcx = self.selcx.tcx();
pending_obligation.stalled_on =
trait_ref_type_vars(self.selcx, data.to_poly_trait_ref(tcx));
trait_ref_infer_vars(self.selcx, data.to_poly_trait_ref(tcx));
ProcessResult::Unchanged
}
Ok(Some(os)) => ProcessResult::Changed(mk_pending(infcx, os)),
Expand Down Expand Up @@ -603,8 +603,8 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
}
}

/// Returns the set of type inference variables contained in a trait ref.
fn trait_ref_type_vars<'a, 'tcx>(
/// Returns the set of inference variables contained in a trait ref.
fn trait_ref_infer_vars<'a, 'tcx>(
selcx: &mut SelectionContext<'a, 'tcx>,
trait_ref: ty::PolyTraitRef<'tcx>,
) -> Vec<TyOrConstInferVar<'tcx>> {
Expand Down
35 changes: 35 additions & 0 deletions src/test/ui/const-generics/issue-70180-1-stalled_on.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// build-pass
#![feature(const_generics)]
#![allow(incomplete_features)]

pub fn works() {
let array/*: [_; _]*/ = default_array();
let _: [_; 4] = array;
Foo::foo(&array);
}

pub fn didnt_work() {
let array/*: [_; _]*/ = default_array();
Foo::foo(&array);
let _: [_; 4] = array;
}

trait Foo {
fn foo(&self) {}
}

impl Foo for [i32; 4] {}
impl Foo for [i64; 8] {}

// Only needed because `[_; _]` is not valid type syntax.
fn default_array<T, const N: usize>() -> [T; N]
where
[T; N]: Default,
{
Default::default()
}

fn main() {
works();
didnt_work();
}
35 changes: 35 additions & 0 deletions src/test/ui/const-generics/issue-70180-2-stalled_on.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// build-pass
#![feature(const_generics)]
#![allow(incomplete_features)]

fn works() {
let array/*: [u8; _]*/ = default_byte_array();
let _: [_; 4] = array;
Foo::foo(&array);
}

fn didnt_work() {
let array/*: [u8; _]*/ = default_byte_array();
Foo::foo(&array);
let _: [_; 4] = array;
}

trait Foo<T> {
fn foo(&self) {}
}

impl Foo<i32> for [u8; 4] {}
impl Foo<i64> for [u8; 8] {}

// Only needed because `[u8; _]` is not valid type syntax.
fn default_byte_array<const N: usize>() -> [u8; N]
where
[u8; N]: Default,
{
Default::default()
}

fn main() {
works();
didnt_work();
}

0 comments on commit b3f1b95

Please sign in to comment.