-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
ref mut bindings fail to enforce invariance #23116
Comments
triage: P-backcompat-lang (1.0 beta) -- soundness violation |
Another test case: #![allow(dead_code)]
use std::fmt::Debug;
struct S(Box<Debug + 'static>);
impl S {
fn bar<'a>(&'a mut self)->&'a mut Box<Debug + 'a> {
let ref mut x = self.0;
x // should error!
}
}
fn main() {} |
This is a little bit more complex than I originally gave it credit for. In particular, the interaction between |
Some comments on my current plans (from the commit): When matching against a pattern (either via This is a [breaking-change] in that it closes a type hole that previously existed, and in that coercion is not performed. You should be able to work around the latter by converting: let ref mut x: T = expr; into let x: T = expr;
let ref mut x = x; Restricting coercion not to apply in the case of
The change to match I feel ok about but similarly unthrilled. There is some subtle text already concerning whether to use eqtype or subtype for identifier bindings. The best fix I think would be to always have match use strict equality but use subtyping on identifier bindings, but the comment |
…=pnkfelix Don't allow upcasting to a supertype in the type of the match discriminant. Fixes rust-lang#23116. This is a [breaking-change] in that it closes a type hole that previously existed. r? @pnkfelix
Don't allow upcasting to a supertype in the type of the match discriminant. Fixes rust-lang#23116. This is a [breaking-change] in that it closes a type hole that previously existed. r? @pnkfelix
As originally "reported" here, ref mut bindings are not working properly:
The text was updated successfully, but these errors were encountered: