When there is food in the offhand and the player right clicks to trade with a villager the player will eat the food if hungry.
Currently only tested in Minecraft version 1.15.2 Single player with a librarian villager and carrots.
I have video evidence to support but I am currently unable to attach it to this report.
Related issues
duplicates
Attachments
Comments

Thank you for your report!
We're actually already tracking this issue in MC-141494, so I resolved and linked this ticket as a duplicate.
If you would like to add a vote and any extra information to the main ticket it would be appreciated.
If you haven't already, you might like to make use of the search feature in the future to see if the issue has already been reported.
Quick Links:
📓 Issue Guidelines – 💬 Community Support – 📧 Customer Support – 📖 Game Wiki

I have noticed the same issue in 20w14a as well when I ate a carrot while trading with a villager.