| /-! | |
| # Warn about visibility (and namespace/type) changes in deprecation lints | |
| https://github.com/leanprover/lean4/issues/7993 | |
| Deprecation lints should indicate if an updated constant is in a different namespace, is protected, | |
| or has a different type from the deprecated one. | |
| -/ | |
| set_option linter.deprecated true | |
| abbrev Foo := Nat | |
| namespace Foo | |
| protected def bar : Foo → Foo | |
| | 0 => 0 | |
| | n + 1 => Foo.bar n + 1 | |
| theorem bar_rfl : Foo.bar = Foo.bar := rfl | |
| @[deprecated Foo.bar (since := "2025-01-01")] | |
| def foo : Foo → Foo := id | |
| end Foo | |
| /-- | |
| warning: `Foo.foo` has been deprecated: Use `Foo.bar` instead | |
| Note: `Foo.bar` is protected. References to this constant must include its prefix `Foo` even when inside its namespace. | |
| Hint: Replace the deprecated name: | |
| f̵o̵o̵F̲o̲o̲.̲b̲a̲r̲ | |
| -/ | |
| #guard_msgs in | |
| open Foo in | |
| example := foo | |
| abbrev Bar := Nat | |
| /-- | |
| warning: `Foo.foo` is itself deprecated in favor of `Foo.bar`; consider deprecating `Bar.bar` in favor of `Foo.bar` instead | |
| Note: This warning can be disabled with `set_option linter.deprecated.deprecatedTarget false` | |
| Hint: Deprecate in favor of `Foo.bar` instead: | |
| Foo.f̵o̵o̵b̲a̲r̲ | |
| -/ | |
| #guard_msgs in | |
| @[deprecated Foo.foo (since := "2025-01-01")] | |
| def Bar.bar : Bar → Bar := id | |
| abbrev b : Bar := 31 | |
| /-- | |
| warning: `Bar.bar` has been deprecated: Use `Foo.foo` instead | |
| Note: The updated constant is in a different namespace. Dot notation may need to be changed (e.g., from `x.bar` to `Foo.foo x`). | |
| -/ | |
| #guard_msgs in | |
| example := b.bar | |
| /-- | |
| warning: `Bar.bar` has been deprecated: Use `Foo.foo` instead | |
| Note: The updated constant is in a different namespace. Dot notation may need to be changed (e.g., from `x.bar` to `foo x`). | |
| -/ | |
| #guard_msgs in | |
| open Foo in | |
| example := b.bar | |
| set_option linter.deprecated false in | |
| @[deprecated Foo.bar_rfl (since := "2025-01-01")] | |
| theorem Bar.bar_rfl : Bar.bar = Bar.bar := rfl | |
| /-- | |
| warning: `Bar.bar_rfl` has been deprecated: Use `Foo.bar_rfl` instead | |
| Note: The updated constant has a different type: | |
| Foo.bar = Foo.bar | |
| instead of | |
| Bar.bar = Bar.bar | |
| Note: The updated constant is in a different namespace. Dot notation may need to be changed (e.g., from `x.bar_rfl` to `Foo.bar_rfl x`). | |
| -/ | |
| #guard_msgs in | |
| example := Bar.bar_rfl | |
| namespace A.B | |
| protected def C := () | |
| @[deprecated B.C (since := "2025-01-01")] | |
| def D := () | |
| end A.B | |
| /-- | |
| warning: `A.B.D` has been deprecated: Use `A.B.C` instead | |
| Note: `A.B.C` is protected. References to this constant must include at least the last component `B` of its prefix `A.B` even when inside its namespace. | |
| Hint: Replace the deprecated name: | |
| D̵B̲.̲C̲ | |
| -/ | |
| #guard_msgs in | |
| open A B in | |
| example := D |