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

remove unreachable error code E0476 #106840

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_error_codes/src/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ E0791: include_str!("./error_codes/E0791.md"),
// E0473, // dereference of reference outside its lifetime
// E0474, // captured variable `..` does not outlive the enclosing closure
// E0475, // index of slice outside its lifetime
E0476, // lifetime of the source pointer does not outlive lifetime bound...
// E0476, // removed: unreachable
// E0479, // the type `..` (provided as the value of a type parameter) is...
// E0480, // lifetime of method receiver does not outlive the method call
// E0481, // lifetime of function argument does not outlive the function call
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_hir_analysis/src/coherence/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::lang_items::LangItem;
use rustc_hir::ItemKind;
use rustc_infer::infer;
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
use rustc_infer::infer::TyCtxtInferExt;
use rustc_middle::ty::adjustment::CoerceUnsizedInfo;
Expand Down Expand Up @@ -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);
Copy link
Member

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.

Copy link
Member

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 😓

Copy link
Member

@compiler-errors compiler-errors Jan 14, 2023

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.

Copy link
Contributor Author

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.

Copy link
Member

@compiler-errors compiler-errors Jan 14, 2023

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.

Copy link
Contributor Author

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.

(&ty::Ref(_, ty_a, mutbl_a), &ty::Ref(r_b, ty_b, mutbl_b)) => {
let mt_a = ty::TypeAndMut { ty: ty_a, mutbl: mutbl_a };
let mt_b = ty::TypeAndMut { ty: ty_b, mutbl: mutbl_b };
check_mutbl(mt_a, mt_b, &|ty| tcx.mk_imm_ref(r_b, ty))
Expand Down
30 changes: 0 additions & 30 deletions compiler/rustc_infer/src/infer/error_reporting/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
infer::Reborrow(span) => {
RegionOriginNote::Plain { span, msg: fluent::infer_reborrow }.add_to_diagnostic(err)
}
infer::RelateObjectBound(span) => {
RegionOriginNote::Plain { span, msg: fluent::infer_relate_object_bound }
.add_to_diagnostic(err);
}
infer::ReferenceOutlivesReferent(ty, span) => {
RegionOriginNote::WithName {
span,
Expand Down Expand Up @@ -143,32 +139,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
);
err
}
infer::RelateObjectBound(span) => {
let mut err = struct_span_err!(
self.tcx.sess,
span,
E0476,
"lifetime of the source pointer does not outlive lifetime bound of the \
object type"
);
note_and_explain_region(
self.tcx,
&mut err,
"object type is valid for ",
sub,
"",
None,
);
note_and_explain_region(
self.tcx,
&mut err,
"source pointer is only valid for ",
sup,
"",
None,
);
err
}
infer::RelateParamBound(span, ty, opt_span) => {
let mut err = struct_span_err!(
self.tcx.sess,
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,6 @@ pub enum SubregionOrigin<'tcx> {
/// Arose from a subtyping relation
Subtype(Box<TypeTrace<'tcx>>),

/// When casting `&'a T` to an `&'b Trait` object,
/// relating `'a` to `'b`
RelateObjectBound(Span),

/// Some type parameter was instantiated with the given type,
/// and that type must outlive some region.
RelateParamBound(Span, Ty<'tcx>, Option<Span>),
Expand Down Expand Up @@ -1971,7 +1967,6 @@ impl<'tcx> SubregionOrigin<'tcx> {
pub fn span(&self) -> Span {
match *self {
Subtype(ref a) => a.span(),
RelateObjectBound(a) => a,
RelateParamBound(a, ..) => a,
RelateRegionParamBound(a) => a,
Reborrow(a) => a,
Expand Down
2 changes: 1 addition & 1 deletion src/tools/tidy/src/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const IGNORE_DOCTEST_CHECK: &[&str] =

// Error codes that don't yet have a UI test. This list will eventually be removed.
const IGNORE_UI_TEST_CHECK: &[&str] =
&["E0461", "E0465", "E0476", "E0514", "E0523", "E0554", "E0640", "E0717", "E0729", "E0789"];
&["E0461", "E0465", "E0514", "E0523", "E0554", "E0640", "E0717", "E0729", "E0789"];

macro_rules! verbose_print {
($verbose:expr, $($fmt:tt)*) => {
Expand Down