-
-
Notifications
You must be signed in to change notification settings - Fork 15.6k
expanding #[rustc_trivial_field_reads] to more targets, place on Derive and Clone
#160666
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
Draft
josetorrs
wants to merge
22
commits into
rust-lang:main
Choose a base branch
from
josetorrs:move-trivial-reads-to-macros
base: main
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.
Draft
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
ebfe7b0
moving trivial field reads attr to macros
josetorrs 1b9c779
formatting
josetorrs 7f8e375
moving attribute for Clone
josetorrs 949df57
adding test
josetorrs 6de1a8d
moving attr on Debug, remove from minicore
josetorrs 609cb03
remove temporary changes
josetorrs b3773ee
revert closer to the original check
josetorrs dc662df
checking on impl item
josetorrs 0b7febf
bless existing tests
josetorrs f26181b
update code comment
josetorrs 7dbd378
bless macro stats tests
josetorrs 6bc0535
blessing deriving all codegen test
josetorrs f3a904b
expanding attr to impl blocks and refactoring should_explore to not c…
josetorrs b2bde61
allow free functions as a target, move find_attr check eagerly in vis…
josetorrs c3526b7
expanding target to traits with a default method also moving and upda…
josetorrs 6282fbd
adding invalid targets tests, rename introduced dead code tests
josetorrs f4e1a1d
remove old named tests
josetorrs 52bd2b3
formatting
josetorrs b8adfe0
move invalid targets test to attributes tests directory
josetorrs cf0f6ce
forget to bless tests after move and rename
josetorrs d1d3be2
restoring previous commit change, putting attr lookup in should_explore
josetorrs 42b9de3
fixing rebase
josetorrs 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
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 |
|---|---|---|
|
|
@@ -59,7 +59,7 @@ fn should_explore(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { | |
| | DefKind::ExternCrate | ||
| | DefKind::Use | ||
| | DefKind::Ctor(..) | ||
| | DefKind::ForeignMod => true, | ||
| | DefKind::ForeignMod => !find_attr!(tcx, def_id, RustcTrivialFieldReads), | ||
|
|
||
| DefKind::TyParam | ||
| | DefKind::ConstParam | ||
|
|
@@ -444,17 +444,16 @@ impl<'tcx> MarkSymbolVisitor<'tcx> { | |
| ControlFlow::Continue(()) | ||
| } | ||
|
|
||
| /// Automatically generated items marked with `rustc_trivial_field_reads` | ||
| /// Items marked with `rustc_trivial_field_reads` | ||
| /// will be ignored for the purposes of dead code analysis (see PR #85200 | ||
| /// for discussion). | ||
| /// for discussion, and PR #160666). | ||
| fn should_ignore_impl_item(&mut self, impl_item: &hir::ImplItem<'_>) -> bool { | ||
| if let hir::ImplItemImplKind::Trait { .. } = impl_item.impl_kind | ||
| && let impl_of = self.tcx.local_parent(impl_item.owner_id.def_id) | ||
| && self.tcx.is_automatically_derived(impl_of.to_def_id()) | ||
| && let trait_ref = | ||
| self.tcx.impl_trait_ref(impl_of).instantiate_identity().skip_norm_wip() | ||
| && find_attr!(self.tcx, trait_ref.def_id, RustcTrivialFieldReads) | ||
| && find_attr!(self.tcx, impl_item.owner_id.def_id, RustcTrivialFieldReads) | ||
|
Member
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. This attribute check is redundant now, right? |
||
| { | ||
| let trait_ref = self.tcx.impl_trait_ref(impl_of).instantiate_identity().skip_norm_wip(); | ||
|
|
||
| if let ty::Adt(adt_def, _) = trait_ref.self_ty().kind() | ||
| && let Some(adt_def_id) = adt_def.did().as_local() | ||
| { | ||
|
|
@@ -463,7 +462,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> { | |
| return true; | ||
| } | ||
|
|
||
| false | ||
| return false; | ||
| } | ||
|
|
||
| fn visit_node( | ||
|
|
||
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
23 changes: 23 additions & 0 deletions
23
tests/ui/attributes/trivial-field-reads-invalid-targets.rs
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,23 @@ | ||
| //! Checks that `#[rustc_trivial_field_reads]` are not allowed due to invalid targets | ||
|
|
||
| #![feature(rustc_attrs)] | ||
| #![deny(dead_code)] | ||
|
|
||
| trait Whatever { | ||
| #[rustc_trivial_field_reads] //~ERROR the `rustc_trivial_field_reads` attribute cannot be used on required trait methods | ||
| fn read(&self); | ||
| } | ||
|
|
||
| #[rustc_trivial_field_reads] //~ERROR the `rustc_trivial_field_reads` attribute cannot be used on traits | ||
| trait Whatever1 {} | ||
|
|
||
| #[rustc_trivial_field_reads] //~ERROR the `rustc_trivial_field_reads` attribute cannot be used on macro defs | ||
| macro_rules! number { | ||
| () => { | ||
| 67 | ||
| }; | ||
| } | ||
|
|
||
| fn main() { | ||
| let _ = number!(); | ||
| } |
26 changes: 26 additions & 0 deletions
26
tests/ui/attributes/trivial-field-reads-invalid-targets.stderr
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,26 @@ | ||
| error: the `rustc_trivial_field_reads` attribute cannot be used on required trait methods | ||
| --> $DIR/trivial-field-reads-invalid-targets.rs:7:7 | ||
| | | ||
| LL | #[rustc_trivial_field_reads] | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = help: the `rustc_trivial_field_reads` attribute can only be applied to functions with a body | ||
|
|
||
| error: the `rustc_trivial_field_reads` attribute cannot be used on traits | ||
| --> $DIR/trivial-field-reads-invalid-targets.rs:11:3 | ||
| | | ||
| LL | #[rustc_trivial_field_reads] | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = help: the `rustc_trivial_field_reads` attribute can only be applied to functions | ||
|
|
||
| error: the `rustc_trivial_field_reads` attribute cannot be used on macro defs | ||
| --> $DIR/trivial-field-reads-invalid-targets.rs:14:3 | ||
| | | ||
| LL | #[rustc_trivial_field_reads] | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = help: the `rustc_trivial_field_reads` attribute can only be applied to functions | ||
|
|
||
| error: aborting due to 3 previous errors | ||
|
|
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Hmm or maybe do this check for the things we support? I think that's
DefKind::FnonlyView changes since the review
Uh oh!
There was an error while loading. Please reload this page.
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 can try this but I'm still getting a lot of the warnings whenever I build. I do not get the warnings when I put it it in
visit_nodebut still trying to figure out why (moving back to draft while I figure it out)