fail_generic_copy.carbon 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/convert.carbon
  6. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/generic/fail_generic_copy.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/generic/fail_generic_copy.carbon
  12. // --- fail_return.carbon
  13. library "[[@TEST_NAME]]";
  14. fn F[T:! type](x: T) -> T {
  15. // CHECK:STDERR: fail_return.carbon:[[@LINE+7]]:10: error: cannot copy value of type `T` [CopyOfUncopyableType]
  16. // CHECK:STDERR: return x;
  17. // CHECK:STDERR: ^
  18. // CHECK:STDERR: fail_return.carbon:[[@LINE+4]]:10: note: type `T` does not implement interface `Core.Copy` [MissingImplInMemberAccessNote]
  19. // CHECK:STDERR: return x;
  20. // CHECK:STDERR: ^
  21. // CHECK:STDERR:
  22. return x;
  23. }
  24. // --- fail_var.carbon
  25. library "[[@TEST_NAME]]";
  26. fn F[T:! Core.Destroy](x: T) {
  27. // CHECK:STDERR: fail_var.carbon:[[@LINE+7]]:14: error: cannot copy value of type `T` [CopyOfUncopyableType]
  28. // CHECK:STDERR: var y: T = x;
  29. // CHECK:STDERR: ^
  30. // CHECK:STDERR: fail_var.carbon:[[@LINE+4]]:14: note: type `T` does not implement interface `Core.Copy` [MissingImplInMemberAccessNote]
  31. // CHECK:STDERR: var y: T = x;
  32. // CHECK:STDERR: ^
  33. // CHECK:STDERR:
  34. var y: T = x;
  35. }