Skip to content

fix: escape keywords used as names in earlier editions #13034

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

Merged
merged 1 commit into from
Aug 17, 2022

Conversation

lowr
Copy link
Contributor

@lowr lowr commented Aug 16, 2022

Fixes #13030

There are keywords in Rust 2018+ that you can use as names without escaping when your crate is in Rust 2015 e.g. "try". We need to be consistent on how to keep track of the names regardless of how they are actually written in each crate. This patch attempts at it by taking such names into account and storing them uniformly in their escaped form.

@lowr
Copy link
Contributor Author

lowr commented Aug 16, 2022

I wanted to add a test, but I couldn't figure out how (I manually tested and confirmed #13030 is resolved with the patch). I even doubt if it's possible for the time being. Ideally we want to test something like this in nameres tests:

//- /main.rs crate:main deps:liba edition:2015
#[macro_use]
extern crate liba;
use liba::try;

//- /lib.rs crate:liba edition:2018
#[macro_export]
macro_rules! r#try { () => {} }

but we cannot, because it seems we unconditionally parse try as keywords besides try! macro in expression position and use liba::try would be syntax error. I'd appreciate if anyone could come up with a way.

@lowr lowr force-pushed the fix/regression-from-12993 branch from 8f740d7 to 6e341fe Compare August 16, 2022 02:26
@Veykril
Copy link
Member

Veykril commented Aug 16, 2022

@bors d+

@Veykril
Copy link
Member

Veykril commented Aug 16, 2022

@bors delegate+

@bors
Copy link
Contributor

bors commented Aug 16, 2022

✌️ @lowr can now approve this pull request

@lowr lowr force-pushed the fix/regression-from-12993 branch from 6e341fe to a3409c3 Compare August 17, 2022 09:46
@lowr
Copy link
Contributor Author

lowr commented Aug 17, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Aug 17, 2022

📌 Commit a3409c3 has been approved by lowr

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Aug 17, 2022

⌛ Testing commit a3409c3 with merge d6412b5...

@bors
Copy link
Contributor

bors commented Aug 17, 2022

☀️ Test successful - checks-actions
Approved by: lowr
Pushing d6412b5 to master...

@bors bors merged commit d6412b5 into rust-lang:master Aug 17, 2022
bors added a commit that referenced this pull request Feb 14, 2023
fix: Search raw identifiers without prefix

When we find references/usages of a raw identifier, we should disregard `r#` prefix because there are keywords one can use without the prefix in earlier editions (see #13034; this bug is actually fallout from the PR). `name`, the text we're searching for, has already been stripped of the prefix, but the text of nodes we compare it to hasn't been.

The second commit is strictly refactoring, I can remove it if it's not much of value.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

More unknown types in webrender after #12993
3 participants