Skip to content

Commit 965dbf6

Browse files
committed
First batch of review feedback changes from rust-lang#102110
1 parent be4059d commit 965dbf6

File tree

9 files changed

+43
-22
lines changed

9 files changed

+43
-22
lines changed

compiler/rustc_error_messages/locales/en-US/middle.ftl

+9
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,12 @@ middle_limit_invalid =
1818
1919
middle_const_eval_non_int =
2020
constant evaluation of enum discriminant resulted in non-integer
21+
22+
middle_unknown_layout =
23+
the type `{$ty}` has an unknown layout
24+
25+
middle_values_too_big =
26+
values of the type `{$ty}` are too big for the current architecture
27+
28+
middle_cannot_be_normalized =
29+
unable to determine layout for `{$ty}` because `{$failure_ty}` cannot be normalized

compiler/rustc_error_messages/locales/en-US/passes.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ passes_no_main_function =
526526
.main_must_be_defined_at_crate = the main function must be defined at the crate level{$has_filename ->
527527
[true] {" "}(in `{$filename}`)
528528
*[false] {""}
529-
}
529+
}
530530
.consider_adding_main_to_file = consider adding a `main` function to `{$filename}`
531531
.consider_adding_main_at_crate = consider adding a `main` function at the crate level
532532
.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/

compiler/rustc_middle/src/ty/layout.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,29 @@ pub enum LayoutError<'tcx> {
191191

192192
impl<'a> IntoDiagnostic<'a, !> for LayoutError<'a> {
193193
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, !> {
194-
handler.struct_fatal(self.to_string())
194+
let mut diag = handler.struct_fatal("");
195+
196+
match self {
197+
LayoutError::Unknown(ty) => {
198+
diag.set_arg("ty", ty);
199+
diag.set_primary_message(rustc_errors::fluent::middle::unknown_layout);
200+
}
201+
LayoutError::SizeOverflow(ty) => {
202+
diag.set_arg("ty", ty);
203+
diag.set_primary_message(rustc_errors::fluent::middle::values_too_big);
204+
}
205+
LayoutError::NormalizationFailure(ty, e) => {
206+
diag.set_arg("ty", ty);
207+
diag.set_arg("failure_ty", e.get_type_for_failure());
208+
diag.set_primary_message(rustc_errors::fluent::middle::cannot_be_normalized);
209+
}
210+
}
211+
diag
195212
}
196213
}
197214

215+
// FIXME: Once the other errors that embed this error have been converted to translateable
216+
// diagnostics, this Display impl should be removed.
198217
impl<'tcx> fmt::Display for LayoutError<'tcx> {
199218
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
200219
match *self {

compiler/rustc_passes/src/diagnostic_items.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_hir::diagnostic_items::DiagnosticItems;
1414
use rustc_middle::ty::query::Providers;
1515
use rustc_middle::ty::TyCtxt;
1616
use rustc_span::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
17-
use rustc_span::symbol::{sym, Symbol};
17+
use rustc_span::symbol::{kw::Empty, sym, Symbol};
1818

1919
use crate::errors::{DuplicateDiagnosticItem, DuplicateDiagnosticItemInCrate};
2020

@@ -46,7 +46,7 @@ fn collect_item(tcx: TyCtxt<'_>, items: &mut DiagnosticItems, name: Symbol, item
4646
None => tcx.sess.emit_err(DuplicateDiagnosticItemInCrate {
4747
span: orig_span,
4848
// FIXME: We should not provide `name` to `orig_crate_name`. How do you create a blank/empty symbol?
49-
orig_crate_name: orig_crate_name.unwrap_or(name),
49+
orig_crate_name: orig_crate_name.unwrap_or(Empty),
5050
have_orig_crate_name: orig_crate_name.map(|_| ()),
5151
crate_name: tcx.crate_name(item_def_id.krate),
5252
name,

compiler/rustc_passes/src/errors.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -830,14 +830,6 @@ pub struct UnrecognizedField {
830830
pub name: Symbol,
831831
}
832832

833-
#[derive(Diagnostic)]
834-
#[diag(passes::layout)]
835-
pub struct Layout {
836-
#[primary_span]
837-
pub span: Span,
838-
pub layout_error: String,
839-
}
840-
841833
#[derive(Diagnostic)]
842834
#[diag(passes::feature_stable_twice, code = "E0711")]
843835
pub struct FeatureStableTwice {
@@ -1259,7 +1251,7 @@ pub struct IncorrectTarget<'a> {
12591251
pub span: Span,
12601252
#[label]
12611253
pub generics_span: Span,
1262-
pub name: &'a str,
1254+
pub name: &'a str, // cannot be symbol because it renders e.g. `r#fn` instead of `fn`
12631255
pub kind: &'static str,
12641256
pub num: usize,
12651257
pub actual_num: usize,

compiler/rustc_passes/src/lang_items.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_hir::lang_items::{extract, GenericRequirement, ITEM_REFS};
2020
use rustc_hir::{HirId, LangItem, LanguageItems, Target};
2121
use rustc_middle::ty::TyCtxt;
2222
use rustc_session::cstore::ExternCrate;
23-
use rustc_span::{Span, Symbol};
23+
use rustc_span::{symbol::kw::Empty, Span};
2424

2525
use rustc_middle::ty::query::Providers;
2626

@@ -66,7 +66,7 @@ impl<'tcx> LanguageItemCollector<'tcx> {
6666
let local_span = self.tcx.hir().span_if_local(item_def_id);
6767
let lang_item_name = LangItem::from_u32(item_index as u32).unwrap().name();
6868
let crate_name = self.tcx.crate_name(item_def_id.krate);
69-
let mut dependency_of = Symbol::intern("");
69+
let mut dependency_of = Empty;
7070
let is_local = item_def_id.is_local();
7171
let path = if is_local {
7272
String::new()
@@ -80,8 +80,8 @@ impl<'tcx> LanguageItemCollector<'tcx> {
8080
.into()
8181
};
8282
let first_defined_span = self.tcx.hir().span_if_local(original_def_id);
83-
let mut orig_crate_name = Symbol::intern("");
84-
let mut orig_dependency_of = Symbol::intern("");
83+
let mut orig_crate_name = Empty;
84+
let mut orig_dependency_of = Empty;
8585
let orig_is_local = original_def_id.is_local();
8686
let orig_path = if orig_is_local {
8787
String::new()

compiler/rustc_passes/src/layout_test.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ use rustc_hir::def::DefKind;
33
use rustc_hir::def_id::LocalDefId;
44
use rustc_middle::ty::layout::{HasParamEnv, HasTyCtxt, LayoutError, LayoutOfHelpers, TyAndLayout};
55
use rustc_middle::ty::{ParamEnv, Ty, TyCtxt};
6+
use rustc_span::source_map::Spanned;
67
use rustc_span::symbol::sym;
78
use rustc_span::Span;
89
use rustc_target::abi::{HasDataLayout, TargetDataLayout};
910

10-
use crate::errors::{Abi, Align, HomogeneousAggregate, Layout, LayoutOf, Size, UnrecognizedField};
11+
use crate::errors::{Abi, Align, HomogeneousAggregate, LayoutOf, Size, UnrecognizedField};
1112

1213
pub fn test_layout(tcx: TyCtxt<'_>) {
1314
if tcx.features().rustc_attrs {
@@ -91,9 +92,9 @@ fn dump_layout_of<'tcx>(tcx: TyCtxt<'tcx>, item_def_id: LocalDefId, attr: &Attri
9192
}
9293

9394
Err(layout_error) => {
94-
tcx.sess.emit_err(Layout {
95+
tcx.sess.emit_fatal(Spanned {
96+
node: layout_error,
9597
span: tcx.def_span(item_def_id.to_def_id()),
96-
layout_error: format!("{:?}", layout_error),
9798
});
9899
}
99100
}

src/test/ui/associated-types/issue-85103.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ use std::borrow::Cow;
44

55
#[rustc_layout(debug)]
66
type Edges<'a, E> = Cow<'a, [E]>;
7-
//~^ ERROR layout error: NormalizationFailure
7+
//~^ 6:1: 6:18: unable to determine layout for `<[E] as ToOwned>::Owned` because `<[E] as ToOwned>::Owned` cannot be normalized
88

99
fn main() {}

src/test/ui/associated-types/issue-85103.stderr

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

0 commit comments

Comments
 (0)