aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-06-16 08:30:29 +0100
committerAleksey Kladov <[email protected]>2021-06-16 08:30:29 +0100
commitd2c9f3add10a020d6ef7b674b7a722a1d0846f2d (patch)
treea20045a4daf48f3de43b96dc623422e895df9fc2 /crates
parent2980fd430dbe30d5d8fd28091a8c47b3ffd4008f (diff)
internal: add deref_mut to minicore
Diffstat (limited to 'crates')
-rw-r--r--crates/ide_completion/src/render.rs22
-rw-r--r--crates/test_utils/src/fixture.rs54
-rw-r--r--crates/test_utils/src/minicore.rs8
3 files changed, 49 insertions, 35 deletions
diff --git a/crates/ide_completion/src/render.rs b/crates/ide_completion/src/render.rs
index 3eb51e80b..fac83b650 100644
--- a/crates/ide_completion/src/render.rs
+++ b/crates/ide_completion/src/render.rs
@@ -1191,21 +1191,11 @@ fn main() {
1191 fn suggest_deref_mut() { 1191 fn suggest_deref_mut() {
1192 check_relevance( 1192 check_relevance(
1193 r#" 1193 r#"
1194#[lang = "deref"] 1194//- minicore: deref_mut
1195trait Deref {
1196 type Target;
1197 fn deref(&self) -> &Self::Target;
1198}
1199
1200#[lang = "deref_mut"]
1201pub trait DerefMut: Deref {
1202 fn deref_mut(&mut self) -> &mut Self::Target;
1203}
1204
1205struct S; 1195struct S;
1206struct T(S); 1196struct T(S);
1207 1197
1208impl Deref for T { 1198impl core::ops::Deref for T {
1209 type Target = S; 1199 type Target = S;
1210 1200
1211 fn deref(&self) -> &Self::Target { 1201 fn deref(&self) -> &Self::Target {
@@ -1213,7 +1203,7 @@ impl Deref for T {
1213 } 1203 }
1214} 1204}
1215 1205
1216impl DerefMut for T { 1206impl core::ops::DerefMut for T {
1217 fn deref_mut(&mut self) -> &mut Self::Target { 1207 fn deref_mut(&mut self) -> &mut Self::Target {
1218 &mut self.0 1208 &mut self.0
1219 } 1209 }
@@ -1232,12 +1222,12 @@ fn main() {
1232 lc m [local] 1222 lc m [local]
1233 lc t [local] 1223 lc t [local]
1234 lc &mut t [type+local] 1224 lc &mut t [type+local]
1235 tt DerefMut []
1236 tt Deref []
1237 fn foo(…) []
1238 st T [] 1225 st T []
1239 st S [] 1226 st S []
1240 fn main() [] 1227 fn main() []
1228 fn foo(…) []
1229 md core []
1230 tt Sized []
1241 "#]], 1231 "#]],
1242 ) 1232 )
1243 } 1233 }
diff --git a/crates/test_utils/src/fixture.rs b/crates/test_utils/src/fixture.rs
index 6ba112de8..313088c37 100644
--- a/crates/test_utils/src/fixture.rs
+++ b/crates/test_utils/src/fixture.rs
@@ -129,8 +129,18 @@ impl Fixture {
129 if line.starts_with("//-") { 129 if line.starts_with("//-") {
130 let meta = Fixture::parse_meta_line(line); 130 let meta = Fixture::parse_meta_line(line);
131 res.push(meta) 131 res.push(meta)
132 } else if let Some(entry) = res.last_mut() { 132 } else {
133 entry.text.push_str(line); 133 if line.starts_with("// ")
134 && line.contains(":")
135 && !line.contains("::")
136 && line.chars().all(|it| !it.is_uppercase())
137 {
138 panic!("looks like invalid metadata line: {:?}", line)
139 }
140
141 if let Some(entry) = res.last_mut() {
142 entry.text.push_str(line);
143 }
134 } 144 }
135 } 145 }
136 146
@@ -276,38 +286,44 @@ impl MiniCore {
276 } 286 }
277 } 287 }
278 288
279 let mut curr_region = ""; 289 let mut active_regions = Vec::new();
280 let mut seen_regions = Vec::new(); 290 let mut seen_regions = Vec::new();
281 for line in lines { 291 for line in lines {
282 let trimmed = line.trim(); 292 let trimmed = line.trim();
283 if let Some(region) = trimmed.strip_prefix("// region:") { 293 if let Some(region) = trimmed.strip_prefix("// region:") {
284 assert_eq!(curr_region, ""); 294 active_regions.push(region);
285 curr_region = region;
286 continue; 295 continue;
287 } 296 }
288 if let Some(region) = trimmed.strip_prefix("// endregion:") { 297 if let Some(region) = trimmed.strip_prefix("// endregion:") {
289 assert_eq!(curr_region, region); 298 let prev = active_regions.pop().unwrap();
290 curr_region = ""; 299 assert_eq!(prev, region);
291 continue; 300 continue;
292 } 301 }
293 seen_regions.push(curr_region);
294 302
295 let mut flag = curr_region; 303 let mut line_region = false;
296 if let Some(idx) = trimmed.find("// :") { 304 if let Some(idx) = trimmed.find("// :") {
297 flag = &trimmed[idx + "// :".len()..]; 305 line_region = true;
306 active_regions.push(&trimmed[idx + "// :".len()..]);
298 } 307 }
299 308
300 let skip = if flag == "" { 309 let mut keep = true;
301 false 310 for &region in &active_regions {
302 } else { 311 assert!(
303 assert!(!flag.starts_with(' '), "region marker starts with a space: {:?}", flag); 312 !region.starts_with(' '),
304 self.assert_valid_flag(flag); 313 "region marker starts with a space: {:?}",
305 !self.has_flag(flag) 314 region
306 }; 315 );
316 self.assert_valid_flag(region);
317 seen_regions.push(region);
318 keep &= self.has_flag(region);
319 }
307 320
308 if !skip { 321 if keep {
309 buf.push_str(line) 322 buf.push_str(line)
310 } 323 }
324 if line_region {
325 active_regions.pop().unwrap();
326 }
311 } 327 }
312 328
313 for flag in &self.valid_flags { 329 for flag in &self.valid_flags {
@@ -315,7 +331,7 @@ impl MiniCore {
315 panic!("unused minicore flag: {:?}", flag); 331 panic!("unused minicore flag: {:?}", flag);
316 } 332 }
317 } 333 }
318 334 format!("{}", buf);
319 buf 335 buf
320 } 336 }
321} 337}
diff --git a/crates/test_utils/src/minicore.rs b/crates/test_utils/src/minicore.rs
index 5ff60178c..8555ff935 100644
--- a/crates/test_utils/src/minicore.rs
+++ b/crates/test_utils/src/minicore.rs
@@ -13,6 +13,7 @@
13//! range: 13//! range:
14//! unsize: sized 14//! unsize: sized
15//! deref: sized 15//! deref: sized
16//! deref_mut: deref
16//! coerce_unsized: unsize 17//! coerce_unsized: unsize
17//! pin: 18//! pin:
18//! future: pin 19//! future: pin
@@ -64,8 +65,15 @@ pub mod ops {
64 type Target: ?Sized; 65 type Target: ?Sized;
65 fn deref(&self) -> &Self::Target; 66 fn deref(&self) -> &Self::Target;
66 } 67 }
68 // region:deref_mut
69 #[lang = "deref_mut"]
70 pub trait DerefMut: Deref {
71 fn deref_mut(&mut self) -> &mut Self::Target;
72 }
73 // endregion:deref_mut
67 } 74 }
68 pub use self::deref::Deref; 75 pub use self::deref::Deref;
76 pub use self::deref::DerefMut; //:deref_mut
69 // endregion:deref 77 // endregion:deref
70 78
71 // region:range 79 // region:range