Skip to content

Subtree update of rust-analyzer #137173

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 97 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
ee6b5cf
Make Pat::Range's start and end Option<ExprId>
alibektas Jan 7, 2025
31a5685
Make higher levels adapt Bodys exprs having ExprOrPatId values
alibektas Jan 7, 2025
8a18dce
Add a test to monitor whats going on
alibektas Jan 7, 2025
d694b20
Make `rust-analyzer.files.excludeDirs` work, actually
ChayimFriedman2 Jan 22, 2025
cee2df2
Refactor `TyLoweringContext::substs_from_args_and_bindings()` to alwa…
ChayimFriedman2 Feb 4, 2025
54ad31b
Fix incorrect terminology
ChayimFriedman2 Feb 4, 2025
66599f1
Remove a no-longer-correct FIXME
ChayimFriedman2 Feb 4, 2025
c7e331b
Do not include excluded files even when the client opens them
ChayimFriedman2 Feb 4, 2025
7201010
fix: Apply adjustments to proper expr when invoking `CoerceMany`
ShoyuVanilla Feb 7, 2025
01794a4
simplify panic_context
eagr Feb 7, 2025
050c63a
Lower ast::Ident to hir::Path when lowering RangePats
alibektas Jan 19, 2025
e402c8c
make SourceAnalyzer::pat_id return ExprOrPatId
alibektas Jan 21, 2025
3e9633b
resolve_bind_pat_to_const does not early return if expr
alibektas Jan 21, 2025
0d544cf
Remove dbg lines
alibektas Jan 21, 2025
fcc7968
Remove fixme and add a missing test attribute
alibektas Jan 21, 2025
bf2f2c4
Fix clippy errors
alibektas Jan 21, 2025
bc5f61c
Check if PatPtr resolves to ExprId
alibektas Feb 3, 2025
9bd9bcf
fix off-by-one error
jyn514 Feb 9, 2025
d2459e5
fix target dir test
jyn514 Feb 9, 2025
b5ad702
Censor cfg_attr for attribute macros
ChayimFriedman2 Feb 9, 2025
ef8574a
Shadowing BuiltinType by Module
Hmikihiro Feb 10, 2025
340e9a3
Merge pull request #19088 from Hmikihiro/all_remove_duplicate_module_adt
ChayimFriedman2 Feb 10, 2025
8f8e1c6
pass struct fields to chalk
Austaras Feb 9, 2025
724b85e
Fix postfix completions inside macros
ChayimFriedman2 Feb 10, 2025
5373014
Merge pull request #19124 from jyn514/range-fmt-off-by-one
Veykril Feb 10, 2025
0dd7aad
add xtask codegen command as well
joshrotenberg Feb 10, 2025
7c68345
fix mdbook paths
joshrotenberg Feb 10, 2025
b4014de
Bump esbuild from 0.18.12 to 0.25.0 in /editors/code
dependabot[bot] Feb 11, 2025
11c49a6
Fix highlighting for extern crate in doc comments
asuto15 Feb 11, 2025
6e6bdc3
don't emit implicit drop inlay hints for macro
gohome001 Feb 11, 2025
4036a7a
add test case for ignoring inlay hint for macro call
gohome001 Feb 11, 2025
4883966
Merge pull request #18998 from ChayimFriedman2/exclude
Veykril Feb 11, 2025
da4c099
Merge pull request #19117 from gohome001/implicit-drop-inlay-hints-bug
ChayimFriedman2 Feb 11, 2025
d695e33
manual: Fix URLs to rustdoc pages
Wilfred Feb 11, 2025
8453e14
Merge pull request #19133 from joshrotenberg/fix-manual-github-paths
ChayimFriedman2 Feb 11, 2025
3a7a47b
remove unused plugin config
joshrotenberg Feb 11, 2025
98096fe
Merge pull request #19139 from Wilfred/fix_assists_urls
Veykril Feb 12, 2025
8ddf82b
Merge pull request #19140 from joshrotenberg/remove-mdbook-toc-config
Veykril Feb 12, 2025
3a041fc
Propogate error types in mir type projections
Veykril Feb 12, 2025
4aa318c
Merge pull request #19143 from Veykril/push-mkokotluzskw
Veykril Feb 12, 2025
c12a2e7
minor: don't show drop hints for other pattern
gohome001 Feb 12, 2025
7abfbee
Merge pull request #19144 from gohome001/follow_up_implicit_drop
Veykril Feb 12, 2025
9a257e9
Merge pull request #19136 from rust-lang/dependabot/npm_and_yarn/edit…
Veykril Feb 12, 2025
f504084
Merge pull request #19132 from joshrotenberg/book-readme-run-codegen
Veykril Feb 12, 2025
ad8c6c6
Merge pull request #19129 from ChayimFriedman2/snippet-macro
Veykril Feb 12, 2025
444c2f9
Merge pull request #18995 from alibektas/12210
Veykril Feb 12, 2025
8159195
Merge pull request #19125 from ChayimFriedman2/cfg-attr-fast
Veykril Feb 12, 2025
53e6870
Merge pull request #19110 from eagr/panic-context
Veykril Feb 12, 2025
4a15593
Merge pull request #19111 from ShoyuVanilla/issue-19021
Veykril Feb 12, 2025
a09ece2
fix: Do not show safety hints for extern items lacking semantics
Veykril Feb 7, 2025
0d8015c
fix: handle character boundary in search mode
roife Jan 12, 2025
2de7529
Merge pull request #19109 from Veykril/push-nzpuuqommpnq
Veykril Feb 12, 2025
537f4b2
Merge pull request #18928 from roife/fix-18918
Veykril Feb 12, 2025
f26f1dd
Spawn toolchain querying processes in parallel
Veykril Feb 12, 2025
d9256ab
Improve error recovery when method-calling a field
Veykril Feb 12, 2025
caa651a
Merge pull request #19148 from Veykril/push-ptnykrwnwwlu
Veykril Feb 12, 2025
875f3e2
Rename sysroot src/lib related things
Veykril Feb 12, 2025
2190e7b
Merge pull request #19142 from Veykril/push-upwqztrsuwpz
Veykril Feb 12, 2025
7ef1fcf
manual: Separate out installation and configuration pages
Wilfred Feb 11, 2025
d72b2df
Add modifiers to highlighting for extern crate
asuto15 Feb 12, 2025
21b0c22
Delete useless comma
asuto15 Feb 12, 2025
b3ef716
Apply cfg.setTest to json projects
darichey Feb 12, 2025
5023945
Merge pull request #19150 from darichey/set-test-json-project
Veykril Feb 13, 2025
1951cf5
Merge pull request #19141 from Wilfred/split_editors
Veykril Feb 13, 2025
7c61ec7
internal: Remove mutable syntax tree usages from `add_missing_match_a…
ShoyuVanilla Feb 13, 2025
bad69a3
add cargo's git checkouts to the list of paths to mark as read-only i…
programmerjake Feb 14, 2025
7f87814
Merge pull request #19156 from programmerjake/patch-1
Veykril Feb 14, 2025
84485a8
Delete library modifier to highlighting for extern crate
asuto15 Feb 15, 2025
eaf22bc
fix: remove unnecessary conversion
asuto15 Feb 15, 2025
6e7838d
Factor out business logic of expand_glob_import
PoignardAzur Feb 15, 2025
1253006
Implement expand_glob_reexport assist
PoignardAzur Feb 15, 2025
4c7b609
Temporarily ignore tests with comments
ShoyuVanilla Feb 13, 2025
824b182
Re-generate doctests
PoignardAzur Feb 15, 2025
af804d2
Set `RUSTUP_TOOLCHAIN` when loading sysroot workspace
Veykril Feb 16, 2025
0a01cab
Merge pull request #19159 from Veykril/push-kwtzytsyktpv
Veykril Feb 16, 2025
930918d
Improve error recovery when method-calling an assoc function
Veykril Feb 16, 2025
b54269c
fix: Stabilize sort order of runnables
Veykril Feb 16, 2025
e6eadd3
Merge pull request #19160 from Veykril/push-f3601671f6a468a8cc0774253…
Veykril Feb 16, 2025
9e507b2
Merge pull request #19161 from Veykril/push-prmuyxlnxzxo
Veykril Feb 16, 2025
c5f49cf
fix: Stabilize sort order of `related_tests`
Veykril Feb 16, 2025
ac2ffdb
Merge pull request #19163 from Veykril/push-owykwupqnzpq
Veykril Feb 16, 2025
c8a5743
Merge pull request #19155 from ShoyuVanilla/migrate-missing-match-arms
Veykril Feb 16, 2025
4273bec
Merge pull request #19137 from asuto15/highlight-extern-crate
Veykril Feb 16, 2025
2e7158b
Refactor path lowering
ChayimFriedman2 Feb 10, 2025
04ab837
Fix sorting of runnables
ChayimFriedman2 Feb 17, 2025
6b46937
Merge pull request #19166 from ChayimFriedman2/runnables-order
lnicola Feb 17, 2025
123f17c
Merge pull request #19127 from ChayimFriedman2/different-generic-args
Veykril Feb 17, 2025
d7fb8f1
Merge pull request #19122 from Austaras/master
Veykril Feb 17, 2025
c7a2986
Merge pull request #19158 from PoignardAzur/expaned_pub_glob_imports
Veykril Feb 17, 2025
b7a9a32
Fix detection of ref patterns for path patterns
ChayimFriedman2 Feb 17, 2025
19fa3de
Preparing for merge from rust-lang/rust
lnicola Feb 17, 2025
b571e8a
Merge from rust-lang/rust
lnicola Feb 17, 2025
2a0d16f
Merge pull request #19167 from ChayimFriedman2/fix-ref-pat
Veykril Feb 17, 2025
952bfae
Bump rustc crates
lnicola Feb 17, 2025
0c9c489
Merge pull request #19169 from lnicola/sync-from-rust
lnicola Feb 17, 2025
bce3d0f
Update lockfile
lnicola Feb 17, 2025
e08736d
Merge pull request #19170 from lnicola/update-lockfile
lnicola Feb 17, 2025
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
6 changes: 5 additions & 1 deletion src/tools/rust-analyzer/.github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ jobs:
run: |
rustup update --no-self-update ${{ env.RUST_CHANNEL }}
rustup default ${{ env.RUST_CHANNEL }}
rustup component add --toolchain ${{ env.RUST_CHANNEL }} rustfmt rust-src
rustup component add --toolchain ${{ env.RUST_CHANNEL }} rust-src
# We always use a nightly rustfmt, regardless of channel, because we need
# --file-lines.
rustup toolchain add nightly --profile minimal
rustup component add --toolchain nightly rustfmt
# https://github.com/actions-rust-lang/setup-rust-toolchain/blob/main/rust.json
- name: Install Rust Problem Matcher
if: matrix.os == 'ubuntu-latest'
Expand Down
24 changes: 12 additions & 12 deletions src/tools/rust-analyzer/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1514,9 +1514,9 @@ dependencies = [

[[package]]
name = "ra-ap-rustc_abi"
version = "0.94.0"
version = "0.95.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fa4333df7b71217edb44a36702cafd2bcfc9850677bdf78b32c9f2c98e5df40"
checksum = "b40c4e339b71a8f075a829b1acaf32f870a11b466d9b8623d50b0ce33e65af95"
dependencies = [
"bitflags 2.7.0",
"ra-ap-rustc_index",
Expand All @@ -1525,19 +1525,19 @@ dependencies = [

[[package]]
name = "ra-ap-rustc_index"
version = "0.94.0"
version = "0.95.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d200275ff3d952cc11108f4dc6a692473659758623d63f2bdcea6104a7f1cec8"
checksum = "872072e2ba11d11147ebe9fde1608fe7f7d9b5c51dac524af28ee07c6dade468"
dependencies = [
"ra-ap-rustc_index_macros",
"smallvec",
]

[[package]]
name = "ra-ap-rustc_index_macros"
version = "0.94.0"
version = "0.95.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06eb63df8c1ce2dcb07647305bed811c9c5ebd157def01a81c1b9479b8592b3b"
checksum = "ffcd77debcaf2ad690a57c2d041c11eb33fe66869754b2c5f35c52954b46af0c"
dependencies = [
"proc-macro2",
"quote",
Expand All @@ -1546,9 +1546,9 @@ dependencies = [

[[package]]
name = "ra-ap-rustc_lexer"
version = "0.94.0"
version = "0.95.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7a4d402b2f85650e8c1f78e2e2defc241b03948d6e30d9f5254c9b82755cc4d"
checksum = "49265cdf8823f8d246e476c79c60bd6e5b551c81ae76e1c8d6a5e0dc73df0bca"
dependencies = [
"memchr",
"unicode-properties",
Expand All @@ -1557,19 +1557,19 @@ dependencies = [

[[package]]
name = "ra-ap-rustc_parse_format"
version = "0.94.0"
version = "0.95.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a23a382dbe392beb26360c1a8ce9193155ef74eeac59bcda0fa0a233e047323a"
checksum = "b3da239fdc971176de0db45cb631d71475b52033a3d0027d91964da7be89eee6"
dependencies = [
"ra-ap-rustc_index",
"ra-ap-rustc_lexer",
]

[[package]]
name = "ra-ap-rustc_pattern_analysis"
version = "0.94.0"
version = "0.95.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d746955d67f315ab79767f1d0bbc17fee4f0970d4a00b9ad76bf09cc7d3cd17e"
checksum = "56057d08fdfa0d95494e461bbdd5d4b3fdb349cca6be05ad7759bc964be1b8d4"
dependencies = [
"ra-ap-rustc_index",
"rustc-hash 2.0.0",
Expand Down
10 changes: 5 additions & 5 deletions src/tools/rust-analyzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ vfs-notify = { path = "./crates/vfs-notify", version = "0.0.0" }
vfs = { path = "./crates/vfs", version = "0.0.0" }
edition = { path = "./crates/edition", version = "0.0.0" }

ra-ap-rustc_lexer = { version = "0.94", default-features = false }
ra-ap-rustc_parse_format = { version = "0.94", default-features = false }
ra-ap-rustc_index = { version = "0.94", default-features = false }
ra-ap-rustc_abi = { version = "0.94", default-features = false }
ra-ap-rustc_pattern_analysis = { version = "0.94", default-features = false }
ra-ap-rustc_lexer = { version = "0.95", default-features = false }
ra-ap-rustc_parse_format = { version = "0.95", default-features = false }
ra-ap-rustc_index = { version = "0.95", default-features = false }
ra-ap-rustc_abi = { version = "0.95", default-features = false }
ra-ap-rustc_pattern_analysis = { version = "0.95", default-features = false }

# local crates that aren't published to crates.io. These should not have versions.

Expand Down
4 changes: 4 additions & 0 deletions src/tools/rust-analyzer/crates/hir-def/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ bitflags::bitflags! {
const RUSTC_HAS_INCOHERENT_INHERENT_IMPLS = 1 << 3;
const SKIP_ARRAY_DURING_METHOD_DISPATCH = 1 << 4;
const SKIP_BOXED_SLICE_DURING_METHOD_DISPATCH = 1 << 5;
const RUSTC_PAREN_SUGAR = 1 << 6;
}
}

Expand Down Expand Up @@ -294,6 +295,9 @@ impl TraitData {
if attrs.by_key(&sym::rustc_has_incoherent_inherent_impls).exists() {
flags |= TraitFlags::RUSTC_HAS_INCOHERENT_INHERENT_IMPLS;
}
if attrs.by_key(&sym::rustc_paren_sugar).exists() {
flags |= TraitFlags::RUSTC_PAREN_SUGAR;
}

let mut skip_array_during_method_dispatch =
attrs.by_key(&sym::rustc_skip_array_during_method_dispatch).exists();
Expand Down
7 changes: 4 additions & 3 deletions src/tools/rust-analyzer/crates/hir-def/src/dyn_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ pub mod keys {

use crate::{
dyn_map::{DynMap, Policy},
BlockId, ConstId, EnumId, EnumVariantId, ExternCrateId, FieldId, FunctionId, ImplId,
LifetimeParamId, Macro2Id, MacroRulesId, ProcMacroId, StaticId, StructId, TraitAliasId,
TraitId, TypeAliasId, TypeOrConstParamId, UnionId, UseId,
BlockId, ConstId, EnumId, EnumVariantId, ExternBlockId, ExternCrateId, FieldId, FunctionId,
ImplId, LifetimeParamId, Macro2Id, MacroRulesId, ProcMacroId, StaticId, StructId,
TraitAliasId, TraitId, TypeAliasId, TypeOrConstParamId, UnionId, UseId,
};

pub type Key<K, V> = crate::dyn_map::Key<AstPtr<K>, V, AstPtrPolicy<K, V>>;
Expand All @@ -44,6 +44,7 @@ pub mod keys {
pub const STATIC: Key<ast::Static, StaticId> = Key::new();
pub const TYPE_ALIAS: Key<ast::TypeAlias, TypeAliasId> = Key::new();
pub const IMPL: Key<ast::Impl, ImplId> = Key::new();
pub const EXTERN_BLOCK: Key<ast::ExternBlock, ExternBlockId> = Key::new();
pub const TRAIT: Key<ast::Trait, TraitId> = Key::new();
pub const TRAIT_ALIAS: Key<ast::TraitAlias, TraitAliasId> = Key::new();
pub const STRUCT: Key<ast::Struct, StructId> = Key::new();
Expand Down
10 changes: 5 additions & 5 deletions src/tools/rust-analyzer/crates/hir-def/src/expr_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ pub struct ExpressionStoreSourceMap {
// AST expressions can create patterns in destructuring assignments. Therefore, `ExprSource` can also map
// to `PatId`, and `PatId` can also map to `ExprSource` (the other way around is unaffected).
expr_map: FxHashMap<ExprSource, ExprOrPatId>,
expr_map_back: ArenaMap<ExprId, ExprSource>,
expr_map_back: ArenaMap<ExprId, ExprOrPatSource>,

pat_map: FxHashMap<PatSource, PatId>,
pat_map: FxHashMap<PatSource, ExprOrPatId>,
pat_map_back: ArenaMap<PatId, ExprOrPatSource>,

label_map: FxHashMap<LabelSource, LabelId>,
Expand Down Expand Up @@ -606,12 +606,12 @@ impl Index<TypeRefId> for ExpressionStore {
impl ExpressionStoreSourceMap {
pub fn expr_or_pat_syntax(&self, id: ExprOrPatId) -> Result<ExprOrPatSource, SyntheticSyntax> {
match id {
ExprOrPatId::ExprId(id) => self.expr_syntax(id).map(|it| it.map(AstPtr::wrap_left)),
ExprOrPatId::ExprId(id) => self.expr_syntax(id),
ExprOrPatId::PatId(id) => self.pat_syntax(id),
}
}

pub fn expr_syntax(&self, expr: ExprId) -> Result<ExprSource, SyntheticSyntax> {
pub fn expr_syntax(&self, expr: ExprId) -> Result<ExprOrPatSource, SyntheticSyntax> {
self.expr_map_back.get(expr).cloned().ok_or(SyntheticSyntax)
}

Expand All @@ -633,7 +633,7 @@ impl ExpressionStoreSourceMap {
self.pat_map_back.get(pat).cloned().ok_or(SyntheticSyntax)
}

pub fn node_pat(&self, node: InFile<&ast::Pat>) -> Option<PatId> {
pub fn node_pat(&self, node: InFile<&ast::Pat>) -> Option<ExprOrPatId> {
self.pat_map.get(&node.map(AstPtr::new)).cloned()
}

Expand Down
53 changes: 36 additions & 17 deletions src/tools/rust-analyzer/crates/hir-def/src/expr_store/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ use crate::{
FormatPlaceholder, FormatSign, FormatTrait,
},
Array, Binding, BindingAnnotation, BindingId, BindingProblems, CaptureBy, ClosureKind,
Expr, ExprId, Item, Label, LabelId, Literal, LiteralOrConst, MatchArm, Movability,
OffsetOf, Pat, PatId, RecordFieldPat, RecordLitField, Statement,
Expr, ExprId, Item, Label, LabelId, Literal, MatchArm, Movability, OffsetOf, Pat, PatId,
RecordFieldPat, RecordLitField, Statement,
},
item_scope::BuiltinShadowMode,
lang_item::LangItem,
Expand Down Expand Up @@ -1784,23 +1784,33 @@ impl ExprCollector<'_> {
self.collect_macro_call(call, macro_ptr, true, |this, expanded_pat| {
this.collect_pat_opt(expanded_pat, binding_list)
});
self.source_map.pat_map.insert(src, pat);
self.source_map.pat_map.insert(src, pat.into());
return pat;
}
None => Pat::Missing,
},
// FIXME: implement in a way that also builds source map and calculates assoc resolutions in type inference.
ast::Pat::RangePat(p) => {
let mut range_part_lower = |p: Option<ast::Pat>| {
p.and_then(|it| match &it {
ast::Pat::LiteralPat(it) => {
Some(Box::new(LiteralOrConst::Literal(pat_literal_to_hir(it)?.0)))
let mut range_part_lower = |p: Option<ast::Pat>| -> Option<ExprId> {
p.and_then(|it| {
let ptr = PatPtr::new(&it);
match &it {
ast::Pat::LiteralPat(it) => Some(self.alloc_expr_from_pat(
Expr::Literal(pat_literal_to_hir(it)?.0),
ptr,
)),
ast::Pat::IdentPat(ident) if ident.is_simple_ident() => ident
.name()
.map(|name| name.as_name())
.map(Path::from)
.map(|path| self.alloc_expr_from_pat(Expr::Path(path), ptr)),
ast::Pat::PathPat(p) => p
.path()
.and_then(|path| self.parse_path(path))
.map(|parsed| self.alloc_expr_from_pat(Expr::Path(parsed), ptr)),
// We only need to handle literal, ident (if bare) and path patterns here,
// as any other pattern as a range pattern operand is semantically invalid.
_ => None,
}
pat @ (ast::Pat::IdentPat(_) | ast::Pat::PathPat(_)) => {
let subpat = self.collect_pat(pat.clone(), binding_list);
Some(Box::new(LiteralOrConst::Const(subpat)))
}
_ => None,
})
};
let start = range_part_lower(p.start());
Expand Down Expand Up @@ -1863,7 +1873,7 @@ impl ExprCollector<'_> {
}
});
if let Some(pat) = pat.left() {
self.source_map.pat_map.insert(src, pat);
self.source_map.pat_map.insert(src, pat.into());
}
pat
}
Expand Down Expand Up @@ -2490,7 +2500,7 @@ impl ExprCollector<'_> {
fn alloc_expr(&mut self, expr: Expr, ptr: ExprPtr) -> ExprId {
let src = self.expander.in_file(ptr);
let id = self.store.exprs.alloc(expr);
self.source_map.expr_map_back.insert(id, src);
self.source_map.expr_map_back.insert(id, src.map(AstPtr::wrap_left));
self.source_map.expr_map.insert(src, id.into());
id
}
Expand All @@ -2502,7 +2512,7 @@ impl ExprCollector<'_> {
fn alloc_expr_desugared_with_ptr(&mut self, expr: Expr, ptr: ExprPtr) -> ExprId {
let src = self.expander.in_file(ptr);
let id = self.store.exprs.alloc(expr);
self.source_map.expr_map_back.insert(id, src);
self.source_map.expr_map_back.insert(id, src.map(AstPtr::wrap_left));
// We intentionally don't fill this as it could overwrite a non-desugared entry
// self.source_map.expr_map.insert(src, id);
id
Expand All @@ -2526,11 +2536,20 @@ impl ExprCollector<'_> {
self.source_map.pat_map_back.insert(id, src.map(AstPtr::wrap_left));
id
}

fn alloc_expr_from_pat(&mut self, expr: Expr, ptr: PatPtr) -> ExprId {
let src = self.expander.in_file(ptr);
let id = self.store.exprs.alloc(expr);
self.source_map.pat_map.insert(src, id.into());
self.source_map.expr_map_back.insert(id, src.map(AstPtr::wrap_right));
id
}

fn alloc_pat(&mut self, pat: Pat, ptr: PatPtr) -> PatId {
let src = self.expander.in_file(ptr);
let id = self.store.pats.alloc(pat);
self.source_map.pat_map_back.insert(id, src.map(AstPtr::wrap_right));
self.source_map.pat_map.insert(src, id);
self.source_map.pat_map.insert(src, id.into());
id
}
// FIXME: desugared pats don't have ptr, that's wrong and should be fixed somehow.
Expand Down
16 changes: 3 additions & 13 deletions src/tools/rust-analyzer/crates/hir-def/src/expr_store/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ use itertools::Itertools;
use span::Edition;

use crate::{
hir::{
Array, BindingAnnotation, CaptureBy, ClosureKind, Literal, LiteralOrConst, Movability,
Statement,
},
hir::{Array, BindingAnnotation, CaptureBy, ClosureKind, Literal, Movability, Statement},
pretty::{print_generic_args, print_path, print_type_ref},
};

Expand Down Expand Up @@ -656,11 +653,11 @@ impl Printer<'_> {
}
Pat::Range { start, end } => {
if let Some(start) = start {
self.print_literal_or_const(start);
self.print_expr(*start);
}
w!(self, "..=");
if let Some(end) = end {
self.print_literal_or_const(end);
self.print_expr(*end);
}
}
Pat::Slice { prefix, slice, suffix } => {
Expand Down Expand Up @@ -757,13 +754,6 @@ impl Printer<'_> {
}
}

fn print_literal_or_const(&mut self, literal_or_const: &LiteralOrConst) {
match literal_or_const {
LiteralOrConst::Literal(l) => self.print_literal(l),
LiteralOrConst::Const(c) => self.print_pat(*c),
}
}

fn print_literal(&mut self, literal: &Literal) {
match literal {
Literal::String(it) => w!(self, "{:?}", it),
Expand Down
45 changes: 43 additions & 2 deletions src/tools/rust-analyzer/crates/hir-def/src/expr_store/tests.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
mod block;

use crate::{hir::MatchArm, test_db::TestDB, ModuleDefId};
use expect_test::{expect, Expect};
use la_arena::RawIdx;
use test_fixture::WithFixture;

use crate::{test_db::TestDB, ModuleDefId};

use super::*;

fn lower(#[rust_analyzer::rust_fixture] ra_fixture: &str) -> (TestDB, Arc<Body>, DefWithBodyId) {
Expand Down Expand Up @@ -460,3 +459,45 @@ async fn foo(a: (), b: i32) -> u32 {
expect!["fn foo(�: (), �: i32) -> impl ::core::future::Future::<Output = u32> �"]
.assert_eq(&printed);
}

#[test]
fn range_bounds_are_hir_exprs() {
let (_, body, _) = lower(
r#"
pub const L: i32 = 6;
mod x {
pub const R: i32 = 100;
}
const fn f(x: i32) -> i32 {
match x {
-1..=5 => x * 10,
L..=x::R => x * 100,
_ => x,
}
}"#,
);

let mtch_arms = body
.exprs
.iter()
.find_map(|(_, expr)| {
if let Expr::Match { arms, .. } = expr {
return Some(arms);
}

None
})
.unwrap();

let MatchArm { pat, .. } = mtch_arms[1];
match body.pats[pat] {
Pat::Range { start, end } => {
let hir_start = &body.exprs[start.unwrap()];
let hir_end = &body.exprs[end.unwrap()];

assert!(matches!(hir_start, Expr::Path { .. }));
assert!(matches!(hir_end, Expr::Path { .. }));
}
_ => {}
}
}
Loading
Loading