Skip to content

Commit b56bbad

Browse files
committed
feat(Tactic/Translate): warn when adding a docstring to an existing declaration (leanprover-community#41883)
1 parent 9e47bf7 commit b56bbad

6 files changed

Lines changed: 62 additions & 12 deletions

File tree

Mathlib/Algebra/Free.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ inductive AddMagma.AssocRel (α : Type u) [Add α] : α → α → Prop
319319
| left : ∀ w x y z, AddMagma.AssocRel α (w + (x + y + z)) (w + (x + (y + z)))
320320

321321
/-- Associativity relations for a magma. -/
322-
@[to_additive AddMagma.AssocRel /-- Associativity relations for an additive magma. -/]
322+
@[to_additive AddMagma.AssocRel]
323323
inductive Magma.AssocRel (α : Type u) [Mul α] : α → α → Prop
324324
| intro : ∀ x y z, Magma.AssocRel α (x * y * z) (x * (y * z))
325325
| left : ∀ w x y z, Magma.AssocRel α (w * (x * y * z)) (w * (x * (y * z)))

Mathlib/GroupTheory/GroupAction/MultiplePrimitivity.lean

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,7 @@ class _root_.AddAction.IsMultiplyPreprimitive
9494
pretransitive and if, when `n ≥ 1`, for every set `s` of cardinality
9595
`n - 1`, the action of `fixingSubgroup M s` on the complement of `s`
9696
is preprimitive. -/
97-
@[mk_iff, to_additive existing
98-
/-- A group action is `n`-multiply preprimitive if it is `n`-multiply
99-
pretransitive and if, when `n ≥ 1`, for every set `s` of cardinality
100-
`n - 1`, the action of `fixingSubgroup M s` on the complement of `s`
101-
is preprimitive. -/]
97+
@[mk_iff, to_additive existing]
10298
class IsMultiplyPreprimitive (M α : Type*) [Group M] [MulAction M α] (n : ℕ) where
10399
/-- An `n`-preprimitive action is `n`-pretransitive. -/
104100
isMultiplyPretransitive (M α n) : IsMultiplyPretransitive M α n

Mathlib/Tactic/Translate/Core.lean

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,12 @@ partial def addTranslationAttr (t : TranslateData) (src : Name) (cfg : Config)
12751275
-- tgt doesn't exist, so let's make it
12761276
transformDeclRec t cfg src tgt src reorder cfg.rename
12771277
if let some doc := cfg.doc then
1278+
if alreadyExists then
1279+
logWarningAt doc <|
1280+
if (← findInternalDocString? (← getEnv) tgt).isSome then
1281+
m!"The target declaration `{.ofConstName tgt}` already has a docstring."
1282+
else
1283+
m!"This docstring should be added directly to `{.ofConstName tgt}`."
12781284
-- TODO: `Syntax.missing` means we do not add binders to the context,
12791285
-- so the docstring is going to have incomplete syntax highlighting.
12801286
addDocString tgt Syntax.missing doc |>.run'.run'

Mathlib/Topology/Algebra/ContinuousMonoidHom.lean

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ over `(F : Type*) [FunLike F A B] [ContinuousMapClass F A B] [MonoidHomClass F A
5353
5454
When you extend this structure,
5555
make sure to extend `ContinuousMapClass` and/or `MonoidHomClass`, if needed. -/
56-
@[to_additive /-- The type of continuous additive monoid homomorphisms from `A` to `B`. -/]
56+
@[to_additive]
5757
structure ContinuousMonoidHom extends A →* B, C(A, B)
5858

5959
/-- Reinterpret a `ContinuousMonoidHom` as a `MonoidHom`. -/
@@ -306,8 +306,7 @@ structure ContinuousAddEquiv [Add G] [Add H] extends G ≃+ H, G ≃ₜ H
306306

307307
/-- The structure of two-sided continuous isomorphisms between groups.
308308
Note that both the map and its inverse have to be continuous. -/
309-
@[to_additive /-- The structure of two-sided continuous isomorphisms between additive groups.
310-
Note that both the map and its inverse have to be continuous. -/]
309+
@[to_additive]
311310
structure ContinuousMulEquiv [Mul G] [Mul H] extends G ≃* H, G ≃ₜ H
312311

313312
/-- The homeomorphism induced from a two-sided continuous isomorphism of groups. -/

Mathlib/Topology/Algebra/OpenSubgroup.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,8 @@ open scoped Pointwise
450450

451451
variable {G : Type*} [TopologicalSpace G]
452452

453+
/-- For a set `W`, `T` is a neighborhood of `0` which is open, stable under negation and satisfies
454+
`T + W ⊆ W`. -/
453455
structure IsTopologicalAddGroup.addNegClosureNhd (T W : Set G) [AddGroup G] : Prop where
454456
nhds : T ∈ 𝓝 0
455457
neg : -T = T
@@ -458,9 +460,7 @@ structure IsTopologicalAddGroup.addNegClosureNhd (T W : Set G) [AddGroup G] : Pr
458460

459461
/-- For a set `W`, `T` is a neighborhood of `1` which is open, stable under inverse and satisfies
460462
`T * W ⊆ W`. -/
461-
@[to_additive
462-
/-- For a set `W`, `T` is a neighborhood of `0` which is open, stable under negation and satisfies
463-
`T + W ⊆ W`. -/]
463+
@[to_additive]
464464
structure IsTopologicalGroup.mulInvClosureNhd (T W : Set G) [Group G] : Prop where
465465
nhds : T ∈ 𝓝 1
466466
inv : T⁻¹ = T

MathlibTest/Attribute/ToAdditive/Basic.lean

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,3 +1023,52 @@ info: @add_comm_alias : ∀ {G : Type u_1} [inst : AddCommMagma G] (a b : G), a
10231023
-/
10241024
#guard_msgs in
10251025
#check @add_comm_alias
1026+
1027+
/-! Warning when adding docstrings to existing declarations -/
1028+
1029+
namespace ExistingDeclDocstring
1030+
1031+
/-- Existing docstring -/
1032+
opaque add (G : Type*) [AddGroup G] : Prop
1033+
1034+
/-- warning: The target declaration `add` already has a docstring. -/
1035+
#guard_msgs in
1036+
@[to_additive existing /-- New docstring -/]
1037+
opaque mul (G : Type*) [Group G] : Prop
1038+
1039+
/-- warning: The target declaration `self` already has a docstring. -/
1040+
#guard_msgs in
1041+
/-- Existing docstring -/
1042+
@[to_additive self (reorder := x y) /-- New docstring -/]
1043+
opaque self (x y : Nat) : Prop
1044+
1045+
/-- Existing docstring -/
1046+
structure addStruct (G : Type*) [AddGroup G] where
1047+
1048+
/-- warning: The target declaration `addStruct` already has a docstring. -/
1049+
#guard_msgs in
1050+
@[to_additive /-- New docstring -/]
1051+
structure mulStruct (G : Type*) [Group G] where
1052+
1053+
-- Examples with no pre-existing docstring
1054+
1055+
opaque add' (G : Type*) [AddGroup G] : Prop
1056+
1057+
/-- warning: This docstring should be added directly to `add'`. -/
1058+
#guard_msgs in
1059+
@[to_additive existing /-- New docstring -/]
1060+
opaque mul' (G : Type*) [Group G] : Prop
1061+
1062+
/-- warning: This docstring should be added directly to `self'`. -/
1063+
#guard_msgs in
1064+
@[to_additive self (reorder := x y) /-- New docstring -/]
1065+
opaque self' (x y : Nat) : Prop
1066+
1067+
structure addStruct' (G : Type*) [AddGroup G] where
1068+
1069+
/-- warning: This docstring should be added directly to `addStruct'`. -/
1070+
#guard_msgs in
1071+
@[to_additive /-- New docstring -/]
1072+
structure mulStruct' (G : Type*) [Group G] where
1073+
1074+
end ExistingDeclDocstring

0 commit comments

Comments
 (0)