Food safety is a property of both the process and the material. You can't stick food-safe material in a printer that has previously been used to print something food-dangerous and expect the result to be food safe.
The only way to know if a given material is food-safe is to ask your supplier, but a lot depends on how you then process it. For instance, FDM printers often have brass nozzles, which contain lead. To print food-safe materials, you need to use a stainless steel nozzle.
Food safe materials can be identified by mean of an universal symbol.
Moreover, to ensure food-safety of a 3D printed model you may need to further process it (for instance, by vapor smoothing or coating with a food-safe lacquer). Some claims circulate on the internet that 3D printed models may have surface porosity in which bacteria can grow, but I've not been able to find a reliable source for this claim. Still, you need to be cautious.
There are regulatory agencies in most developed countries that regulate food containers. In the USA, the Food and Drug Administration (FDA) regulates Food Contact Substances (FCS) which are materials that come into contact with food during production, manufacturing, storage, packing, and use.
They have many lists of FCS which are either approved for use, generally recognized as safe, regulated, restricted, or otherwise already evaluated and for which they have recommendations.
It is up to the manufacturer to ensure that FCS are safe, so the liability rests with the person making the 3D prints. If you make something that looks like a cup and could be confused with a cup, you may be responsible for following these guidelines.
The FDA has an online resource to help guide manufacturers through these lists, Determining the Regulatory Status of Components of a Food Contact Material.
Within this, for instance, you will find the list for materials that are appropriately regulated indirect additive, under which you'll find where polymers are listed, 21 CFR 177.
Part 177, INDIRECT FOOD ADDITIVES: POLYMERS
Notably, PLA is not present in this section, or any other list that I've searched (but a more thorough search may prove productive).
ABS is included here, in section 1020, which I've quoted below. Whether your filament manufacturer is following this ABS formula or not is something you will have to determine for each ABS supplier you use, though. Additives, colorants, and other ingredients may make a specific ABS non food safe, according to the FDA.
§177.1020 Acrylonitrile/butadiene/styrene co-polymer. Acrylonitrile/butadiene/styrene copolymer identified in this section may be safely used as an article or component of articles intended for use with all foods, except those containing alcohol, under conditions of use E, F, and G described in table 2 of §176.170(c) of this chapter.
(a) Identity. For the purpose of this section, the acrylonitrile/butadiene/styrene copolymer consists of:
(1) Eighty-four to eighty-nine parts by weight of a matrix polymer containing 73 to 78 parts by weight of acrylonitrile and 22 to 27 parts by weight of styrene; and
(2) Eleven to sixteen parts by weight of a grafted rubber consisting of (i) 8 to 13 parts of butadiene/styrene elastomer containing 72 to 77 parts by weight of butadiene and 23 to 28 parts by weight of styrene and (ii) 3 to 8 parts by weight of a graft polymer having the same composition range as the matrix polymer.
(b) Adjuvants. The copolymer identified in paragraph (a) of this section may contain adjuvant substances required in its production. Such adjuvants may include substances generally recognized as safe in food, substances used in accordance with prior sanction, substances permitted in this part, and the following:
Substance Limitations 2-Mercapto- ethanol The finished copolymer shall contain not more than 100 ppm 2-mercaptoethanol acrylonitrile adduct as determined by a method titled “Analysis of Cycopac Resin for Residual β-(2-Hydroxyethylmercapto) propionitrile,” which is incorporated by reference. Copies are available from the Bureau of Foods (HFS-200), Food and Drug Administration, 5100 Paint Branch Pkwy., College Park, MD 20740, or available for inspection at the National Archives and Records Administration (NARA). For information on the availability of this material at NARA, call 202-741-6030, or go to: http://www.archives.gov/federal_register/code_of_federal_regulations/ibr_locations.html. (c) Specifications. (1) Nitrogen content of the copolymer is in the range of 16 to 18.5 percent as determined by Micro-Kjeldahl analysis.
(2) Residual acrylonitrile monomer content of the finished copolymer articles is not more than 11 parts per million as determined by a gas chromatographic method titled “Determination of Residual Acrylonitrile and Styrene Monomers-Gas Chromatographic Internal Standard Method,” which is incorporated by reference. Copies are available from the Center for Food Safety and Applied Nutrition (HFS-200), Food and Drug Administration, 5100 Paint Branch Pkwy., College Park, MD 20740, or available for inspection at the National Archives and Records Administration (NARA). For information on the availability of this material at NARA, call 202-741-6030, or go to: http://www.archives.gov/federal_register/code_of_federal_regulations/ibr_locations.html.
(d) Extractive limitations. (1) Total nonvolatile extractives not to exceed 0.0005 milligram per square inch surface area when the finished food contact article is exposed to distilled water, 3 percent acetic acid, or n-heptane for 8 days at 120 °F.
(2) The finished food-contact article shall yield not more than 0.0015 milligram per square inch of acrylonitrile monomer when exposed to distilled water and 3 percent acetic acid at 150 °F for 15 days when analyzed by a polarographic method titled “Extracted Acrylonitrile by Differential Pulse Polarography,” which is incorporated by reference. Copies are available from the Center for Food Safety and Applied Nutrition (HFS-200), Food and Drug Administration, 5100 Paint Branch Pkwy., College Park, MD 20740, or available for inspection at the National Archives and Records Administration (NARA). For information on the availability of this material at NARA, call 202-741-6030, or go to: http://www.archives.gov/federal_register/code_of_federal_regulations/ibr_locations.html.
(e) Acrylonitrile copolymers identified in this section shall comply with the provisions of §180.22 of this chapter.
(f) Acrylonitrile copolymers identified in this section are not authorized to be used to fabricate beverage containers.
[42 FR 14572, Mar. 15, 1977, as amended at 42 FR 48543, Sept. 23, 1977; 47 FR 11841, Mar. 19, 1982; 54 FR 24897, June 12, 1989]
The EU has a database for this, though without some industry specific experience it appears difficult to search. For instance, rather than listing ABS as an item, it lists the three monomers that constitute ABS seperately, so you have to read through the Acrylonitrile section, the butadiene section, and the styrene sections seperately to understand the food safety aspects of ABS.
Of course someone has gone to the trouble of parsing all these different regulations in different countries and created a book that summarizes much of what you can glean from individual databases, Global Legislation for Food Contact Materials J S Baughan but it's not an inexpensive resource, and needs constant update so may need to be repurchased each year to keep up with the latest legislation worldwide. It would, however, be a handy reference and starting point for a hack space or library for makers.
Keep in mind that these are regulations formulated by government bodies. They may have a scientific basis (and hopefully they all do) but they do not replace your own testing and common sense. Even if you follow these regulations, you may still be liable for any unsafe objects you create.
There are 3 things that might affect food safety of 3D printed objects:
The filament - it's food safe only if it says so on the package (even if the plastic is not toxic you don't know about the color and other additives)
The hotend - the hotend and nozzle may leak metals into the filament, you need something like a full stainless steel hothead.
And finally, 3D printed objects contain little holes that bacteria can get into - so nothing printed on an FDM printer is food safe unless coated with some food safe sealing material (except for single use)
I have looked at this a lot, both from the standpoint of my own use, and of selling items on Etsy.
As far as I can determine, PLA and ABS are both generally safe.
The FDA lists ABS and PLA as safe plastics for food contact, although some pigments and additives can bring their own problems. ABS is nit generally safe (per the FDA) for contact with alcohol. I don't know why.
So, for my use, I make wine, beer, and cocktail containers from PLA, and coffee mugs from ABS.
PETG softens too much with boiling water and does not work for coffee and tea mugs. I've tried. It fails.
Be careful if you use acetone smoothing on ABS. The acetone enters the ABS, and even after a few days of ambient conditions, the plastic may contain enough acetone to create bubbles in the plastic when the acetone boils off in response to hot water. I had heavily smoothed this particular teacup. Perhaps if it was less exposed to acetone vapors, it may have let the disolved acetone escape faster.
I have used non-smoothed ABS coffee mugs for months without problems.
You will read about brass nozzles contaminating the print with lead. You will read about the ridges being bacterial breading grounds. This may be true.
ABS still makes a fine coffee mug for personal use.