1
Fork 0

First batch of review feedback changes from #102110

This commit is contained in:
Nathan Stocks 2022-10-03 17:34:59 -06:00
parent be4059dd3e
commit 965dbf6c28
9 changed files with 43 additions and 22 deletions

View file

@ -18,3 +18,12 @@ middle_limit_invalid =
middle_const_eval_non_int = middle_const_eval_non_int =
constant evaluation of enum discriminant resulted in non-integer constant evaluation of enum discriminant resulted in non-integer
middle_unknown_layout =
the type `{$ty}` has an unknown layout
middle_values_too_big =
values of the type `{$ty}` are too big for the current architecture
middle_cannot_be_normalized =
unable to determine layout for `{$ty}` because `{$failure_ty}` cannot be normalized

View file

@ -526,7 +526,7 @@ passes_no_main_function =
.main_must_be_defined_at_crate = the main function must be defined at the crate level{$has_filename -> .main_must_be_defined_at_crate = the main function must be defined at the crate level{$has_filename ->
[true] {" "}(in `{$filename}`) [true] {" "}(in `{$filename}`)
*[false] {""} *[false] {""}
} }
.consider_adding_main_to_file = consider adding a `main` function to `{$filename}` .consider_adding_main_to_file = consider adding a `main` function to `{$filename}`
.consider_adding_main_at_crate = consider adding a `main` function at the crate level .consider_adding_main_at_crate = consider adding a `main` function at the crate level
.teach_note = If you don't know the basics of Rust, you can go look to the Rust Book to get started: https://doc.rust-lang.org/book/ .teach_note = If you don't know the basics of Rust, you can go look to the Rust Book to get started: https://doc.rust-lang.org/book/

View file

@ -191,10 +191,29 @@ pub enum LayoutError<'tcx> {
impl<'a> IntoDiagnostic<'a, !> for LayoutError<'a> { impl<'a> IntoDiagnostic<'a, !> for LayoutError<'a> {
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, !> { fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, !> {
handler.struct_fatal(self.to_string()) let mut diag = handler.struct_fatal("");
match self {
LayoutError::Unknown(ty) => {
diag.set_arg("ty", ty);
diag.set_primary_message(rustc_errors::fluent::middle::unknown_layout);
}
LayoutError::SizeOverflow(ty) => {
diag.set_arg("ty", ty);
diag.set_primary_message(rustc_errors::fluent::middle::values_too_big);
}
LayoutError::NormalizationFailure(ty, e) => {
diag.set_arg("ty", ty);
diag.set_arg("failure_ty", e.get_type_for_failure());
diag.set_primary_message(rustc_errors::fluent::middle::cannot_be_normalized);
}
}
diag
} }
} }
// FIXME: Once the other errors that embed this error have been converted to translateable
// diagnostics, this Display impl should be removed.
impl<'tcx> fmt::Display for LayoutError<'tcx> { impl<'tcx> fmt::Display for LayoutError<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self { match *self {

View file

@ -14,7 +14,7 @@ use rustc_hir::diagnostic_items::DiagnosticItems;
use rustc_middle::ty::query::Providers; use rustc_middle::ty::query::Providers;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
use rustc_span::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE}; use rustc_span::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
use rustc_span::symbol::{sym, Symbol}; use rustc_span::symbol::{kw::Empty, sym, Symbol};
use crate::errors::{DuplicateDiagnosticItem, DuplicateDiagnosticItemInCrate}; use crate::errors::{DuplicateDiagnosticItem, DuplicateDiagnosticItemInCrate};
@ -46,7 +46,7 @@ fn collect_item(tcx: TyCtxt<'_>, items: &mut DiagnosticItems, name: Symbol, item
None => tcx.sess.emit_err(DuplicateDiagnosticItemInCrate { None => tcx.sess.emit_err(DuplicateDiagnosticItemInCrate {
span: orig_span, span: orig_span,
// FIXME: We should not provide `name` to `orig_crate_name`. How do you create a blank/empty symbol? // FIXME: We should not provide `name` to `orig_crate_name`. How do you create a blank/empty symbol?
orig_crate_name: orig_crate_name.unwrap_or(name), orig_crate_name: orig_crate_name.unwrap_or(Empty),
have_orig_crate_name: orig_crate_name.map(|_| ()), have_orig_crate_name: orig_crate_name.map(|_| ()),
crate_name: tcx.crate_name(item_def_id.krate), crate_name: tcx.crate_name(item_def_id.krate),
name, name,

View file

@ -830,14 +830,6 @@ pub struct UnrecognizedField {
pub name: Symbol, pub name: Symbol,
} }
#[derive(Diagnostic)]
#[diag(passes::layout)]
pub struct Layout {
#[primary_span]
pub span: Span,
pub layout_error: String,
}
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(passes::feature_stable_twice, code = "E0711")] #[diag(passes::feature_stable_twice, code = "E0711")]
pub struct FeatureStableTwice { pub struct FeatureStableTwice {
@ -1259,7 +1251,7 @@ pub struct IncorrectTarget<'a> {
pub span: Span, pub span: Span,
#[label] #[label]
pub generics_span: Span, pub generics_span: Span,
pub name: &'a str, pub name: &'a str, // cannot be symbol because it renders e.g. `r#fn` instead of `fn`
pub kind: &'static str, pub kind: &'static str,
pub num: usize, pub num: usize,
pub actual_num: usize, pub actual_num: usize,

View file

@ -20,7 +20,7 @@ use rustc_hir::lang_items::{extract, GenericRequirement, ITEM_REFS};
use rustc_hir::{HirId, LangItem, LanguageItems, Target}; use rustc_hir::{HirId, LangItem, LanguageItems, Target};
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
use rustc_session::cstore::ExternCrate; use rustc_session::cstore::ExternCrate;
use rustc_span::{Span, Symbol}; use rustc_span::{symbol::kw::Empty, Span};
use rustc_middle::ty::query::Providers; use rustc_middle::ty::query::Providers;
@ -66,7 +66,7 @@ impl<'tcx> LanguageItemCollector<'tcx> {
let local_span = self.tcx.hir().span_if_local(item_def_id); let local_span = self.tcx.hir().span_if_local(item_def_id);
let lang_item_name = LangItem::from_u32(item_index as u32).unwrap().name(); let lang_item_name = LangItem::from_u32(item_index as u32).unwrap().name();
let crate_name = self.tcx.crate_name(item_def_id.krate); let crate_name = self.tcx.crate_name(item_def_id.krate);
let mut dependency_of = Symbol::intern(""); let mut dependency_of = Empty;
let is_local = item_def_id.is_local(); let is_local = item_def_id.is_local();
let path = if is_local { let path = if is_local {
String::new() String::new()
@ -80,8 +80,8 @@ impl<'tcx> LanguageItemCollector<'tcx> {
.into() .into()
}; };
let first_defined_span = self.tcx.hir().span_if_local(original_def_id); let first_defined_span = self.tcx.hir().span_if_local(original_def_id);
let mut orig_crate_name = Symbol::intern(""); let mut orig_crate_name = Empty;
let mut orig_dependency_of = Symbol::intern(""); let mut orig_dependency_of = Empty;
let orig_is_local = original_def_id.is_local(); let orig_is_local = original_def_id.is_local();
let orig_path = if orig_is_local { let orig_path = if orig_is_local {
String::new() String::new()

View file

@ -3,11 +3,12 @@ use rustc_hir::def::DefKind;
use rustc_hir::def_id::LocalDefId; use rustc_hir::def_id::LocalDefId;
use rustc_middle::ty::layout::{HasParamEnv, HasTyCtxt, LayoutError, LayoutOfHelpers, TyAndLayout}; use rustc_middle::ty::layout::{HasParamEnv, HasTyCtxt, LayoutError, LayoutOfHelpers, TyAndLayout};
use rustc_middle::ty::{ParamEnv, Ty, TyCtxt}; use rustc_middle::ty::{ParamEnv, Ty, TyCtxt};
use rustc_span::source_map::Spanned;
use rustc_span::symbol::sym; use rustc_span::symbol::sym;
use rustc_span::Span; use rustc_span::Span;
use rustc_target::abi::{HasDataLayout, TargetDataLayout}; use rustc_target::abi::{HasDataLayout, TargetDataLayout};
use crate::errors::{Abi, Align, HomogeneousAggregate, Layout, LayoutOf, Size, UnrecognizedField}; use crate::errors::{Abi, Align, HomogeneousAggregate, LayoutOf, Size, UnrecognizedField};
pub fn test_layout(tcx: TyCtxt<'_>) { pub fn test_layout(tcx: TyCtxt<'_>) {
if tcx.features().rustc_attrs { if tcx.features().rustc_attrs {
@ -91,9 +92,9 @@ fn dump_layout_of<'tcx>(tcx: TyCtxt<'tcx>, item_def_id: LocalDefId, attr: &Attri
} }
Err(layout_error) => { Err(layout_error) => {
tcx.sess.emit_err(Layout { tcx.sess.emit_fatal(Spanned {
node: layout_error,
span: tcx.def_span(item_def_id.to_def_id()), span: tcx.def_span(item_def_id.to_def_id()),
layout_error: format!("{:?}", layout_error),
}); });
} }
} }

View file

@ -4,6 +4,6 @@ use std::borrow::Cow;
#[rustc_layout(debug)] #[rustc_layout(debug)]
type Edges<'a, E> = Cow<'a, [E]>; type Edges<'a, E> = Cow<'a, [E]>;
//~^ ERROR layout error: NormalizationFailure //~^ 6:1: 6:18: unable to determine layout for `<[E] as ToOwned>::Owned` because `<[E] as ToOwned>::Owned` cannot be normalized
fn main() {} fn main() {}

View file

@ -1,4 +1,4 @@
error: layout error: NormalizationFailure(<[E] as std::borrow::ToOwned>::Owned, Type(<[E] as std::borrow::ToOwned>::Owned)) error: unable to determine layout for `<[E] as ToOwned>::Owned` because `<[E] as ToOwned>::Owned` cannot be normalized
--> $DIR/issue-85103.rs:6:1 --> $DIR/issue-85103.rs:6:1
| |
LL | type Edges<'a, E> = Cow<'a, [E]>; LL | type Edges<'a, E> = Cow<'a, [E]>;