Apparently the concept of the Baptism of Desire goes back further than Trent. This from the article:
This is something the Church has always been aware of. For example, in A.D. 256, Cyprian of Carthage stated of catechumens who are martyred before baptism, “They certainly are not deprived of the sacrament of baptism who are baptized with the most glorious and greatest baptism of blood, concerning which the Lord also said that he had ‘another baptism to be baptized with’ (Luke 12:50)” (Letters 72 :22).
It also talks about Trent:
Canon four of Trent’s Canons on the Sacraments in General states, “If anyone shall say that the sacraments of the New Law are not necessary for salvation but are superfluous, and that although all are not necessary for every individual, without them or without the desire of them . . . men obtain from God the grace of justification, let him be anathema [i.e., ceremonially excommunicated].”
This is confirmed in chapter four of Trent’s Decree on Justification, which states that “This translation [i.e., justification], however, cannot, since promulgation of the Gospel, be effected except through the laver of regeneration [i.e., baptism] or its desire, as it is written: ‘Unless a man be born again of water and the Holy Ghost, he cannot enter into the kingdom of God’ (John 3:5).”
Trent teaches that, although not all the sacraments are necessary for salvation, the sacraments in general are necessary. Without them or the desire of them men cannot obtain the grace of justification, but with them or the desire of them men can be justified. The sacrament through which we initially receive justification is baptism. But since the canon teaches that we can be justified with the desire of the sacraments rather than the sacraments themselves, we can be justified with the desire for baptism rather than baptism itself.