def drop_engine_after(prev_engine):
    """
    Removes an engine from the singly-linked list of engines.

    Args:
        prev_engine (projectq.cengines.BasicEngine):
            The engine just before the engine to drop.
    Returns:
        Engine: The dropped engine.
    """
    dropped_engine = prev_engine.next_engine
    prev_engine.next_engine = dropped_engine.next_engine
    dropped_engine.next_engine = None
    dropped_engine.main_engine = None
    return dropped_engine
