The EAT–Lancet Commission devised a sustainable reference diet with the aim of reducing the incidence of non-communicable diseases and mortality globally while improving food system sustainability. The extent to which the reference diet supports cognitive function across the life course, however, has not yet been evaluated. This Review assesses the evidence for diet supporting cognitive function from childhood into old age. A comprehensive but non-exhaustive literature search was done, synthesising studies that investigated the effect of whole foods on cognition in healthy, community-dwelling human participants. We found that the current evidence base is weak with mixed conclusions and multiple methodological caveats, which precludes strong conclusions pertaining to the suitability of dietary recommendations for each food group per age group. Long-term intervention and prospective cohort studies are needed to reduce this knowledge deficit. Revising dietary recommendations with the aim of maintaining an adequate nutrient intake to sustain healthy cognitive function across the life course could be worthwhile. This Review outlines recommendations for future work to help improve the current knowledge deficit regarding dietary intake and cognitive function across the life course and its implications for dietary guidelines such as the EAT–Lancet Commission.