What is the product of magnesium reacting with carbon?
This asnswer is intended to extend my comment. Most of the information is taken from this site.



Both types of magnesium carbide($\ce{MgC2, Mg2C3}$) is formed when acetylene gas is passed over magnesium. At different temperatures, one type of carbide predominates over the other. At 570°C-610° C, $\ce{MgC2}$ converts to $\ce{Mg2C3}$:

$$\ce{2MgC2 -&gt; Mg2C3 + C }$$

Above 610° C, $\ce{Mg2C3}$ decomposes:

$$\ce{Mg2C3 -&gt; 2Mg + C}$$ 

Both types of magnesium carbide can be hydrolysed:

$$\ce{MgC2 + 2H2O -&gt; Mg(OH)2 + C2H2}$$ 
$$\ce{Mg2C3 + 4H2O -&gt; 2Mg(OH)2 + C3H4}$$



For more information on the structure of magnesium carbide, see this old paper from 1943. Also, how magnesium carbide behaves at high pressure is discussed in this new paper(2015). Another type of magnesium carbide, $\ce{Mg2C}$ exist at high pressure and it along with $\ce{MgC2}$ behaves as semiconductor while $\ce{Mg2C3}$ behave as insulator-metal transition. (OP is requested to see both papers if interested)