-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
implied bounds from impl header are not used in associated functions/consts #98852
Labels
A-associated-items
Area: Associated items (types, constants & functions)
A-implied-bounds
Area: Implied bounds / inferred outlives-bounds
C-bug
Category: This is a bug.
P-medium
Medium priority
regression-from-stable-to-stable
Performance or correctness regression from one stable version to another.
T-types
Relevant to the types team, which will review and decide on the PR/issue.
Comments
rustbot
added
A-associated-items
Area: Associated items (types, constants & functions)
A-implied-bounds
Area: Implied bounds / inferred outlives-bounds
regression-from-stable-to-stable
Performance or correctness regression from one stable version to another.
T-types
Relevant to the types team, which will review and decide on the PR/issue.
I-prioritize
Issue: Indicates that prioritization has been requested for this issue.
labels
Jul 3, 2022
WG-prioritization assigning priority (Zulip discussion). @rustbot label -I-prioritize +P-medium |
rustbot
added
P-medium
Medium priority
and removed
I-prioritize
Issue: Indicates that prioritization has been requested for this issue.
labels
Jul 4, 2022
This was referenced Nov 5, 2022
bors
added a commit
to rust-lang-ci/rust
that referenced
this issue
Nov 8, 2023
fix fn item implied bounds and wf check These are two distinct changes: 1. Wf-check all fn item substs. Fixes rust-lang#104005 2. Use implied bounds from impl header. Fixes rust-lang#98852 Fixes rust-lang#102611 The first is a breaking change and will likely have big impact without the the second one. See the first commit for how it breaks libstd. Landing the second one without the first will allow more incorrect code to pass. For example an exploit of rust-lang#104005 would be as simple as: ```rust use core::fmt::Display; trait ExtendLt<Witness> { fn extend(self) -> Box<dyn Display>; } impl<T: Display> ExtendLt<&'static T> for T { fn extend(self) -> Box<dyn Display> { Box::new(self) } } fn main() { let val = (&String::new()).extend(); println!("{val}"); } ``` cc `@lcnr` r? types
bors
added a commit
to rust-lang-ci/rust
that referenced
this issue
Nov 9, 2023
fix fn item implied bounds and wf check These are two distinct changes: 1. Wf-check all fn item substs. Fixes rust-lang#104005 2. Use implied bounds from impl header. Fixes rust-lang#98852 Fixes rust-lang#102611 The first is a breaking change and will likely have big impact without the the second one. See the first commit for how it breaks libstd. Landing the second one without the first will allow more incorrect code to pass. For example an exploit of rust-lang#104005 would be as simple as: ```rust use core::fmt::Display; trait ExtendLt<Witness> { fn extend(self) -> Box<dyn Display>; } impl<T: Display> ExtendLt<&'static T> for T { fn extend(self) -> Box<dyn Display> { Box::new(self) } } fn main() { let val = (&String::new()).extend(); println!("{val}"); } ``` cc `@lcnr` r? types
The same issue exists for associated consts: /// A type with an implied bound `'b: 'a`
struct Ty<'a, 'b>(&'a &'b ());
impl<'a, 'b> Ty<'a, 'b> {
const CONST_1: () = ();
const CONST_2: () = {
Self::CONST_1
//~^ ERROR lifetime may not live long enough
};
} |
aliemjay
changed the title
implied bounds from impl header are not used in associated functions
implied bounds from impl header are not used in associated functions/consts
Nov 13, 2023
bors
added a commit
to rust-lang-ci/rust
that referenced
this issue
Nov 20, 2023
fix fn/const items implied bounds and wf check These are two distinct changes (edit: actually three, see below): 1. Wf-check all fn item args. This is a soundness fix. Fixes rust-lang#104005 2. Use implied bounds from impl header in borrowck of associated functions/consts. This strictly accepts more code and helps to mitigate the impact of other breaking changes. Fixes rust-lang#98852 Fixes rust-lang#102611 The first is a breaking change and will likely have a big impact without the the second one. See the first commit for how it breaks libstd. Landing the second one without the first will allow more incorrect code to pass. For example an exploit of rust-lang#104005 would be as simple as: ```rust use core::fmt::Display; trait ExtendLt<Witness> { fn extend(self) -> Box<dyn Display>; } impl<T: Display> ExtendLt<&'static T> for T { fn extend(self) -> Box<dyn Display> { Box::new(self) } } fn main() { let val = (&String::new()).extend(); println!("{val}"); } ``` The third change is to to check WF of user type annotations before normalizing them (fixes rust-lang#104764, fixes rust-lang#104763). It is mutually dependent on the second change above: an attempt to land it separately in rust-lang#104746 caused several crater regressions that can all be mitigated by using the implied from the impl header. It is also necessary for the soundness of associated consts that use the implied bounds of impl header. See rust-lang#104763 and how the third commit fixes the soundness issue in `tests/ui/wf/wf-associated-const.rs` that was introduces by the previous commit. cc `@lcnr` r? types
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-associated-items
Area: Associated items (types, constants & functions)
A-implied-bounds
Area: Implied bounds / inferred outlives-bounds
C-bug
Category: This is a bug.
P-medium
Medium priority
regression-from-stable-to-stable
Performance or correctness regression from one stable version to another.
T-types
Relevant to the types team, which will review and decide on the PR/issue.
The following fails to compile although it shouldn't: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=f7287b6897a385360f7190001b58348d
Another repro:
The first repro regressed in 1.43 while the second one is as old as implied bounds.
@rustbot label A-implied-bounds A-associated-items regression-from-stable-to-stable T-types
Meta
Nightly version: 1.64.0-nightly
(2022-07-01 46b8c23)
Backtrace
The text was updated successfully, but these errors were encountered: