Glue then trim!
First, be sure that the concrete slab is clean and dry. Check for moisture problems by securely taping a 12 inch square piece of plastic sheeting to the slab using duct tape. If moisture appears between the plastic and the slab, it should be sealed with a high quality concrete sealer.
Use a "stair tool" (a large chisel-like tool) to seat and crease the edge of the carpet into the joint between the floor and the wall. Finish the job by trimming the carpet with a utility knife.