IOTL, Charles was persuaded by his ministers to sign a will making Philip of Anjou the heir to the Spanish crown, conflicting with the existing claim of Archduke Charles of Austria and kicking off the War of the Spanish Succession. What if he, in a fit of insanity, had instead signed the throne over to James Francis Edward Stuart, the son of the deposed King James II of England, known as the "Old Pretender"? England will obviously be...displeased, but what might the other effects be?
England might not be pleased, but it could cause France and the Habsburgs to end up on the same side. Both have better claims to the Spanish crown than Jamie. However, I can think of a way you might get the Bourbons on-side: Philippe d'Anjou and Charles de Berri are either born girls or stillborn, leaving the duc de Bourgogne as the only
son of the dauphin. The French claim the crown for girl-Philippe as queen, and Carlos accepts this. Originally the plan is that girl-Philippe marries OTL Archduke Leopold and when he dies, Archduke Karl. But then the Bourbons think that that price is too high, and marry her to Jamie instead. Boom, James is Diego I of Spain
jure uxoris.
The problem comes in with the Stuarts not being willing to give up their English thrones. James II OTL was proposed by Louis XIV to stand in as the French candidate in the Polish royal election after Jan III Sobieski's death. James refused, because he saw the English throne as his God-given right, not some other throne on the arse-end of Europe (no offense Poland).
England might actually be supportive of this move if you can make it happen. James III/Diego I will be so busy with Spanish affairs that he'll have no time to plot for England, and secondly, this would be an equivalent of him doing what he OTL did when he moved to Rome: namely nailing his colors to the mast as a Catholic. Even some of his most loyal supporters at the time made their peace of with the Georges because they saw it as an outright betrayal.
Either way, a Stuardo (that is the Spanish rendition of Stuart, right?) Spain could be interesting.