Skip to content

Commit a8c152d

Browse files
committed
add regression tests + improve method name
1 parent 7c59a81 commit a8c152d

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
@@ -355,7 +355,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
355355
// trait selection is because we don't have enough
356356
// information about the types in the trait.
357357
pending_obligation.stalled_on =
358-
trait_ref_type_vars(self.selcx, data.to_poly_trait_ref());
358+
trait_ref_infer_vars(self.selcx, data.to_poly_trait_ref());
359359

360360
debug!(
361361
"process_predicate: pending obligation {:?} now stalled on {:?}",
@@ -433,7 +433,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
433433
Ok(None) => {
434434
let tcx = self.selcx.tcx();
435435
pending_obligation.stalled_on =
436-
trait_ref_type_vars(self.selcx, data.to_poly_trait_ref(tcx));
436+
trait_ref_infer_vars(self.selcx, data.to_poly_trait_ref(tcx));
437437
ProcessResult::Unchanged
438438
}
439439
Ok(Some(os)) => ProcessResult::Changed(mk_pending(infcx, os)),
@@ -539,8 +539,8 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
539539
}
540540
}
541541

542-
/// Returns the set of type inference variables contained in a trait ref.
543-
fn trait_ref_type_vars<'a, 'tcx>(
542+
/// Returns the set of inference variables contained in a trait ref.
543+
fn trait_ref_infer_vars<'a, 'tcx>(
544544
selcx: &mut SelectionContext<'a, 'tcx>,
545545
trait_ref: ty::PolyTraitRef<'tcx>,
546546
) -> 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)