Commit graph

160417 commits

Author SHA1 Message Date
Matthias Krüger
b57a6b38c5
Rollup merge of #90586 - jswrenn:relax-privacy-lints, r=petrochenkov
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-27 21:42:25 +01:00
Wesley Wiser
4361d9778b Add myself to .mailmap 2021-12-27 15:37:12 -05:00
Michael Goulet
b1529a680a Visit patterns' literal expressions before binding new idents 2021-12-27 12:20:13 -08:00
Eric Huss
4d6bb4d881 compiletest: Remove some vestigial code 2021-12-26 20:33:10 -08:00
Hiroshi Kori
7a3a668bc9 fix typo: intialized -> initialized 2021-12-26 18:37:11 -08:00
Hiroshi Kori
7ddad349b1 fix typo: the use f.pad -> then use f.pad 2021-12-26 17:44:53 -08:00
Jack Wrenn
ebef8a8cee relax priv-in-pub lint on generic bounds and where clauses in trait impls 2021-12-27 00:22:09 +00:00
PFPoitras
fe80124098 Add test cases for issue #26186 2021-12-26 20:13:29 -04:00
Andre Bogus
3ebd2bc2e4 new lint: init-numbered-fields 2021-12-26 16:19:22 +01:00
bors
bb7b6beca3 Auto merge of #8133 - surechen:fix_8128, r=xFrednet
Fix 8128

Fixes #8128

changelog: Fix  error suggestion of `skip(..).next()` for immutable variable.
2021-12-26 14:05:35 +00:00
surechen
4ffd66074a Fixes #8128
changelog: Fix error suggestion of skip(..).next() for immutable variable.
2021-12-26 21:37:57 +08:00
AngelicosPhosphoros
72b0c8f233 Reverts #92135 because perf regression 2021-12-26 16:02:33 +03:00
bors
f8abed9ed4 Auto merge of #92257 - fee1-dead:fix_env_further_bounds, r=oli-obk
normalize env constness for nested obligations

Closes #92230.
2021-12-26 08:52:31 +00:00
Roc Yu
bbbeefd860
Remove unneeded call to collect 2021-12-25 21:35:05 -05:00
Roc Yu
141c542052
Remove String allocation in loop 2021-12-25 19:41:19 -05:00
bors
51e8031e14 Auto merge of #92262 - notriddle:notriddle/unused-hash, r=jyn514
rustdoc: remove unused Hash impl
2021-12-25 19:41:11 +00:00
bors
c096176fb4 Auto merge of #92227 - Kobzol:rustdoc-doc-hidden, r=jyn514
Rustdoc: use `is_doc_hidden` method on more places

While profiling `rustdoc`, I noticed that finding out if some item is marked with `#[doc(hidden)]` is relatively hot, so I tried to optimize it.

I noticed that there is already a method called `is_doc_hidden` on `TyCtxt`, but it wasn't used much, so I replaced the manual calls to `attrs(...).has_word(...)` with this method. Just by doing that, perf. was improved locally, although I'm not sure if the semantics of the previous calls and this method are the same?

As another step, I tried to querify `is_doc_hidden`, but I didn't include that here until we see the perf. results from the first commit and until I find whether this change is OK at all :)

Can I ask for a perf. run? Thanks.

r? `@jyn514`
2021-12-25 14:47:12 +00:00
dswij
b82c9ce3af Add limitation description for enum_variant_names
`enum_variant_names` will consider characters with no case to be a part
of prefixes/suffixes substring that are compared. This means `Foo1` and
`Foo2` has different prefixes (`Foo1` and `Foo2` prefix respeectively).
This applies to all non-ascii characters with no casing.
2021-12-25 21:55:20 +08:00
dswij
6f7e5cbe21 Some minor cleanup 2021-12-25 21:55:20 +08:00
dswij
c8f016f921 Fix reversed suggestion on postfix 2021-12-25 21:55:20 +08:00
dswij
8ed723bb1f Update str_utils test 2021-12-25 21:55:20 +08:00
dswij
df2e4d17c6 update enum_variants test 2021-12-25 21:55:20 +08:00
dswij
c76e2d1e59 Add str_util helpers to split camelcase strings 2021-12-25 21:55:15 +08:00
dswij
d58fdfbf3c Fix False Positive on enum_variants when prefixes are not camel-case 2021-12-25 21:54:35 +08:00
dswij
f327f0e2b6 Refactor enum_variants 2021-12-25 21:54:35 +08:00
bors
547efad945 Auto merge of #8167 - rust-lang:fix-8166, r=xFredNet
fix an ICE on unwrapping a None

This very likely fixes #8166 though I wasn't able to meaningfully reduce a test case. This line is the only call to `unwrap` within that function, which was the one in the stack trace that triggered the ICE, so I think we'll be OK.

`@hackmad` can you pull and build this branch and check if it indeed fixes your problem?

---

changelog: Fixed ICE in [`unnecessary_cast`]
2021-12-25 13:38:08 +00:00
Andre Bogus
23ffa3ca04 fix an ICE on unwrapping a None 2021-12-25 13:11:54 +01:00
bors
eb24acf60d Auto merge of #8165 - ebobrow:shadow_reuse_fn, r=xFrednet
fix [`shadow_reuse`] false negative for if let bindings

fixes #8087

changelog: trigger [`shadow_reuse`] instead of [`shadow_unrelated`] on shadowed `if let` bindings
2021-12-25 11:58:25 +00:00
bors
67491a22db Auto merge of #92247 - lnicola:rust-analyzer-2021-12-24, r=lnicola
⬆️ rust-analyzer

r? `@ghost`
2021-12-25 02:19:48 +00:00
bors
83bde52116 Auto merge of #92229 - fee1-dead:fix-rustdoc-const-drop, r=dtolnay
Do not display `~const Drop` in rustdoc

Although `T: ~const Drop` is still at an experimental stage, we have already begun inserting these bounds in libstd. This change hides them from rustdoc because 1. `~const` should not be documented in general as it is not yet official syntax; 2. users are not expected to know what `~const Drop` means yet.
2021-12-24 23:12:14 +00:00
Shadlock0133
584e88d41d
Remove maybe_uninit_extra feature from Vec docs
In `Vec`, two doc tests are using `MaybeUninit::write` , stabilized in 1.55. This makes docs' usage of `maybe_uninit_extra` feature unnecessary.
2021-12-24 23:04:10 +01:00
Elliot Bobrow
1b67aa74bd fix shadow_reuse false negative for if let bindings 2021-12-24 13:20:40 -08:00
Michael Howell
551829b6ad rustdoc: remove unused Hash impl 2021-12-24 13:23:03 -07:00
bors
475b00aa40 Auto merge of #92135 - AngelicosPhosphoros:typeid_inline_74362, r=dtolnay
Add `#[inline]` modifier to `TypeId::of`

It was already inlined but it happened only in 4th InlinerPass on my testcase.
With `#[inline]` modifier it happens on 2nd pass.

Closes #74362
2021-12-24 20:06:15 +00:00
Deadbeef
bb4c5515c1
bless ui test 2021-12-25 01:33:13 +08:00
hotate29
a172439f29
Change to enclose both sides of Range in parentheses. 2021-12-25 02:24:31 +09:00
bors
aad4f1039f Auto merge of #92156 - petrochenkov:ctorkind, r=davidtwco
rustc_metadata: Merge `get_ctor_def_id` and `get_ctor_kind`

Also avoid decoding the whole `ty::AssocItem` to get a `has_self` flag.

A small optimization and cleanup extracted from https://github.com/rust-lang/rust/pull/89059.
2021-12-24 17:09:21 +00:00
hotate29
07b6927180
Change ``floating_point_arthmetic::detect_hypot()`` to enclose the expression in parentheses. 2021-12-25 02:02:37 +09:00
Deadbeef
77297e5f1c
normalize env constness for nested obligations 2021-12-25 00:33:23 +08:00
hotate29
45a3b51c6d
Use helper functions in ``Sugg`` tests. 2021-12-25 00:29:30 +09:00
hotate29
0b6d1fdea2
refactor ``Sugg::BinOp`` 2021-12-25 00:29:29 +09:00
hotate29
b3b65a1bf6
Add test 2021-12-25 00:29:24 +09:00
bors
5956600e65 Auto merge of #92253 - RalfJung:miri, r=RalfJung
update Miri

Fixes https://github.com/rust-lang/rust/issues/92246
r? `@ghost`
2021-12-24 13:15:21 +00:00
Krasimir Georgiev
9127f497be Bump gsgdt to 0.1.3
No functional changes intended.

The 0.1.2 -> 0.1.3 commit 3e1dcec539
renames `Node::new` to `Node::from_list`.
2021-12-24 13:46:37 +01:00
bors
8529b2a056 Auto merge of #8163 - pmnoxx:piotr-improve-unwrap-or-default, r=Manishearth
Improve `unwrap_or_else_default` when handling `unwrap_or_else(XXX::new)`

changelog:  change `unwrap_or_else_default` to work with std constructors like `Vec::new`, `HashSet::new`, `HashMap::new`.

Notes:
- Code to handle detecting those constructors is already there. I moved it out to `is_default_equivalent_call`
2021-12-24 12:34:09 +00:00
Ralf Jung
88fb86251a update Miri 2021-12-24 13:04:15 +01:00
bors
fca4b155a7 Auto merge of #92226 - woppopo:const_black_box, r=joshtriplett
Constify `core::intrinsics::black_box` and `core::hint::black_box`.

`core::intrinsics::black_box` is already constified, but it wasn't marked as const (see: https://github.com/rust-lang/rust/blob/master/compiler/rustc_const_eval/src/interpret/intrinsics.rs#L471).

Tracking issue: None
2021-12-24 10:02:54 +00:00
Laurențiu Nicola
464188488b ⬆️ rust-analyzer 2021-12-24 11:20:13 +02:00
Piotr Mikulski
2a47dbc7a6 Simplify code 2021-12-23 22:12:08 -08:00
Piotr Mikulski
01b7411482 Refactor 2021-12-23 22:00:20 -08:00