-
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
remove unreachable error code E0476
#106840
Conversation
Some changes occurred in diagnostic error codes |
Looks good to me but since it's changing compiler's code, we'll need someone from their team. r? @estebank |
@@ -386,8 +385,7 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn | |||
(mt_a.ty, mt_b.ty, unsize_trait, None) | |||
}; | |||
let (source, target, trait_def_id, kind) = match (source.kind(), target.kind()) { | |||
(&ty::Ref(r_a, ty_a, mutbl_a), &ty::Ref(r_b, ty_b, mutbl_b)) => { | |||
infcx.sub_regions(infer::RelateObjectBound(span), r_b, r_a); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this line removed? This has side-effects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could give it a different subregion origin, but this is required for soundness 😓
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code reproduces this error:
#![feature(coerce_unsized)]
#![feature(unsize)]
use core::marker::Unsize;
use core::ops::CoerceUnsized;
struct Wrapper<T>(T);
impl<'a, 'b, T, S> CoerceUnsized<&'a Wrapper<T>> for &'b Wrapper<S> where S: Unsize<T> {}
Although it has a coherence error as well. Presumably if you made https://doc.rust-lang.org/src/core/ops/unsize.rs.html#55 this implementation unsound by removing 'b: 'a
, then it would also trigger there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, my mistake, I assumed that this error code was no longer used. I'll close this PR and document/test it instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's alright -- in general, I would never remove side-effect-ful logic just because you think it's dead code. Sometimes people just forget to add a UI test for an error code.
Replace it with a delay_span_bug
or bug!()
if necessary, but unless you can statically prove that something is unreachable, you're very likely to introduce unsoundness or other subtle bugs into the compiler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I was kind of naive. I assumed that untested error codes (basically all of them are like this) were from old Rust versions and had never been formally removed.
Remove
E0476
unreachable/undocumented/untested error code.r? @GuillaumeGomez (I don't think you've noticed my other PRs for #61137 so I'll do more than just ping)