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

Migrate typeck::outlives::mod.rs to SessionDiagnostic #100659

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: 2 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/typeck.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,5 @@ typeck_manual_implementation =
.help = add `#![feature(unboxed_closures)]` to the crate attributes to enable

typeck_substs_on_overridden_impl = could not resolve substs on overridden impl

typeck_rustc_outlives = rustc_outlives
17 changes: 17 additions & 0 deletions compiler/rustc_typeck/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,20 @@ pub struct SubstsOnOverriddenImpl {
#[primary_span]
pub span: Span,
}

pub struct RustcOutlives {
pub span: Span,
pub pred: Vec<String>,
}

impl SessionDiagnostic<'_> for RustcOutlives {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not use a manual implementation of SessionDiagnostic but instead be using the derive macro, I think.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you will be able to simplify this with a diagnostic derive, you can see examples in the blog post.

fn into_diagnostic(self, sess: &ParseSess) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
let mut diag = sess
.span_diagnostic
.struct_span_err(self.span, rustc_errors::fluent::typeck::rustc_outlives);
for p in self.pred {
diag.note(p);
}
diag
}
}
9 changes: 3 additions & 6 deletions compiler/rustc_typeck/src/outlives/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use rustc_middle::ty::{self, CratePredicatesMap, ToPredicate, TyCtxt};
use rustc_span::symbol::sym;
use rustc_span::Span;

use crate::errors::RustcOutlives;

mod explicit;
mod implicit_infer;
pub(crate) mod outlives_bounds;
Expand Down Expand Up @@ -59,12 +61,7 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[(ty::Predicate
.collect();
pred.sort();

let span = tcx.def_span(item_def_id);
let mut err = tcx.sess.struct_span_err(span, "rustc_outlives");
Copy link
Member

@davidtwco davidtwco Aug 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pre-existing: this is a bizarre error message.. and the blame is from many years ago.

for p in &pred {
err.note(p);
}
err.emit();
tcx.sess.emit_err(RustcOutlives { span: tcx.def_span(item_def_id), pred });
}

debug!("inferred_outlives_of({:?}) = {:?}", item_def_id, predicates);
Expand Down