Skip to content
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

Tracking issue for IMPLIED_BOUNDS_ENTAILMENT lint #105572

Closed
compiler-errors opened this issue Dec 11, 2022 · 1 comment · Fixed by #117984
Closed

Tracking issue for IMPLIED_BOUNDS_ENTAILMENT lint #105572

compiler-errors opened this issue Dec 11, 2022 · 1 comment · Fixed by #117984
Labels
C-tracking-issue Category: A tracking issue for an RFC or an unstable feature.

Comments

@compiler-errors
Copy link
Member

compiler-errors commented Dec 11, 2022

This is a tracking issue for the IMPLIED_BOUNDS_ENTAILMENT lint, which was added in #105575. The lint detects cases where the arguments of an impl method have stronger implied bounds than those from the trait method it's implementing.

Example

This warning will trigger for code like:

#![deny(implied_bounds_entailment)]

use std::borrow::Cow;

pub trait Decoder { type Error; }

pub trait Decodable: Sized {
   fn decode<D: Decoder>(d: &mut D) -> Result<Self, D::Error>;
}

impl<'a, T: ?Sized> Decodable for Cow<'a, T>
where T: ToOwned, T::Owned: Decodable
{
    fn decode<D: Decoder>(d: &mut D) -> Result<Cow<'static, T>, D::Error> {
        Ok(Cow::Owned(Decodable::decode(d)?))
    }
}

Unsoundness Exploitation

This can be used to implement an unsound API if used incorrectly, see #80176. While the previous example is sound, it can result in undefined behavior not previously caught by the compiler:

#![deny(implied_bounds_entailment)]

trait Trait {
    fn get<'s>(s: &'s str, _: &'static &'static ()) -> &'static str;
}

impl Trait for () {
    fn get<'s>(s: &'s str, _: &'static &'s ()) -> &'static str {
        s
    }
}

let val = <() as Trait>::get(&String::from("blah blah blah"), &&());
println!("{}", val);

Explanation

Neither the trait method, which provides no implied bounds about 's, nor the impl, which can't name 's, requires the main function to prove that 's: 'static, but the impl method is able to assume that 's: 'static within its own body.


See: #105483, #105295

bumped to deny-by-default in #106465

bors added a commit to rust-lang-ci/rust that referenced this issue Dec 20, 2022
Add `IMPLIED_BOUNDS_ENTAILMENT` lint

Implements a lint (rust-lang#105572) version of the hard-error introduced in rust-lang#105483. Context is in that PR.

r? `@lcnr`
cc `@oli-obk` who had asked for this to be a lint first

Not sure if this needs to be an FCP, since it's a lint for now.
dgreid added a commit to dgreid/salus that referenced this issue Dec 30, 2022
See: rust-lang/rust#105572
Trait implementations adding more restrictive constrains to a trait
definition will soon be an error.

Luckily, it doesn't seem that this 'static lifetime bound is needed by
`PageBox` so remove it to make newer versions of rust happy.

Signed-off-by: Dylan Reid <dgreid@rivosinc.com>
abrestic-rivos pushed a commit to rivosinc/salus that referenced this issue Jan 3, 2023
See: rust-lang/rust#105572
Trait implementations adding more restrictive constrains to a trait
definition will soon be an error.

Luckily, it doesn't seem that this 'static lifetime bound is needed by
`PageBox` so remove it to make newer versions of rust happy.

Signed-off-by: Dylan Reid <dgreid@rivosinc.com>
@Dylan-DPC Dylan-DPC added the C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. label Feb 4, 2023
bors bot added a commit to tock/tock that referenced this issue Feb 7, 2023
3391: kernel: sched: mlfq r=hudson-ayers a=bradjc



### Pull Request Overview

I updated the Rust compiler to a February 2023 nightly, and encountered build errors. Specifically:

```
error: impl method assumes more implied bounds than the corresponding trait method
  --> kernel/src/scheduler/mlfq.rs:54:26
   |
54 |     fn next(&'a self) -> &'static ListLink<'a, MLFQProcessNode<'a>> {
   |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace this type to make the impl signature compatible: `&'a ListLink<'a, MLFQProcessNode<'a>>`
   |
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
   = note: for more information, see issue #105572 <rust-lang/rust#105572>
   = note: `#[deny(implied_bounds_entailment)]` on by default
```
This implements the proposed change.

We need to fix this before we will be able to update to a new nightly. However, this seemed perhaps more substantial that the typical fixes needed to update nightlies, so I thought it was worth making a dedicated PR.

### Testing Strategy

compiling


### TODO or Help Wanted

n/a


### Documentation Updated

- [x] Updated the relevant files in `/docs`, or no updates are required.

### Formatting

- [x] Ran `make prepush`.


Co-authored-by: Brad Campbell <bradjc5@gmail.com>
bors bot added a commit to tock/tock that referenced this issue Feb 20, 2023
3392: kernel: util: static ref deref return type r=hudson-ayers a=bradjc



### Pull Request Overview

I updated the Rust compiler to a February 2023 nightly, and encountered build errors. Specifically:


```
error: impl method assumes more implied bounds than the corresponding trait method
  --> kernel/src/utilities/static_ref.rs:40:24
   |
40 |     fn deref(&self) -> &'static T {
   |                        ^^^^^^^^^^ help: replace this type to make the impl signature compatible: `&T`
   |
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
   = note: for more information, see issue #105572 <rust-lang/rust#105572>
```

Again, this changes a very core file, which I don't think should be swept up in an "Update Nightly" pr. 

### Testing Strategy

This pull request was tested by travis.


### TODO or Help Wanted

n/a


### Documentation Updated

- [x] Updated the relevant files in `/docs`, or no updates are required.

### Formatting

- [x] Ran `make prepush`.


Co-authored-by: Brad Campbell <bradjc5@gmail.com>
@compiler-errors
Copy link
Member Author

cc #108544, before we make this a hard-error.

ivan added a commit to ludios/natural-sort-rs that referenced this issue Apr 13, 2023
This fixes

```
The package `rustc-serialize v0.3.24` currently triggers the following future incompatibility lints:
> warning: impl method assumes more implied bounds than the corresponding trait method
>     --> /home/at/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustc-serialize-0.3.24/src/serialize.rs:1155:41
>      |
> 1155 |     fn decode<D: Decoder>(d: &mut D) -> Result<Cow<'static, T>, D::Error> {
>      |                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace this type to make the impl signature compatible: `Result<Cow<'a, T>, <D as serialize::Decoder>::Error>`
>      |
>      = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
>      = note: for more information, see issue #105572 <rust-lang/rust#105572>
>      = note: `#[allow(implied_bounds_entailment)]` on by default
>
```
metatoaster added a commit to Physiome/pmrplatform that referenced this issue Jul 17, 2023
- The bounded version will own an inner copy and a reference to the
  origin backend, this will allow additional querying of data.
- However, there were some lifetime difficulties with traits and impls
  when trying to convert the existing impls fns from returning the
  current unbound version to return the bounded ref version.
- Reference: rust-lang/rust#105572
bors added a commit to rust-lang-ci/rust that referenced this issue Nov 17, 2023
…lment, r=<try>

Make `IMPLIED_BOUNDS_ENTAILMENT` into a hard error from a lint

closes rust-lang#105572

Removes the `IMPLIED_BOUNDS_ENTAILMENT` and makes the `compare_method_predicate_entailment` logic just run once.

r? lcnr
bors added a commit to rust-lang-ci/rust that referenced this issue Dec 16, 2023
…lment, r=lcnr

Make `IMPLIED_BOUNDS_ENTAILMENT` into a hard error from a lint

closes rust-lang#105572

Removes the `IMPLIED_BOUNDS_ENTAILMENT` and makes the `compare_method_predicate_entailment` logic just run once.

r? lcnr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-tracking-issue Category: A tracking issue for an RFC or an unstable feature.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants