Перейти к содержимому
Топаздокументация
6.05.21

Поиск в документации

Спецификация 6.0

Выберите результат стрелками и нажмите Enter, чтобы открыть его.

Введите имя API, номер диагностики, правило или тему проекта.

    Загрузка →

    Диагностика TPZ5027

    A mutator changed a value without a root binding, and its result is discarded.

    What TPZ5027 means

    Discarded mutation of a temporary

    Семейство
    topaz
    Этап
    check
    Код
    TPZ5027

    Причина и условия

    A mutator call on a value without a root binding produces TPZ5027 when its result is discarded. Taking a mutator method as a value produces TPZ5028. A mutation through an immutable root produces TPZ5003.

    PositionResult consumption
    Expression statement, let _ = E, normal tail of defer, tail of a for or while bodyDiscarded
    Parentheses, block, normal result of if with else, or matchInherits the parent position
    Then tail of if without elseDiscarded regardless of the parent
    Explicit return, function or lambda return tailUsed at that function boundary
    Named binding initializer, argument, condition, operator operand, or receiverUsed

    On the same access or call, TPZ5028 takes priority over TPZ5003, which takes priority over TPZ5027. Errors in other subexpressions, the existing optional-assignment prohibition, and import-reassignment diagnostics remain visible. Whether a named binding is later read, or a caller uses a returned value, is not tracked.

    Действия

    Use the result, or bind the value with let mut before changing it.

    Compiler phase: check. The primary location is the mutator call expression.

    The change has no observable owner or retained result.

    A mutator call on a value without a root binding is rejected when the language discards its result.

    How to fix it

    Use the result, or bind the value with let mut before changing it.

    Examples

    Rejected mutator use

    example.tpzRejected mutator useОткрыть песочницу →
    1. [1, 2].push(3)
    Ожидаемый выводНенулевой код завершения
    $ topaz check example.tpz
    Ожидаемый результат

    Ожидаемый результат

    Этап отклонения check. Ненулевой код завершения.

    Контракт обязательного основного местоположения не определён.

    Accepted repair

    example.tpzAccepted repairОткрыть песочницу →
    1. let mut xs = [1, 2]
    2. xs.push(3)
    Ожидаемый выводКод завершения 0
    $ topaz check example.tpz
    Ожидаемый результат

    Ожидаемый результат

    Проверка принимает программу. Код завершения 0.