Skip to content

Commit 4b4a5b4

Browse files
committed
test(stack-encrypt): pin the borrowed element refusal on the trait, not the method
Calling `encrypt_into` as a method on `Vec<&str>` fails method resolution (E0599), and rustc then quotes the `Vec` definition from the standard library source when the `rust-src` component is installed. CI's toolchain does not install it, so the recorded expectation matched locally and not in CI. Calling the trait function directly fails on the element bound instead (`&str: OpaqueEncode`), which names the actual refusal and prints the same text with or without `rust-src`.
1 parent c762f40 commit 4b4a5b4

2 files changed

Lines changed: 45 additions & 31 deletions

File tree

‎packages/stack-encrypt/tests/ui/owned_collection_elements.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use stack_encrypt::{Ciphertext, DecryptFrom, EncryptInto};
99
fn unsupported<K: 'static>(keyset: &stack_encrypt::KeysetCipher<'_, K>, column: Vec<Ciphertext>) {
1010
let _ = vec![1u8, 2].encrypt_into::<Vec<Ciphertext>, _>(keyset);
1111
let _ = vec![Some(1i32), None].encrypt_into::<Vec<Ciphertext>, _>(keyset);
12-
let _ = vec!["borrowed", "plaintext"].encrypt_into::<Vec<Ciphertext>, _>(keyset);
12+
let _ = EncryptInto::encrypt_into::<Vec<Ciphertext>, _>(vec!["borrowed", "plaintext"], keyset);
1313
let _ = vec![1u8, 2].encrypt_into::<Ciphertext, _>(keyset);
1414
let _ = vec![1i32, 2].encrypt_into::<Ciphertext, _>(keyset);
1515
let _ = Vec::<u8>::decrypt_from(column.clone(), keyset);

‎packages/stack-encrypt/tests/ui/owned_collection_elements.stderr‎

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -38,37 +38,51 @@ error[E0277]: the trait bound `Option<i32>: OpaqueEncode` is not satisfied
3838
= note: 1 redundant requirement hidden
3939
= note: required for `Vec<stack_encrypt::Ciphertext>` to implement `EncryptTarget<Vec<Option<i32>>>`
4040

41-
error[E0599]: the method `encrypt_into` exists for struct `Vec<&str>`, but its trait bounds were not satisfied
42-
--> tests/ui/owned_collection_elements.rs:12:43
43-
|
44-
12 | let _ = vec!["borrowed", "plaintext"].encrypt_into::<Vec<Ciphertext>, _>(keyset);
45-
| ^^^^^^^^^^^^
46-
|
47-
::: $RUST/alloc/src/vec/mod.rs
48-
|
49-
| pub struct Vec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global> {
50-
| ------------------------------------------------------------------------------------------------ doesn't satisfy `Vec<&str>: stack_encrypt::EncryptInto` or `Vec<&str>: zeroize::Zeroize`
51-
|
52-
= note: the following trait bounds were not satisfied:
53-
`Vec<&str>: zeroize::Zeroize`
54-
which is required by `Vec<&str>: stack_encrypt::EncryptInto`
55-
`&Vec<&str>: zeroize::Zeroize`
56-
which is required by `&Vec<&str>: stack_encrypt::EncryptInto`
57-
`&mut Vec<&str>: zeroize::Zeroize`
58-
which is required by `&mut Vec<&str>: stack_encrypt::EncryptInto`
59-
`[&str]: Sized`
60-
which is required by `[&str]: stack_encrypt::EncryptInto`
61-
`[&str]: zeroize::Zeroize`
62-
which is required by `[&str]: stack_encrypt::EncryptInto`
63-
`&[&str]: zeroize::Zeroize`
64-
which is required by `&[&str]: stack_encrypt::EncryptInto`
65-
`&mut [&str]: zeroize::Zeroize`
66-
which is required by `&mut [&str]: stack_encrypt::EncryptInto`
67-
= help: items from traits can only be used if the trait is in scope
68-
help: trait `LegacyEncryptInto` which provides `encrypt_into` is implemented but not in scope; perhaps you want to import it
69-
|
70-
8 + use stack_encrypt::target::legacy::EncryptInto;
41+
error[E0277]: the trait bound `&str: OpaqueEncode` is not satisfied
42+
--> tests/ui/owned_collection_elements.rs:12:41
7143
|
44+
12 | let _ = EncryptInto::encrypt_into::<Vec<Ciphertext>, _>(vec!["borrowed", "plaintext"], keyset);
45+
| ^^^^^^^^^^^^^^^ the trait `OpaqueEncode` is not implemented for `&str`
46+
|
47+
help: the trait `OpaqueEncode` is implemented for `std::string::String`
48+
--> src/scalar.rs
49+
|
50+
| impl OpaqueEncode for $ty {}
51+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
52+
...
53+
| opaque!(bool, i8, i16, i32, i64, i128, u16, u32, u64, u128, f32, f64, String);
54+
| ----------------------------------------------------------------------------- in this macro invocation
55+
= note: required for `stack_encrypt::Ciphertext` to implement `EncryptTarget<&str>`
56+
= note: 1 redundant requirement hidden
57+
= note: required for `Vec<stack_encrypt::Ciphertext>` to implement `EncryptTarget<Vec<&str>>`
58+
note: required by a bound in `stack_encrypt::EncryptInto::encrypt_into`
59+
--> src/target/conversion.rs
60+
|
61+
| fn encrypt_into<'a, T, K: 'static>(self, cipher: &'a KeysetCipher<'_, K>) -> Pending<'a, T, K>
62+
| ------------ required by a bound in this associated function
63+
| where
64+
| T: EncryptTarget<Self>,
65+
| ^^^^^^^^^^^^^^^^^^^ required by this bound in `EncryptInto::encrypt_into`
66+
= note: this error originates in the macro `opaque` (in Nightly builds, run with -Z macro-backtrace for more info)
67+
68+
error[E0277]: the trait bound `&str: zeroize::Zeroize` is not satisfied
69+
--> tests/ui/owned_collection_elements.rs:12:13
70+
|
71+
12 | let _ = EncryptInto::encrypt_into::<Vec<Ciphertext>, _>(vec!["borrowed", "plaintext"], keyset);
72+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `zeroize::DefaultIsZeroes` is not implemented for `&str`
73+
|
74+
= help: the following other types implement trait `zeroize::DefaultIsZeroes`:
75+
()
76+
PhantomPinned
77+
bool
78+
char
79+
f32
80+
f64
81+
i128
82+
i16
83+
and $N others
84+
= note: required for `&str` to implement `zeroize::Zeroize`
85+
= note: required for `Vec<stack_encrypt::Ciphertext>` to implement `EncryptTarget<Vec<&str>>`
7286

7387
error[E0277]: the trait bound `Vec<u8>: OpaqueEncode` is not satisfied
7488
--> tests/ui/owned_collection_elements.rs:13:26

0 commit comments

Comments
 (0)