Skip to content

Commit dc05f60

Browse files
committed
Auto merge of #103829 - JohnTitor:rollup-o03nzr8, r=JohnTitor
Rollup of 10 pull requests Successful merges: - #103007 (Add better python discovery) - #103674 (Update note about unstable split-debuginfo flag.) - #103692 (Add `walk_generic_arg`) - #103749 (Reduce span of let else irrefutable_let_patterns warning) - #103772 (better error for `rustc_strict_coherence` misuse) - #103788 (Fix ICE in checking transmutability of NaughtyLenArray) - #103793 (rustdoc: add margins to all impl-item toggles, not just methods) - #103798 (interpret: move type_name implementation to an interpreter-independent helper file) - #103799 (Remove generation of tuple struct fields in the search index) - #103805 (Enable RUSTC_BOOTSTRAP for a few steps) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 024207a + 669e3cd commit dc05f60

File tree

24 files changed

+238
-57
lines changed

24 files changed

+238
-57
lines changed

compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use std::convert::TryFrom;
77
use rustc_hir::def_id::DefId;
88
use rustc_middle::mir::{
99
self,
10-
interpret::{ConstValue, GlobalId, InterpResult, PointerArithmetic, Scalar},
10+
interpret::{
11+
Allocation, ConstAllocation, ConstValue, GlobalId, InterpResult, PointerArithmetic, Scalar,
12+
},
1113
BinOp, NonDivergingIntrinsic,
1214
};
1315
use rustc_middle::ty;
@@ -23,7 +25,6 @@ use super::{
2325
};
2426

2527
mod caller_location;
26-
mod type_name;
2728

2829
fn numeric_intrinsic<Prov>(name: Symbol, bits: u128, kind: Primitive) -> Scalar<Prov> {
2930
let size = match kind {
@@ -42,6 +43,13 @@ fn numeric_intrinsic<Prov>(name: Symbol, bits: u128, kind: Primitive) -> Scalar<
4243
Scalar::from_uint(bits_out, size)
4344
}
4445

46+
/// Directly returns an `Allocation` containing an absolute path representation of the given type.
47+
pub(crate) fn alloc_type_name<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ConstAllocation<'tcx> {
48+
let path = crate::util::type_name(tcx, ty);
49+
let alloc = Allocation::from_bytes_byte_aligned_immutable(path.into_bytes());
50+
tcx.intern_const_alloc(alloc)
51+
}
52+
4553
/// The logic for all nullary intrinsics is implemented here. These intrinsics don't get evaluated
4654
/// inside an `InterpCx` and instead have their value computed directly from rustc internal info.
4755
pub(crate) fn eval_nullary_intrinsic<'tcx>(
@@ -55,7 +63,7 @@ pub(crate) fn eval_nullary_intrinsic<'tcx>(
5563
Ok(match name {
5664
sym::type_name => {
5765
ensure_monomorphic_enough(tcx, tp_ty)?;
58-
let alloc = type_name::alloc_type_name(tcx, tp_ty);
66+
let alloc = alloc_type_name(tcx, tp_ty);
5967
ConstValue::Slice { data: alloc, start: 0, end: alloc.inner().len() }
6068
}
6169
sym::needs_drop => {

compiler/rustc_const_eval/src/util/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ mod call_kind;
44
pub mod collect_writes;
55
mod find_self_call;
66
mod might_permit_raw_init;
7+
mod type_name;
78

89
pub use self::aggregate::expand_aggregate;
910
pub use self::alignment::is_disaligned;
1011
pub use self::call_kind::{call_kind, CallDesugaringKind, CallKind};
1112
pub use self::find_self_call::find_self_call;
1213
pub use self::might_permit_raw_init::might_permit_raw_init;
14+
pub use self::type_name::type_name;

compiler/rustc_const_eval/src/interpret/intrinsics/type_name.rs renamed to compiler/rustc_const_eval/src/util/type_name.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use rustc_data_structures::intern::Interned;
22
use rustc_hir::def_id::CrateNum;
33
use rustc_hir::definitions::DisambiguatedDefPathData;
4-
use rustc_middle::mir::interpret::{Allocation, ConstAllocation};
54
use rustc_middle::ty::{
65
self,
76
print::{PrettyPrinter, Print, Printer},
@@ -193,9 +192,6 @@ impl Write for AbsolutePathPrinter<'_> {
193192
}
194193
}
195194

196-
/// Directly returns an `Allocation` containing an absolute path representation of the given type.
197-
pub(crate) fn alloc_type_name<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ConstAllocation<'tcx> {
198-
let path = AbsolutePathPrinter { tcx, path: String::new() }.print_type(ty).unwrap().path;
199-
let alloc = Allocation::from_bytes_byte_aligned_immutable(path.into_bytes());
200-
tcx.intern_const_alloc(alloc)
195+
pub fn type_name<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> String {
196+
AbsolutePathPrinter { tcx, path: String::new() }.print_type(ty).unwrap().path
201197
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ middle_values_too_big =
2727
2828
middle_cannot_be_normalized =
2929
unable to determine layout for `{$ty}` because `{$failure_ty}` cannot be normalized
30+
31+
middle_strict_coherence_needs_negative_coherence =
32+
to use `strict_coherence` on this trait, the `with_negative_coherence` feature must be enabled
33+
.label = due to this attribute

compiler/rustc_hir/src/intravisit.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -410,12 +410,7 @@ pub trait Visitor<'v>: Sized {
410410
walk_inf(self, inf);
411411
}
412412
fn visit_generic_arg(&mut self, generic_arg: &'v GenericArg<'v>) {
413-
match generic_arg {
414-
GenericArg::Lifetime(lt) => self.visit_lifetime(lt),
415-
GenericArg::Type(ty) => self.visit_ty(ty),
416-
GenericArg::Const(ct) => self.visit_anon_const(&ct.value),
417-
GenericArg::Infer(inf) => self.visit_infer(inf),
418-
}
413+
walk_generic_arg(self, generic_arg);
419414
}
420415
fn visit_lifetime(&mut self, lifetime: &'v Lifetime) {
421416
walk_lifetime(self, lifetime)
@@ -480,6 +475,15 @@ pub fn walk_label<'v, V: Visitor<'v>>(visitor: &mut V, label: &'v Label) {
480475
visitor.visit_ident(label.ident);
481476
}
482477

478+
pub fn walk_generic_arg<'v, V: Visitor<'v>>(visitor: &mut V, generic_arg: &'v GenericArg<'v>) {
479+
match generic_arg {
480+
GenericArg::Lifetime(lt) => visitor.visit_lifetime(lt),
481+
GenericArg::Type(ty) => visitor.visit_ty(ty),
482+
GenericArg::Const(ct) => visitor.visit_anon_const(&ct.value),
483+
GenericArg::Infer(inf) => visitor.visit_infer(inf),
484+
}
485+
}
486+
483487
pub fn walk_lifetime<'v, V: Visitor<'v>>(visitor: &mut V, lifetime: &'v Lifetime) {
484488
visitor.visit_id(lifetime.hir_id);
485489
match lifetime.name {

compiler/rustc_middle/src/error.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,12 @@ pub struct ConstEvalNonIntError {
5555
#[primary_span]
5656
pub span: Span,
5757
}
58+
59+
#[derive(Diagnostic)]
60+
#[diag(middle_strict_coherence_needs_negative_coherence)]
61+
pub(crate) struct StrictCoherenceNeedsNegativeCoherence {
62+
#[primary_span]
63+
pub span: Span,
64+
#[label]
65+
pub attr_span: Option<Span>,
66+
}

compiler/rustc_middle/src/traits/specialization_graph.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::error::StrictCoherenceNeedsNegativeCoherence;
12
use crate::ty::fast_reject::SimplifiedType;
23
use crate::ty::visit::TypeVisitable;
34
use crate::ty::{self, TyCtxt};
@@ -65,9 +66,21 @@ impl OverlapMode {
6566

6667
if with_negative_coherence {
6768
if strict_coherence { OverlapMode::Strict } else { OverlapMode::WithNegative }
68-
} else if strict_coherence {
69-
bug!("To use strict_coherence you need to set with_negative_coherence feature flag");
7069
} else {
70+
if strict_coherence {
71+
let attr_span = trait_id
72+
.as_local()
73+
.into_iter()
74+
.flat_map(|local_def_id| {
75+
tcx.hir().attrs(tcx.hir().local_def_id_to_hir_id(local_def_id))
76+
})
77+
.find(|attr| attr.has_name(sym::rustc_strict_coherence))
78+
.map(|attr| attr.span);
79+
tcx.sess.emit_err(StrictCoherenceNeedsNegativeCoherence {
80+
span: tcx.def_span(trait_id),
81+
attr_span,
82+
});
83+
}
7184
OverlapMode::Stable
7285
}
7386
}

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ impl<'tcx> Visitor<'tcx> for MatchVisitor<'_, '_, 'tcx> {
7979
intravisit::walk_local(self, loc);
8080
let els = loc.els;
8181
if let Some(init) = loc.init && els.is_some() {
82-
self.check_let(&loc.pat, init, loc.span);
82+
// Build a span without the else { ... } as we don't want to underline
83+
// the entire else block in the IDE setting.
84+
let span = loc.span.with_hi(init.span.hi());
85+
self.check_let(&loc.pat, init, span);
8386
}
8487

8588
let (msg, sp) = match loc.source {
@@ -630,11 +633,6 @@ fn irrefutable_let_patterns(
630633
count: usize,
631634
span: Span,
632635
) {
633-
let span = match source {
634-
LetSource::LetElse(span) => span,
635-
_ => span,
636-
};
637-
638636
macro_rules! emit_diag {
639637
(
640638
$lint:expr,
@@ -680,7 +678,7 @@ fn irrefutable_let_patterns(
680678
"removing the guard and adding a `let` inside the match arm"
681679
);
682680
}
683-
LetSource::LetElse(..) => {
681+
LetSource::LetElse => {
684682
emit_diag!(
685683
lint,
686684
"`let...else`",
@@ -1127,7 +1125,7 @@ pub enum LetSource {
11271125
GenericLet,
11281126
IfLet,
11291127
IfLetGuard,
1130-
LetElse(Span),
1128+
LetElse,
11311129
WhileLet,
11321130
}
11331131

@@ -1156,8 +1154,8 @@ fn let_source_parent(tcx: TyCtxt<'_>, parent: HirId, pat_id: Option<HirId>) -> L
11561154
let parent_parent = hir.get_parent_node(parent);
11571155
let parent_parent_node = hir.get(parent_parent);
11581156
match parent_parent_node {
1159-
hir::Node::Stmt(hir::Stmt { kind: hir::StmtKind::Local(_), span, .. }) => {
1160-
return LetSource::LetElse(*span);
1157+
hir::Node::Stmt(hir::Stmt { kind: hir::StmtKind::Local(_), .. }) => {
1158+
return LetSource::LetElse;
11611159
}
11621160
hir::Node::Arm(hir::Arm { guard: Some(hir::Guard::If(_)), .. }) => {
11631161
return LetSource::IfLetGuard;

compiler/rustc_transmute/src/layout/tree.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ pub(crate) mod rustc {
284284
}
285285

286286
ty::Array(ty, len) => {
287-
let len = len.try_eval_usize(tcx, ParamEnv::reveal_all()).unwrap();
287+
let len =
288+
len.try_eval_usize(tcx, ParamEnv::reveal_all()).ok_or(Err::Unspecified)?;
288289
let elt = Tree::from_ty(*ty, tcx)?;
289290
Ok(std::iter::repeat(elt)
290291
.take(len as usize)

src/bootstrap/test.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,7 @@ impl Step for RustdocGUI {
986986
.arg("doc")
987987
.arg("--target-dir")
988988
.arg(&out_dir)
989+
.env("RUSTC_BOOTSTRAP", "1")
989990
.env("RUSTDOC", builder.rustdoc(self.compiler))
990991
.env("RUSTC", builder.rustc(self.compiler))
991992
.current_dir(path);
@@ -1725,6 +1726,8 @@ impl BookTest {
17251726

17261727
let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
17271728
let path = builder.src.join(&self.path);
1729+
// Books often have feature-gated example text.
1730+
rustbook_cmd.env("RUSTC_BOOTSTRAP", "1");
17281731
rustbook_cmd.env("PATH", new_path).arg("test").arg(path);
17291732
builder.add_rust_test_threads(&mut rustbook_cmd);
17301733
builder.info(&format!("Testing rustbook {}", self.path.display()));

0 commit comments

Comments
 (0)