Skip to content

Commit 68e4d96

Browse files
committed
Auto merge of rust-lang#131399 - lnicola:sync-from-ra, r=lnicola
Subtree update of `rust-analyzer` r? `@ghost`
2 parents 6a3c45e + 84a16c4 commit 68e4d96

File tree

89 files changed

+1377
-666
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+1377
-666
lines changed

Diff for: src/tools/rust-analyzer/.github/workflows/release.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ env:
1616
RUSTFLAGS: "-D warnings -W unreachable-pub"
1717
RUSTUP_MAX_RETRIES: 10
1818
FETCH_DEPTH: 0 # pull in the tags for the version string
19-
MACOSX_DEPLOYMENT_TARGET: 10.15
19+
MACOSX_DEPLOYMENT_TARGET: 13.0
2020
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
2121
CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABIHF_LINKER: arm-linux-gnueabihf-gcc
2222

@@ -43,10 +43,10 @@ jobs:
4343
- os: ubuntu-20.04
4444
target: arm-unknown-linux-gnueabihf
4545
code-target: linux-armhf
46-
- os: macos-12
46+
- os: macos-13
4747
target: x86_64-apple-darwin
4848
code-target: darwin-x64
49-
- os: macos-12
49+
- os: macos-13
5050
target: aarch64-apple-darwin
5151
code-target: darwin-arm64
5252

Diff for: src/tools/rust-analyzer/Cargo.lock

+11-2
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,12 @@ dependencies = [
145145

146146
[[package]]
147147
name = "cc"
148-
version = "1.1.10"
148+
version = "1.1.22"
149149
source = "registry+https://github.com/rust-lang/crates.io-index"
150-
checksum = "e9e8aabfac534be767c909e0690571677d49f41bd8465ae876fe043d52ba5292"
150+
checksum = "9540e661f81799159abee814118cc139a2004b3a3aa3ea37724a1b66530b90e0"
151+
dependencies = [
152+
"shlex",
153+
]
151154

152155
[[package]]
153156
name = "cfg"
@@ -1852,6 +1855,12 @@ dependencies = [
18521855
"lazy_static",
18531856
]
18541857

1858+
[[package]]
1859+
name = "shlex"
1860+
version = "1.3.0"
1861+
source = "registry+https://github.com/rust-lang/crates.io-index"
1862+
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
1863+
18551864
[[package]]
18561865
name = "smallvec"
18571866
version = "1.13.2"

Diff for: src/tools/rust-analyzer/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ exclude = ["crates/proc-macro-srv/proc-macro-test/imp"]
44
resolver = "2"
55

66
[workspace.package]
7-
rust-version = "1.80"
7+
rust-version = "1.81"
88
edition = "2021"
99
license = "MIT OR Apache-2.0"
1010
authors = ["rust-analyzer team"]

Diff for: src/tools/rust-analyzer/crates/cfg/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ impl CfgOptions {
4949
cfg.fold(&|atom| self.enabled.contains(atom))
5050
}
5151

52+
pub fn check_atom(&self, cfg: &CfgAtom) -> bool {
53+
self.enabled.contains(cfg)
54+
}
55+
5256
pub fn insert_atom(&mut self, key: Symbol) {
5357
self.enabled.insert(CfgAtom::Flag(key));
5458
}

Diff for: src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/mbe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ macro_rules! f {
3636
}
3737
3838
struct#0:[email protected]#1# MyTraitMap2#0:[email protected]#0# {#0:[email protected]#1#
39-
map#0:[email protected]#1#:#0:[email protected]#1# #0:[email protected]#1#::#0:1@91..92#1#std#0:[email protected]#1#::#0:1@96..97#1#collections#0:[email protected]#1#::#0:1@109..110#1#HashSet#0:[email protected]#1#<#0:[email protected]#1#(#0:[email protected]#1#)#0:[email protected]#1#>#0:[email protected]#1#,#0:[email protected]#1#
39+
map#0:[email protected]#1#:#0:[email protected]#1# #0:[email protected]#1#::#0:1@91..93#1#std#0:[email protected]#1#::#0:1@96..98#1#collections#0:[email protected]#1#::#0:1@109..111#1#HashSet#0:[email protected]#1#<#0:[email protected]#1#(#0:[email protected]#1#)#0:[email protected]#1#>#0:[email protected]#1#,#0:[email protected]#1#
4040
4141
"#]],
4242
);

Diff for: src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use std::{cmp::Ordering, iter, mem, ops::Not};
77

88
use base_db::{CrateId, CrateOrigin, Dependency, LangCrateOrigin};
9-
use cfg::{CfgExpr, CfgOptions};
9+
use cfg::{CfgAtom, CfgExpr, CfgOptions};
1010
use either::Either;
1111
use hir_expand::{
1212
attrs::{Attr, AttrId},
@@ -1324,13 +1324,21 @@ impl DefCollector<'_> {
13241324
};
13251325

13261326
// Skip #[test]/#[bench] expansion, which would merely result in more memory usage
1327-
// due to duplicating functions into macro expansions
1327+
// due to duplicating functions into macro expansions, but only if `cfg(test)` is active,
1328+
// otherwise they are expanded to nothing and this can impact e.g. diagnostics (due to things
1329+
// being cfg'ed out).
1330+
// Ideally we will just expand them to nothing here. But we are only collecting macro calls,
1331+
// not expanding them, so we have no way to do that.
13281332
if matches!(
13291333
def.kind,
13301334
MacroDefKind::BuiltInAttr(_, expander)
13311335
if expander.is_test() || expander.is_bench()
13321336
) {
1333-
return recollect_without(self);
1337+
let test_is_active =
1338+
self.cfg_options.check_atom(&CfgAtom::Flag(sym::test.clone()));
1339+
if test_is_active {
1340+
return recollect_without(self);
1341+
}
13341342
}
13351343

13361344
let call_id = || {

Diff for: src/tools/rust-analyzer/crates/hir-expand/src/builtin/attr_macro.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use span::{MacroCallId, Span};
44

55
use crate::{db::ExpandDatabase, name, tt, ExpandResult, MacroCallKind};
66

7+
use super::quote;
8+
79
macro_rules! register_builtin {
810
($(($name:ident, $variant:ident) => $expand:ident),* ) => {
911
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -52,15 +54,15 @@ impl BuiltinAttrExpander {
5254
}
5355

5456
register_builtin! {
55-
(bench, Bench) => dummy_attr_expand,
57+
(bench, Bench) => dummy_gate_test_expand,
5658
(cfg_accessible, CfgAccessible) => dummy_attr_expand,
5759
(cfg_eval, CfgEval) => dummy_attr_expand,
5860
(derive, Derive) => derive_expand,
5961
// derive const is equivalent to derive for our proposes.
6062
(derive_const, DeriveConst) => derive_expand,
6163
(global_allocator, GlobalAllocator) => dummy_attr_expand,
62-
(test, Test) => dummy_attr_expand,
63-
(test_case, TestCase) => dummy_attr_expand
64+
(test, Test) => dummy_gate_test_expand,
65+
(test_case, TestCase) => dummy_gate_test_expand
6466
}
6567

6668
pub fn find_builtin_attr(ident: &name::Name) -> Option<BuiltinAttrExpander> {
@@ -76,6 +78,19 @@ fn dummy_attr_expand(
7678
ExpandResult::ok(tt.clone())
7779
}
7880

81+
fn dummy_gate_test_expand(
82+
_db: &dyn ExpandDatabase,
83+
_id: MacroCallId,
84+
tt: &tt::Subtree,
85+
span: Span,
86+
) -> ExpandResult<tt::Subtree> {
87+
let result = quote::quote! { span=>
88+
#[cfg(test)]
89+
#tt
90+
};
91+
ExpandResult::ok(result)
92+
}
93+
7994
/// We generate a very specific expansion here, as we do not actually expand the `#[derive]` attribute
8095
/// itself in name res, but we do want to expand it to something for the IDE layer, so that the input
8196
/// derive attributes can be downmapped, and resolved as proper paths.

Diff for: src/tools/rust-analyzer/crates/hir-expand/src/db.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ use crate::{
1616
cfg_process,
1717
declarative::DeclarativeMacroExpander,
1818
fixup::{self, SyntaxFixupUndoInfo},
19-
hygiene::{span_with_call_site_ctxt, span_with_def_site_ctxt, span_with_mixed_site_ctxt},
19+
hygiene::{
20+
span_with_call_site_ctxt, span_with_def_site_ctxt, span_with_mixed_site_ctxt,
21+
SyntaxContextExt as _,
22+
},
2023
proc_macro::ProcMacros,
2124
span_map::{RealSpanMap, SpanMap, SpanMapRef},
2225
tt, AstId, BuiltinAttrExpander, BuiltinDeriveExpander, BuiltinFnLikeExpander,
@@ -300,14 +303,16 @@ pub fn expand_speculative(
300303
token_tree_to_syntax_node(&speculative_expansion.value, expand_to, loc.def.edition);
301304

302305
let syntax_node = node.syntax_node();
303-
let token = rev_tmap
306+
let (token, _) = rev_tmap
304307
.ranges_with_span(span_map.span_for_range(token_to_map.text_range()))
305-
.filter_map(|range| syntax_node.covering_element(range).into_token())
306-
.min_by_key(|t| {
307-
// prefer tokens of the same kind and text
308+
.filter_map(|(range, ctx)| syntax_node.covering_element(range).into_token().zip(Some(ctx)))
309+
.min_by_key(|(t, ctx)| {
310+
// prefer tokens of the same kind and text, as well as non opaque marked ones
308311
// Note the inversion of the score here, as we want to prefer the first token in case
309312
// of all tokens having the same score
310-
(t.kind() != token_to_map.kind()) as u8 + 2 * ((t.text() != token_to_map.text()) as u8)
313+
ctx.is_opaque(db) as u8
314+
+ 2 * (t.kind() != token_to_map.kind()) as u8
315+
+ 4 * ((t.text() != token_to_map.text()) as u8)
311316
})?;
312317
Some((node.syntax_node(), token))
313318
}

Diff for: src/tools/rust-analyzer/crates/hir-expand/src/hygiene.rs

+4
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ pub trait SyntaxContextExt {
151151
fn remove_mark(&mut self, db: &dyn ExpandDatabase) -> (Option<MacroCallId>, Transparency);
152152
fn outer_mark(self, db: &dyn ExpandDatabase) -> (Option<MacroCallId>, Transparency);
153153
fn marks(self, db: &dyn ExpandDatabase) -> Vec<(MacroCallId, Transparency)>;
154+
fn is_opaque(self, db: &dyn ExpandDatabase) -> bool;
154155
}
155156

156157
impl SyntaxContextExt for SyntaxContextId {
@@ -177,6 +178,9 @@ impl SyntaxContextExt for SyntaxContextId {
177178
marks.reverse();
178179
marks
179180
}
181+
fn is_opaque(self, db: &dyn ExpandDatabase) -> bool {
182+
!self.is_root() && db.lookup_intern_syntax_context(self).outer_transparency.is_opaque()
183+
}
180184
}
181185

182186
// FIXME: Make this a SyntaxContextExt method once we have RPIT

Diff for: src/tools/rust-analyzer/crates/hir-expand/src/lib.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ mod prettify_macro_expansion_;
2525

2626
use attrs::collect_attrs;
2727
use rustc_hash::FxHashMap;
28+
use stdx::TupleExt;
2829
use triomphe::Arc;
2930

3031
use std::hash::Hash;
@@ -772,14 +773,15 @@ impl ExpansionInfo {
772773
/// Maps the passed in file range down into a macro expansion if it is the input to a macro call.
773774
///
774775
/// Note this does a linear search through the entire backing vector of the spanmap.
776+
// FIXME: Consider adding a reverse map to ExpansionInfo to get rid of the linear search which
777+
// potentially results in quadratic look ups (notably this might improve semantic highlighting perf)
775778
pub fn map_range_down_exact(
776779
&self,
777780
span: Span,
778-
) -> Option<InMacroFile<impl Iterator<Item = SyntaxToken> + '_>> {
779-
let tokens = self
780-
.exp_map
781-
.ranges_with_span_exact(span)
782-
.flat_map(move |range| self.expanded.value.covering_element(range).into_token());
781+
) -> Option<InMacroFile<impl Iterator<Item = (SyntaxToken, SyntaxContextId)> + '_>> {
782+
let tokens = self.exp_map.ranges_with_span_exact(span).flat_map(move |(range, ctx)| {
783+
self.expanded.value.covering_element(range).into_token().zip(Some(ctx))
784+
});
783785

784786
Some(InMacroFile::new(self.expanded.file_id, tokens))
785787
}
@@ -791,11 +793,10 @@ impl ExpansionInfo {
791793
pub fn map_range_down(
792794
&self,
793795
span: Span,
794-
) -> Option<InMacroFile<impl Iterator<Item = SyntaxToken> + '_>> {
795-
let tokens = self
796-
.exp_map
797-
.ranges_with_span(span)
798-
.flat_map(move |range| self.expanded.value.covering_element(range).into_token());
796+
) -> Option<InMacroFile<impl Iterator<Item = (SyntaxToken, SyntaxContextId)> + '_>> {
797+
let tokens = self.exp_map.ranges_with_span(span).flat_map(move |(range, ctx)| {
798+
self.expanded.value.covering_element(range).into_token().zip(Some(ctx))
799+
});
799800

800801
Some(InMacroFile::new(self.expanded.file_id, tokens))
801802
}
@@ -845,7 +846,8 @@ impl ExpansionInfo {
845846
self.arg.file_id,
846847
arg_map
847848
.ranges_with_span_exact(span)
848-
.filter(|range| range.intersect(arg_range).is_some())
849+
.filter(|(range, _)| range.intersect(arg_range).is_some())
850+
.map(TupleExt::head)
849851
.collect(),
850852
)
851853
}

Diff for: src/tools/rust-analyzer/crates/hir-ty/src/chalk_db.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,9 @@ impl chalk_solve::RustIrDatabase<Interner> for ChalkContext<'_> {
382382
}
383383

384384
fn is_object_safe(&self, trait_id: chalk_ir::TraitId<Interner>) -> bool {
385+
// FIXME: When cargo is updated, change to dyn_compatibility
385386
let trait_ = from_chalk_trait_id(trait_id);
386-
crate::object_safety::object_safety(self.db, trait_).is_none()
387+
crate::dyn_compatibility::dyn_compatibility(self.db, trait_).is_none()
387388
}
388389

389390
fn closure_kind(

Diff for: src/tools/rust-analyzer/crates/hir-ty/src/db.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ use triomphe::Arc;
2020
use crate::{
2121
chalk_db,
2222
consteval::ConstEvalError,
23+
dyn_compatibility::DynCompatibilityViolation,
2324
layout::{Layout, LayoutError},
2425
lower::{GenericDefaults, GenericPredicates},
2526
method_resolution::{InherentImpls, TraitImpls, TyFingerprint},
2627
mir::{BorrowckResult, MirBody, MirLowerError},
27-
object_safety::ObjectSafetyViolation,
2828
Binders, ClosureId, Const, FnDefId, ImplTraitId, ImplTraits, InferenceResult, Interner,
2929
PolyFnSig, Substitution, TraitEnvironment, TraitRef, Ty, TyDefId, ValueTyDefId,
3030
};
@@ -108,8 +108,8 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
108108
#[salsa::invoke(crate::layout::target_data_layout_query)]
109109
fn target_data_layout(&self, krate: CrateId) -> Result<Arc<TargetDataLayout>, Arc<str>>;
110110

111-
#[salsa::invoke(crate::object_safety::object_safety_of_trait_query)]
112-
fn object_safety_of_trait(&self, trait_: TraitId) -> Option<ObjectSafetyViolation>;
111+
#[salsa::invoke(crate::dyn_compatibility::dyn_compatibility_of_trait_query)]
112+
fn dyn_compatibility_of_trait(&self, trait_: TraitId) -> Option<DynCompatibilityViolation>;
113113

114114
#[salsa::invoke(crate::lower::ty_query)]
115115
#[salsa::cycle(crate::lower::ty_recover)]
@@ -280,8 +280,8 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
280280
}
281281

282282
#[test]
283-
fn hir_database_is_object_safe() {
284-
fn _assert_object_safe(_: &dyn HirDatabase) {}
283+
fn hir_database_is_dyn_compatible() {
284+
fn _assert_dyn_compatible(_: &dyn HirDatabase) {}
285285
}
286286

287287
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]

Diff for: src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/decl_check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl fmt::Display for CaseType {
5858
let repr = match self {
5959
CaseType::LowerSnakeCase => "snake_case",
6060
CaseType::UpperSnakeCase => "UPPER_SNAKE_CASE",
61-
CaseType::UpperCamelCase => "CamelCase",
61+
CaseType::UpperCamelCase => "UpperCamelCase",
6262
};
6363

6464
repr.fmt(f)

Diff for: src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/decl_check/case_conv.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ mod tests {
111111
check(to_lower_snake_case, "lower_snake_case", expect![[""]]);
112112
check(to_lower_snake_case, "UPPER_SNAKE_CASE", expect![["upper_snake_case"]]);
113113
check(to_lower_snake_case, "Weird_Case", expect![["weird_case"]]);
114-
check(to_lower_snake_case, "CamelCase", expect![["camel_case"]]);
114+
check(to_lower_snake_case, "UpperCamelCase", expect![["upper_camel_case"]]);
115115
check(to_lower_snake_case, "lowerCamelCase", expect![["lower_camel_case"]]);
116116
check(to_lower_snake_case, "a", expect![[""]]);
117117
check(to_lower_snake_case, "abc", expect![[""]]);
@@ -121,8 +121,8 @@ mod tests {
121121

122122
#[test]
123123
fn test_to_camel_case() {
124-
check(to_camel_case, "CamelCase", expect![[""]]);
125-
check(to_camel_case, "CamelCase_", expect![[""]]);
124+
check(to_camel_case, "UpperCamelCase", expect![[""]]);
125+
check(to_camel_case, "UpperCamelCase_", expect![[""]]);
126126
check(to_camel_case, "_CamelCase", expect![[""]]);
127127
check(to_camel_case, "lowerCamelCase", expect![["LowerCamelCase"]]);
128128
check(to_camel_case, "lower_snake_case", expect![["LowerSnakeCase"]]);
@@ -143,7 +143,7 @@ mod tests {
143143
check(to_upper_snake_case, "UPPER_SNAKE_CASE", expect![[""]]);
144144
check(to_upper_snake_case, "lower_snake_case", expect![["LOWER_SNAKE_CASE"]]);
145145
check(to_upper_snake_case, "Weird_Case", expect![["WEIRD_CASE"]]);
146-
check(to_upper_snake_case, "CamelCase", expect![["CAMEL_CASE"]]);
146+
check(to_upper_snake_case, "UpperCamelCase", expect![["UPPER_CAMEL_CASE"]]);
147147
check(to_upper_snake_case, "lowerCamelCase", expect![["LOWER_CAMEL_CASE"]]);
148148
check(to_upper_snake_case, "A", expect![[""]]);
149149
check(to_upper_snake_case, "ABC", expect![[""]]);

0 commit comments

Comments
 (0)