summaryrefslogtreecommitdiff
path: root/src/scaladoc/scala/tools/nsc
diff options
context:
space:
mode:
authorAntoine Gourlay <antoine@gourlay.fr>2016-04-29 19:33:47 +0200
committerAntoine Gourlay <antoine@gourlay.fr>2016-06-06 20:45:28 +0200
commit1149453c9a762b0a5792d6139ec2c201e418c914 (patch)
tree3bfc88cc3abdb45c06161b788d6f2471bba10e71 /src/scaladoc/scala/tools/nsc
parent28e0e18106a93fd8fd9a086c29836631c754ba35 (diff)
downloadscala-1149453c9a762b0a5792d6139ec2c201e418c914.tar.gz
scala-1149453c9a762b0a5792d6139ec2c201e418c914.tar.bz2
scala-1149453c9a762b0a5792d6139ec2c201e418c914.zip
SI-9585 hide auto-implicit conversions from scaladoc
This hides implicits conversions (and potential members obtained through it) that converts a type into itself, because these conversions are usually non-sensical. They are not completely removed, just placed behind `-doc-implicits-show-all`, like other implicits deemed probably useless. --- Consider the scaladoc for the following class: ``` object Box { implicit def anyToBox[T](t: T): Box[T] = new Box(t) } class Box[T](val t: T) ``` When looking for implicits members to add to class `Box`, it finds the implicit conversion `anyToBox`, and applies it to itself to have an implicit conversion to Box[Box[T]], which brings a useless implicit member `t: Box[T]`. This commit makes scaladoc ignore any conversion from a type to itself (even if type parameters differ) by default. Using the (very useful) `tools/scaladoc-diff` script, I found that this change removes the following conversion from the library doc: ``` Ensuring[A] to Ensuring[Ensuring[A]] anytostringadd[A] to any2stringadd[anytostringadd[A]] ArrowAssoc[A] to ArrowAssoc[ArrowAssoc[A]] =:=[From,To] to =:=[From,To] SearchImpl[A,Repr] to SearchImpl[A,SearchImpl[A,Repr]] CollectionsHaveToParArray[C, T] to CollectionsHaveToParArray[CollectionsHaveToParArray[C, T], T] Ordered[A] to Ordered[Ordered[A]] StringFormat[A] to StringFormat[StringFormat[A]] ```
Diffstat (limited to 'src/scaladoc/scala/tools/nsc')
-rw-r--r--src/scaladoc/scala/tools/nsc/doc/model/ModelFactoryImplicitSupport.scala14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/scaladoc/scala/tools/nsc/doc/model/ModelFactoryImplicitSupport.scala b/src/scaladoc/scala/tools/nsc/doc/model/ModelFactoryImplicitSupport.scala
index e67a717257..cedbdd1547 100644
--- a/src/scaladoc/scala/tools/nsc/doc/model/ModelFactoryImplicitSupport.scala
+++ b/src/scaladoc/scala/tools/nsc/doc/model/ModelFactoryImplicitSupport.scala
@@ -171,6 +171,20 @@ trait ModelFactoryImplicitSupport {
return Nil
}
+ if (!settings.docImplicitsShowAll && viewSimplifiedType.resultType.typeSymbol == sym) {
+ // If, when looking at views for a class A, we find one that returns A as well
+ // (possibly with different type parameters), we ignore it.
+ // It usually is a way to build a "whatever" into an A, but we already have an A, as in:
+ // {{{
+ // object Box {
+ // implicit def anyToBox[T](t: T): Box[T] = new Box(t)
+ // }
+ // class Box[T](val t: T)
+ // }}}
+ // We don't want the implicit conversion from Box[T] to Box[Box[T]] to appear.
+ return Nil
+ }
+
// type the view application so we get the exact type of the result (not the formal type)
val viewTree = result.tree.setType(viewSimplifiedType)
val appliedTree = new ApplyImplicitView(viewTree, List(Ident("<argument>") setType viewTree.tpe.paramTypes.head))