-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Recover statics better #125555
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
Open
Noratrieb
wants to merge
3
commits into
rust-lang:master
Choose a base branch
from
Noratrieb:recover-statics-better
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+118
−26
Open
Recover statics better #125555
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -403,7 +403,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty | |||||
|
||||||
Node::Item(item) => match item.kind { | ||||||
ItemKind::Static(ty, .., body_id) => { | ||||||
if ty.is_suggestable_infer_ty() { | ||||||
if ty.is_suggestable_infer_ty() || ty.references_error().is_some() { | ||||||
infer_placeholder_type( | ||||||
tcx, | ||||||
def_id, | ||||||
|
@@ -571,8 +571,7 @@ fn infer_placeholder_type<'a>( | |||||
// then the user may have written e.g. `const A = 42;`. | ||||||
// In this case, the parser has stashed a diagnostic for | ||||||
// us to improve in typeck so we do that now. | ||||||
let guar = tcx | ||||||
.dcx() | ||||||
tcx.dcx() | ||||||
.try_steal_modify_and_emit_err(span, StashKey::ItemNoType, |err| { | ||||||
if !ty.references_error() { | ||||||
// Only suggest adding `:` if it was missing (and suggested by parsing diagnostic). | ||||||
|
@@ -619,7 +618,16 @@ fn infer_placeholder_type<'a>( | |||||
} | ||||||
diag.emit() | ||||||
}); | ||||||
Ty::new_error(tcx, guar) | ||||||
|
||||||
// Typeck returns regions as erased. We can't deal with erased regions here though, so we | ||||||
// turn them into `&'static`, which is *generally* correct for statics and consts. | ||||||
// Assoc consts can reference generic lifetimes from the parent generics, but treating them | ||||||
// as static is unlikely to cause issues. | ||||||
let ty = tcx.fold_regions(ty, |region, _| match region.kind() { | ||||||
ty::ReErased => tcx.lifetimes.re_static, | ||||||
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.
Suggested change
would also fix this issue without requiring any of the other changes, because then the error type is tainted, without replacing any of the types. So you'd still get the suggestions, but const eval won't attempt to run. |
||||||
_ => region, | ||||||
}); | ||||||
ty | ||||||
} | ||||||
|
||||||
fn check_feature_inherent_assoc_ty(tcx: TyCtxt<'_>, span: Span) { | ||||||
|
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// A regression test for #124164 | ||
// const-eval used to complain because the allocation was mutable (due to the atomic) | ||
// while it expected `{type error}` allocations to be immutable. | ||
|
||
static S_COUNT: = std::sync::atomic::AtomicUsize::new(0); | ||
//~^ ERROR missing type for `static` item | ||
|
||
fn main() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
error: missing type for `static` item | ||
--> $DIR/error-type-interior-mutable.rs:5:16 | ||
| | ||
LL | static S_COUNT: = std::sync::atomic::AtomicUsize::new(0); | ||
| ^ help: provide a type for the static variable: `AtomicUsize` | ||
|
||
error: aborting due to 1 previous error | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It is a bad sign that this check is needed. We should never even evaluate a static whose type references an error. So something still seems wrong here.