lint ineffective #[unstable] annotations on re-exports - #161178
Conversation
This comment has been minimized.
This comment has been minimized.
8dd3a1f to
13f91d6
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
r? @mejrs rustbot has assigned @mejrs. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
r? clarfonthey |
| }; | ||
|
|
||
| let (has_target, all_targets_stable) = self.classify_reexport_targets( | ||
| [path.res.type_ns, path.res.value_ns, path.res.macro_ns].into_iter().flatten(), |
There was a problem hiding this comment.
| [path.res.type_ns, path.res.value_ns, path.res.macro_ns].into_iter().flatten(), | |
| path.res.present_items() |
| for (span, reexport) in &self.unstable_reexports { | ||
| if reexport.has_target && reexport.all_targets_stable { | ||
| self.tcx.emit_node_span_lint( | ||
| UNUSED_ATTRIBUTES, |
There was a problem hiding this comment.
Can you make a standalone lint for this, not reuse UNUSED_ATTRIBUTES? And make it deny by default?
It looks like this fix is just a temporary measure, but a proper fix looks hard so I suspect this will end up becoming somewhat permanent.
| // Do not emit the lint if resolution is incomplete or the | ||
| // target cannot be classified. |
There was a problem hiding this comment.
Can "resolution being incomplete" even happen? And what does "the target cannot be classified" mean?
There was a problem hiding this comment.
I switched this to explicit Res handling
| let mut all_targets_stable = true; | ||
|
|
||
| for res in targets { | ||
| let Some(def_id) = res.opt_def_id() else { |
There was a problem hiding this comment.
I don't think this handles re-exports of primitives correctly. We do have modules that re-export primitives, like std::primitive.
| fn unstable_reexport_span(&self, item: &'tcx hir::Item<'tcx>) -> Option<Span> { | ||
| let attrs = self.tcx.hir_attrs(item.hir_id()); | ||
| let (stability, span) = | ||
| find_attr!(attrs, Stability { stability, span } => (*stability, *span))?; | ||
|
|
||
| matches!(stability.level, StabilityLevel::Unstable { .. }).then_some(span) | ||
| } |
There was a problem hiding this comment.
this span would be more helpful if it pointed to the item being re-exported
There was a problem hiding this comment.
the attribute span is only kept as the grouping key for grouped reexport for now
This comment has been minimized.
This comment has been minimized.
c1b5930 to
17f1859
Compare
| declare_lint! { | ||
| /// The `ineffective_unstable_reexport` lint detects `#[unstable]` attributes | ||
| /// on re-exports where the attribute does not make the re-exported path unstable. | ||
| /// | ||
| /// ### Example | ||
| /// | ||
| /// ```rust,compile_fail | ||
| /// #![feature(staged_api)] | ||
| /// #![stable(feature = "test", since = "1.0.0")] | ||
| /// | ||
| /// #[stable(feature = "test", since = "1.0.0")] | ||
| /// pub struct S; | ||
| /// | ||
| /// #[unstable(feature = "reexport", issue = "none")] | ||
| /// pub use crate::S as T; | ||
| /// | ||
| /// fn main() {} | ||
| /// ``` | ||
| /// | ||
| /// {{produces}} | ||
| /// | ||
| /// ### Explanation | ||
| /// | ||
| /// Stability attributes on re-exports do not currently change the | ||
| /// stability of an otherwise stable re-exported item. | ||
| pub INEFFECTIVE_UNSTABLE_REEXPORT, | ||
| Deny, | ||
| "detects ineffective `#[unstable]` attributes on re-exports" | ||
| } |
There was a problem hiding this comment.
Can you also feature gate this lint behind the staged_api feature? and add a feature gate test for it?
(If you can suppress the "use #![feature(staged_api)] .." suggestion that'd be nice - we suppress that suggestion elsewhere as well.)
| slice_write_vectored, take, | ||
| }; | ||
|
|
||
| pub use self::buf_read::BufRead; |
There was a problem hiding this comment.
I don't think having publicly reachable items without any stability annotations is a right thing.
The current stability logic is right in at least one thing - it requires stability annotations on everything reachable.
The new behavior should be the same, IMO, it just needs to make sure that the reexport's stability annotation is compatible with the stability that is actually used (stability of that reexport's ultimate definition).
cc #146028 (comment)
There was a problem hiding this comment.
I agree we should keep explicit stability annotations on public re-exports but one concern remains if i am correct. if the intended semantics allow a stable item to be reexported through an unstable path should this lint really reject that case? perhaps the check should only reject reexports that weaken the stability of the ultimate definition
There was a problem hiding this comment.
If cases like this are rare, they can use allow(ineffective_unstable_reexport) with a comment.
|
(Also the lint doesn't follow the lint naming conventions - https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints.) |
This comment has been minimized.
This comment has been minimized.
Signed-off-by: Amirhossein Akhlaghpour <m9.akhlaghpoor@gmail.com>
Signed-off-by: Amirhossein Akhlaghpour <m9.akhlaghpoor@gmail.com>
Signed-off-by: Amirhossein Akhlaghpour <m9.akhlaghpoor@gmail.com>
Signed-off-by: Amirhossein Akhlaghpour <m9.akhlaghpoor@gmail.com>
Signed-off-by: Amirhossein Akhlaghpour <m9.akhlaghpoor@gmail.com>
790a8ab to
fbec8a6
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
a78fc29 to
973af67
Compare
973af67 to
54ae450
Compare
This comment has been minimized.
This comment has been minimized.
54ae450 to
ef7850c
Compare
This comment has been minimized.
This comment has been minimized.
Signed-off-by: Amirhossein Akhlaghpour <m9.akhlaghpoor@gmail.com>
ef7850c to
b91102a
Compare
This comment has been minimized.
This comment has been minimized.
Signed-off-by: Amirhossein Akhlaghpour <m9.akhlaghpoor@gmail.com>
|
|
||
| #[derive(Diagnostic)] | ||
| #[diag("stability annotation on this re-export does not match the re-exported item")] | ||
| pub(crate) struct IncompatibleReexportStability; |
There was a problem hiding this comment.
It would be nice to provide the spans of the two attributes being checked, but it does appear that these spans aren't retained in the Stability type you seem to be comparing against. So, perhaps as a compromise, simply stating what the two stability attributes were (even debug-printing them) might be helpful in the output.
There was a problem hiding this comment.
Yeah, gonna say that debug-printing is fine for now. Since this is just an internal lint, I think it should be fine to just show raw debug output on an initial version.
One small concern is that storing the format string directly might affect perf, but will run perf before merging anyway.
There was a problem hiding this comment.
Sounds good thanks. it works for me and we can revisit the representation if the perf run shows anything concerning
Signed-off-by: Amirhossein Akhlaghpour <m9.akhlaghpoor@gmail.com>
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
lint ineffective #[unstable] annotations on re-exports
|
Side note: will code review the whole thing, but will probably pass off to compiler for a final review after verifying the functionality is good for libs, since I'm not familiar enough with the lint code to be able to say it's doing things "the right way" in that sense. |
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (f3482bf): comparison URL. Overall result: ❌✅ regressions and improvements - no action neededBenchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up. @rustbot label: -S-waiting-on-perf -perf-regression Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (secondary -4.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary 5.6%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 475.357s -> 474.541s (-0.17%) |
View all comments
Refs #161153
https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/topic/stability.20attributes.20on.20imports.20.26.20cargo-semver-checks/with/616818373