Skip to content

Commit 4ff8ff0

Browse files
committed
Auto merge of #133077 - cuviper:beta-next, r=cuviper
[beta] backports - Use completion item indices instead of property matching #132987, rust-lang/rust-analyzer#18503 - Reject raw lifetime followed by `'`, like regular lifetimes do #132341 - Only disable cache if predicate has opaques within it #132625 - rustdoc-search: case-sensitive only when capitals are used #133043 - (ci) Update macOS Xcode to 15 #131570 r? cuviper
2 parents eb6e3fa + 48c21ba commit 4ff8ff0

File tree

14 files changed

+180
-50
lines changed

14 files changed

+180
-50
lines changed

compiler/rustc_lexer/src/lib.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,17 @@ impl Cursor<'_> {
715715
self.bump();
716716
self.bump();
717717
self.eat_while(is_id_continue);
718-
return RawLifetime;
718+
match self.first() {
719+
'\'' => {
720+
// Check if after skipping literal contents we've met a closing
721+
// single quote (which means that user attempted to create a
722+
// string with single quotes).
723+
self.bump();
724+
let kind = Char { terminated: true };
725+
return Literal { kind, suffix_start: self.pos_within_token() };
726+
}
727+
_ => return RawLifetime,
728+
}
719729
}
720730

721731
// Either a lifetime or a character literal with

compiler/rustc_trait_selection/src/traits/select/mod.rs

+45-21
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,26 @@ use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
1212
use rustc_data_structures::stack::ensure_sufficient_stack;
1313
use rustc_errors::{Diag, EmissionGuarantee};
1414
use rustc_hir as hir;
15-
use rustc_hir::LangItem;
1615
use rustc_hir::def_id::DefId;
17-
use rustc_infer::infer::BoundRegionConversionTime::{self, HigherRankedType};
18-
use rustc_infer::infer::DefineOpaqueTypes;
16+
use rustc_hir::LangItem;
1917
use rustc_infer::infer::at::ToTrace;
2018
use rustc_infer::infer::relate::TypeRelation;
19+
use rustc_infer::infer::BoundRegionConversionTime::{self, HigherRankedType};
20+
use rustc_infer::infer::DefineOpaqueTypes;
2121
use rustc_infer::traits::TraitObligation;
2222
use rustc_middle::bug;
23-
use rustc_middle::dep_graph::{DepNodeIndex, dep_kinds};
23+
use rustc_middle::dep_graph::{dep_kinds, DepNodeIndex};
2424
use rustc_middle::mir::interpret::ErrorHandled;
2525
pub use rustc_middle::traits::select::*;
2626
use rustc_middle::ty::abstract_const::NotConstEvaluatable;
2727
use rustc_middle::ty::error::TypeErrorToStringExt;
28-
use rustc_middle::ty::print::{PrintTraitRefExt as _, with_no_trimmed_paths};
28+
use rustc_middle::ty::print::{with_no_trimmed_paths, PrintTraitRefExt as _};
2929
use rustc_middle::ty::{
3030
self, GenericArgsRef, PolyProjectionPredicate, Ty, TyCtxt, TypeFoldable, TypeVisitableExt,
3131
Upcast,
3232
};
33-
use rustc_span::Symbol;
3433
use rustc_span::symbol::sym;
34+
use rustc_span::Symbol;
3535
use tracing::{debug, instrument, trace};
3636

3737
use self::EvaluationResult::*;
@@ -40,9 +40,9 @@ use super::coherence::{self, Conflict};
4040
use super::project::ProjectionTermObligation;
4141
use super::util::closure_trait_ref_and_return_type;
4242
use super::{
43-
ImplDerivedCause, Normalized, Obligation, ObligationCause, ObligationCauseCode, Overflow,
44-
PolyTraitObligation, PredicateObligation, Selection, SelectionError, SelectionResult,
45-
TraitQueryMode, const_evaluatable, project, util, wf,
43+
const_evaluatable, project, util, wf, ImplDerivedCause, Normalized, Obligation,
44+
ObligationCause, ObligationCauseCode, Overflow, PolyTraitObligation, PredicateObligation,
45+
Selection, SelectionError, SelectionResult, TraitQueryMode,
4646
};
4747
use crate::error_reporting::InferCtxtErrorExt;
4848
use crate::infer::{InferCtxt, InferOk, TypeFreshener};
@@ -1306,7 +1306,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
13061306
}
13071307

13081308
let tcx = self.tcx();
1309-
if self.can_use_global_caches(param_env) {
1309+
if self.can_use_global_caches(param_env, trait_pred) {
13101310
if let Some(res) = tcx.evaluation_cache.get(&(param_env, trait_pred), tcx) {
13111311
return Some(res);
13121312
}
@@ -1335,7 +1335,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
13351335
return;
13361336
}
13371337

1338-
if self.can_use_global_caches(param_env) && !trait_pred.has_infer() {
1338+
if self.can_use_global_caches(param_env, trait_pred) && !trait_pred.has_infer() {
13391339
debug!(?trait_pred, ?result, "insert_evaluation_cache global");
13401340
// This may overwrite the cache with the same value
13411341
// FIXME: Due to #50507 this overwrites the different values
@@ -1479,7 +1479,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
14791479
}
14801480

14811481
/// Returns `true` if the global caches can be used.
1482-
fn can_use_global_caches(&self, param_env: ty::ParamEnv<'tcx>) -> bool {
1482+
fn can_use_global_caches(
1483+
&self,
1484+
param_env: ty::ParamEnv<'tcx>,
1485+
pred: ty::PolyTraitPredicate<'tcx>,
1486+
) -> bool {
14831487
// If there are any inference variables in the `ParamEnv`, then we
14841488
// always use a cache local to this particular scope. Otherwise, we
14851489
// switch to a global cache.
@@ -1500,7 +1504,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
15001504

15011505
// Avoid using the global cache when we're defining opaque types
15021506
// as their hidden type may impact the result of candidate selection.
1503-
if !self.infcx.defining_opaque_types().is_empty() {
1507+
//
1508+
// HACK: This is still theoretically unsound. Goals can indirectly rely
1509+
// on opaques in the defining scope, and it's easier to do so with TAIT.
1510+
// However, if we disqualify *all* goals from being cached, perf suffers.
1511+
// This is likely fixed by better caching in general in the new solver.
1512+
// See: <https://github.com/rust-lang/rust/issues/132064>.
1513+
if !self.infcx.defining_opaque_types().is_empty() && pred.has_opaque_types() {
15041514
return false;
15051515
}
15061516

@@ -1523,7 +1533,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
15231533
let tcx = self.tcx();
15241534
let pred = cache_fresh_trait_pred.skip_binder();
15251535

1526-
if self.can_use_global_caches(param_env) {
1536+
if self.can_use_global_caches(param_env, cache_fresh_trait_pred) {
15271537
if let Some(res) = tcx.selection_cache.get(&(param_env, pred), tcx) {
15281538
return Some(res);
15291539
}
@@ -1580,7 +1590,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
15801590
return;
15811591
}
15821592

1583-
if self.can_use_global_caches(param_env) {
1593+
if self.can_use_global_caches(param_env, cache_fresh_trait_pred) {
15841594
if let Err(Overflow(OverflowError::Canonical)) = candidate {
15851595
// Don't cache overflow globally; we only produce this in certain modes.
15861596
} else if !pred.has_infer() && !candidate.has_infer() {
@@ -1787,7 +1797,11 @@ enum DropVictim {
17871797

17881798
impl DropVictim {
17891799
fn drop_if(should_drop: bool) -> DropVictim {
1790-
if should_drop { DropVictim::Yes } else { DropVictim::No }
1800+
if should_drop {
1801+
DropVictim::Yes
1802+
} else {
1803+
DropVictim::No
1804+
}
17911805
}
17921806
}
17931807

@@ -1891,7 +1905,11 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
18911905
(ObjectCandidate(_) | ProjectionCandidate(_), ParamCandidate(victim_cand)) => {
18921906
// Prefer these to a global where-clause bound
18931907
// (see issue #50825).
1894-
if is_global(*victim_cand) { DropVictim::Yes } else { DropVictim::No }
1908+
if is_global(*victim_cand) {
1909+
DropVictim::Yes
1910+
} else {
1911+
DropVictim::No
1912+
}
18951913
}
18961914
(
18971915
ImplCandidate(_)
@@ -2450,9 +2468,11 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
24502468
} else {
24512469
// If this is an ill-formed auto/built-in trait, then synthesize
24522470
// new error args for the missing generics.
2453-
let err_args = ty::GenericArgs::extend_with_error(tcx, trait_def_id, &[
2454-
normalized_ty.into(),
2455-
]);
2471+
let err_args = ty::GenericArgs::extend_with_error(
2472+
tcx,
2473+
trait_def_id,
2474+
&[normalized_ty.into()],
2475+
);
24562476
ty::TraitRef::new_from_args(tcx, trait_def_id, err_args)
24572477
};
24582478

@@ -3154,7 +3174,11 @@ impl<'o, 'tcx> TraitObligationStackList<'o, 'tcx> {
31543174
}
31553175

31563176
fn depth(&self) -> usize {
3157-
if let Some(head) = self.head { head.depth } else { 0 }
3177+
if let Some(head) = self.head {
3178+
head.depth
3179+
} else {
3180+
0
3181+
}
31583182
}
31593183
}
31603184

src/ci/github-actions/jobs.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ envs:
4646
RUSTC_RETRY_LINKER_ON_SEGFAULT: 1
4747
MACOSX_DEPLOYMENT_TARGET: 10.12
4848
MACOSX_STD_DEPLOYMENT_TARGET: 10.12
49-
SELECT_XCODE: /Applications/Xcode_14.3.1.app
49+
SELECT_XCODE: /Applications/Xcode_15.2.app
5050
NO_LLVM_ASSERTIONS: 1
5151
NO_DEBUG_ASSERTIONS: 1
5252
NO_OVERFLOW_CHECKS: 1
@@ -282,7 +282,7 @@ auto:
282282
RUST_CONFIGURE_ARGS: --enable-full-tools --enable-sanitizers --enable-profiler --set rust.jemalloc --set rust.lto=thin --set rust.codegen-units=1
283283
RUSTC_RETRY_LINKER_ON_SEGFAULT: 1
284284
MACOSX_DEPLOYMENT_TARGET: 10.12
285-
SELECT_XCODE: /Applications/Xcode_14.3.1.app
285+
SELECT_XCODE: /Applications/Xcode_15.2.app
286286
NO_LLVM_ASSERTIONS: 1
287287
NO_DEBUG_ASSERTIONS: 1
288288
NO_OVERFLOW_CHECKS: 1
@@ -298,7 +298,7 @@ auto:
298298
RUST_CONFIGURE_ARGS: --enable-sanitizers --enable-profiler --set rust.jemalloc --set target.aarch64-apple-ios-macabi.sanitizers=false --set target.x86_64-apple-ios-macabi.sanitizers=false
299299
RUSTC_RETRY_LINKER_ON_SEGFAULT: 1
300300
MACOSX_DEPLOYMENT_TARGET: 10.12
301-
SELECT_XCODE: /Applications/Xcode_14.3.1.app
301+
SELECT_XCODE: /Applications/Xcode_15.2.app
302302
NO_LLVM_ASSERTIONS: 1
303303
NO_DEBUG_ASSERTIONS: 1
304304
NO_OVERFLOW_CHECKS: 1
@@ -327,7 +327,7 @@ auto:
327327
--set llvm.ninja=false
328328
--set rust.lto=thin
329329
RUSTC_RETRY_LINKER_ON_SEGFAULT: 1
330-
SELECT_XCODE: /Applications/Xcode_14.3.1.app
330+
SELECT_XCODE: /Applications/Xcode_15.4.app
331331
USE_XCODE_CLANG: 1
332332
MACOSX_DEPLOYMENT_TARGET: 11.0
333333
MACOSX_STD_DEPLOYMENT_TARGET: 11.0
@@ -347,7 +347,7 @@ auto:
347347
--enable-profiler
348348
--set rust.jemalloc
349349
RUSTC_RETRY_LINKER_ON_SEGFAULT: 1
350-
SELECT_XCODE: /Applications/Xcode_14.3.1.app
350+
SELECT_XCODE: /Applications/Xcode_15.4.app
351351
USE_XCODE_CLANG: 1
352352
MACOSX_DEPLOYMENT_TARGET: 11.0
353353
MACOSX_STD_DEPLOYMENT_TARGET: 11.0

src/librustdoc/html/static/js/search.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -2098,6 +2098,7 @@ class DocSearch {
20982098
const sortResults = async(results, isType, preferredCrate) => {
20992099
const userQuery = parsedQuery.userQuery;
21002100
const casedUserQuery = parsedQuery.original;
2101+
const isMixedCase = casedUserQuery !== userQuery;
21012102
const result_list = [];
21022103
for (const result of results.values()) {
21032104
result.item = this.searchIndex[result.id];
@@ -2109,10 +2110,12 @@ class DocSearch {
21092110
let a, b;
21102111

21112112
// sort by exact case-sensitive match
2112-
a = (aaa.item.name !== casedUserQuery);
2113-
b = (bbb.item.name !== casedUserQuery);
2114-
if (a !== b) {
2115-
return a - b;
2113+
if (isMixedCase) {
2114+
a = (aaa.item.name !== casedUserQuery);
2115+
b = (bbb.item.name !== casedUserQuery);
2116+
if (a !== b) {
2117+
return a - b;
2118+
}
21162119
}
21172120

21182121
// sort by exact match with regard to the last word (mismatch goes later)

src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/request.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ pub(crate) fn handle_completion_resolve(
10681068
else {
10691069
return Ok(original_completion);
10701070
};
1071-
let resolved_completions = to_proto::completion_items(
1071+
let mut resolved_completions = to_proto::completion_items(
10721072
&snap.config,
10731073
&forced_resolve_completions_config.fields_to_resolve,
10741074
&line_index,
@@ -1077,15 +1077,13 @@ pub(crate) fn handle_completion_resolve(
10771077
resolve_data.trigger_character,
10781078
resolved_completions,
10791079
);
1080-
let Some(mut resolved_completion) = resolved_completions.into_iter().find(|completion| {
1081-
completion.label == original_completion.label
1082-
&& completion.kind == original_completion.kind
1083-
&& completion.deprecated == original_completion.deprecated
1084-
&& completion.preselect == original_completion.preselect
1085-
&& completion.sort_text == original_completion.sort_text
1086-
}) else {
1087-
return Ok(original_completion);
1088-
};
1080+
1081+
let mut resolved_completion =
1082+
if resolved_completions.get(resolve_data.completion_item_index).is_some() {
1083+
resolved_completions.swap_remove(resolve_data.completion_item_index)
1084+
} else {
1085+
return Ok(original_completion);
1086+
};
10891087

10901088
if !resolve_data.imports.is_empty() {
10911089
let additional_edits = snap

src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/ext.rs

+1
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,7 @@ pub struct CompletionResolveData {
826826
pub imports: Vec<CompletionImport>,
827827
pub version: Option<i32>,
828828
pub trigger_character: Option<char>,
829+
pub completion_item_index: usize,
829830
}
830831

831832
#[derive(Debug, Serialize, Deserialize)]

src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/to_proto.rs

+24-5
Original file line numberDiff line numberDiff line change
@@ -391,18 +391,36 @@ fn completion_item(
391391
} else {
392392
Vec::new()
393393
};
394-
if something_to_resolve || !imports.is_empty() {
395-
let data = lsp_ext::CompletionResolveData {
394+
let (ref_resolve_data, resolve_data) = if something_to_resolve || !imports.is_empty() {
395+
let mut item_index = acc.len();
396+
let ref_resolve_data = if ref_match.is_some() {
397+
let ref_resolve_data = lsp_ext::CompletionResolveData {
398+
position: tdpp.clone(),
399+
imports: Vec::new(),
400+
version,
401+
trigger_character: completion_trigger_character,
402+
completion_item_index: item_index,
403+
};
404+
item_index += 1;
405+
Some(to_value(ref_resolve_data).unwrap())
406+
} else {
407+
None
408+
};
409+
let resolve_data = lsp_ext::CompletionResolveData {
396410
position: tdpp.clone(),
397411
imports,
398412
version,
399413
trigger_character: completion_trigger_character,
414+
completion_item_index: item_index,
400415
};
401-
lsp_item.data = Some(to_value(data).unwrap());
402-
}
416+
(ref_resolve_data, Some(to_value(resolve_data).unwrap()))
417+
} else {
418+
(None, None)
419+
};
403420

404421
if let Some((label, indel, relevance)) = ref_match {
405-
let mut lsp_item_with_ref = lsp_types::CompletionItem { label, ..lsp_item.clone() };
422+
let mut lsp_item_with_ref =
423+
lsp_types::CompletionItem { label, data: ref_resolve_data, ..lsp_item.clone() };
406424
lsp_item_with_ref
407425
.additional_text_edits
408426
.get_or_insert_with(Default::default)
@@ -411,6 +429,7 @@ fn completion_item(
411429
acc.push(lsp_item_with_ref);
412430
};
413431

432+
lsp_item.data = resolve_data;
414433
acc.push(lsp_item);
415434

416435
fn set_score(

src/tools/rust-analyzer/docs/dev/lsp-extensions.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!---
2-
lsp/ext.rs hash: 90cf7718d54fe3c2
2+
lsp/ext.rs hash: 96f88b7a5d0080c6
33
44
If you need to change the above hash to make the test pass, please check if you
55
need to adjust this doc as well and ping this issue:

tests/debuginfo/constant-ordering-prologue.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
// lldb-command:run
2121

2222
// lldb-command:print a
23-
// lldb-check: = 19
23+
// lldb-check: 19
2424
// lldb-command:print b
25-
// lldb-check: = 20
25+
// lldb-check: 20
2626
// lldb-command:print c
27-
// lldb-check: = 21.5
27+
// lldb-check: 21.5
2828

2929
fn binding(a: i64, b: u64, c: f64) {
3030
let x = 0;

tests/rustdoc-js-std/write.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const EXPECTED = [
2+
{
3+
'query': 'write',
4+
'others': [
5+
{ 'path': 'std::fmt', 'name': 'write' },
6+
{ 'path': 'std::fs', 'name': 'write' },
7+
{ 'path': 'std::ptr', 'name': 'write' },
8+
{ 'path': 'std::fmt', 'name': 'Write' },
9+
{ 'path': 'std::io', 'name': 'Write' },
10+
{ 'path': 'std::hash::Hasher', 'name': 'write' },
11+
],
12+
},
13+
{
14+
'query': 'Write',
15+
'others': [
16+
{ 'path': 'std::fmt', 'name': 'Write' },
17+
{ 'path': 'std::io', 'name': 'Write' },
18+
{ 'path': 'std::fmt', 'name': 'write' },
19+
{ 'path': 'std::fs', 'name': 'write' },
20+
{ 'path': 'std::ptr', 'name': 'write' },
21+
{ 'path': 'std::hash::Hasher', 'name': 'write' },
22+
],
23+
},
24+
];

0 commit comments

Comments
 (0)