]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/missing_const_for_fn/cant_be_const.rs
Fix missing_const_for_fn false positive
[rust.git] / tests / ui / missing_const_for_fn / cant_be_const.rs
index 4a2e6adb8f069e1b87b45cfc24b69430b6d3c385..f367279906fda13f992c8bd3bb715f556da6e7d6 100644 (file)
@@ -59,3 +59,34 @@ fn g() -> u32 {
 // Don't lint in external macros (derive)
 #[derive(PartialEq, Eq)]
 struct Point(isize, isize);
+
+impl std::ops::Add for Point {
+    type Output = Self;
+
+    // Don't lint in trait impls of derived methods
+    fn add(self, other: Self) -> Self {
+        Point(self.0 + other.0, self.1 + other.1)
+    }
+}
+
+mod with_drop {
+    pub struct A;
+    pub struct B;
+    impl Drop for A {
+        fn drop(&mut self) {}
+    }
+
+    impl A {
+        // This can not be const because the type implements `Drop`.
+        pub fn a(self) -> B {
+            B
+        }
+    }
+
+    impl B {
+        // This can not be const because `a` implements `Drop`.
+        pub fn a(self, a: A) -> B {
+            B
+        }
+    }
+}