summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/match_as_ref.fixed
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/clippy/tests/ui/match_as_ref.fixed')
-rw-r--r--src/tools/clippy/tests/ui/match_as_ref.fixed43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/match_as_ref.fixed b/src/tools/clippy/tests/ui/match_as_ref.fixed
new file mode 100644
index 000000000..ddfa1e741
--- /dev/null
+++ b/src/tools/clippy/tests/ui/match_as_ref.fixed
@@ -0,0 +1,43 @@
+// run-rustfix
+
+#![allow(unused)]
+#![warn(clippy::match_as_ref)]
+
+fn match_as_ref() {
+ let owned: Option<()> = None;
+ let borrowed: Option<&()> = owned.as_ref();
+
+ let mut mut_owned: Option<()> = None;
+ let borrow_mut: Option<&mut ()> = mut_owned.as_mut();
+}
+
+mod issue4437 {
+ use std::{error::Error, fmt, num::ParseIntError};
+
+ #[derive(Debug)]
+ struct E {
+ source: Option<ParseIntError>,
+ }
+
+ impl Error for E {
+ fn source(&self) -> Option<&(dyn Error + 'static)> {
+ self.source.as_ref().map(|x| x as _)
+ }
+ }
+
+ impl fmt::Display for E {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ unimplemented!()
+ }
+ }
+}
+
+fn main() {
+ // Don't lint
+ let _ = match Some(0) {
+ #[cfg(feature = "foo")]
+ Some(ref x) if *x > 50 => None,
+ Some(ref x) => Some(x),
+ None => None,
+ };
+}