about summary refs log tree commit diff
path: root/src/test/ui/privacy
AgeCommit message (Collapse)AuthorLines
2023-01-11Move /src/test to /testsAlbert Larsan-8039/+0
2023-01-09Consider method return type for various method suggestionsMichael Goulet-5/+0
2023-01-08Suppress type errors that come from private fieldsMichael Goulet-0/+34
2022-12-13Make some diagnostics not depend on the source of what they reference being ↵Oli Scherer-6/+6
available
2022-12-01rustc_ast_lowering: Stop lowering imports into multiple itemsVadim Petrochenkov-8/+1
Lower them into a single item with multiple resolutions instead. This also allows to remove additional `NodId`s and `DefId`s related to those additional items.
2022-11-24effective visibility: Fix private visibility calculation for modulesVadim Petrochenkov-1/+1
Optimizations removed in the previous commit required this function to behave incorrectly, but now those optimizations are gone so we can fix the bug. Fixes https://github.com/rust-lang/rust/issues/104249
2022-11-24effective visibility: Remove questionable optimizationsVadim Petrochenkov-6/+50
First, they require eagerly calculating private visibility (current normal module), which is somewhat expensive. Private visibilities are also lost once calculated, instead of being cached in the table. Second, I cannot prove that the optimizations are correct. Maybe they can be partially reinstated in the future in cases when it's cheap and provably correct to do them. They will also probably be merged into `fn update` in that case. Partially fixes https://github.com/rust-lang/rust/issues/104249 Fixes https://github.com/rust-lang/rust/issues/104539
2022-11-20Move testsCaio-0/+28
2022-11-12Move testsCaio-0/+109
2022-11-05privacy: Print effective visibilities of constructorsVadim Petrochenkov-16/+30
2022-11-05resolve: More detailed effective visibility tracking for importsVadim Petrochenkov-2/+49
Also drop `extern` blocks from the effective visibility table, they are nominally private and it doesn't make sense to keep them there.
2022-10-31resolve: Turn the binding from `#[macro_export]` into a proper `Import`Vadim Petrochenkov-4/+4
2022-10-26privacy: Rename "accessibility levels" to "effective visibilities"Vadim Petrochenkov-209/+209
And a couple of other naming tweaks Related to https://github.com/rust-lang/rust/issues/48054
2022-10-25Perf improvements for effective visibility calculatingBryanskiy-6/+6
2022-10-19resolve: Revert "Set effective visibilities for imports more precisely"Vadim Petrochenkov-1/+8
2022-10-16Auto merge of #102026 - Bryanskiy:resolve_update, r=petrochenkovbors-40/+33
Populate effective visibilities in 'rustc_resolve' Next part of RFC https://github.com/rust-lang/rust/issues/48054. previous: https://github.com/rust-lang/rust/pull/101713 `@rustbot` author r? `@petrochenkov`
2022-10-16Populate effective visibilities in 'rustc_resolve'Bryanskiy-40/+33
2022-10-13Move some tests to more reasonable directoriesCaio-0/+51
2022-10-01bless ui testsMaybe Waffle-6/+6
2022-09-26address reviewb-naber-16/+16
2022-09-24Rollup merge of #102109 - petrochenkov:addids, r=oli-obkMatthias Krüger-2/+45
resolve: Set effective visibilities for imports more precisely Instead of setting them for all primary and additional IDs of the import, only set them for the binding's true ID.
2022-09-23Restore ignore tagFlorian Bartels-1/+0
This test case actually requires std::process.
2022-09-22resolve: Set effective visibilities for imports more preciselyVadim Petrochenkov-2/+2
Instead of setting them for all primary and additional IDs of the import, only set them for the binding's true ID.
2022-09-22effective visibility: Add test for a reexport of two namesVadim Petrochenkov-2/+45
in different namespaces, one public and another private.
2022-09-14change AccessLevels representationBryanskiy-114/+106
2022-08-31add TestReachabilityVisitorBryanskiy-0/+174
2022-07-19use `par_for_each_in` in `par_body_owners` and `collect_crate_mono_items`SparrowLii-2/+14
2022-07-01Shorten def_span for more items.Camille GILLOT-174/+138
2022-06-23Rollup merge of #98283 - TaKO8Ki:point-at-private-fields-in-struct-literal, ↵Michael Goulet-2/+4
r=compiler-errors Point at private fields in struct literal closes #95872
2022-06-22add "was" to pluralize macro and use itTakayuki Maeda-1/+1
2022-06-22stop pointing at definitions of missing fieldsTakayuki Maeda-5/+1
2022-06-20point at private fields in struct literalTakayuki Maeda-2/+8
2022-06-16diagnostics: fix trailing spaceklensy-2/+2
2022-06-15add a test case for `decl_macro`Takayuki Maeda-3/+21
2022-06-14change edition to 2021Takayuki Maeda-1/+1
2022-06-14suggest adding a `#[macro_export]` to a private macroTakayuki Maeda-0/+28
2022-06-01Rollup merge of #97264 - ↵Matthias Krüger-0/+2
TaKO8Ki:suggest-extern-crate-when-failing-to-resolve-use-crate, r=estebank Suggest `extern crate foo` when failing to resolve `use foo` closes #97095 r? ``@estebank``
2022-05-25suggest `extern crate foo` when failing to resolve `use foo`Takayuki Maeda-0/+2
fix ci error
2022-05-21Remove `crate` visibility modifier in libs, testsJacob Pratt-27/+21
2022-05-17Types with reachable constructors are reachableTomasz Miąsko-0/+41
2022-04-11fix a bad error message for `relative paths are not supported in ↵Takayuki Maeda-2/+2
visibilities` error
2022-01-14fix: set struct/union/enum fields/variants as reachable when item isLamb-0/+27
2021-12-27Rollup merge of #90586 - jswrenn:relax-privacy-lints, r=petrochenkovMatthias Krüger-42/+317
Relax priv-in-pub lint on generic bounds and where clauses of trait impls. The priv-in-pub lint is a legacy mechanism of the compiler, supplanted by a reachability-based [type privacy](https://github.com/rust-lang/rfcs/blob/master/text/2145-type-privacy.md) analysis. This PR does **not** relax type privacy; it only relaxes the lint (as proposed by the type privacy RFC) in the case of trait impls. ## Current Behavior On public trait impls, it's currently an **error** to have a `where` bound constraining a private type with a trait: ```rust pub trait Trait {} pub struct Type {} struct Priv {} impl Trait for Priv {} impl Trait for Type where Priv: Trait // ERROR {} ``` ...and it's a **warning** to have have a public type constrained by a private trait: ```rust pub trait Trait {} pub struct Type {} pub struct Pub {} trait Priv {} impl Priv for Pub {} impl Trait for Type where Pub: Priv // WARNING {} ``` This lint applies to `where` clauses in other contexts, too; e.g. on free functions: ```rust struct Priv<T>(T); pub trait Pub {} impl<T: Pub> Pub for Priv<T> {} pub fn function<T>() where Priv<T>: Pub // WARNING {} ``` **These constraints could be relaxed without issue.** ## New Behavior This lint is relaxed for `where` clauses on trait impls, such that it's okay to have a `where` bound constraining a private type with a trait: ```rust pub trait Trait {} pub struct Type {} struct Priv {} impl Trait for Priv {} impl Trait for Type where Priv: Trait // OK {} ``` ...and it's okay to have a public type constrained by a private trait: ```rust pub trait Trait {} pub struct Type {} pub struct Pub {} trait Priv {} impl Priv for Pub {} impl Trait for Type where Pub: Priv // OK {} ``` ## Rationale While the priv-in-pub lint is not essential for soundness, it *can* help programmers avoid pitfalls that would make their libraries difficult to use by others. For instance, such a lint *is* useful for free functions; e.g. if a downstream crate tries to call the `function` in the previous snippet in a generic context: ```rust fn callsite<T>() where Priv<T>: Pub // ERROR: omitting this bound is a compile error, but including it is too { function::<T>() } ``` ...it cannot do so without repeating `function`'s `where` bound, which we cannot do because `Priv` is out-of-scope. A lint for this case is arguably helpful. However, this same reasoning **doesn't** hold for trait impls. To call an unconstrained method on a public trait impl with private bounds, you don't need to forward those private bounds, you can forward the public trait: ```rust mod upstream { pub trait Trait { fn method(&self) {} } pub struct Type<T>(T); pub struct Pub<T>(T); trait Priv {} impl<T: Priv> Priv for Pub<T> {} impl<T> Trait for Type<T> where Pub<T>: Priv // WARNING {} } mod downstream { use super::upstream::*; fn function<T>(value: Type<T>) where Type<T>: Trait // <- no private deets! { value.method(); } } ``` **This PR only eliminates the lint on trait impls.** It leaves it intact for all other contexts, including trait definitions, inherent impls, and function definitions. It doesn't need to exist in those cases either, but I figured I'd first target a case where it's mostly pointless. ## Other Notes - See discussion [on zulip](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/relax.20priv-in-pub.20lint.20for.20trait.20impl.20.60where.60.20bounds/near/222458397). - This PR effectively reverts #79291.
2021-12-27relax priv-in-pub lint on generic bounds and where clauses in trait implsJack Wrenn-42/+317
2021-12-09Add needs-unwind to tests that depend on panickingDavid Koloski-0/+1
This directive isn't automatically set by compiletest or x.py, but can be turned on manually for targets that require it.
2021-11-20Rollup merge of #90628 - ↵Matthias Krüger-7/+293
ken-matsui:clarify-error-messages-caused-by-reexporting-pub-crate-visibility-to-outside, r=oli-obk Clarify error messages caused by re-exporting `pub(crate)` visibility to outside This PR clarifies error messages and suggestions caused by re-exporting pub(crate) visibility outside the crate. Here is a small example ([Rust Playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=e2cd0bd4422d4f20e6522dcbad167d3b)): ```rust mod m { pub(crate) enum E {} } pub use m::E; fn main() {} ``` This code is compiled to: ``` error[E0365]: `E` is private, and cannot be re-exported --> prog.rs:4:9 | 4 | pub use m::E; | ^^^^ re-export of private `E` | = note: consider declaring type or module `E` with `pub` error: aborting due to previous error For more information about this error, try `rustc --explain E0365`. ``` However, enum `E` is actually public to the crate, not private totally—nevertheless, rustc treats `pub(crate)` and private visibility as the same on the error messages. They are not clear and should be segmented distinctly. By applying changes in this PR, the error message below will be the following message that would be clearer: ``` error[E0365]: `E` is only public to inside of the crate, and cannot be re-exported outside --> prog.rs:4:9 | 4 | pub use m::E; | ^^^^ re-export of crate public `E` | = note: consider declaring type or module `E` with `pub` error: aborting due to previous error For more information about this error, try `rustc --explain E0365`. ```
2021-11-20Clarify error messages caused by re-exporting `pub(crate)` visibility to outsideKen Matsui-7/+293
2021-11-18Move some tests to more reasonable directoriesCaio-0/+182
2021-11-14Move some tests to more reasonable directoriesCaio-0/+37
2021-11-03Clean up some `-Z unstable-options` in tests.Eric Huss-4/+5