-
Notifications
You must be signed in to change notification settings - Fork 13k
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 linkage diagnostic so it doesn't ICE for external crates #61231
Fix linkage diagnostic so it doesn't ICE for external crates #61231
Conversation
…dd `bug!`s to rustc.
Update pre-existing test's diagnostic output accordingly.
(rust_highfive has picked a reviewer for you, use r? to override) |
As I commented on the issue, I have a separate change drafted (but not yet posted to a PR) that adds a similar check earlier in the compiler pipeline, so that we would get this error at the definition site where the attribute occurs, rather that at the usage site where the item is used. (That is, AFAICT, when you add this attribute to an incompatibly-typed definition, there is no way to use it correctly, so we should consider erroring at the definition site instead.) That would be a somewhat riskier change, since it would actually break existing code, unlike this PR, which is strictly keeping the compiler's behavior the same in non-ICE cases. But then again, this is an unstable feature anyway, so we don't have to be quite so cautious. |
I agree, I suspect the feature isn't so widely used anyways so I think it would be good to follow this up with your draft. |
8bcad65
to
c8887ab
Compare
The problem is that we would need to decide which variants of (The way the code in |
One reason that answering this question may be harder than you expect is that back in PR #18890, we blindly added support for all variants of The comments for the code that parses the variant sort of hints at this: rust/src/librustc_typeck/collect.rs Lines 2485 to 2489 in ae8975c
but the point is, its pretty hard to go through and write tests for each case when some of them do not seem to make any sense for definitions in Rust code. Consider e.g. the appending case from LLVM:
|
Another reason why its tricky to "just" go through and try writing tests for each (This may just be adding fuel to the argument that I should not be worrying about adding the check at the definition site. I am going to switch to looking at the cases that fail in our test suite when that definition site check is added, as that will help me understand what cases we supposedly support now.) Update: This claim, that all #[no_mangle]
#[linkage = "external"]
static BAZ: i32 = 21;
// ...
fn main() {
unsafe {
assert_eq!(what(), BAZ);
}
} I find all of this quite weird since in my own experiments it seemed like raw-ptrs were always required (even though that seemed like a generally unworkable restriction). Looking some more into this. Update 2: Okay, I had misread the code earlier. The current compiler doesn't require all uses of The check does require
That second bullet is a reason why its hard to do this check at the definition site; unless I make the check fire based on visibility (that is, any visibility strictly looser than (And it seems more likely to me that the check within our codegen is broken, and not many people are complaining because the feature itself is unstable and buggy?) |
@bors r+ |
📌 Commit c8887ab has been approved by |
…stic, r=petrochenkov Fix linkage diagnostic so it doesn't ICE for external crates Fix linkage diagnostic so it doesn't ICE for external crates (As a drive-by improvement, improved the diagnostic to indicate *why* `*const T` or `*mut T` is required.) Fix rust-lang#59548 Fix rust-lang#61232
…stic, r=petrochenkov Fix linkage diagnostic so it doesn't ICE for external crates Fix linkage diagnostic so it doesn't ICE for external crates (As a drive-by improvement, improved the diagnostic to indicate *why* `*const T` or `*mut T` is required.) Fix rust-lang#59548 Fix rust-lang#61232
Rollup of 11 pull requests Successful merges: - #60802 (upgrade rustdoc's `pulldown-cmark` to 0.5.2) - #60839 (Fix ICE with struct ctors and const generics.) - #60850 (Stabilize RefCell::try_borrow_unguarded) - #61231 (Fix linkage diagnostic so it doesn't ICE for external crates) - #61244 (Box::into_vec: use Box::into_raw instead of mem::forget) - #61279 (implicit `Option`-returning doctests) - #61280 (Revert "Disable solaris target since toolchain no longer builds") - #61284 (Update all s3 URLs used on CI with subdomains) - #61321 (libsyntax: introduce 'fn is_keyword_ahead(dist, keywords)'.) - #61322 (ci: display more debug information in the init_repo script) - #61333 (Fix ICE with APIT in a function with a const parameter) Failed merges: - #61304 (Speed up Azure CI installing Windows dependencies) r? @ghost
Rollup of 11 pull requests Successful merges: - #60802 (upgrade rustdoc's `pulldown-cmark` to 0.5.2) - #60839 (Fix ICE with struct ctors and const generics.) - #60850 (Stabilize RefCell::try_borrow_unguarded) - #61231 (Fix linkage diagnostic so it doesn't ICE for external crates) - #61244 (Box::into_vec: use Box::into_raw instead of mem::forget) - #61279 (implicit `Option`-returning doctests) - #61280 (Revert "Disable solaris target since toolchain no longer builds") - #61284 (Update all s3 URLs used on CI with subdomains) - #61321 (libsyntax: introduce 'fn is_keyword_ahead(dist, keywords)'.) - #61322 (ci: display more debug information in the init_repo script) - #61333 (Fix ICE with APIT in a function with a const parameter) Failed merges: - #61304 (Speed up Azure CI installing Windows dependencies) r? @ghost
Fix linkage diagnostic so it doesn't ICE for external crates
(As a drive-by improvement, improved the diagnostic to indicate why
*const T
or*mut T
is required.)Fix #59548
Fix #61232