Skip to content

Commit 27e3cff

Browse files
committed
Merge branch 'master' into mo-usefull-order
2 parents 1eac62a + dd07f1f commit 27e3cff

Some content is hidden

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

41 files changed

+582
-385
lines changed

Cargo.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ rustc-dependencies = { path = "./crates/rustc-dependencies", version = "0.0.0" }
8585
proc-macro-test = { path = "./crates/proc-macro-test" }
8686

8787
# In-tree crates that are published separately and follow semver. See lib/README.md
88-
line-index = { version = "0.1.0-pre.1" }
88+
line-index = { version = "0.1.1" }
8989
la-arena = { version = "0.3.1" }
9090
lsp-server = { version = "0.7.4" }
9191

crates/hir-def/src/attr/builtin.rs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//!
33
//! The actual definitions were copied from rustc's `compiler/rustc_feature/src/builtin_attrs.rs`.
44
//!
5-
//! It was last synchronized with upstream commit e29821ff85a2a3000d226f99f62f89464028d5d6.
5+
//! It was last synchronized with upstream commit c3def263a44e07e09ae6d57abfc8650227fb4972.
66
//!
77
//! The macros were adjusted to only expand to the attribute name, since that is all we need to do
88
//! name resolution, and `BUILTIN_ATTRIBUTES` is almost entirely unchanged from the original, to
@@ -240,7 +240,7 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
240240
template!(List: "address, kcfi, memory, thread"), DuplicatesOk,
241241
experimental!(no_sanitize)
242242
),
243-
gated!(coverage, Normal, template!(Word, List: "on|off"), WarnFollowing, experimental!(coverage)),
243+
gated!(coverage, Normal, template!(Word, List: "on|off"), WarnFollowing, coverage_attribute, experimental!(coverage)),
244244

245245
ungated!(
246246
doc, Normal, template!(List: "hidden|inline|...", NameValueStr: "string"), DuplicatesOk
@@ -364,7 +364,6 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
364364
allow_internal_unsafe, Normal, template!(Word), WarnFollowing,
365365
"allow_internal_unsafe side-steps the unsafe_code lint",
366366
),
367-
ungated!(rustc_safe_intrinsic, Normal, template!(Word), DuplicatesOk),
368367
rustc_attr!(rustc_allowed_through_unstable_modules, Normal, template!(Word), WarnFollowing,
369368
"rustc_allowed_through_unstable_modules special cases accidental stabilizations of stable items \
370369
through unstable paths"),
@@ -453,6 +452,12 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
453452
ErrorFollowing,
454453
INTERNAL_UNSTABLE
455454
),
455+
rustc_attr!(
456+
rustc_confusables, Normal,
457+
template!(List: r#""name1", "name2", ..."#),
458+
ErrorFollowing,
459+
INTERNAL_UNSTABLE,
460+
),
456461
// Enumerates "identity-like" conversion methods to suggest on type mismatch.
457462
rustc_attr!(
458463
rustc_conversion_suggestion, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE
@@ -488,6 +493,10 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
488493
rustc_attr!(
489494
rustc_do_not_const_check, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE
490495
),
496+
// Ensure the argument to this function is &&str during const-check.
497+
rustc_attr!(
498+
rustc_const_panic_str, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE
499+
),
491500

492501
// ==========================================================================
493502
// Internal attributes, Layout related:
@@ -520,6 +529,10 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
520529
rustc_pass_by_value, Normal, template!(Word), ErrorFollowing,
521530
"#[rustc_pass_by_value] is used to mark types that must be passed by value instead of reference."
522531
),
532+
rustc_attr!(
533+
rustc_never_returns_null_ptr, Normal, template!(Word), ErrorFollowing,
534+
"#[rustc_never_returns_null_ptr] is used to mark functions returning non-null pointers."
535+
),
523536
rustc_attr!(
524537
rustc_coherence_is_core, AttributeType::CrateLevel, template!(Word), ErrorFollowing, @only_local: true,
525538
"#![rustc_coherence_is_core] allows inherent methods on builtin types, only intended to be used in `core`."
@@ -533,7 +546,11 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
533546
"#[rustc_allow_incoherent_impl] has to be added to all impl items of an incoherent inherent impl."
534547
),
535548
rustc_attr!(
536-
rustc_deny_explicit_impl, AttributeType::Normal, template!(Word), ErrorFollowing, @only_local: false,
549+
rustc_deny_explicit_impl,
550+
AttributeType::Normal,
551+
template!(List: "implement_via_object = (true|false)"),
552+
ErrorFollowing,
553+
@only_local: true,
537554
"#[rustc_deny_explicit_impl] enforces that a trait can have no user-provided impls"
538555
),
539556
rustc_attr!(
@@ -614,6 +631,10 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
614631
rustc_doc_primitive, Normal, template!(NameValueStr: "primitive name"), ErrorFollowing,
615632
r#"`rustc_doc_primitive` is a rustc internal attribute"#,
616633
),
634+
rustc_attr!(
635+
rustc_safe_intrinsic, Normal, template!(Word), WarnFollowing,
636+
"the `#[rustc_safe_intrinsic]` attribute is used internally to mark intrinsics as safe"
637+
),
617638

618639
// ==========================================================================
619640
// Internal attributes, Testing:
@@ -625,13 +646,16 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
625646
rustc_attr!(TEST, rustc_insignificant_dtor, Normal, template!(Word), WarnFollowing),
626647
rustc_attr!(TEST, rustc_strict_coherence, Normal, template!(Word), WarnFollowing),
627648
rustc_attr!(TEST, rustc_variance, Normal, template!(Word), WarnFollowing),
649+
rustc_attr!(TEST, rustc_variance_of_opaques, Normal, template!(Word), WarnFollowing),
650+
rustc_attr!(TEST, rustc_hidden_type_of_opaques, Normal, template!(Word), WarnFollowing),
628651
rustc_attr!(TEST, rustc_layout, Normal, template!(List: "field1, field2, ..."), WarnFollowing),
652+
rustc_attr!(TEST, rustc_abi, Normal, template!(List: "field1, field2, ..."), WarnFollowing),
629653
rustc_attr!(TEST, rustc_regions, Normal, template!(Word), WarnFollowing),
630654
rustc_attr!(
631655
TEST, rustc_error, Normal,
632656
template!(Word, List: "span_delayed_bug_from_inside_query"), WarnFollowingWordOnly
633657
),
634-
rustc_attr!(TEST, rustc_dump_user_substs, Normal, template!(Word), WarnFollowing),
658+
rustc_attr!(TEST, rustc_dump_user_args, Normal, template!(Word), WarnFollowing),
635659
rustc_attr!(TEST, rustc_evaluate_where_clauses, Normal, template!(Word), WarnFollowing),
636660
rustc_attr!(
637661
TEST, rustc_if_this_changed, Normal, template!(Word, List: "DepNode"), DuplicatesOk

crates/hir-def/src/child_by_source.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
//! node for a *child*, and get its hir.
66
77
use either::Either;
8-
use hir_expand::HirFileId;
9-
use syntax::ast::HasDocComments;
8+
use hir_expand::{attrs::collect_attrs, HirFileId};
109

1110
use crate::{
1211
db::DefDatabase,
@@ -118,8 +117,8 @@ impl ChildBySource for ItemScope {
118117
|(ast_id, calls)| {
119118
let adt = ast_id.to_node(db.upcast());
120119
calls.for_each(|(attr_id, call_id, calls)| {
121-
if let Some(Either::Left(attr)) =
122-
adt.doc_comments_and_attrs().nth(attr_id.ast_index())
120+
if let Some((_, Either::Left(attr))) =
121+
collect_attrs(&adt).nth(attr_id.ast_index())
123122
{
124123
res[keys::DERIVE_MACRO_CALL].insert(attr, (attr_id, call_id, calls.into()));
125124
}

crates/hir-def/src/import_map.rs

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use indexmap::IndexMap;
99
use itertools::Itertools;
1010
use rustc_hash::{FxHashSet, FxHasher};
1111
use smallvec::SmallVec;
12+
use stdx::format_to;
1213
use triomphe::Arc;
1314

1415
use crate::{
@@ -53,13 +54,25 @@ pub struct ImportMap {
5354
fst: fst::Map<Vec<u8>>,
5455
}
5556

56-
#[derive(Copy, Clone, PartialEq, Eq)]
57+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd)]
5758
enum IsTraitAssocItem {
5859
Yes,
5960
No,
6061
}
6162

6263
impl ImportMap {
64+
pub fn dump(&self, db: &dyn DefDatabase) -> String {
65+
let mut out = String::new();
66+
for (k, v) in self.map.iter() {
67+
format_to!(out, "{:?} ({:?}) -> ", k, v.1);
68+
for v in &v.0 {
69+
format_to!(out, "{}:{:?}, ", v.name.display(db.upcast()), v.container);
70+
}
71+
format_to!(out, "\n");
72+
}
73+
out
74+
}
75+
6376
pub(crate) fn import_map_query(db: &dyn DefDatabase, krate: CrateId) -> Arc<Self> {
6477
let _p = profile::span("import_map_query");
6578

@@ -68,26 +81,31 @@ impl ImportMap {
6881
let mut importables: Vec<_> = map
6982
.iter()
7083
// We've only collected items, whose name cannot be tuple field.
71-
.flat_map(|(&item, (info, _))| {
72-
info.iter()
73-
.map(move |info| (item, info.name.as_str().unwrap().to_ascii_lowercase()))
84+
.flat_map(|(&item, (info, is_assoc))| {
85+
info.iter().map(move |info| {
86+
(item, *is_assoc, info.name.as_str().unwrap().to_ascii_lowercase())
87+
})
7488
})
7589
.collect();
76-
importables.sort_by(|(_, lhs_name), (_, rhs_name)| lhs_name.cmp(rhs_name));
90+
importables.sort_by(|(_, l_is_assoc, lhs_name), (_, r_is_assoc, rhs_name)| {
91+
lhs_name.cmp(rhs_name).then_with(|| l_is_assoc.cmp(r_is_assoc))
92+
});
7793
importables.dedup();
7894

7995
// Build the FST, taking care not to insert duplicate values.
8096
let mut builder = fst::MapBuilder::memory();
81-
let iter =
82-
importables.iter().enumerate().dedup_by(|(_, (_, lhs)), (_, (_, rhs))| lhs == rhs);
83-
for (start_idx, (_, name)) in iter {
97+
let iter = importables
98+
.iter()
99+
.enumerate()
100+
.dedup_by(|(_, (_, _, lhs)), (_, (_, _, rhs))| lhs == rhs);
101+
for (start_idx, (_, _, name)) in iter {
84102
let _ = builder.insert(name, start_idx as u64);
85103
}
86104

87105
Arc::new(ImportMap {
88106
map,
89107
fst: builder.into_map(),
90-
importables: importables.into_iter().map(|(item, _)| item).collect(),
108+
importables: importables.into_iter().map(|(item, _, _)| item).collect(),
91109
})
92110
}
93111

@@ -332,20 +350,20 @@ impl Query {
332350
}
333351

334352
/// Checks whether the import map entry matches the query.
335-
fn import_matches(
336-
&self,
337-
db: &dyn DefDatabase,
338-
import: &ImportInfo,
339-
enforce_lowercase: bool,
340-
) -> bool {
353+
fn import_matches(&self, import: &ImportInfo, enforce_lowercase: bool) -> bool {
341354
let _p = profile::span("import_map::Query::import_matches");
342355

343356
// FIXME: Can we get rid of the alloc here?
344-
let mut input = import.name.display(db.upcast()).to_string();
357+
let input = import.name.to_smol_str();
358+
let mut _s_slot;
345359
let case_insensitive = enforce_lowercase || !self.case_sensitive;
346-
if case_insensitive {
347-
input.make_ascii_lowercase();
348-
}
360+
let input = if case_insensitive {
361+
_s_slot = String::from(input);
362+
_s_slot.make_ascii_lowercase();
363+
&*_s_slot
364+
} else {
365+
&*input
366+
};
349367

350368
let query_string = if case_insensitive { &self.lowercased } else { &self.query };
351369

@@ -355,7 +373,7 @@ impl Query {
355373
SearchMode::Fuzzy => {
356374
let mut input_chars = input.chars();
357375
for query_char in query_string.chars() {
358-
if input_chars.find(|&it| it == query_char).is_none() {
376+
if !input_chars.any(|it| it == query_char) {
359377
return false;
360378
}
361379
}
@@ -376,6 +394,7 @@ pub fn search_dependencies(
376394
let _p = profile::span("search_dependencies").detail(|| format!("{query:?}"));
377395

378396
let graph = db.crate_graph();
397+
379398
let import_maps: Vec<_> =
380399
graph[krate].dependencies.iter().map(|dep| db.import_map(dep.crate_id)).collect();
381400

@@ -390,22 +409,23 @@ pub fn search_dependencies(
390409

391410
let mut res = FxHashSet::default();
392411
let mut common_importable_data_scratch = vec![];
412+
// FIXME: Improve this, its rather unreadable and does duplicate amount of work
393413
while let Some((_, indexed_values)) = stream.next() {
394414
for &IndexedValue { index, value } in indexed_values {
395415
let import_map = &import_maps[index];
396416
let importables @ [importable, ..] = &import_map.importables[value as usize..] else {
397417
continue;
398418
};
399-
400419
let &(ref importable_data, is_trait_assoc_item) = &import_map.map[importable];
401420
if !query.matches_assoc_mode(is_trait_assoc_item) {
402421
continue;
403422
}
404423

424+
// Fetch all the known names of this importable item (to handle import aliases/renames)
405425
common_importable_data_scratch.extend(
406426
importable_data
407427
.iter()
408-
.filter(|&info| query.import_matches(db, info, true))
428+
.filter(|&info| query.import_matches(info, true))
409429
// Name shared by the importable items in this group.
410430
.map(|info| info.name.to_smol_str()),
411431
);
@@ -419,6 +439,7 @@ pub fn search_dependencies(
419439
common_importable_data_scratch.drain(..).flat_map(|common_importable_name| {
420440
// Add the items from this name group. Those are all subsequent items in
421441
// `importables` whose name match `common_importable_name`.
442+
422443
importables
423444
.iter()
424445
.copied()
@@ -434,11 +455,8 @@ pub fn search_dependencies(
434455
.filter(move |item| {
435456
!query.case_sensitive || {
436457
// we've already checked the common importables name case-insensitively
437-
let &(ref import_infos, assoc_mode) = &import_map.map[item];
438-
query.matches_assoc_mode(assoc_mode)
439-
&& import_infos
440-
.iter()
441-
.any(|info| query.import_matches(db, info, false))
458+
let &(ref import_infos, _) = &import_map.map[item];
459+
import_infos.iter().any(|info| query.import_matches(info, false))
442460
}
443461
})
444462
});

0 commit comments

Comments
 (0)