mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 20:42:04 +00:00
⬆️ rust-analyzer
This commit is contained in:
parent
61c744d4fd
commit
a2a1d99545
126 changed files with 2098 additions and 904 deletions
|
@ -236,11 +236,19 @@ impl TraitData {
|
|||
.by_key("rustc_skip_array_during_method_dispatch")
|
||||
.exists();
|
||||
|
||||
let mut collector =
|
||||
AssocItemCollector::new(db, module_id, tree_id.file_id(), ItemContainerId::TraitId(tr));
|
||||
collector.collect(&item_tree, tree_id.tree_id(), &tr_def.items);
|
||||
let (items, attribute_calls, diagnostics) = collector.finish();
|
||||
|
||||
let (items, attribute_calls, diagnostics) = match &tr_def.items {
|
||||
Some(items) => {
|
||||
let mut collector = AssocItemCollector::new(
|
||||
db,
|
||||
module_id,
|
||||
tree_id.file_id(),
|
||||
ItemContainerId::TraitId(tr),
|
||||
);
|
||||
collector.collect(&item_tree, tree_id.tree_id(), items);
|
||||
collector.finish()
|
||||
}
|
||||
None => Default::default(),
|
||||
};
|
||||
(
|
||||
Arc::new(TraitData {
|
||||
name,
|
||||
|
|
|
@ -666,7 +666,8 @@ pub struct Trait {
|
|||
pub generic_params: Interned<GenericParams>,
|
||||
pub is_auto: bool,
|
||||
pub is_unsafe: bool,
|
||||
pub items: Box<[AssocItem]>,
|
||||
/// This is [`None`] if this Trait is a trait alias.
|
||||
pub items: Option<Box<[AssocItem]>>,
|
||||
pub ast_id: FileAstId<ast::Trait>,
|
||||
}
|
||||
|
||||
|
|
|
@ -451,15 +451,7 @@ impl<'a> Ctx<'a> {
|
|||
.collect()
|
||||
});
|
||||
let ast_id = self.source_ast_id_map.ast_id(trait_def);
|
||||
let res = Trait {
|
||||
name,
|
||||
visibility,
|
||||
generic_params,
|
||||
is_auto,
|
||||
is_unsafe,
|
||||
items: items.unwrap_or_default(),
|
||||
ast_id,
|
||||
};
|
||||
let res = Trait { name, visibility, generic_params, is_auto, is_unsafe, items, ast_id };
|
||||
Some(id(self.data().traits.alloc(res)))
|
||||
}
|
||||
|
||||
|
|
|
@ -375,12 +375,21 @@ impl<'a> Printer<'a> {
|
|||
}
|
||||
w!(self, "trait {}", name);
|
||||
self.print_generic_params(generic_params);
|
||||
self.print_where_clause_and_opening_brace(generic_params);
|
||||
self.indented(|this| {
|
||||
for item in &**items {
|
||||
this.print_mod_item((*item).into());
|
||||
match items {
|
||||
Some(items) => {
|
||||
self.print_where_clause_and_opening_brace(generic_params);
|
||||
self.indented(|this| {
|
||||
for item in &**items {
|
||||
this.print_mod_item((*item).into());
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
None => {
|
||||
w!(self, " = ");
|
||||
// FIXME: Print the aliased traits
|
||||
self.print_where_clause_and_opening_brace(generic_params);
|
||||
}
|
||||
}
|
||||
wln!(self, "}}");
|
||||
}
|
||||
ModItem::Impl(it) => {
|
||||
|
|
|
@ -94,11 +94,11 @@ macro_rules! m {
|
|||
($($s:stmt)*) => (stringify!($($s |)*);)
|
||||
}
|
||||
stringify!(;
|
||||
|;
|
||||
|92|;
|
||||
|let x = 92|;
|
||||
| ;
|
||||
|92| ;
|
||||
|let x = 92| ;
|
||||
|loop {}
|
||||
|;
|
||||
| ;
|
||||
|);
|
||||
"#]],
|
||||
);
|
||||
|
@ -118,7 +118,7 @@ m!(.. .. ..);
|
|||
macro_rules! m {
|
||||
($($p:pat)*) => (stringify!($($p |)*);)
|
||||
}
|
||||
stringify!(.. .. ..|);
|
||||
stringify!(.. .. .. |);
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
|
|
@ -82,14 +82,14 @@ fn attribute_macro_syntax_completion_2() {
|
|||
#[proc_macros::identity_when_valid]
|
||||
fn foo() { bar.; blub }
|
||||
"#,
|
||||
expect![[r##"
|
||||
expect![[r#"
|
||||
#[proc_macros::identity_when_valid]
|
||||
fn foo() { bar.; blub }
|
||||
|
||||
fn foo() {
|
||||
bar.;
|
||||
bar. ;
|
||||
blub
|
||||
}"##]],
|
||||
}"#]],
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -212,6 +212,7 @@ impl Import {
|
|||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
struct ImportDirective {
|
||||
/// The module this import directive is in.
|
||||
module_id: LocalModuleId,
|
||||
import: Import,
|
||||
status: PartialResolvedImport,
|
||||
|
@ -963,8 +964,10 @@ impl DefCollector<'_> {
|
|||
|
||||
fn update(
|
||||
&mut self,
|
||||
// The module for which `resolutions` have been resolve
|
||||
module_id: LocalModuleId,
|
||||
resolutions: &[(Option<Name>, PerNs)],
|
||||
// Visibility this import will have
|
||||
vis: Visibility,
|
||||
import_type: ImportType,
|
||||
) {
|
||||
|
@ -974,6 +977,7 @@ impl DefCollector<'_> {
|
|||
|
||||
fn update_recursive(
|
||||
&mut self,
|
||||
// The module for which `resolutions` have been resolve
|
||||
module_id: LocalModuleId,
|
||||
resolutions: &[(Option<Name>, PerNs)],
|
||||
// All resolutions are imported with this visibility; the visibilities in
|
||||
|
|
|
@ -73,7 +73,10 @@ impl DefMap {
|
|||
pub(crate) fn resolve_visibility(
|
||||
&self,
|
||||
db: &dyn DefDatabase,
|
||||
// module to import to
|
||||
original_module: LocalModuleId,
|
||||
// pub(path)
|
||||
// ^^^^ this
|
||||
visibility: &RawVisibility,
|
||||
) -> Option<Visibility> {
|
||||
let mut vis = match visibility {
|
||||
|
@ -115,6 +118,7 @@ impl DefMap {
|
|||
&self,
|
||||
db: &dyn DefDatabase,
|
||||
mode: ResolveMode,
|
||||
// module to import to
|
||||
mut original_module: LocalModuleId,
|
||||
path: &ModPath,
|
||||
shadow: BuiltinShadowMode,
|
||||
|
@ -361,6 +365,9 @@ impl DefMap {
|
|||
);
|
||||
}
|
||||
};
|
||||
|
||||
curr_per_ns = curr_per_ns
|
||||
.filter_visibility(|vis| vis.is_visible_from_def_map(db, self, original_module));
|
||||
}
|
||||
|
||||
ResolvePathResult::with(curr_per_ns, ReachedFixedPoint::Yes, None, Some(self.krate))
|
||||
|
|
|
@ -58,9 +58,9 @@ extern {
|
|||
"#,
|
||||
expect![[r#"
|
||||
crate
|
||||
E: t
|
||||
E: _
|
||||
S: t v
|
||||
V: t v
|
||||
V: _
|
||||
foo: t
|
||||
|
||||
crate::foo
|
||||
|
@ -307,7 +307,7 @@ pub struct FromLib;
|
|||
Bar: t v
|
||||
|
||||
crate::foo
|
||||
Bar: t v
|
||||
Bar: _
|
||||
FromLib: t v
|
||||
"#]],
|
||||
);
|
||||
|
|
|
@ -119,7 +119,7 @@ use foo::*;
|
|||
use foo::bar::*;
|
||||
|
||||
//- /foo/mod.rs
|
||||
mod bar;
|
||||
pub mod bar;
|
||||
fn Foo() {};
|
||||
pub struct Foo {};
|
||||
|
||||
|
@ -132,6 +132,7 @@ pub(crate) struct PubCrateStruct;
|
|||
crate
|
||||
Foo: t
|
||||
PubCrateStruct: t v
|
||||
bar: t
|
||||
foo: t
|
||||
|
||||
crate::foo
|
||||
|
@ -336,3 +337,33 @@ mod d {
|
|||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn glob_name_collision_check_visibility() {
|
||||
check(
|
||||
r#"
|
||||
mod event {
|
||||
mod serenity {
|
||||
pub fn Event() {}
|
||||
}
|
||||
use serenity::*;
|
||||
|
||||
pub struct Event {}
|
||||
}
|
||||
|
||||
use event::Event;
|
||||
"#,
|
||||
expect![[r#"
|
||||
crate
|
||||
Event: t
|
||||
event: t
|
||||
|
||||
crate::event
|
||||
Event: t v
|
||||
serenity: t
|
||||
|
||||
crate::event::serenity
|
||||
Event: v
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
|
|
@ -580,7 +580,7 @@ fn module_resolution_decl_inside_inline_module_in_crate_root() {
|
|||
//- /main.rs
|
||||
mod foo {
|
||||
#[path = "baz.rs"]
|
||||
mod bar;
|
||||
pub mod bar;
|
||||
}
|
||||
use self::foo::bar::Baz;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue