Consider the following example:
Definition cast {A : Set} (B : Set) (prf : A = B) (x : A) : B. rewrite prf in x. refine x. Defined. Lemma castLemma0 {A : S