Skip to content

Rust: Adjust the inferred type of string literals #19996

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 3 commits into from
Jul 8, 2025

Conversation

hvitved
Copy link
Contributor

@hvitved hvitved commented Jul 8, 2025

Adjusts the types from str type &str.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Jul 8, 2025
@hvitved hvitved force-pushed the rust/type-inference-str-literal branch from e7ba741 to d93e516 Compare July 8, 2025 08:56
@hvitved hvitved added the no-change-note-required This PR does not need a change note label Jul 8, 2025
@hvitved hvitved marked this pull request as ready for review July 8, 2025 10:53
@Copilot Copilot AI review requested due to automatic review settings July 8, 2025 10:53
@hvitved hvitved requested a review from a team as a code owner July 8, 2025 10:53
@@ -651,20 +651,20 @@ pub fn test_implicit_derefs() {
let str2;
{
let str1 = "bar";
str2 = "foo".to_string() + &str1; // $ Source[rust/access-after-lifetime-ended]=str1
str2 = "foo".to_string() + &str1;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@geoffw0 : &str1 is no longer considered a source because of this restriction.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it actually is still considered a source, but the results are excluded due to the restriction you linked to. And these inline expectations only show sources associated with results, as I understand it, hence it is now hidden.

In any case both results we lost here are spurious, so I'm happy with this.

@hvitved hvitved force-pushed the rust/type-inference-str-literal branch from 3aa472c to 2a207f9 Compare July 8, 2025 11:03
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Contributor

@geoffw0 geoffw0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes LGTM. DCA is showing a rather surprising 21% analysis time regression!

@@ -651,20 +651,20 @@ pub fn test_implicit_derefs() {
let str2;
{
let str1 = "bar";
str2 = "foo".to_string() + &str1; // $ Source[rust/access-after-lifetime-ended]=str1
str2 = "foo".to_string() + &str1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it actually is still considered a source, but the results are excluded due to the restriction you linked to. And these inline expectations only show sources associated with results, as I understand it, hence it is now hidden.

In any case both results we lost here are spurious, so I'm happy with this.

@hvitved
Copy link
Contributor Author

hvitved commented Jul 8, 2025

DCA is showing a rather surprising 21% analysis time regression!

I have pushed another commit that should fix it.

Copy link
Contributor

@geoffw0 geoffw0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the performance fix, this LGTM. :)

@hvitved hvitved merged commit 156f867 into github:main Jul 8, 2025
19 checks passed
@hvitved hvitved deleted the rust/type-inference-str-literal branch July 8, 2025 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-change-note-required This PR does not need a change note Rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants