From 1db76c1bff60584e46f75fad99a78dd9ad7e9fd6 Mon Sep 17 00:00:00 2001 From: Oliver Middleton Date: Sun, 14 Apr 2019 23:53:51 +0100 Subject: [PATCH] rustdoc: Remove default keyword from re-exported trait methods --- src/librustdoc/clean/mod.rs | 6 ++++- src/test/rustdoc/default-trait-method.rs | 26 +++++++++++++++++++ src/test/rustdoc/default_trait_method.rs | 15 ----------- .../auxiliary/default-trait-method.rs | 16 ++++++++++++ .../inline_cross/default-trait-method.rs | 20 ++++++++++++++ 5 files changed, 67 insertions(+), 16 deletions(-) create mode 100644 src/test/rustdoc/default-trait-method.rs delete mode 100644 src/test/rustdoc/default_trait_method.rs create mode 100644 src/test/rustdoc/inline_cross/auxiliary/default-trait-method.rs create mode 100644 src/test/rustdoc/inline_cross/default-trait-method.rs diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index e994c661fdceb..80e796b0af732 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2325,6 +2325,10 @@ impl<'tcx> Clean for ty::AssociatedItem { } else { hir::Constness::NotConst }; + let defaultness = match self.container { + ty::ImplContainer(_) => Some(self.defaultness), + ty::TraitContainer(_) => None, + }; MethodItem(Method { generics, decl, @@ -2334,7 +2338,7 @@ impl<'tcx> Clean for ty::AssociatedItem { constness, asyncness: hir::IsAsync::NotAsync, }, - defaultness: Some(self.defaultness), + defaultness, all_types, ret_types, }) diff --git a/src/test/rustdoc/default-trait-method.rs b/src/test/rustdoc/default-trait-method.rs new file mode 100644 index 0000000000000..3d6ebef5a1d5b --- /dev/null +++ b/src/test/rustdoc/default-trait-method.rs @@ -0,0 +1,26 @@ +#![feature(specialization)] + +// @has default_trait_method/trait.Item.html +// @has - '//*[@id="tymethod.foo"]' 'fn foo()' +// @!has - '//*[@id="tymethod.foo"]' 'default fn foo()' +// @has - '//*[@id="tymethod.bar"]' 'fn bar()' +// @!has - '//*[@id="tymethod.bar"]' 'default fn bar()' +// @has - '//*[@id="method.baz"]' 'fn baz()' +// @!has - '//*[@id="method.baz"]' 'default fn baz()' +pub trait Item { + fn foo(); + fn bar(); + fn baz() {} +} + +// @has default_trait_method/struct.Foo.html +// @has - '//*[@id="method.foo"]' 'default fn foo()' +// @has - '//*[@id="method.bar"]' 'fn bar()' +// @!has - '//*[@id="method.bar"]' 'default fn bar()' +// @has - '//*[@id="method.baz"]' 'fn baz()' +// @!has - '//*[@id="method.baz"]' 'default fn baz()' +pub struct Foo; +impl Item for Foo { + default fn foo() {} + fn bar() {} +} diff --git a/src/test/rustdoc/default_trait_method.rs b/src/test/rustdoc/default_trait_method.rs deleted file mode 100644 index dfbd8f2210fa4..0000000000000 --- a/src/test/rustdoc/default_trait_method.rs +++ /dev/null @@ -1,15 +0,0 @@ -#![feature(specialization)] - -pub trait Item { - fn foo(); - fn bar(); -} - -// @has default_trait_method/trait.Item.html -// @has - '//*[@id="method.foo"]' 'default fn foo()' -// @has - '//*[@id="method.bar"]' 'fn bar()' -// @!has - '//*[@id="method.bar"]' 'default fn bar()' -impl Item for T { - default fn foo() {} - fn bar() {} -} diff --git a/src/test/rustdoc/inline_cross/auxiliary/default-trait-method.rs b/src/test/rustdoc/inline_cross/auxiliary/default-trait-method.rs new file mode 100644 index 0000000000000..ce60bbfb4b0de --- /dev/null +++ b/src/test/rustdoc/inline_cross/auxiliary/default-trait-method.rs @@ -0,0 +1,16 @@ +#![feature(specialization)] + +#![crate_name = "foo"] + +pub trait Item { + fn foo(); + fn bar(); + fn baz() {} +} + +pub struct Foo; + +impl Item for Foo { + default fn foo() {} + fn bar() {} +} diff --git a/src/test/rustdoc/inline_cross/default-trait-method.rs b/src/test/rustdoc/inline_cross/default-trait-method.rs new file mode 100644 index 0000000000000..a4ec73a127d4e --- /dev/null +++ b/src/test/rustdoc/inline_cross/default-trait-method.rs @@ -0,0 +1,20 @@ +// aux-build:default-trait-method.rs + +extern crate foo; + +// @has default_trait_method/trait.Item.html +// @has - '//*[@id="tymethod.foo"]' 'fn foo()' +// @!has - '//*[@id="tymethod.foo"]' 'default fn foo()' +// @has - '//*[@id="tymethod.bar"]' 'fn bar()' +// @!has - '//*[@id="tymethod.bar"]' 'default fn bar()' +// @has - '//*[@id="method.baz"]' 'fn baz()' +// @!has - '//*[@id="method.baz"]' 'default fn baz()' +pub use foo::Item; + +// @has default_trait_method/struct.Foo.html +// @has - '//*[@id="method.foo"]' 'default fn foo()' +// @has - '//*[@id="method.bar"]' 'fn bar()' +// @!has - '//*[@id="method.bar"]' 'default fn bar()' +// @has - '//*[@id="method.baz"]' 'fn baz()' +// @!has - '//*[@id="method.baz"]' 'default fn baz()' +pub use foo::Foo;