This question is based on question $3.11$ from chapter $2$ of Hartshorne, found on page $92$.
Part $a)$ of said question asks to show that closed immersions are stable under base extension. In other words, if $f:Y \rightarrow X$ is a closed immersions and $g:X'\rightarrow X$ a morphism of schemes, then the induced map $f':Z=Y\times_X X' \rightarrow X'$ is also a closed immersion.
My question is:
How can we prove this without using that a closed immersion is affine?
I ask because although I can reduce to the case where $X'$ and $X$ are affine fairly easily, I have not been able to find a proof anywhere (including on related questions such as this one on the site) that doesn't use part $b)$ of the question in Hartshorne, namely that if $X = \operatorname{Spec}A$ then $Y$ is affine, and in fact is the closed subscheme determined by some ideal of $A$. Without this, I can't see how to reduce to the affine case since even if $X$ is affine, the restriction of $f$ to an arbitrary affine piece of $Y$ need not be a closed immersion.
Although part $b)$ doesn't rely on part $a)$ and we therefore could use it to prove part $a)$, I can't help but think that if this is what Hartshorne had in mind then he would have switched the order around. This is the first time that I've had to use a later exercise to prove an earlier one and would like to avoid it if at all possible.
Of course it's pretty much impossible to prove that such a proof doesn't exist. I would however accept an answer from someone who feels that they have enough experience to say that if such a proof exists they would most likely have seen it, or who can provide some reasonably convincing heuristic argument that it can't be done.