Account for version number in NtIdent hack
Issue #74616 tracks a backwards-compatibility hack for certain macros. This has is implemented by hard-coding the filenames and macro names of certain code that we want to continue to compile. However, the initial implementation of the hack was based on the directory structure when building the crate from its repository (e.g. `js-sys/src/lib.rs`). When the crate is build as a dependency, it will include a version number from the clone from the cargo registry (e.g. `js-sys-0.3.17/src/lib.rs`), which would fail the check. This commit modifies the backwards-compatibility hack to check that desired crate name (`js-sys` or `time-macros-impl`) is a prefix of the proper part of the path. See https://github.com/rust-lang/rust/issues/76070#issuecomment-687215646 for more details.
This commit is contained in:
parent
80cacd7795
commit
9e7ef659e1
5 changed files with 57 additions and 11 deletions
|
@ -809,9 +809,19 @@ impl Nonterminal {
|
|||
if let ExpnKind::Macro(_, macro_name) = orig_span.ctxt().outer_expn_data().kind {
|
||||
let filename = source_map.span_to_filename(orig_span);
|
||||
if let FileName::Real(RealFileName::Named(path)) = filename {
|
||||
if (path.ends_with("time-macros-impl/src/lib.rs")
|
||||
&& macro_name == sym::impl_macros)
|
||||
|| (path.ends_with("js-sys/src/lib.rs") && macro_name == sym::arrays)
|
||||
let matches_prefix = |prefix| {
|
||||
// Check for a path that ends with 'prefix*/src/lib.rs'
|
||||
let mut iter = path.components().rev();
|
||||
iter.next().and_then(|p| p.as_os_str().to_str()) == Some("lib.rs")
|
||||
&& iter.next().and_then(|p| p.as_os_str().to_str()) == Some("src")
|
||||
&& iter
|
||||
.next()
|
||||
.and_then(|p| p.as_os_str().to_str())
|
||||
.map_or(false, |p| p.starts_with(prefix))
|
||||
};
|
||||
|
||||
if (macro_name == sym::impl_macros && matches_prefix("time-macros-impl"))
|
||||
|| (macro_name == sym::arrays && matches_prefix("js-sys"))
|
||||
{
|
||||
let snippet = source_map.span_to_snippet(orig_span);
|
||||
if snippet.as_deref() == Ok("$name") {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue