Let C be a smooth projective curve of genus g≥11, non-tetragonal, considered in its canonical embedding in Pg−1. We prove that C is a linear section of an arithmetically Gorenstein normal variety Y in Pg+r, not a cone, with dim(Y)=r+2 and ωY=OY(−r), if the Gauss--Wahl map of C has corank larger or equal than r+1. This relies on previous work of Wahl and Arbarello-Bruno-Sernesi; a partial converse is given via a theorem of Lvovski. We derive a similar result for K3 surfaces: Let (S,L) be a polarized K3 surface of genus g≥11, non-tetragonal, and considered in its embedding in ∣L∣∨≅Pg. It is a linear section of a variety Y as above if H1(TS⊗L∨) has dimension larger or equal than r. We give various applications, including one to the following forgetful modular map: Let Kg be the moduli space of polarized K3 surfaces of genus g, and KCg the space of pairs (S,C) with C a smooth curve on S and (S,OS(C))∈Kg; we consider the map cg:(S,C)∈Kg↦C∈Mg. If g≥11, we show that this map has smooth fibres over the locus of non-tetragonal curves, with fibre-dimension over non-tetragonal C the corank of the Gauss--Wahl map of C minus one.