mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 20:42:04 +00:00
Make known paths use core
instead of std
This commit is contained in:
parent
32157d48f4
commit
90331ea035
7 changed files with 52 additions and 48 deletions
|
@ -99,7 +99,7 @@ impl FunctionData {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn desugar_future_path(orig: TypeRef) -> Path {
|
fn desugar_future_path(orig: TypeRef) -> Path {
|
||||||
let path = path![std::future::Future];
|
let path = path![core::future::Future];
|
||||||
let mut generic_args: Vec<_> = std::iter::repeat(None).take(path.segments.len() - 1).collect();
|
let mut generic_args: Vec<_> = std::iter::repeat(None).take(path.segments.len() - 1).collect();
|
||||||
let mut last = GenericArgs::empty();
|
let mut last = GenericArgs::empty();
|
||||||
last.bindings.push(AssociatedTypeBinding {
|
last.bindings.push(AssociatedTypeBinding {
|
||||||
|
|
|
@ -323,16 +323,16 @@ pub use hir_expand::name as __name;
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! __known_path {
|
macro_rules! __known_path {
|
||||||
(std::iter::IntoIterator) => {};
|
(core::iter::IntoIterator) => {};
|
||||||
(std::result::Result) => {};
|
(core::result::Result) => {};
|
||||||
(std::ops::Range) => {};
|
(core::ops::Range) => {};
|
||||||
(std::ops::RangeFrom) => {};
|
(core::ops::RangeFrom) => {};
|
||||||
(std::ops::RangeFull) => {};
|
(core::ops::RangeFull) => {};
|
||||||
(std::ops::RangeTo) => {};
|
(core::ops::RangeTo) => {};
|
||||||
(std::ops::RangeToInclusive) => {};
|
(core::ops::RangeToInclusive) => {};
|
||||||
(std::ops::RangeInclusive) => {};
|
(core::ops::RangeInclusive) => {};
|
||||||
(std::future::Future) => {};
|
(core::future::Future) => {};
|
||||||
(std::ops::Try) => {};
|
(core::ops::Try) => {};
|
||||||
($path:path) => {
|
($path:path) => {
|
||||||
compile_error!("Please register your known path in the path module")
|
compile_error!("Please register your known path in the path module")
|
||||||
};
|
};
|
||||||
|
|
|
@ -226,17 +226,19 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
|
||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
let std_result_path = path![std::result::Result];
|
let core_result_path = path![core::result::Result];
|
||||||
|
|
||||||
let resolver = self.func.resolver(db.upcast());
|
let resolver = self.func.resolver(db.upcast());
|
||||||
let std_result_enum = match resolver.resolve_known_enum(db.upcast(), &std_result_path) {
|
let core_result_enum = match resolver.resolve_known_enum(db.upcast(), &core_result_path) {
|
||||||
Some(it) => it,
|
Some(it) => it,
|
||||||
_ => return,
|
_ => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
let std_result_ctor = TypeCtor::Adt(AdtId::EnumId(std_result_enum));
|
let core_result_ctor = TypeCtor::Adt(AdtId::EnumId(core_result_enum));
|
||||||
let params = match &mismatch.expected {
|
let params = match &mismatch.expected {
|
||||||
Ty::Apply(ApplicationTy { ctor, parameters }) if ctor == &std_result_ctor => parameters,
|
Ty::Apply(ApplicationTy { ctor, parameters }) if ctor == &core_result_ctor => {
|
||||||
|
parameters
|
||||||
|
}
|
||||||
_ => return,
|
_ => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -555,13 +555,13 @@ impl<'a> InferenceContext<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_into_iter_item(&self) -> Option<TypeAliasId> {
|
fn resolve_into_iter_item(&self) -> Option<TypeAliasId> {
|
||||||
let path = path![std::iter::IntoIterator];
|
let path = path![core::iter::IntoIterator];
|
||||||
let trait_ = self.resolver.resolve_known_trait(self.db.upcast(), &path)?;
|
let trait_ = self.resolver.resolve_known_trait(self.db.upcast(), &path)?;
|
||||||
self.db.trait_data(trait_).associated_type_by_name(&name![Item])
|
self.db.trait_data(trait_).associated_type_by_name(&name![Item])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_ops_try_ok(&self) -> Option<TypeAliasId> {
|
fn resolve_ops_try_ok(&self) -> Option<TypeAliasId> {
|
||||||
let path = path![std::ops::Try];
|
let path = path![core::ops::Try];
|
||||||
let trait_ = self.resolver.resolve_known_trait(self.db.upcast(), &path)?;
|
let trait_ = self.resolver.resolve_known_trait(self.db.upcast(), &path)?;
|
||||||
self.db.trait_data(trait_).associated_type_by_name(&name![Ok])
|
self.db.trait_data(trait_).associated_type_by_name(&name![Ok])
|
||||||
}
|
}
|
||||||
|
@ -587,37 +587,37 @@ impl<'a> InferenceContext<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_range_full(&self) -> Option<AdtId> {
|
fn resolve_range_full(&self) -> Option<AdtId> {
|
||||||
let path = path![std::ops::RangeFull];
|
let path = path![core::ops::RangeFull];
|
||||||
let struct_ = self.resolver.resolve_known_struct(self.db.upcast(), &path)?;
|
let struct_ = self.resolver.resolve_known_struct(self.db.upcast(), &path)?;
|
||||||
Some(struct_.into())
|
Some(struct_.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_range(&self) -> Option<AdtId> {
|
fn resolve_range(&self) -> Option<AdtId> {
|
||||||
let path = path![std::ops::Range];
|
let path = path![core::ops::Range];
|
||||||
let struct_ = self.resolver.resolve_known_struct(self.db.upcast(), &path)?;
|
let struct_ = self.resolver.resolve_known_struct(self.db.upcast(), &path)?;
|
||||||
Some(struct_.into())
|
Some(struct_.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_range_inclusive(&self) -> Option<AdtId> {
|
fn resolve_range_inclusive(&self) -> Option<AdtId> {
|
||||||
let path = path![std::ops::RangeInclusive];
|
let path = path![core::ops::RangeInclusive];
|
||||||
let struct_ = self.resolver.resolve_known_struct(self.db.upcast(), &path)?;
|
let struct_ = self.resolver.resolve_known_struct(self.db.upcast(), &path)?;
|
||||||
Some(struct_.into())
|
Some(struct_.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_range_from(&self) -> Option<AdtId> {
|
fn resolve_range_from(&self) -> Option<AdtId> {
|
||||||
let path = path![std::ops::RangeFrom];
|
let path = path![core::ops::RangeFrom];
|
||||||
let struct_ = self.resolver.resolve_known_struct(self.db.upcast(), &path)?;
|
let struct_ = self.resolver.resolve_known_struct(self.db.upcast(), &path)?;
|
||||||
Some(struct_.into())
|
Some(struct_.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_range_to(&self) -> Option<AdtId> {
|
fn resolve_range_to(&self) -> Option<AdtId> {
|
||||||
let path = path![std::ops::RangeTo];
|
let path = path![core::ops::RangeTo];
|
||||||
let struct_ = self.resolver.resolve_known_struct(self.db.upcast(), &path)?;
|
let struct_ = self.resolver.resolve_known_struct(self.db.upcast(), &path)?;
|
||||||
Some(struct_.into())
|
Some(struct_.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_range_to_inclusive(&self) -> Option<AdtId> {
|
fn resolve_range_to_inclusive(&self) -> Option<AdtId> {
|
||||||
let path = path![std::ops::RangeToInclusive];
|
let path = path![core::ops::RangeToInclusive];
|
||||||
let struct_ = self.resolver.resolve_known_struct(self.db.upcast(), &path)?;
|
let struct_ = self.resolver.resolve_known_struct(self.db.upcast(), &path)?;
|
||||||
Some(struct_.into())
|
Some(struct_.into())
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,7 @@ fn foo() {
|
||||||
fn infer_ranges() {
|
fn infer_ranges() {
|
||||||
let (db, pos) = TestDB::with_position(
|
let (db, pos) = TestDB::with_position(
|
||||||
r#"
|
r#"
|
||||||
//- /main.rs crate:main deps:std
|
//- /main.rs crate:main deps:core
|
||||||
fn test() {
|
fn test() {
|
||||||
let a = ..;
|
let a = ..;
|
||||||
let b = 1..;
|
let b = 1..;
|
||||||
|
@ -108,7 +108,7 @@ fn test() {
|
||||||
t<|>;
|
t<|>;
|
||||||
}
|
}
|
||||||
|
|
||||||
//- /std.rs crate:std
|
//- /core.rs crate:core
|
||||||
#[prelude_import] use prelude::*;
|
#[prelude_import] use prelude::*;
|
||||||
mod prelude {}
|
mod prelude {}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ use super::{infer, infer_with_mismatches, type_at, type_at_pos};
|
||||||
fn infer_await() {
|
fn infer_await() {
|
||||||
let (db, pos) = TestDB::with_position(
|
let (db, pos) = TestDB::with_position(
|
||||||
r#"
|
r#"
|
||||||
//- /main.rs crate:main deps:std
|
//- /main.rs crate:main deps:core
|
||||||
|
|
||||||
struct IntFuture;
|
struct IntFuture;
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ fn test() {
|
||||||
v<|>;
|
v<|>;
|
||||||
}
|
}
|
||||||
|
|
||||||
//- /std.rs crate:std
|
//- /core.rs crate:core
|
||||||
#[prelude_import] use future::*;
|
#[prelude_import] use future::*;
|
||||||
mod future {
|
mod future {
|
||||||
#[lang = "future_trait"]
|
#[lang = "future_trait"]
|
||||||
|
@ -42,7 +42,7 @@ mod future {
|
||||||
fn infer_async() {
|
fn infer_async() {
|
||||||
let (db, pos) = TestDB::with_position(
|
let (db, pos) = TestDB::with_position(
|
||||||
r#"
|
r#"
|
||||||
//- /main.rs crate:main deps:std
|
//- /main.rs crate:main deps:core
|
||||||
|
|
||||||
async fn foo() -> u64 {
|
async fn foo() -> u64 {
|
||||||
128
|
128
|
||||||
|
@ -54,7 +54,7 @@ fn test() {
|
||||||
v<|>;
|
v<|>;
|
||||||
}
|
}
|
||||||
|
|
||||||
//- /std.rs crate:std
|
//- /core.rs crate:core
|
||||||
#[prelude_import] use future::*;
|
#[prelude_import] use future::*;
|
||||||
mod future {
|
mod future {
|
||||||
#[lang = "future_trait"]
|
#[lang = "future_trait"]
|
||||||
|
@ -72,7 +72,7 @@ mod future {
|
||||||
fn infer_desugar_async() {
|
fn infer_desugar_async() {
|
||||||
let (db, pos) = TestDB::with_position(
|
let (db, pos) = TestDB::with_position(
|
||||||
r#"
|
r#"
|
||||||
//- /main.rs crate:main deps:std
|
//- /main.rs crate:main deps:core
|
||||||
|
|
||||||
async fn foo() -> u64 {
|
async fn foo() -> u64 {
|
||||||
128
|
128
|
||||||
|
@ -83,7 +83,7 @@ fn test() {
|
||||||
r<|>;
|
r<|>;
|
||||||
}
|
}
|
||||||
|
|
||||||
//- /std.rs crate:std
|
//- /core.rs crate:core
|
||||||
#[prelude_import] use future::*;
|
#[prelude_import] use future::*;
|
||||||
mod future {
|
mod future {
|
||||||
trait Future {
|
trait Future {
|
||||||
|
@ -100,7 +100,7 @@ mod future {
|
||||||
fn infer_try() {
|
fn infer_try() {
|
||||||
let (db, pos) = TestDB::with_position(
|
let (db, pos) = TestDB::with_position(
|
||||||
r#"
|
r#"
|
||||||
//- /main.rs crate:main deps:std
|
//- /main.rs crate:main deps:core
|
||||||
|
|
||||||
fn test() {
|
fn test() {
|
||||||
let r: Result<i32, u64> = Result::Ok(1);
|
let r: Result<i32, u64> = Result::Ok(1);
|
||||||
|
@ -108,7 +108,7 @@ fn test() {
|
||||||
v<|>;
|
v<|>;
|
||||||
}
|
}
|
||||||
|
|
||||||
//- /std.rs crate:std
|
//- /core.rs crate:core
|
||||||
|
|
||||||
#[prelude_import] use ops::*;
|
#[prelude_import] use ops::*;
|
||||||
mod ops {
|
mod ops {
|
||||||
|
@ -140,9 +140,9 @@ mod result {
|
||||||
fn infer_for_loop() {
|
fn infer_for_loop() {
|
||||||
let (db, pos) = TestDB::with_position(
|
let (db, pos) = TestDB::with_position(
|
||||||
r#"
|
r#"
|
||||||
//- /main.rs crate:main deps:std
|
//- /main.rs crate:main deps:core,alloc
|
||||||
|
|
||||||
use std::collections::Vec;
|
use alloc::collections::Vec;
|
||||||
|
|
||||||
fn test() {
|
fn test() {
|
||||||
let v = Vec::new();
|
let v = Vec::new();
|
||||||
|
@ -152,7 +152,7 @@ fn test() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//- /std.rs crate:std
|
//- /core.rs crate:core
|
||||||
|
|
||||||
#[prelude_import] use iter::*;
|
#[prelude_import] use iter::*;
|
||||||
mod iter {
|
mod iter {
|
||||||
|
@ -161,6 +161,8 @@ mod iter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//- /alloc.rs crate:alloc deps:core
|
||||||
|
|
||||||
mod collections {
|
mod collections {
|
||||||
struct Vec<T> {}
|
struct Vec<T> {}
|
||||||
impl<T> Vec<T> {
|
impl<T> Vec<T> {
|
||||||
|
@ -168,7 +170,7 @@ mod collections {
|
||||||
fn push(&mut self, t: T) { }
|
fn push(&mut self, t: T) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> crate::iter::IntoIterator for Vec<T> {
|
impl<T> IntoIterator for Vec<T> {
|
||||||
type Item=T;
|
type Item=T;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2846,12 +2848,12 @@ fn test() {
|
||||||
fn integer_range_iterate() {
|
fn integer_range_iterate() {
|
||||||
let t = type_at(
|
let t = type_at(
|
||||||
r#"
|
r#"
|
||||||
//- /main.rs crate:main deps:std
|
//- /main.rs crate:main deps:core
|
||||||
fn test() {
|
fn test() {
|
||||||
for x in 0..100 { x<|>; }
|
for x in 0..100 { x<|>; }
|
||||||
}
|
}
|
||||||
|
|
||||||
//- /std.rs crate:std
|
//- /core.rs crate:core
|
||||||
pub mod ops {
|
pub mod ops {
|
||||||
pub struct Range<Idx> {
|
pub struct Range<Idx> {
|
||||||
pub start: Idx,
|
pub start: Idx,
|
||||||
|
|
|
@ -321,7 +321,7 @@ mod tests {
|
||||||
fn test_wrap_return_type() {
|
fn test_wrap_return_type() {
|
||||||
let before = r#"
|
let before = r#"
|
||||||
//- /main.rs
|
//- /main.rs
|
||||||
use std::{string::String, result::Result::{self, Ok, Err}};
|
use core::{string::String, result::Result::{self, Ok, Err}};
|
||||||
|
|
||||||
fn div(x: i32, y: i32) -> Result<i32, String> {
|
fn div(x: i32, y: i32) -> Result<i32, String> {
|
||||||
if y == 0 {
|
if y == 0 {
|
||||||
|
@ -330,7 +330,7 @@ mod tests {
|
||||||
x / y<|>
|
x / y<|>
|
||||||
}
|
}
|
||||||
|
|
||||||
//- /std/lib.rs
|
//- /core/lib.rs
|
||||||
pub mod string {
|
pub mod string {
|
||||||
pub struct String { }
|
pub struct String { }
|
||||||
}
|
}
|
||||||
|
@ -339,7 +339,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
"#;
|
"#;
|
||||||
let after = r#"
|
let after = r#"
|
||||||
use std::{string::String, result::Result::{self, Ok, Err}};
|
use core::{string::String, result::Result::{self, Ok, Err}};
|
||||||
|
|
||||||
fn div(x: i32, y: i32) -> Result<i32, String> {
|
fn div(x: i32, y: i32) -> Result<i32, String> {
|
||||||
if y == 0 {
|
if y == 0 {
|
||||||
|
@ -355,7 +355,7 @@ mod tests {
|
||||||
fn test_wrap_return_type_handles_generic_functions() {
|
fn test_wrap_return_type_handles_generic_functions() {
|
||||||
let before = r#"
|
let before = r#"
|
||||||
//- /main.rs
|
//- /main.rs
|
||||||
use std::result::Result::{self, Ok, Err};
|
use core::result::Result::{self, Ok, Err};
|
||||||
|
|
||||||
fn div<T>(x: T) -> Result<T, i32> {
|
fn div<T>(x: T) -> Result<T, i32> {
|
||||||
if x == 0 {
|
if x == 0 {
|
||||||
|
@ -364,13 +364,13 @@ mod tests {
|
||||||
<|>x
|
<|>x
|
||||||
}
|
}
|
||||||
|
|
||||||
//- /std/lib.rs
|
//- /core/lib.rs
|
||||||
pub mod result {
|
pub mod result {
|
||||||
pub enum Result<T, E> { Ok(T), Err(E) }
|
pub enum Result<T, E> { Ok(T), Err(E) }
|
||||||
}
|
}
|
||||||
"#;
|
"#;
|
||||||
let after = r#"
|
let after = r#"
|
||||||
use std::result::Result::{self, Ok, Err};
|
use core::result::Result::{self, Ok, Err};
|
||||||
|
|
||||||
fn div<T>(x: T) -> Result<T, i32> {
|
fn div<T>(x: T) -> Result<T, i32> {
|
||||||
if x == 0 {
|
if x == 0 {
|
||||||
|
@ -386,7 +386,7 @@ mod tests {
|
||||||
fn test_wrap_return_type_handles_type_aliases() {
|
fn test_wrap_return_type_handles_type_aliases() {
|
||||||
let before = r#"
|
let before = r#"
|
||||||
//- /main.rs
|
//- /main.rs
|
||||||
use std::{string::String, result::Result::{self, Ok, Err}};
|
use core::{string::String, result::Result::{self, Ok, Err}};
|
||||||
|
|
||||||
type MyResult<T> = Result<T, String>;
|
type MyResult<T> = Result<T, String>;
|
||||||
|
|
||||||
|
@ -397,7 +397,7 @@ mod tests {
|
||||||
x <|>/ y
|
x <|>/ y
|
||||||
}
|
}
|
||||||
|
|
||||||
//- /std/lib.rs
|
//- /core/lib.rs
|
||||||
pub mod string {
|
pub mod string {
|
||||||
pub struct String { }
|
pub struct String { }
|
||||||
}
|
}
|
||||||
|
@ -406,7 +406,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
"#;
|
"#;
|
||||||
let after = r#"
|
let after = r#"
|
||||||
use std::{string::String, result::Result::{self, Ok, Err}};
|
use core::{string::String, result::Result::{self, Ok, Err}};
|
||||||
|
|
||||||
type MyResult<T> = Result<T, String>;
|
type MyResult<T> = Result<T, String>;
|
||||||
fn div(x: i32, y: i32) -> MyResult<i32> {
|
fn div(x: i32, y: i32) -> MyResult<i32> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue