mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-16 13:05:18 +03:00
74 lines
1.5 KiB
Rust
74 lines
1.5 KiB
Rust
#![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;
|
|
use std::fmt;
|
|
use std::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,
|
|
};
|
|
}
|
|
|
|
mod issue15691 {
|
|
use std::ops::{Deref, DerefMut};
|
|
|
|
struct A(B);
|
|
struct B;
|
|
|
|
impl Deref for A {
|
|
type Target = B;
|
|
fn deref(&self) -> &Self::Target {
|
|
&self.0
|
|
}
|
|
}
|
|
|
|
impl DerefMut for A {
|
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
&mut self.0
|
|
}
|
|
}
|
|
|
|
fn func() {
|
|
let mut a = Some(A(B));
|
|
let mut b = Some(B);
|
|
// Do not lint, we don't have `None => None`
|
|
let _ = match b {
|
|
Some(ref mut x) => Some(x),
|
|
None => a.as_deref_mut(),
|
|
};
|
|
}
|
|
}
|