diff --git a/src/test/run-pass/default-ty-param-fallback/associated_type_as_default.rs b/src/test/run-pass/default-ty-param-fallback/associated_type_as_default.rs new file mode 100644 index 0000000000000..43e92f9f1ff74 --- /dev/null +++ b/src/test/run-pass/default-ty-param-fallback/associated_type_as_default.rs @@ -0,0 +1,64 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. +// compile-flags: --error-format=human + +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. +// + +#![feature(default_type_parameter_fallback)] + +use std::vec::IntoIter; +use std::iter::Sum; +use std::slice::Iter; +use std::ops::Add; + +trait Itarator: Iterator { + type Iten; + // Bug: Even though it's unambiguos, using Self::Iten dosen't work here. + // probably can be fixed in fn associated_path_def_to_ty. + fn foo::Iten>(&self) -> T { + T::default() + } + + fn suma::Iten as Add>::Output>(self) -> S + where Self: Sized, + S: Sum<::Item>, + { + Sum::sum(self) + } +} + +impl Itarator for IntoIter { + type Iten = as Iterator>::Item; +} + +impl<'a> Itarator for Iter<'a, u32> { + type Iten = as Iterator>::Item; +} + +fn main() { + let x = vec![0u32]; + { + let v = x.iter(); + // Bug: if we put a cast such as `as u64`, inference fails. + //The usual guess is that we propagate the origin but not the default of the inference var. + v.suma(); + } + x.clone().into_iter().suma(); + x.into_iter().suma(); +} diff --git a/src/test/ui/default-ty-param-fallback/elided_is_not_inferred.rs b/src/test/ui/default-ty-param-fallback/elided_is_not_inferred.rs new file mode 100644 index 0000000000000..7efcf64e9f807 --- /dev/null +++ b/src/test/ui/default-ty-param-fallback/elided_is_not_inferred.rs @@ -0,0 +1,30 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. +// compile-flags: --error-format=human + +#![feature(default_type_parameter_fallback)] + +struct Bar(T); + +impl Bar { + fn new() -> Bar { + Bar(Z::default()) + } +} + +fn main() { + let _:u32 = foo::(); + let _:Bar = Bar::new::(); +} + +fn foo() -> T { + T::default() +} + diff --git a/src/test/ui/default-ty-param-fallback/elided_is_not_inferred.stderr b/src/test/ui/default-ty-param-fallback/elided_is_not_inferred.stderr new file mode 100644 index 0000000000000..1bb7b710ddc7f --- /dev/null +++ b/src/test/ui/default-ty-param-fallback/elided_is_not_inferred.stderr @@ -0,0 +1,26 @@ +error[E0412]: cannot find type `T` in this scope + --> $DIR/elided_is_not_inferred.rs:16:10 + | +16 | impl Bar { + | ^ not found in this scope + +error[E0308]: mismatched types + --> $DIR/elided_is_not_inferred.rs:23:17 + | +23 | let _:u32 = foo::(); + | ^^^^^^^^^^^^^^ expected u32, found struct `std::string::String` + | + = note: expected type `u32` + found type `std::string::String` + +error[E0308]: mismatched types + --> $DIR/elided_is_not_inferred.rs:24:22 + | +24 | let _:Bar = Bar::new::(); + | ^^^^^^^^^^^^^^^^^^^ expected u32, found struct `std::string::String` + | + = note: expected type `Bar` + found type `Bar` + +error: aborting due to 3 previous errors +