File: consume_operator_noop_warning.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (60 lines) | stat: -rw-r--r-- 3,246 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// RUN: %target-swift-emit-sil %s -verify -sil-verify-all

struct Point {
  let x: Float
  let y: Float
}

struct ConditionallyBC<T> {
  var t: T
}
extension ConditionallyBC: BitwiseCopyable where T: BitwiseCopyable {}

func test<T, BCG: BitwiseCopyable>(_ t: T, // expected-error {{'t' is borrowed and cannot be consumed}}
                                   _ bcg: BCG, // expected-error {{'bcg' is borrowed and cannot be consumed}}
                                   _ cbcg_generic: ConditionallyBC<BCG>, // expected-error {{'cbcg_generic' is borrowed and cannot be consumed}}
                                   _ maybeBCG: BCG?, // expected-error {{'maybeBCG' is borrowed and cannot be consumed}}
                                   _ maybeT: T?, // expected-error {{'maybeT' is borrowed and cannot be consumed}}
                                   _ anyBC: any BitwiseCopyable, // expected-error {{'anyBC' is borrowed and cannot be consumed}}
                                   _ x: Int,
                                   _ point: Point,
                                   _ cbcg_concrete: ConditionallyBC<Int>,
                                   _ maybeFloat: Float?) {
  _ = consume t  // expected-note {{consumed here}}
  _ = consume bcg // expected-note {{consumed here}}
  _ = consume cbcg_generic // expected-note {{consumed here}}
  _ = consume maybeBCG // expected-note {{consumed here}}
  _ = consume maybeT // expected-note {{consumed here}}
  _ = consume anyBC // expected-note {{consumed here}}

  _ = consume x // expected-warning {{'consume' applied to bitwise-copyable type 'Int' has no effect}}{{7-15=}}
  _ = consume point // expected-warning {{'consume' applied to bitwise-copyable type 'Point' has no effect}}{{7-15=}}
  _ = consume  cbcg_concrete // expected-warning {{'consume' applied to bitwise-copyable type 'ConditionallyBC<Int>' has no effect}}{{7-16=}}
   _ = consume maybeFloat // expected-warning {{'consume' applied to bitwise-copyable type 'Float?' has no effect}}{{8-16=}}
}

func proofOfUseAfterConsume() -> Int {
  let someInt = 10
  let y = consume someInt // expected-warning {{'consume' applied to bitwise-copyable type 'Int' has no effect}}
  print(y)
  return someInt  // undiagnosed use-after-consume
}

func moreProofs(_ share: __shared Int,
                _ own: __owned Int,
                _ snd: sending Int, // expected-error {{'snd' used after consume}}
                _ ino: inout Int, // expected-error {{'ino' used after consume}}
                _ brw: borrowing Int, // expected-error {{'brw' is borrowed and cannot be consumed}}
                _ csm: consuming Int // expected-error {{'csm' consumed more than once}}
               ) {
  _ = consume share // expected-warning {{'consume' applied to bitwise-copyable type 'Int' has no effect}}
  _ = consume own // expected-warning {{'consume' applied to bitwise-copyable type 'Int' has no effect}}
  let _ = (share, own)

   _ = consume ino // expected-note {{consumed}}
   _ = consume brw // expected-note {{consumed}}
   _ = consume csm // expected-note {{consumed}}
   _ = consume csm // expected-note {{consumed}}
   _ = consume snd // expected-note {{consumed}}
   _ = snd // expected-note {{used}}
} // expected-note {{used here}}