-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Fix #2443 #2444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #2443 #2444
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -395,6 +395,13 @@ where | |
|
||
let resolution = Resolution { def, import: Some(import_id) }; | ||
self.update(module_id, Some(import_id), &[(name, resolution)]); | ||
|
||
// insert alias information to module | ||
if let Some(alias) = &import.alias { | ||
self.def_map.modules[module_id] | ||
.aliases | ||
.insert(last_segment.name.clone(), alias.clone()); | ||
} | ||
} | ||
None => tested_by!(bogus_paths), | ||
} | ||
|
@@ -407,7 +414,18 @@ where | |
import: Option<LocalImportId>, | ||
resolutions: &[(Name, Resolution)], | ||
) { | ||
self.update_recursive(module_id, import, resolutions, 0) | ||
self.update_recursive(module_id, import, resolutions, 0); | ||
|
||
// update alias | ||
let alias_resolutions: Vec<_> = resolutions | ||
.iter() | ||
.filter_map(|(name, res)| { | ||
let alias = self.def_map.modules[module_id].aliases.get(name)?; | ||
Some((alias.clone(), res.clone())) | ||
}) | ||
.collect(); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, I am feeling uneasy about this approach. Seems like And I think we actually have all the required infrastructure in place to fix this properly? Basically, an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Um.. imagine this example: mod m {
macro_rules! _foo {
($x:ident) => { type $x = u64; }
}
pub(crate) use _foo as foo;
}
macro_rules! foo {
() => {}
}
m::foo!(foo);
use foo as bar; // <----- The order of resolving will be:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, I agree, I didn't think of this problem. Can I fix it by adding more information to alias map ? Or do you feel there is a better approach to solve it ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, so the problem is that we end up with So looks like the problem is that we remove type T = ();
use self::T as Y;
use m::*;
mod m {
pub const T: () = ();
}
fn main() { let _: Y = Y; } Looks like rust-analyzer indeed fails to see that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes indeed. The problem here is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Okay, my alias fix won't work in your case. :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just checked that IntelliJ also doesn't handle the above example 😩 |
||
self.update_recursive(module_id, None, &alias_resolutions, 0); | ||
} | ||
|
||
fn update_recursive( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This info is only need during name-resolutrion process, not afterweards, so this field should be a part of
ModCollector
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agreed.