Skip to content

Commit dc05f60

Browse files
committed
Auto merge of rust-lang#103829 - JohnTitor:rollup-o03nzr8, r=JohnTitor
Rollup of 10 pull requests Successful merges: - rust-lang#103007 (Add better python discovery) - rust-lang#103674 (Update note about unstable split-debuginfo flag.) - rust-lang#103692 (Add `walk_generic_arg`) - rust-lang#103749 (Reduce span of let else irrefutable_let_patterns warning) - rust-lang#103772 (better error for `rustc_strict_coherence` misuse) - rust-lang#103788 (Fix ICE in checking transmutability of NaughtyLenArray) - rust-lang#103793 (rustdoc: add margins to all impl-item toggles, not just methods) - rust-lang#103798 (interpret: move type_name implementation to an interpreter-independent helper file) - rust-lang#103799 (Remove generation of tuple struct fields in the search index) - rust-lang#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

+11-3
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

+2
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 compiler/rustc_const_eval/src/util/type_name.rs

+2-6
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

+4
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

+10-6
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

+9
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

+15-2
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

+8-10
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

+2-1
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

+3
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()));

src/doc/rustc/src/codegen-options/index.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -531,8 +531,10 @@ platforms. Possible values are:
531531
debug information. On other Unix platforms this means that `*.dwo` files will
532532
contain debug information.
533533

534-
Note that `packed` and `unpacked` are gated behind `-Z unstable-options` on
535-
non-macOS platforms at this time.
534+
Note that all three options are supported on Linux and Apple platforms,
535+
`packed` is supported on Windows-MSVC, and all other platforms support `off`.
536+
Attempting to use an unsupported option requires using the nightly channel
537+
with the `-Z unstable-options` flag.
536538

537539
## strip
538540

src/librustdoc/formats/cache.rs

+22-15
Original file line numberDiff line numberDiff line change
@@ -316,21 +316,28 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
316316
let desc = item.doc_value().map_or_else(String::new, |x| {
317317
short_markdown_summary(x.as_str(), &item.link_names(self.cache))
318318
});
319-
self.cache.search_index.push(IndexItem {
320-
ty: item.type_(),
321-
name: s.to_string(),
322-
path: join_with_double_colon(path),
323-
desc,
324-
parent,
325-
parent_idx: None,
326-
search_type: get_function_type_for_search(
327-
&item,
328-
self.tcx,
329-
clean_impl_generics(self.cache.parent_stack.last()).as_ref(),
330-
self.cache,
331-
),
332-
aliases: item.attrs.get_doc_aliases(),
333-
});
319+
let ty = item.type_();
320+
let name = s.to_string();
321+
if ty != ItemType::StructField || u16::from_str_radix(&name, 10).is_err() {
322+
// In case this is a field from a tuple struct, we don't add it into
323+
// the search index because its name is something like "0", which is
324+
// not useful for rustdoc search.
325+
self.cache.search_index.push(IndexItem {
326+
ty,
327+
name,
328+
path: join_with_double_colon(path),
329+
desc,
330+
parent,
331+
parent_idx: None,
332+
search_type: get_function_type_for_search(
333+
&item,
334+
self.tcx,
335+
clean_impl_generics(self.cache.parent_stack.last()).as_ref(),
336+
self.cache,
337+
),
338+
aliases: item.attrs.get_doc_aliases(),
339+
});
340+
}
334341
}
335342
}
336343
(Some(parent), None) if is_inherent_impl_item => {

src/librustdoc/html/static/css/rustdoc.css

+8-6
Original file line numberDiff line numberDiff line change
@@ -1968,24 +1968,26 @@ in storage.js
19681968
}
19691969
}
19701970

1971-
.method-toggle > summary,
19721971
.implementors-toggle > summary,
19731972
.impl,
19741973
#implementors-list > .docblock,
19751974
.impl-items > section,
1976-
.methods > section
1975+
.impl-items > .rustdoc-toggle > summary,
1976+
.methods > section,
1977+
.methods > .rustdoc-toggle > summary
19771978
{
19781979
margin-bottom: 0.75em;
19791980
}
19801981

1981-
.method-toggle[open]:not(:last-child),
1982+
.impl-items > .rustdoc-toggle[open]:not(:last-child),
1983+
.methods > .rustdoc-toggle[open]:not(:last-child),
19821984
.implementors-toggle[open]:not(:last-child) {
19831985
margin-bottom: 2em;
19841986
}
19851987

1986-
#trait-implementations-list .method-toggle:not(:last-child),
1987-
#synthetic-implementations-list .method-toggle:not(:last-child),
1988-
#blanket-implementations-list .method-toggle:not(:last-child) {
1988+
#trait-implementations-list .impl-items > .rustdoc-toggle:not(:last-child),
1989+
#synthetic-implementations-list .impl-items > .rustdoc-toggle:not(:last-child),
1990+
#blanket-implementations-list .impl-items > .rustdoc-toggle:not(:last-child) {
19891991
margin-bottom: 1em;
19901992
}
19911993

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
goto: "file://" + |DOC_PATH| + "/test_docs/trait_members/struct.HasTrait.html#impl-TraitMembers-for-HasTrait"
2+
3+
assert-count: ("#trait-implementations-list > .rustdoc-toggle", 1)
4+
5+
compare-elements-css: (
6+
// compare margin on type with margin on method
7+
"#trait-implementations-list .impl-items > .rustdoc-toggle:nth-child(1) > summary",
8+
"#trait-implementations-list .impl-items > .rustdoc-toggle:nth-child(2) > summary",
9+
["margin"]
10+
)
11+
12+
compare-elements-css: (
13+
// compare margin on type with margin on method
14+
"#trait-implementations-list .impl-items > .rustdoc-toggle:nth-child(1)",
15+
"#trait-implementations-list .impl-items > .rustdoc-toggle:nth-child(2)",
16+
["margin"]
17+
)

src/test/rustdoc-gui/src/test_docs/lib.rs

+17
Original file line numberDiff line numberDiff line change
@@ -416,3 +416,20 @@ pub trait TraitWithoutGenerics {
416416

417417
fn foo();
418418
}
419+
420+
pub mod trait_members {
421+
pub trait TraitMembers {
422+
/// Some type
423+
type Type;
424+
/// Some function
425+
fn function();
426+
/// Some other function
427+
fn function2();
428+
}
429+
pub struct HasTrait;
430+
impl TraitMembers for HasTrait {
431+
type Type = u8;
432+
fn function() {}
433+
fn function2() {}
434+
}
435+
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// This test ensures that the tuple struct fields are not generated in the
2+
// search index.
3+
4+
// @!hasraw search-index.js '"0"'
5+
// @!hasraw search-index.js '"1"'
6+
// @hasraw search-index.js '"foo_a"'
7+
// @hasraw search-index.js '"bar_a"'
8+
9+
pub struct Bar(pub u32, pub u8);
10+
pub struct Foo {
11+
pub foo_a: u8,
12+
}
13+
pub enum Enum {
14+
Foo(u8),
15+
Bar {
16+
bar_a: u8,
17+
},
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![feature(rustc_attrs)]
2+
3+
#[rustc_strict_coherence]
4+
trait Foo {}
5+
//~^ ERROR to use `strict_coherence` on this trait, the `with_negative_coherence` feature must be enabled
6+
7+
fn main() {}

0 commit comments

Comments
 (0)