Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - fix: prevent Int.ofNat being used instead of Nat.cast #2878

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Mathlib/Data/Nat/Cast/Defs.lean
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ instance [NatCast R] : CoeTail ℕ R where coe := Nat.cast
-- see note [coercion into rings]
instance [NatCast R] : CoeHTCT ℕ R where coe := Nat.cast
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two are in std4 now. ^^


/-- This instance is needed to ensure that `instCoeNatInt` is not used. -/
instance : Coe ℕ ℤ where coe := Nat.cast

-- the following four declarations are not in mathlib3 and are relevant to the way numeric
-- literals are handled in Lean 4.

Expand Down
3 changes: 2 additions & 1 deletion Mathlib/Data/PNat/Defs.lean
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Authors: Mario Carneiro, Neil Strickland
-/

import Mathlib.Algebra.NeZero
import Mathlib.Data.Nat.Cast.Defs
import Mathlib.Order.Basic
import Mathlib.Tactic.Coe
import Mathlib.Tactic.Lift
Expand Down Expand Up @@ -299,7 +300,7 @@ instance Nat.canLiftPNat : CanLift ℕ ℕ+ (↑) (fun n => 0 < n) :=
instance Int.canLiftPNat : CanLift ℤ ℕ+ (↑) ((0 < ·)) :=
⟨fun n hn =>
⟨Nat.toPNat' (Int.natAbs n), by
rw [Nat.toPNat'_coe, if_pos (Int.natAbs_pos.2 hn.ne'), Int.ofNat_eq_coe,
rw [Nat.toPNat'_coe, if_pos (Int.natAbs_pos.2 hn.ne'),
Int.natAbs_of_nonneg hn.le]⟩⟩
#align int.can_lift_pnat Int.canLiftPNat

Expand Down