Skip to content

Commit 76b1198

Browse files
committed
Auto merge of rust-lang#70672 - Dylan-DPC:rollup-cco9bbd, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - rust-lang#70535 (Track the finalizing node in the specialization graph) - rust-lang#70590 (Miri: make backtrace function names and spans match up) - rust-lang#70616 (rustc_target::abi: rename FieldPlacement to FieldsShape.) - rust-lang#70626 (cargotest: remove webrender) - rust-lang#70649 (clean up E0468 explanation) - rust-lang#70662 (compiletest: don't use `std::io::stdout()`, as it bypasses `set_print`.) Failed merges: r? @ghost
2 parents 235938d + 7d4d450 commit 76b1198

File tree

36 files changed

+411
-363
lines changed

36 files changed

+411
-363
lines changed

src/librustc_codegen_llvm/type_of.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ fn uncached_llvm_type<'a, 'tcx>(
7979
};
8080

8181
match layout.fields {
82-
layout::FieldPlacement::Union(_) => {
82+
layout::FieldsShape::Union(_) => {
8383
let fill = cx.type_padding_filler(layout.size, layout.align.abi);
8484
let packed = false;
8585
match name {
@@ -91,10 +91,10 @@ fn uncached_llvm_type<'a, 'tcx>(
9191
}
9292
}
9393
}
94-
layout::FieldPlacement::Array { count, .. } => {
94+
layout::FieldsShape::Array { count, .. } => {
9595
cx.type_array(layout.field(cx, 0).llvm_type(cx), count)
9696
}
97-
layout::FieldPlacement::Arbitrary { .. } => match name {
97+
layout::FieldsShape::Arbitrary { .. } => match name {
9898
None => {
9999
let (llfields, packed) = struct_llfields(cx, layout);
100100
cx.type_struct(&llfields, packed)
@@ -371,13 +371,13 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
371371
_ => {}
372372
}
373373
match self.fields {
374-
layout::FieldPlacement::Union(_) => {
374+
layout::FieldsShape::Union(_) => {
375375
bug!("TyAndLayout::llvm_field_index({:?}): not applicable", self)
376376
}
377377

378-
layout::FieldPlacement::Array { .. } => index as u64,
378+
layout::FieldsShape::Array { .. } => index as u64,
379379

380-
layout::FieldPlacement::Arbitrary { .. } => {
380+
layout::FieldsShape::Arbitrary { .. } => {
381381
1 + (self.fields.memory_index(index) as u64) * 2
382382
}
383383
}

src/librustc_codegen_ssa/mir/place.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
6666
}
6767

6868
pub fn len<Cx: ConstMethods<'tcx, Value = V>>(&self, cx: &Cx) -> V {
69-
if let layout::FieldPlacement::Array { count, .. } = self.layout.fields {
69+
if let layout::FieldsShape::Array { count, .. } = self.layout.fields {
7070
if self.layout.is_unsized() {
7171
assert_eq!(count, 0);
7272
self.llextra.unwrap()

src/librustc_error_codes/error_codes/E0468.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
A non-root module attempts to import macros from another crate.
1+
A non-root module tried to import macros from another crate.
22

33
Example of erroneous code:
44

@@ -17,7 +17,7 @@ Either move the macro import to crate root or do without the foreign macros.
1717
This will work:
1818

1919
```
20-
#[macro_use(debug_assert)]
20+
#[macro_use(debug_assert)] // ok!
2121
extern crate core;
2222
2323
mod foo {

src/librustc_middle/mir/interpret/error.rs

+9-13
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ pub struct ConstEvalErr<'tcx> {
5353

5454
#[derive(Debug)]
5555
pub struct FrameInfo<'tcx> {
56-
/// This span is in the caller.
57-
pub call_site: Span,
5856
pub instance: ty::Instance<'tcx>,
57+
pub span: Span,
5958
pub lint_root: Option<hir::HirId>,
6059
}
6160

@@ -65,12 +64,12 @@ impl<'tcx> fmt::Display for FrameInfo<'tcx> {
6564
if tcx.def_key(self.instance.def_id()).disambiguated_data.data
6665
== DefPathData::ClosureExpr
6766
{
68-
write!(f, "inside call to closure")?;
67+
write!(f, "inside closure")?;
6968
} else {
70-
write!(f, "inside call to `{}`", self.instance)?;
69+
write!(f, "inside `{}`", self.instance)?;
7170
}
72-
if !self.call_site.is_dummy() {
73-
let lo = tcx.sess.source_map().lookup_char_pos(self.call_site.lo());
71+
if !self.span.is_dummy() {
72+
let lo = tcx.sess.source_map().lookup_char_pos(self.span.lo());
7473
write!(f, " at {}:{}:{}", lo.file.name, lo.line, lo.col.to_usize() + 1)?;
7574
}
7675
Ok(())
@@ -168,13 +167,10 @@ impl<'tcx> ConstEvalErr<'tcx> {
168167
if let Some(span_msg) = span_msg {
169168
err.span_label(self.span, span_msg);
170169
}
171-
// Add spans for the stacktrace.
172-
// Skip the last, which is just the environment of the constant. The stacktrace
173-
// is sometimes empty because we create "fake" eval contexts in CTFE to do work
174-
// on constant values.
175-
if !self.stacktrace.is_empty() {
176-
for frame_info in &self.stacktrace[..self.stacktrace.len() - 1] {
177-
err.span_label(frame_info.call_site, frame_info.to_string());
170+
// Add spans for the stacktrace. Don't print a single-line backtrace though.
171+
if self.stacktrace.len() > 1 {
172+
for frame_info in &self.stacktrace {
173+
err.span_label(frame_info.span, frame_info.to_string());
178174
}
179175
}
180176
// Let the caller finish the job.

src/librustc_middle/traits/specialization_graph.rs

+59-11
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,44 @@ impl Iterator for Ancestors<'_> {
154154
}
155155
}
156156

157-
pub struct NodeItem<T> {
158-
pub node: Node,
159-
pub item: T,
157+
/// Information about the most specialized definition of an associated item.
158+
pub struct LeafDef {
159+
/// The associated item described by this `LeafDef`.
160+
pub item: ty::AssocItem,
161+
162+
/// The node in the specialization graph containing the definition of `item`.
163+
pub defining_node: Node,
164+
165+
/// The "top-most" (ie. least specialized) specialization graph node that finalized the
166+
/// definition of `item`.
167+
///
168+
/// Example:
169+
///
170+
/// ```
171+
/// trait Tr {
172+
/// fn assoc(&self);
173+
/// }
174+
///
175+
/// impl<T> Tr for T {
176+
/// default fn assoc(&self) {}
177+
/// }
178+
///
179+
/// impl Tr for u8 {}
180+
/// ```
181+
///
182+
/// If we start the leaf definition search at `impl Tr for u8`, that impl will be the
183+
/// `finalizing_node`, while `defining_node` will be the generic impl.
184+
///
185+
/// If the leaf definition search is started at the generic impl, `finalizing_node` will be
186+
/// `None`, since the most specialized impl we found still allows overriding the method
187+
/// (doesn't finalize it).
188+
pub finalizing_node: Option<Node>,
160189
}
161190

162-
impl<T> NodeItem<T> {
163-
pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> NodeItem<U> {
164-
NodeItem { node: self.node, item: f(self.item) }
191+
impl LeafDef {
192+
/// Returns whether this definition is known to not be further specializable.
193+
pub fn is_final(&self) -> bool {
194+
self.finalizing_node.is_some()
165195
}
166196
}
167197

@@ -173,18 +203,36 @@ impl<'tcx> Ancestors<'tcx> {
173203
tcx: TyCtxt<'tcx>,
174204
trait_item_name: Ident,
175205
trait_item_kind: ty::AssocKind,
176-
) -> Option<NodeItem<ty::AssocItem>> {
206+
) -> Option<LeafDef> {
177207
let trait_def_id = self.trait_def_id;
208+
let mut finalizing_node = None;
209+
178210
self.find_map(|node| {
179-
node.item(tcx, trait_item_name, trait_item_kind, trait_def_id)
180-
.map(|item| NodeItem { node, item })
211+
if let Some(item) = node.item(tcx, trait_item_name, trait_item_kind, trait_def_id) {
212+
if finalizing_node.is_none() {
213+
let is_specializable = item.defaultness.is_default()
214+
|| tcx.impl_defaultness(node.def_id()).is_default();
215+
216+
if !is_specializable {
217+
finalizing_node = Some(node);
218+
}
219+
}
220+
221+
Some(LeafDef { item, defining_node: node, finalizing_node })
222+
} else {
223+
// Item not mentioned. This "finalizes" any defaulted item provided by an ancestor.
224+
finalizing_node = Some(node);
225+
None
226+
}
181227
})
182228
}
183229
}
184230

185231
/// Walk up the specialization ancestors of a given impl, starting with that
186-
/// impl itself. Returns `None` if an error was reported while building the
187-
/// specialization graph.
232+
/// impl itself.
233+
///
234+
/// Returns `Err` if an error was reported while building the specialization
235+
/// graph.
188236
pub fn ancestors(
189237
tcx: TyCtxt<'tcx>,
190238
trait_def_id: DefId,

0 commit comments

Comments
 (0)