about summary refs log tree commit diff
path: root/src/test/ui/privacy
AgeCommit message (Collapse)AuthorLines
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
2021-10-18Auto merge of #89124 - cjgillot:owner-info, r=michaelwoeristerbors-14/+2
Index and hash HIR as part of lowering Part of https://github.com/rust-lang/rust/pull/88186 ~Based on https://github.com/rust-lang/rust/pull/88880 (see merge commit).~ Once HIR is lowered, it is later indexed by the `index_hir` query and hashed for `crate_hash`. This PR moves those post-processing steps to lowering itself. As a side objective, the HIR crate data structure is refactored as an `IndexVec<LocalDefId, Option<OwnerInfo<'hir>>>` where `OwnerInfo` stores all the relevant information for an HIR owner. r? `@michaelwoerister` cc `@petrochenkov`
2021-10-15Bless testsCameron Steffen-80/+80
2021-10-10Bless ui tests.Camille GILLOT-14/+2
2021-09-30Bless tests.Camille GILLOT-2/+14
2021-09-15Move some tests to more reasonable directoriesCaio-0/+62
2021-08-14Auto merge of #87600 - JohnTitor:classify-ui-tests, r=petrochenkovbors-0/+40
Move some UI tests to more suitable subdirs The classifui result: https://gist.github.com/JohnTitor/c9e00840990b5e4a8fc562ec3571e427/e06c42226c6038da91e403c33b9947843420cf44 Some notes: - backtrace-debuginfo.rs: previously I skipped this, I'm still not sure what the best dir is. Any ideas? - estr-subtyping.rs: Seems a quite old test so removed, shouldn't? - deref-suggestion.rs: moved to inference as `suggestions` is not an ideal dir. - issue-43023.rs: a bit misclassified, moved to `derives` cc #73494 r? `@petrochenkov`
2021-08-11Modify structured suggestion outputEsteban Küber-9/+11
* On suggestions that include deletions, use a diff inspired output format * When suggesting addition, use `+` as underline * Color highlight modified span
2021-08-10Move some UI tests to more suitable subdirsYuki Okushi-0/+40
2021-08-04Remove trailing whitespace from error messagesFabian Wolff-27/+27
2021-07-27Remove min_tait and full_tait stderr dangling filesSantiago Pastorino-136/+0
2021-07-27Make all tests use type_alias_impl_trait feature instead of minSantiago Pastorino-6/+70
2021-07-27Use type_alias_impl_trait instead of min in compiler and libSantiago Pastorino-38/+18
2021-07-19Various diagnostics clean ups/tweaksEsteban Küber-0/+45
* Always point at macros, including derive macros * Point at non-local items that introduce a trait requirement * On private associated item, point at definition
2021-05-12Show macro name in 'this error originates in macro' messageAaron Hill-80/+80
When there are multiple macros in use, it can be difficult to tell which one was responsible for producing an error.
2021-04-25Improve diagnostics for function passed when a type was expected.Hameer Abbasi-0/+9
2021-04-03Remove redundant `ignore-tidy-linelength` annotationsSimon Jakobi-32/+30
This is step 2 towards fixing #77548. In the codegen and codegen-units test suites, the `//` comment markers were kept in order not to affect any source locations. This is because these tests cannot be automatically `--bless`ed.
2021-03-17Rollup merge of #83092 - petrochenkov:qspan, r=estebankYuki Okushi-2/+2
More precise spans for HIR paths `Ty::assoc_item` is lowered to `<Ty>::assoc_item` in HIR, but `Ty` got span from the whole path. This PR fixes that, and adjusts some diagnostic code that relied on `Ty` having the whole path span. This is a pre-requisite for https://github.com/rust-lang/rust/pull/82868 (we cannot report suggestions like `Tr::assoc` -> `<dyn Tr>::assoc` with the current imprecise spans). r? ````@estebank````
2021-03-15More precise spans for HIR pathsVadim Petrochenkov-2/+2
2021-03-15Replace `type_alias_impl_trait` by `min_type_alias_impl_trait` with no ↵Oli Scherer-9/+103
actual changes in behaviour This makes `type_alias_impl_trait` not actually do anything anymore
2021-02-10resolve: Remove visibility hacks for enum variants and trait itemsVadim Petrochenkov-40/+68
Special treatment like this was necessary before `pub(restricted)` had been implemented and only two visibilities existed - `pub` and non-`pub`. Now it's no longer necessary and the desired behavior follows from `pub(restricted)`-style visibilities naturally assigned to enum variants and trait items.
2021-01-16Move some tests to more reasonable directories - 2Caio-0/+155
Address comments Update limits
2021-01-13Update tests for extern block lintingMark Rousskov-3/+3
2020-12-29Remove `compile-fail` test suiteVadim Petrochenkov-0/+85
2020-11-23Rename `optin_builtin_traits` to `auto_traits`Camelid-2/+2
They were originally called "opt-in, built-in traits" (OIBITs), but people realized that the name was too confusing and a mouthful, and so they were renamed to just "auto traits". The feature flag's name wasn't updated, though, so that's what this PR does. There are some other spots in the compiler that still refer to OIBITs, but I don't think changing those now is worth it since they are internal and not particularly relevant to this PR. Also see <https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/opt-in.2C.20built-in.20traits.20(auto.20traits).20feature.20name>.
2020-11-16improve error message for const ty param mismatchBastian Kauschke-44/+24
2020-10-25Merge remote-tracking branch 'upstream/master' into box-allocTim Diekmann-49/+49
2020-10-19Calculate visibilities once in resolveVadim Petrochenkov-49/+49
Then use them through a query based on resolver outputs
2020-10-07Support custom allocators in `Box`Tim Diekmann-9/+9
Remove `Box::leak_with_alloc` Add leak-test for box with allocator Rename `AllocErr` to `AllocError` in leak-test Add `Box::alloc` and adjust examples to use the new API
2020-10-06Fix tests from rebaseMatthew Jasper-13/+8
2020-10-06Separate bounds and predicates for associated/opaque typesMatthew Jasper-48/+25
2020-09-11Improve E0118 descriptionaticu-7/+9
2020-09-02pretty: trim paths of unique symbolsDan Aloni-194/+194
If a symbol name can only be imported from one place for a type, and as long as it was not glob-imported anywhere in the current crate, we can trim its printed path and print only the name. This has wide implications on error messages with types, for example, shortening `std::vec::Vec` to just `Vec`, as long as there is no other `Vec` importable anywhere. This adds a new '-Z trim-diagnostic-paths=false' option to control this feature. On the good path, with no diagnosis printed, we should try to avoid issuing this query, so we need to prevent trimmed_def_paths query on several cases. This change also relies on a previous commit that differentiates between `Debug` and `Display` on various rustc types, where the latter is trimmed and presented to the user and the former is not.
2020-08-22Use smaller def span for functionsAaron Hill-32/+32
Currently, the def span of a funtion encompasses the entire function signature and body. However, this is usually unnecessarily verbose - when we are pointing at an entire function in a diagnostic, we almost always want to point at the signature. The actual contents of the body tends to be irrelevant to the diagnostic we are emitting, and just takes up additional screen space. This commit changes the `def_span` of all function items (freestanding functions, `impl`-block methods, and `trait`-block methods) to be the span of the signature. For example, the function ```rust pub fn foo<T>(val: T) -> T { val } ``` now has a `def_span` corresponding to `pub fn foo<T>(val: T) -> T` (everything before the opening curly brace). Trait methods without a body have a `def_span` which includes the trailing semicolon. For example: ```rust trait Foo { fn bar(); }``` the function definition `Foo::bar` has a `def_span` of `fn bar();` This makes our diagnostic output much shorter, and emphasizes information that is relevant to whatever diagnostic we are reporting. We continue to use the full span (including the body) in a few of places: * MIR building uses the full span when building source scopes. * 'Outlives suggestions' use the full span to sort the diagnostics being emitted. * The `#[rustc_on_unimplemented(enclosing_scope="in this scope")]` attribute points the entire scope body. * The 'unconditional recursion' lint uses the full span to show additional context for the recursive call. All of these cases work only with local items, so we don't need to add anything extra to crate metadata.
2020-08-10Do not suggest similarly named enclosing itemEsteban Küber-3/+1
2020-08-05Handle fieldless tuple structs in diagnostic codeAaron Hill-0/+25
Fixes #75062
2020-06-21Prefer accessible paths in 'use' suggestionsDan Aloni-30/+6
This fixes an issue with the following sample: mod foo { mod inaccessible { pub struct X; } pub mod avail { pub struct X; } } fn main() { X; } Instead of suggesting both `use crate::foo::inaccessible::X;` and `use crate::foo::avail::X;`, it should only suggest the latter. It is done by trimming the list of suggestions from inaccessible paths if accessible paths are present. Visibility is checked with `is_accessible_from` now instead of being hard-coded. - Some tests fixes are trivial, and others require a bit more explaining, here are my comments: src/test/ui/issues/issue-35675.stderr: Only needs to make the enum public to have the suggestion make sense. src/test/ui/issues/issue-42944.stderr: Importing the tuple struct won't help because its constructor is not visible, so the attempted constructor does not work. In that case, it's better not to suggest it. The case where the constructor is public is covered in `issue-26545.rs`.
2020-06-11Stop special casing top level TAITMatthew Jasper-20/+14
2020-05-07reword "possible candidate" import suggestionAndy Russell-6/+6
2020-04-11rustc: Add a warning count upon completionRoccoDev-3/+3
2020-04-07Do not suggest adding type param when `use` is already suggestedEsteban Küber-4/+0
Fix #70365, cc #70572.
2020-03-27Rollup merge of #70344 - Centril:hir-pretty, r=eddybDylan DPC-5/+5
Decouple `rustc_hir::print` into `rustc_hir_pretty` High level summary: - The HIR pretty printer, `rustc_hir::print` is moved into a new crate `rustc_hir_pretty`. - `rustc_ast_pretty` and `rustc_errors` are dropped as `rustc_hir` dependencies. - The dependence on HIR pretty is generally reduced, leaving `rustc_save_analysis`, `rustdoc`, `rustc_metadata`, and `rustc_driver` as the remaining clients. The main goal here is to reduce `rustc_hir`'s dependencies and its size such that it can start and finish earlier, thereby working towards https://github.com/rust-lang/rust/issues/65031. r? @Zoxc