As mentioned above, Walker's, McLaws' and Hill's divisions not attached to either the right or left wing of the army at 2nd Manassas as they had been left behind to watch McClellan. General Longstreet says once Lee was certain McClellan's troops were then reinforcing Pope's army, he had called for those three divisions from near Richmond to join him in the field..
They did not join in time to participate in the victory at Second Manassas, but followed Lee into Maryland... By Antietam D.H. Hill's division was attached to Jackson's left wing, and McLaws to Longstreet's right wing, etc.
Confederate act allowing for the combination of divisions into army corps by President Davis, with lieutenant generals to command them, etc. was only passed the day after the Sept. 17th battle at Antietam...
Several days after this act was approved, Jefferson Davis informed General Lee that he had authority to promote lieutenant generals to command multiple divisions, etc.
Next came an act authorizing the President to form provisional army divisions into fixed army corps...
So under these laws, General Longstreet was promoted to lieutenant General, on Oct. 11, 1862 (ranking from Oct. 9). Jackson was promoted to lieutenant general the same day, but ranking from Oct. 10, so that Longstreet had the seniority.
Then two army corps were formed in Lee's army along the Rappahannock, and their organization completed by orders dated November 6, 1862, with Longstreet commanding the first, and Jackson the second corps, of the Army of Northern Virginia.
This reorganization was completed in the winter of 1862-63.
Then, on May 30, 1863, Lee's army was reorganized again into three from two corps. A fourth corps was organized in late 1864.