mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-01 03:03:40 +00:00
internal: add deref_mut to minicore
This commit is contained in:
parent
2980fd430d
commit
d2c9f3add1
@ -1191,21 +1191,11 @@ fn main() {
|
||||
fn suggest_deref_mut() {
|
||||
check_relevance(
|
||||
r#"
|
||||
#[lang = "deref"]
|
||||
trait Deref {
|
||||
type Target;
|
||||
fn deref(&self) -> &Self::Target;
|
||||
}
|
||||
|
||||
#[lang = "deref_mut"]
|
||||
pub trait DerefMut: Deref {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target;
|
||||
}
|
||||
|
||||
//- minicore: deref_mut
|
||||
struct S;
|
||||
struct T(S);
|
||||
|
||||
impl Deref for T {
|
||||
impl core::ops::Deref for T {
|
||||
type Target = S;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
@ -1213,7 +1203,7 @@ impl Deref for T {
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for T {
|
||||
impl core::ops::DerefMut for T {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.0
|
||||
}
|
||||
@ -1232,12 +1222,12 @@ fn main() {
|
||||
lc m [local]
|
||||
lc t [local]
|
||||
lc &mut t [type+local]
|
||||
tt DerefMut []
|
||||
tt Deref []
|
||||
fn foo(…) []
|
||||
st T []
|
||||
st S []
|
||||
fn main() []
|
||||
fn foo(…) []
|
||||
md core []
|
||||
tt Sized []
|
||||
"#]],
|
||||
)
|
||||
}
|
||||
|
@ -129,8 +129,18 @@ impl Fixture {
|
||||
if line.starts_with("//-") {
|
||||
let meta = Fixture::parse_meta_line(line);
|
||||
res.push(meta)
|
||||
} else if let Some(entry) = res.last_mut() {
|
||||
entry.text.push_str(line);
|
||||
} else {
|
||||
if line.starts_with("// ")
|
||||
&& line.contains(":")
|
||||
&& !line.contains("::")
|
||||
&& line.chars().all(|it| !it.is_uppercase())
|
||||
{
|
||||
panic!("looks like invalid metadata line: {:?}", line)
|
||||
}
|
||||
|
||||
if let Some(entry) = res.last_mut() {
|
||||
entry.text.push_str(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -276,38 +286,44 @@ impl MiniCore {
|
||||
}
|
||||
}
|
||||
|
||||
let mut curr_region = "";
|
||||
let mut active_regions = Vec::new();
|
||||
let mut seen_regions = Vec::new();
|
||||
for line in lines {
|
||||
let trimmed = line.trim();
|
||||
if let Some(region) = trimmed.strip_prefix("// region:") {
|
||||
assert_eq!(curr_region, "");
|
||||
curr_region = region;
|
||||
active_regions.push(region);
|
||||
continue;
|
||||
}
|
||||
if let Some(region) = trimmed.strip_prefix("// endregion:") {
|
||||
assert_eq!(curr_region, region);
|
||||
curr_region = "";
|
||||
let prev = active_regions.pop().unwrap();
|
||||
assert_eq!(prev, region);
|
||||
continue;
|
||||
}
|
||||
seen_regions.push(curr_region);
|
||||
|
||||
let mut flag = curr_region;
|
||||
let mut line_region = false;
|
||||
if let Some(idx) = trimmed.find("// :") {
|
||||
flag = &trimmed[idx + "// :".len()..];
|
||||
line_region = true;
|
||||
active_regions.push(&trimmed[idx + "// :".len()..]);
|
||||
}
|
||||
|
||||
let skip = if flag == "" {
|
||||
false
|
||||
} else {
|
||||
assert!(!flag.starts_with(' '), "region marker starts with a space: {:?}", flag);
|
||||
self.assert_valid_flag(flag);
|
||||
!self.has_flag(flag)
|
||||
};
|
||||
let mut keep = true;
|
||||
for ®ion in &active_regions {
|
||||
assert!(
|
||||
!region.starts_with(' '),
|
||||
"region marker starts with a space: {:?}",
|
||||
region
|
||||
);
|
||||
self.assert_valid_flag(region);
|
||||
seen_regions.push(region);
|
||||
keep &= self.has_flag(region);
|
||||
}
|
||||
|
||||
if !skip {
|
||||
if keep {
|
||||
buf.push_str(line)
|
||||
}
|
||||
if line_region {
|
||||
active_regions.pop().unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
for flag in &self.valid_flags {
|
||||
@ -315,7 +331,7 @@ impl MiniCore {
|
||||
panic!("unused minicore flag: {:?}", flag);
|
||||
}
|
||||
}
|
||||
|
||||
format!("{}", buf);
|
||||
buf
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
//! range:
|
||||
//! unsize: sized
|
||||
//! deref: sized
|
||||
//! deref_mut: deref
|
||||
//! coerce_unsized: unsize
|
||||
//! pin:
|
||||
//! future: pin
|
||||
@ -64,8 +65,15 @@ pub mod ops {
|
||||
type Target: ?Sized;
|
||||
fn deref(&self) -> &Self::Target;
|
||||
}
|
||||
// region:deref_mut
|
||||
#[lang = "deref_mut"]
|
||||
pub trait DerefMut: Deref {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target;
|
||||
}
|
||||
// endregion:deref_mut
|
||||
}
|
||||
pub use self::deref::Deref;
|
||||
pub use self::deref::DerefMut; //:deref_mut
|
||||
// endregion:deref
|
||||
|
||||
// region:range
|
||||
|
Loading…
Reference in New Issue
Block a user