mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
internal: use minicore deref more
This commit is contained in:
parent
991919e71f
commit
89a0e58393
5 changed files with 81 additions and 127 deletions
|
@ -114,6 +114,9 @@ impl ChangeFixture {
|
||||||
|
|
||||||
let meta = FileMeta::from(entry);
|
let meta = FileMeta::from(entry);
|
||||||
assert!(meta.path.starts_with(&source_root_prefix));
|
assert!(meta.path.starts_with(&source_root_prefix));
|
||||||
|
if !meta.deps.is_empty() {
|
||||||
|
assert!(meta.krate.is_some(), "can't specify deps without naming the crate")
|
||||||
|
}
|
||||||
|
|
||||||
if meta.introduce_new_source_root {
|
if meta.introduce_new_source_root {
|
||||||
roots.push(SourceRoot::new_local(mem::take(&mut file_set)));
|
roots.push(SourceRoot::new_local(mem::take(&mut file_set)));
|
||||||
|
@ -199,6 +202,7 @@ impl ChangeFixture {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
struct FileMeta {
|
struct FileMeta {
|
||||||
path: String,
|
path: String,
|
||||||
krate: Option<String>,
|
krate: Option<String>,
|
||||||
|
|
|
@ -792,6 +792,7 @@ fn issue_4800() {
|
||||||
fn issue_4966() {
|
fn issue_4966() {
|
||||||
check_infer(
|
check_infer(
|
||||||
r#"
|
r#"
|
||||||
|
//- minicore: deref
|
||||||
pub trait IntoIterator {
|
pub trait IntoIterator {
|
||||||
type Item;
|
type Item;
|
||||||
}
|
}
|
||||||
|
@ -802,12 +803,7 @@ fn issue_4966() {
|
||||||
|
|
||||||
struct Vec<T> {}
|
struct Vec<T> {}
|
||||||
|
|
||||||
#[lang = "deref"]
|
impl<T> core::ops::Deref for Vec<T> {
|
||||||
pub trait Deref {
|
|
||||||
type Target;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> Deref for Vec<T> {
|
|
||||||
type Target = [T];
|
type Target = [T];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -824,23 +820,23 @@ fn issue_4966() {
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
270..274 'iter': T
|
225..229 'iter': T
|
||||||
289..291 '{}': ()
|
244..246 '{}': ()
|
||||||
303..447 '{ ...r(); }': ()
|
258..402 '{ ...r(); }': ()
|
||||||
313..318 'inner': Map<|&f64| -> f64>
|
268..273 'inner': Map<|&f64| -> f64>
|
||||||
321..345 'Map { ... 0.0 }': Map<|&f64| -> f64>
|
276..300 'Map { ... 0.0 }': Map<|&f64| -> f64>
|
||||||
330..343 '|_: &f64| 0.0': |&f64| -> f64
|
285..298 '|_: &f64| 0.0': |&f64| -> f64
|
||||||
331..332 '_': &f64
|
286..287 '_': &f64
|
||||||
340..343 '0.0': f64
|
295..298 '0.0': f64
|
||||||
356..362 'repeat': Repeat<Map<|&f64| -> f64>>
|
311..317 'repeat': Repeat<Map<|&f64| -> f64>>
|
||||||
365..390 'Repeat...nner }': Repeat<Map<|&f64| -> f64>>
|
320..345 'Repeat...nner }': Repeat<Map<|&f64| -> f64>>
|
||||||
383..388 'inner': Map<|&f64| -> f64>
|
338..343 'inner': Map<|&f64| -> f64>
|
||||||
401..404 'vec': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>>
|
356..359 'vec': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>>
|
||||||
407..416 'from_iter': fn from_iter<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>, Repeat<Map<|&f64| -> f64>>>(Repeat<Map<|&f64| -> f64>>) -> Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>>
|
362..371 'from_iter': fn from_iter<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>, Repeat<Map<|&f64| -> f64>>>(Repeat<Map<|&f64| -> f64>>) -> Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>>
|
||||||
407..424 'from_i...epeat)': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>>
|
362..379 'from_i...epeat)': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>>
|
||||||
417..423 'repeat': Repeat<Map<|&f64| -> f64>>
|
372..378 'repeat': Repeat<Map<|&f64| -> f64>>
|
||||||
431..434 'vec': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>>
|
386..389 'vec': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>>
|
||||||
431..444 'vec.foo_bar()': {unknown}
|
386..399 'vec.foo_bar()': {unknown}
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -853,12 +853,9 @@ fn test<T>(t: T) { t.foo(); }
|
||||||
fn generic_param_env_deref() {
|
fn generic_param_env_deref() {
|
||||||
check_types(
|
check_types(
|
||||||
r#"
|
r#"
|
||||||
#[lang = "deref"]
|
//- minicore: deref
|
||||||
trait Deref {
|
|
||||||
type Target;
|
|
||||||
}
|
|
||||||
trait Trait {}
|
trait Trait {}
|
||||||
impl<T> Deref for T where T: Trait {
|
impl<T> core::ops::Deref for T where T: Trait {
|
||||||
type Target = i128;
|
type Target = i128;
|
||||||
}
|
}
|
||||||
fn test<T: Trait>(t: T) { (*t); }
|
fn test<T: Trait>(t: T) { (*t); }
|
||||||
|
@ -1727,20 +1724,7 @@ fn test() {
|
||||||
fn fn_trait_deref_with_ty_default() {
|
fn fn_trait_deref_with_ty_default() {
|
||||||
check_infer(
|
check_infer(
|
||||||
r#"
|
r#"
|
||||||
#[lang = "deref"]
|
//- minicore: deref, fn
|
||||||
trait Deref {
|
|
||||||
type Target;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[lang="fn_once"]
|
|
||||||
trait FnOnce<Args> {
|
|
||||||
type Output;
|
|
||||||
|
|
||||||
fn call_once(self, args: Args) -> Self::Output;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Foo;
|
struct Foo;
|
||||||
|
|
||||||
impl Foo {
|
impl Foo {
|
||||||
|
@ -1753,7 +1737,7 @@ impl<T, F> Lazy<T, F> {
|
||||||
pub fn new(f: F) -> Lazy<T, F> {}
|
pub fn new(f: F) -> Lazy<T, F> {}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, F: FnOnce() -> T> Deref for Lazy<T, F> {
|
impl<T, F: FnOnce() -> T> core::ops::Deref for Lazy<T, F> {
|
||||||
type Target = T;
|
type Target = T;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1767,32 +1751,29 @@ fn test() {
|
||||||
let r2 = lazy2.foo();
|
let r2 = lazy2.foo();
|
||||||
}"#,
|
}"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
64..68 'self': &Self
|
36..40 'self': &Foo
|
||||||
165..169 'self': Self
|
51..53 '{}': ()
|
||||||
171..175 'args': Args
|
131..132 'f': F
|
||||||
239..243 'self': &Foo
|
151..153 '{}': ()
|
||||||
254..256 '{}': ()
|
251..497 '{ ...o(); }': ()
|
||||||
334..335 'f': F
|
261..266 'lazy1': Lazy<Foo, || -> Foo>
|
||||||
354..356 '{}': ()
|
283..292 'Lazy::new': fn new<Foo, || -> Foo>(|| -> Foo) -> Lazy<Foo, || -> Foo>
|
||||||
443..689 '{ ...o(); }': ()
|
283..300 'Lazy::...| Foo)': Lazy<Foo, || -> Foo>
|
||||||
453..458 'lazy1': Lazy<Foo, || -> Foo>
|
293..299 '|| Foo': || -> Foo
|
||||||
475..484 'Lazy::new': fn new<Foo, || -> Foo>(|| -> Foo) -> Lazy<Foo, || -> Foo>
|
296..299 'Foo': Foo
|
||||||
475..492 'Lazy::...| Foo)': Lazy<Foo, || -> Foo>
|
310..312 'r1': usize
|
||||||
485..491 '|| Foo': || -> Foo
|
315..320 'lazy1': Lazy<Foo, || -> Foo>
|
||||||
488..491 'Foo': Foo
|
315..326 'lazy1.foo()': usize
|
||||||
502..504 'r1': usize
|
368..383 'make_foo_fn_ptr': fn() -> Foo
|
||||||
507..512 'lazy1': Lazy<Foo, || -> Foo>
|
399..410 'make_foo_fn': fn make_foo_fn() -> Foo
|
||||||
507..518 'lazy1.foo()': usize
|
420..425 'lazy2': Lazy<Foo, fn() -> Foo>
|
||||||
560..575 'make_foo_fn_ptr': fn() -> Foo
|
442..451 'Lazy::new': fn new<Foo, fn() -> Foo>(fn() -> Foo) -> Lazy<Foo, fn() -> Foo>
|
||||||
591..602 'make_foo_fn': fn make_foo_fn() -> Foo
|
442..468 'Lazy::...n_ptr)': Lazy<Foo, fn() -> Foo>
|
||||||
612..617 'lazy2': Lazy<Foo, fn() -> Foo>
|
452..467 'make_foo_fn_ptr': fn() -> Foo
|
||||||
634..643 'Lazy::new': fn new<Foo, fn() -> Foo>(fn() -> Foo) -> Lazy<Foo, fn() -> Foo>
|
478..480 'r2': usize
|
||||||
634..660 'Lazy::...n_ptr)': Lazy<Foo, fn() -> Foo>
|
483..488 'lazy2': Lazy<Foo, fn() -> Foo>
|
||||||
644..659 'make_foo_fn_ptr': fn() -> Foo
|
483..494 'lazy2.foo()': usize
|
||||||
670..672 'r2': usize
|
357..359 '{}': ()
|
||||||
675..680 'lazy2': Lazy<Foo, fn() -> Foo>
|
|
||||||
675..686 'lazy2.foo()': usize
|
|
||||||
549..551 '{}': ()
|
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -2941,28 +2922,13 @@ fn infer_box_fn_arg() {
|
||||||
// The type mismatch is because we don't define Unsize and CoerceUnsized
|
// The type mismatch is because we don't define Unsize and CoerceUnsized
|
||||||
check_infer_with_mismatches(
|
check_infer_with_mismatches(
|
||||||
r#"
|
r#"
|
||||||
//- /lib.rs deps:std
|
//- minicore: fn, deref, option
|
||||||
|
|
||||||
#[lang = "fn_once"]
|
|
||||||
pub trait FnOnce<Args> {
|
|
||||||
type Output;
|
|
||||||
|
|
||||||
extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[lang = "deref"]
|
|
||||||
pub trait Deref {
|
|
||||||
type Target: ?Sized;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[lang = "owned_box"]
|
#[lang = "owned_box"]
|
||||||
pub struct Box<T: ?Sized> {
|
pub struct Box<T: ?Sized> {
|
||||||
inner: *mut T,
|
inner: *mut T,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ?Sized> Deref for Box<T> {
|
impl<T: ?Sized> core::ops::Deref for Box<T> {
|
||||||
type Target = T;
|
type Target = T;
|
||||||
|
|
||||||
fn deref(&self) -> &T {
|
fn deref(&self) -> &T {
|
||||||
|
@ -2970,38 +2936,30 @@ impl<T: ?Sized> Deref for Box<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Option<T> {
|
|
||||||
None,
|
|
||||||
Some(T)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn foo() {
|
fn foo() {
|
||||||
let s = Option::None;
|
let s = None;
|
||||||
let f: Box<dyn FnOnce(&Option<i32>)> = box (|ps| {});
|
let f: Box<dyn FnOnce(&Option<i32>)> = box (|ps| {});
|
||||||
f(&s);
|
f(&s);
|
||||||
}"#,
|
}"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
100..104 'self': Self
|
154..158 'self': &Box<T>
|
||||||
106..110 'args': Args
|
166..193 '{ ... }': &T
|
||||||
214..218 'self': &Self
|
176..187 '&self.inner': &*mut T
|
||||||
384..388 'self': &Box<T>
|
177..181 'self': &Box<T>
|
||||||
396..423 '{ ... }': &T
|
177..187 'self.inner': *mut T
|
||||||
406..417 '&self.inner': &*mut T
|
206..296 '{ ...&s); }': ()
|
||||||
407..411 'self': &Box<T>
|
216..217 's': Option<i32>
|
||||||
407..417 'self.inner': *mut T
|
220..224 'None': Option<i32>
|
||||||
478..576 '{ ...&s); }': ()
|
234..235 'f': Box<dyn FnOnce(&Option<i32>)>
|
||||||
488..489 's': Option<i32>
|
269..282 'box (|ps| {})': Box<|{unknown}| -> ()>
|
||||||
492..504 'Option::None': Option<i32>
|
274..281 '|ps| {}': |{unknown}| -> ()
|
||||||
514..515 'f': Box<dyn FnOnce(&Option<i32>)>
|
275..277 'ps': {unknown}
|
||||||
549..562 'box (|ps| {})': Box<|{unknown}| -> ()>
|
279..281 '{}': ()
|
||||||
554..561 '|ps| {}': |{unknown}| -> ()
|
288..289 'f': Box<dyn FnOnce(&Option<i32>)>
|
||||||
555..557 'ps': {unknown}
|
288..293 'f(&s)': ()
|
||||||
559..561 '{}': ()
|
290..292 '&s': &Option<i32>
|
||||||
568..569 'f': Box<dyn FnOnce(&Option<i32>)>
|
291..292 's': Option<i32>
|
||||||
568..573 'f(&s)': ()
|
269..282: expected Box<dyn FnOnce(&Option<i32>)>, got Box<|{unknown}| -> ()>
|
||||||
570..572 '&s': &Option<i32>
|
|
||||||
571..572 's': Option<i32>
|
|
||||||
549..562: expected Box<dyn FnOnce(&Option<i32>)>, got Box<|{unknown}| -> ()>
|
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3014,8 +3014,8 @@ fn foo() {
|
||||||
file_id: FileId(
|
file_id: FileId(
|
||||||
1,
|
1,
|
||||||
),
|
),
|
||||||
full_range: 250..432,
|
full_range: 251..433,
|
||||||
focus_range: 289..295,
|
focus_range: 290..296,
|
||||||
name: "Future",
|
name: "Future",
|
||||||
kind: Trait,
|
kind: Trait,
|
||||||
description: "pub trait Future",
|
description: "pub trait Future",
|
||||||
|
|
|
@ -1269,16 +1269,11 @@ fn bar(t: &Foo) {}
|
||||||
fn suggest_deref_fn_ret() {
|
fn suggest_deref_fn_ret() {
|
||||||
check_relevance(
|
check_relevance(
|
||||||
r#"
|
r#"
|
||||||
#[lang = "deref"]
|
//- minicore: deref
|
||||||
trait Deref {
|
|
||||||
type Target;
|
|
||||||
fn deref(&self) -> &Self::Target;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct S;
|
struct S;
|
||||||
struct T(S);
|
struct T(S);
|
||||||
|
|
||||||
impl Deref for T {
|
impl core::ops::Deref for T {
|
||||||
type Target = S;
|
type Target = S;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
|
@ -1294,13 +1289,14 @@ fn main() {
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
tt Deref []
|
|
||||||
fn bar() []
|
|
||||||
fn &bar() [type]
|
|
||||||
fn foo(…) []
|
|
||||||
st T []
|
st T []
|
||||||
st S []
|
st S []
|
||||||
fn main() []
|
fn main() []
|
||||||
|
fn bar() []
|
||||||
|
fn &bar() [type]
|
||||||
|
fn foo(…) []
|
||||||
|
md core []
|
||||||
|
tt Sized []
|
||||||
"#]],
|
"#]],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue