Skip to content

⬆️ rust-analyzer #114003

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
004971f
Remove `crate` visibility modifier
lowr Jul 15, 2023
4704881
Merge commit '37f84c101bca43b11027f30ab0c2852f9325bc3d' into sync-fro…
lnicola Jul 17, 2023
de1f766
Fix highlighting of byte escape sequences
oxalica Jul 17, 2023
e64a10f
Use `.kind(Interner)` instead of `.data(Interner).kind`
HKalbasi Jul 17, 2023
d2b7ab0
Auto merge of #15304 - HKalbasi:mir, r=HKalbasi
bors Jul 17, 2023
84897fd
Merge remote-tracking branch 'upstream/master' into sync-from-rust
lnicola Jul 17, 2023
cc2f0ec
Auto merge of #15306 - lnicola:sync-from-rust, r=lnicola
bors Jul 17, 2023
59a3e42
Fix unescaping of C string literals
oxalica Jul 18, 2023
3759c41
Auto merge of #15287 - lowr:internal/remove-crate-vis, r=lnicola
bors Jul 18, 2023
1f35e4d
Introduce `invalidEscapeSequence` semantic token type
oxalica Jul 19, 2023
5187533
Don't follow raw pointer derefs for method receiver type candidates
alexkirsz Jul 19, 2023
cecbd3f
Auto merge of #15312 - alexkirsz:alexkirsz/resolve-deref-raw-follow-u…
bors Jul 19, 2023
eb14338
Pass `TraitEnvironment` into `layout_ty` and `const_eval`
HKalbasi Jul 20, 2023
6b8eb75
Auto merge of #15316 - HKalbasi:mir, r=HKalbasi
bors Jul 20, 2023
b6f31f0
docs: Add example on how to change configuration options in Kate
prez Jul 19, 2023
cbf3713
Auto merge of #15313 - prez:patch-1, r=lnicola
bors Jul 20, 2023
ed8e1fd
Lookup super traits in `is_dyn_method`
HKalbasi Jul 20, 2023
be82869
Auto merge of #15317 - HKalbasi:mir, r=HKalbasi
bors Jul 20, 2023
5d67cbe
Use notification command links for debugger installation
igorskyflyer Jul 15, 2023
994f4f6
Auto merge of #15290 - igorskyflyer:igorskyflyer-dx-install-extension…
bors Jul 20, 2023
b53a078
Report incorrect case for fn inner items
lowr Jul 21, 2023
33b7b45
Report incorrect case for inner items within all bodies
lowr Jul 21, 2023
59d35d2
Auto merge of #15320 - lowr:fix/incorrect-name-case-for-inner-items, …
bors Jul 21, 2023
dfb32cd
Optimize `DepKindInfo` -> `DepKind` conversion
lowr Jul 21, 2023
899dd84
Auto merge of #15323 - lowr:patch/dep-kind-no-alloc, r=lnicola
bors Jul 21, 2023
b7d91ca
Normalize expected ty in call arguments
HKalbasi Jul 21, 2023
a317fa8
Auto merge of #15325 - HKalbasi:mir, r=flodiebold
bors Jul 22, 2023
65823b0
limit change_visibility assist to applicable items
1Kinoti Jul 22, 2023
b17be27
Auto merge of #15277 - 1Kinoti:pub-assist, r=lowr
bors Jul 22, 2023
5cca093
editor/code: Break down CI steps to know what is failing easily
tetsuharuohzeki Jul 14, 2023
c99bb3c
Auto merge of #15281 - tetsuharuohzeki:split-ci-steps, r=lnicola
bors Jul 22, 2023
51b35cc
Add comments for why skip highlighting for invalid char/byte literals
oxalica Jul 22, 2023
99718d0
Auto merge of #15303 - oxalica:fix/byte-escape-highlight, r=lowr
bors Jul 22, 2023
6a94418
Merge commit '99718d0c8bc5aadd993acdcabc1778fc7b5cc572' into sync-fro…
lnicola Jul 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/tools/rust-analyzer/.github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,21 @@ jobs:
# if: runner.os == 'Linux'
# working-directory: ./editors/code

# If this steps fails, your code's type integrity might be wrong at some places at TypeScript level.
- run: npm run typecheck
working-directory: ./editors/code
if: needs.changes.outputs.typescript == 'true'

# You may fix the code automatically by running `npm run lint:fix` if this steps fails.
- run: npm run lint
working-directory: ./editors/code
if: needs.changes.outputs.typescript == 'true'

# To fix this steps, please run `npm run format`.
- run: npm run format:check
working-directory: ./editors/code
if: needs.changes.outputs.typescript == 'true'

- name: Run VS Code tests (Linux)
if: matrix.os == 'ubuntu-latest' && needs.changes.outputs.typescript == 'true'
env:
Expand All @@ -179,10 +190,6 @@ jobs:
run: npm test
working-directory: ./editors/code

- run: npm run pretest
working-directory: ./editors/code
if: needs.changes.outputs.typescript == 'true'

- run: npm run package --scripts-prepend-node-path
working-directory: ./editors/code
if: needs.changes.outputs.typescript == 'true'
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/hir-def/src/body/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ impl Printer<'_> {
match literal {
Literal::String(it) => w!(self, "{:?}", it),
Literal::ByteString(it) => w!(self, "\"{}\"", it.escape_ascii()),
Literal::CString(it) => w!(self, "\"{}\\0\"", it),
Literal::CString(it) => w!(self, "\"{}\\0\"", it.escape_ascii()),
Literal::Char(it) => w!(self, "'{}'", it.escape_debug()),
Literal::Bool(it) => w!(self, "{}", it),
Literal::Int(i, suffix) => {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/hir-def/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl fmt::Display for FloatTypeWrapper {
pub enum Literal {
String(Box<str>),
ByteString(Box<[u8]>),
CString(Box<str>),
CString(Box<[u8]>),
Char(char),
Bool(bool),
Int(i128, Option<BuiltinInt>),
Expand Down
17 changes: 10 additions & 7 deletions src/tools/rust-analyzer/crates/hir-ty/src/consteval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ use triomphe::Arc;
use crate::{
db::HirDatabase, infer::InferenceContext, lower::ParamLoweringMode,
mir::monomorphize_mir_body_bad, to_placeholder_idx, utils::Generics, Const, ConstData,
ConstScalar, ConstValue, GenericArg, Interner, MemoryMap, Substitution, Ty, TyBuilder,
ConstScalar, ConstValue, GenericArg, Interner, MemoryMap, Substitution, TraitEnvironment, Ty,
TyBuilder,
};

use super::mir::{interpret_mir, lower_to_mir, pad16, MirEvalError, MirLowerError};
Expand Down Expand Up @@ -135,7 +136,7 @@ pub fn intern_const_ref(
ty: Ty,
krate: CrateId,
) -> Const {
let layout = db.layout_of_ty(ty.clone(), krate);
let layout = db.layout_of_ty(ty.clone(), Arc::new(TraitEnvironment::empty(krate)));
let bytes = match value {
LiteralConstRef::Int(i) => {
// FIXME: We should handle failure of layout better.
Expand Down Expand Up @@ -173,7 +174,7 @@ pub fn try_const_usize(db: &dyn HirDatabase, c: &Const) -> Option<u128> {
chalk_ir::ConstValue::Concrete(c) => match &c.interned {
ConstScalar::Bytes(it, _) => Some(u128::from_le_bytes(pad16(&it, false))),
ConstScalar::UnevaluatedConst(c, subst) => {
let ec = db.const_eval(*c, subst.clone()).ok()?;
let ec = db.const_eval(*c, subst.clone(), None).ok()?;
try_const_usize(db, &ec)
}
_ => None,
Expand All @@ -186,6 +187,7 @@ pub(crate) fn const_eval_recover(
_: &[String],
_: &GeneralConstId,
_: &Substitution,
_: &Option<Arc<TraitEnvironment>>,
) -> Result<Const, ConstEvalError> {
Err(ConstEvalError::MirLowerError(MirLowerError::Loop))
}
Expand All @@ -210,6 +212,7 @@ pub(crate) fn const_eval_query(
db: &dyn HirDatabase,
def: GeneralConstId,
subst: Substitution,
trait_env: Option<Arc<TraitEnvironment>>,
) -> Result<Const, ConstEvalError> {
let body = match def {
GeneralConstId::ConstId(c) => {
Expand All @@ -228,7 +231,7 @@ pub(crate) fn const_eval_query(
}
GeneralConstId::InTypeConstId(c) => db.mir_body(c.into())?,
};
let c = interpret_mir(db, body, false).0?;
let c = interpret_mir(db, body, false, trait_env).0?;
Ok(c)
}

Expand All @@ -241,7 +244,7 @@ pub(crate) fn const_eval_static_query(
Substitution::empty(Interner),
db.trait_environment_for_body(def.into()),
)?;
let c = interpret_mir(db, body, false).0?;
let c = interpret_mir(db, body, false, None).0?;
Ok(c)
}

Expand All @@ -268,7 +271,7 @@ pub(crate) fn const_eval_discriminant_variant(
Substitution::empty(Interner),
db.trait_environment_for_body(def),
)?;
let c = interpret_mir(db, mir_body, false).0?;
let c = interpret_mir(db, mir_body, false, None).0?;
let c = try_const_usize(db, &c).unwrap() as i128;
Ok(c)
}
Expand All @@ -293,7 +296,7 @@ pub(crate) fn eval_to_const(
}
let infer = ctx.clone().resolve_all();
if let Ok(mir_body) = lower_to_mir(ctx.db, ctx.owner, &ctx.body, &infer, expr) {
if let Ok(result) = interpret_mir(db, Arc::new(mir_body), true).0 {
if let Ok(result) = interpret_mir(db, Arc::new(mir_body), true, None).0 {
return result;
}
}
Expand Down
51 changes: 50 additions & 1 deletion src/tools/rust-analyzer/crates/hir-ty/src/consteval/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ fn eval_goal(db: &TestDB, file_id: FileId) -> Result<Const, ConstEvalError> {
_ => None,
})
.expect("No const named GOAL found in the test");
db.const_eval(const_id.into(), Substitution::empty(Interner))
db.const_eval(const_id.into(), Substitution::empty(Interner), None)
}

#[test]
Expand Down Expand Up @@ -1941,6 +1941,33 @@ fn dyn_trait() {
"#,
900,
);
check_number(
r#"
//- minicore: coerce_unsized, index, slice
trait A {
fn x(&self) -> i32;
}

trait B: A {}

impl A for i32 {
fn x(&self) -> i32 {
5
}
}

impl B for i32 {

}

const fn f(x: &dyn B) -> i32 {
x.x()
}

const GOAL: i32 = f(&2i32);
"#,
5,
);
}

#[test]
Expand Down Expand Up @@ -2492,6 +2519,28 @@ fn const_trait_assoc() {
"#,
5,
);
check_number(
r#"
//- minicore: size_of
//- /a/lib.rs crate:a
use core::mem::size_of;
pub struct S<T>(T);
impl<T> S<T> {
pub const X: usize = core::mem::size_of::<T>();
}
//- /main.rs crate:main deps:a
use a::{S};
trait Tr {
type Ty;
}
impl Tr for i32 {
type Ty = u64;
}
struct K<T: Tr>(<T as Tr>::Ty);
const GOAL: usize = S::<K<i32>>::X;
"#,
8,
);
check_number(
r#"
struct S<T>(*mut T);
Expand Down
16 changes: 12 additions & 4 deletions src/tools/rust-analyzer/crates/hir-ty/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,12 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {

#[salsa::invoke(crate::consteval::const_eval_query)]
#[salsa::cycle(crate::consteval::const_eval_recover)]
fn const_eval(&self, def: GeneralConstId, subst: Substitution)
-> Result<Const, ConstEvalError>;
fn const_eval(
&self,
def: GeneralConstId,
subst: Substitution,
trait_env: Option<Arc<crate::TraitEnvironment>>,
) -> Result<Const, ConstEvalError>;

#[salsa::invoke(crate::consteval::const_eval_static_query)]
#[salsa::cycle(crate::consteval::const_eval_static_recover)]
Expand All @@ -100,12 +104,16 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
&self,
def: AdtId,
subst: Substitution,
krate: CrateId,
env: Arc<crate::TraitEnvironment>,
) -> Result<Arc<Layout>, LayoutError>;

#[salsa::invoke(crate::layout::layout_of_ty_query)]
#[salsa::cycle(crate::layout::layout_of_ty_recover)]
fn layout_of_ty(&self, ty: Ty, krate: CrateId) -> Result<Arc<Layout>, LayoutError>;
fn layout_of_ty(
&self,
ty: Ty,
env: Arc<crate::TraitEnvironment>,
) -> Result<Arc<Layout>, LayoutError>;

#[salsa::invoke(crate::layout::target_data_layout_query)]
fn target_data_layout(&self, krate: CrateId) -> Option<Arc<TargetDataLayout>>;
Expand Down
Loading