summaryrefslogtreecommitdiffstats
path: root/tests/ui/btreemap
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
commit64d98f8ee037282c35007b64c2649055c56af1db (patch)
tree5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/btreemap
parentAdding debian version 1.67.1+dfsg1-1. (diff)
downloadrustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz
rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/btreemap')
-rw-r--r--tests/ui/btreemap/btreemap-index-mut.rs6
-rw-r--r--tests/ui/btreemap/btreemap-index-mut.stderr19
-rw-r--r--tests/ui/btreemap/btreemap_dropck.rs16
-rw-r--r--tests/ui/btreemap/btreemap_dropck.stderr13
-rw-r--r--tests/ui/btreemap/btreemap_into_iterator_lifetime.rs23
5 files changed, 77 insertions, 0 deletions
diff --git a/tests/ui/btreemap/btreemap-index-mut.rs b/tests/ui/btreemap/btreemap-index-mut.rs
new file mode 100644
index 000000000..62972acab
--- /dev/null
+++ b/tests/ui/btreemap/btreemap-index-mut.rs
@@ -0,0 +1,6 @@
+use std::collections::BTreeMap;
+
+fn main() {
+ let mut map = BTreeMap::<u32, u32>::new();
+ map[&0] = 1; //~ ERROR cannot assign
+}
diff --git a/tests/ui/btreemap/btreemap-index-mut.stderr b/tests/ui/btreemap/btreemap-index-mut.stderr
new file mode 100644
index 000000000..26f2a4c4b
--- /dev/null
+++ b/tests/ui/btreemap/btreemap-index-mut.stderr
@@ -0,0 +1,19 @@
+error[E0594]: cannot assign to data in an index of `BTreeMap<u32, u32>`
+ --> $DIR/btreemap-index-mut.rs:5:5
+ |
+LL | map[&0] = 1;
+ | ^^^^^^^^^^^ cannot assign
+ |
+ = help: trait `IndexMut` is required to modify indexed content, but it is not implemented for `BTreeMap<u32, u32>`
+help: to modify a `BTreeMap<u32, u32>`, use `.get_mut()`, `.insert()` or the entry API
+ |
+LL | map.insert(&0, 1);
+ | ~~~~~~~~ ~ +
+LL | map.get_mut(&0).map(|val| { *val = 1; });
+ | ~~~~~~~~~ ~~~~~~~~~~~~~~~~~~ ++++
+LL | let val = map.entry(&0).or_insert(1);
+ | +++++++++ ~~~~~~~ ~~~~~~~~~~~~ +
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0594`.
diff --git a/tests/ui/btreemap/btreemap_dropck.rs b/tests/ui/btreemap/btreemap_dropck.rs
new file mode 100644
index 000000000..c58727df3
--- /dev/null
+++ b/tests/ui/btreemap/btreemap_dropck.rs
@@ -0,0 +1,16 @@
+struct PrintOnDrop<'a>(&'a str);
+
+impl Drop for PrintOnDrop<'_> {
+ fn drop(&mut self) {
+ println!("printint: {}", self.0);
+ }
+}
+
+use std::collections::BTreeMap;
+use std::iter::FromIterator;
+
+fn main() {
+ let s = String::from("Hello World!");
+ let _map = BTreeMap::from_iter([((), PrintOnDrop(&s))]);
+ drop(s); //~ ERROR cannot move out of `s` because it is borrowed
+}
diff --git a/tests/ui/btreemap/btreemap_dropck.stderr b/tests/ui/btreemap/btreemap_dropck.stderr
new file mode 100644
index 000000000..e953e7ae8
--- /dev/null
+++ b/tests/ui/btreemap/btreemap_dropck.stderr
@@ -0,0 +1,13 @@
+error[E0505]: cannot move out of `s` because it is borrowed
+ --> $DIR/btreemap_dropck.rs:15:10
+ |
+LL | let _map = BTreeMap::from_iter([((), PrintOnDrop(&s))]);
+ | -- borrow of `s` occurs here
+LL | drop(s);
+ | ^ move out of `s` occurs here
+LL | }
+ | - borrow might be used here, when `_map` is dropped and runs the `Drop` code for type `BTreeMap`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0505`.
diff --git a/tests/ui/btreemap/btreemap_into_iterator_lifetime.rs b/tests/ui/btreemap/btreemap_into_iterator_lifetime.rs
new file mode 100644
index 000000000..fda825bc6
--- /dev/null
+++ b/tests/ui/btreemap/btreemap_into_iterator_lifetime.rs
@@ -0,0 +1,23 @@
+// check-pass
+
+use std::collections::{BTreeMap, HashMap};
+
+trait Map
+where
+ for<'a> &'a Self: IntoIterator<Item = (&'a Self::Key, &'a Self::Value)>,
+{
+ type Key;
+ type Value;
+}
+
+impl<K, V> Map for HashMap<K, V> {
+ type Key = K;
+ type Value = V;
+}
+
+impl<K, V> Map for BTreeMap<K, V> {
+ type Key = K;
+ type Value = V;
+}
+
+fn main() {}