mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-07 12:48:30 +00:00
Auto merge of #16348 - Veykril:nested-includes, r=Veykril
fix: Fix nested includes resolving from the wrong base file Fixes https://github.com/rust-lang/rust-analyzer/issues/16109
This commit is contained in:
commit
9d8889cdfc
@ -1264,6 +1264,54 @@ struct A;
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn nested_include() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
//- minicore: include
|
||||||
|
//- /lib.rs
|
||||||
|
include!("out_dir/includes.rs");
|
||||||
|
|
||||||
|
//- /out_dir/includes.rs
|
||||||
|
pub mod company_name {
|
||||||
|
pub mod network {
|
||||||
|
pub mod v1 {
|
||||||
|
include!("company_name.network.v1.rs");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//- /out_dir/company_name.network.v1.rs
|
||||||
|
pub struct IpAddress {
|
||||||
|
pub ip_type: &'static str,
|
||||||
|
}
|
||||||
|
/// Nested message and enum types in `IpAddress`.
|
||||||
|
pub mod ip_address {
|
||||||
|
pub enum IpType {
|
||||||
|
IpV4(u32),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
crate
|
||||||
|
company_name: t
|
||||||
|
|
||||||
|
crate::company_name
|
||||||
|
network: t
|
||||||
|
|
||||||
|
crate::company_name::network
|
||||||
|
v1: t
|
||||||
|
|
||||||
|
crate::company_name::network::v1
|
||||||
|
IpAddress: t
|
||||||
|
ip_address: t
|
||||||
|
|
||||||
|
crate::company_name::network::v1::ip_address
|
||||||
|
IpType: t
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn macro_use_imports_all_macro_types() {
|
fn macro_use_imports_all_macro_types() {
|
||||||
let db = TestDB::with_files(
|
let db = TestDB::with_files(
|
||||||
|
@ -15,7 +15,7 @@ use crate::{
|
|||||||
quote,
|
quote,
|
||||||
quote::dollar_crate,
|
quote::dollar_crate,
|
||||||
tt::{self, DelimSpan},
|
tt::{self, DelimSpan},
|
||||||
ExpandError, ExpandResult, HirFileIdExt, MacroCallId,
|
ExpandError, ExpandResult, HirFileIdExt, MacroCallId, MacroFileIdExt,
|
||||||
};
|
};
|
||||||
|
|
||||||
macro_rules! register_builtin {
|
macro_rules! register_builtin {
|
||||||
@ -609,7 +609,7 @@ fn relative_file(
|
|||||||
path_str: &str,
|
path_str: &str,
|
||||||
allow_recursion: bool,
|
allow_recursion: bool,
|
||||||
) -> Result<FileId, ExpandError> {
|
) -> Result<FileId, ExpandError> {
|
||||||
let call_site = call_id.as_file().original_file(db);
|
let call_site = call_id.as_macro_file().parent(db).original_file_respecting_includes(db);
|
||||||
let path = AnchoredPath { anchor: call_site, path: path_str };
|
let path = AnchoredPath { anchor: call_site, path: path_str };
|
||||||
let res = db
|
let res = db
|
||||||
.resolve_path(path)
|
.resolve_path(path)
|
||||||
|
@ -318,6 +318,7 @@ pub trait MacroFileIdExt {
|
|||||||
fn expansion_level(self, db: &dyn ExpandDatabase) -> u32;
|
fn expansion_level(self, db: &dyn ExpandDatabase) -> u32;
|
||||||
/// If this is a macro call, returns the syntax node of the call.
|
/// If this is a macro call, returns the syntax node of the call.
|
||||||
fn call_node(self, db: &dyn ExpandDatabase) -> InFile<SyntaxNode>;
|
fn call_node(self, db: &dyn ExpandDatabase) -> InFile<SyntaxNode>;
|
||||||
|
fn parent(self, db: &dyn ExpandDatabase) -> HirFileId;
|
||||||
|
|
||||||
fn expansion_info(self, db: &dyn ExpandDatabase) -> ExpansionInfo;
|
fn expansion_info(self, db: &dyn ExpandDatabase) -> ExpansionInfo;
|
||||||
|
|
||||||
@ -353,6 +354,9 @@ impl MacroFileIdExt for MacroFileId {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fn parent(self, db: &dyn ExpandDatabase) -> HirFileId {
|
||||||
|
self.macro_call_id.lookup(db).kind.file_id()
|
||||||
|
}
|
||||||
|
|
||||||
/// Return expansion information if it is a macro-expansion file
|
/// Return expansion information if it is a macro-expansion file
|
||||||
fn expansion_info(self, db: &dyn ExpandDatabase) -> ExpansionInfo {
|
fn expansion_info(self, db: &dyn ExpandDatabase) -> ExpansionInfo {
|
||||||
|
Loading…
Reference in New Issue
Block a user