-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
rustc: fix check_attr() for methods, closures and foreign functions #71205
Conversation
UI tests are updated with additional error messages that were missing before.
Add testcases for the `#[track_caller]` and `#[target_feature(..)]` function attributes for errors that were not not caught before.
r? @cramertj (rust_highfive has picked a reviewer for you, use r? to override) |
This would close #70307 by the way. |
@@ -8,24 +8,28 @@ | |||
struct Foo; | |||
impl Fn<()> for Foo { | |||
//~^ ERROR the precise format of `Fn`-family traits' type parameters is subject to change | |||
//~| ERROR manual implementations of `Fn` are experimental |
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's not clear to me how the attribute checking changes made this new error to appear.
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.
I don't know the rustc code well yet, so I can only tell where this difference happens, not why.
Without this PR, rustc_typeck::check_crate()
errors out early in the "type_collecting" step (I assume tcx.ensure().collect_mod_item_types()
fails?), so the the code never makes it to the coherence::check_coherence()
call a few lines below.
While I have no idea why my PR fixes the type_collecting, it does look like an improvement - all new error messages seem correct to me.
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.
We could maybe use -Ztreat-err-as-bug
to determine why this happens? This would give us a backtrace which hopefully would include check_attrs
.
Thanks, I have updated the PR description. |
r? @eddyb |
Running
gives me the following:
So calling @petrochenkov 🎁 😄 |
@LeSeulArtichaut We do get the "the precise format of I now have a better idea of what is happening: In current nightly, the error "the precise format of With my PR, "the precise format of I see the point of @matthewjasper, who left a "FIXME: Remove this method, it should never be needed." comment at the In any case, I don't think a solution for the |
@bors r+ |
📌 Commit 6c700dc has been approved by |
…vink rustc: fix check_attr() for methods, closures and foreign functions This fixes an issue that previously turned up for methods in rust-lang#69274, but also exists for closures and foreign function: `check_attr` does not call `codegen_fn_attrs()` for these types when it should, meaning that incorrectly used function attributes are not diagnosed without codegen. The issue affects our UI tests, as they run with `--emit=metadata` by default, but as it turns out, this is not the only case: Function attributes are not checked on any dead code without this fix! This makes the fix a **breaking change**. The following very silly Rust programs compiles fine on stable Rust when it should not, which is fixed by this PR. ```rust fn main() { #[target_feature(enable = "sse2")] || {}; } ``` I assume any real-world program which may trigger this issue would at least emit a dead code warning, but of course that is no guarantee that such code does not exist... Fixes rust-lang#70307
Rollup of 5 pull requests Successful merges: - rust-lang#71205 (rustc: fix check_attr() for methods, closures and foreign functions) - rust-lang#71540 (Suggest deref when coercing `ty::Ref` to `ty::RawPtr`) - rust-lang#71655 (Miri: better document and fix dynamic const pattern soundness checks) - rust-lang#71672 (document missing stable counterparts of intrinsics) - rust-lang#71692 (Add clarification on std::cfg macro docs v. #[cfg] attribute) Failed merges: r? @ghost
This fixes an issue that previously turned up for methods in #69274, but also exists for closures and foreign function:
check_attr
does not callcodegen_fn_attrs()
for these types when it should, meaning that incorrectly used function attributes are not diagnosed without codegen.The issue affects our UI tests, as they run with
--emit=metadata
by default, but as it turns out, this is not the only case: Function attributes are not checked on any dead code without this fix!This makes the fix a breaking change. The following very silly Rust programs compiles fine on stable Rust when it should not, which is fixed by this PR.
I assume any real-world program which may trigger this issue would at least emit a dead code warning, but of course that is no guarantee that such code does not exist...
Fixes #70307