From d84f3edff5836cc5bcb2a991052248d82807815a Mon Sep 17 00:00:00 2001 From: "leonardo.yvens" Date: Wed, 29 Nov 2017 10:33:56 -0200 Subject: [PATCH] Test that trait definition owns the default, not the impl. I don't know if it's what we want but it's how it works now. If we want to keep it then we should forbid writing the default in the impl. --- .../trait_def_rules_over_impl.rs | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/test/run-pass/default-ty-param-fallback/trait_def_rules_over_impl.rs diff --git a/src/test/run-pass/default-ty-param-fallback/trait_def_rules_over_impl.rs b/src/test/run-pass/default-ty-param-fallback/trait_def_rules_over_impl.rs new file mode 100644 index 0000000000000..4bcf7a1176848 --- /dev/null +++ b/src/test/run-pass/default-ty-param-fallback/trait_def_rules_over_impl.rs @@ -0,0 +1,31 @@ +// 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)] + +trait Bar { + // Current we consider only the default in the trait, + // never the one in the impl. + // Is this good? Is it bad? Is it just the way it works? + // If this is ok then we should forbid writing the default in the impl. + fn method(&self) -> A; +} + +struct Foo; + +impl Bar for Foo { + fn method(&self) -> A { + A::default() + } +} + +fn main() { + Foo.method(); +}