Skip to content

Rollup of 10 pull requests #103829

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c2b0cc1
Update note about unstable split-debuginfo flag.
ehuss Oct 28, 2022
86a4009
Add `walk_generic_arg`
smoelius Oct 28, 2022
5556841
fix #103783, fix ICE checking transmutability of NaughtyLenArray
chenyukang Oct 29, 2022
7b55d17
Reduce span of let else irrefutable_let_patterns warning
est31 Oct 30, 2022
953727f
better error for rustc_strict_coherence misuse
compiler-errors Oct 30, 2022
791f04e
rustdoc: add margins to all impl-item toggles, not just methods
notriddle Oct 31, 2022
c83ddae
Add better python discovery
albertlarsan68 Oct 13, 2022
fa2aa1c
interpret: move type_name implementation to an interpreter-independen…
RalfJung Oct 31, 2022
e802e99
Don't generate tuple struct fields into the search index
GuillaumeGomez Oct 31, 2022
5062a77
Add test for tuple struct field generation in search index
GuillaumeGomez Oct 31, 2022
492ee6a
rustdoc: add test case for associated type margins
notriddle Oct 31, 2022
b123a66
Enable RUSTC_BOOTSTRAP for a few steps
Mark-Simulacrum Aug 8, 2022
a6ac6b2
Rollup merge of #103007 - albertlarsan68:better-python-discovery, r=j…
Nov 1, 2022
d1ca708
Rollup merge of #103674 - ehuss:split-debuginfo-doc-unstable, r=david…
Nov 1, 2022
2125181
Rollup merge of #103692 - smoelius:walk_generic_arg, r=fee1-dead
Nov 1, 2022
2a6a8f4
Rollup merge of #103749 - est31:reduce_irrefutable_let_else_span, r=c…
Nov 1, 2022
5bf9d61
Rollup merge of #103772 - compiler-errors:better-strict-coherence-err…
Nov 1, 2022
ff89cec
Rollup merge of #103788 - chenyukang:yukang/fix-ice-103783, r=compile…
Nov 1, 2022
2c7f137
Rollup merge of #103793 - notriddle:notriddle/rustdoc-toggle-in-impl-…
Nov 1, 2022
0f40e95
Rollup merge of #103798 - RalfJung:type_name, r=oli-obk
Nov 1, 2022
fca9093
Rollup merge of #103799 - GuillaumeGomez:search-index-tuple-struct-fi…
Nov 1, 2022
669e3cd
Rollup merge of #103805 - Mark-Simulacrum:forward-port, r=jyn514
Nov 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions compiler/rustc_const_eval/src/interpret/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use std::convert::TryFrom;
use rustc_hir::def_id::DefId;
use rustc_middle::mir::{
self,
interpret::{ConstValue, GlobalId, InterpResult, PointerArithmetic, Scalar},
interpret::{
Allocation, ConstAllocation, ConstValue, GlobalId, InterpResult, PointerArithmetic, Scalar,
},
BinOp, NonDivergingIntrinsic,
};
use rustc_middle::ty;
Expand All @@ -23,7 +25,6 @@ use super::{
};

mod caller_location;
mod type_name;

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

/// Directly returns an `Allocation` containing an absolute path representation of the given type.
pub(crate) fn alloc_type_name<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ConstAllocation<'tcx> {
let path = crate::util::type_name(tcx, ty);
let alloc = Allocation::from_bytes_byte_aligned_immutable(path.into_bytes());
tcx.intern_const_alloc(alloc)
}

/// The logic for all nullary intrinsics is implemented here. These intrinsics don't get evaluated
/// inside an `InterpCx` and instead have their value computed directly from rustc internal info.
pub(crate) fn eval_nullary_intrinsic<'tcx>(
Expand All @@ -55,7 +63,7 @@ pub(crate) fn eval_nullary_intrinsic<'tcx>(
Ok(match name {
sym::type_name => {
ensure_monomorphic_enough(tcx, tp_ty)?;
let alloc = type_name::alloc_type_name(tcx, tp_ty);
let alloc = alloc_type_name(tcx, tp_ty);
ConstValue::Slice { data: alloc, start: 0, end: alloc.inner().len() }
}
sym::needs_drop => {
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_const_eval/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ mod call_kind;
pub mod collect_writes;
mod find_self_call;
mod might_permit_raw_init;
mod type_name;

pub use self::aggregate::expand_aggregate;
pub use self::alignment::is_disaligned;
pub use self::call_kind::{call_kind, CallDesugaringKind, CallKind};
pub use self::find_self_call::find_self_call;
pub use self::might_permit_raw_init::might_permit_raw_init;
pub use self::type_name::type_name;
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use rustc_data_structures::intern::Interned;
use rustc_hir::def_id::CrateNum;
use rustc_hir::definitions::DisambiguatedDefPathData;
use rustc_middle::mir::interpret::{Allocation, ConstAllocation};
use rustc_middle::ty::{
self,
print::{PrettyPrinter, Print, Printer},
Expand Down Expand Up @@ -193,9 +192,6 @@ impl Write for AbsolutePathPrinter<'_> {
}
}

/// Directly returns an `Allocation` containing an absolute path representation of the given type.
pub(crate) fn alloc_type_name<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ConstAllocation<'tcx> {
let path = AbsolutePathPrinter { tcx, path: String::new() }.print_type(ty).unwrap().path;
let alloc = Allocation::from_bytes_byte_aligned_immutable(path.into_bytes());
tcx.intern_const_alloc(alloc)
pub fn type_name<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> String {
AbsolutePathPrinter { tcx, path: String::new() }.print_type(ty).unwrap().path
}
4 changes: 4 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/middle.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ middle_values_too_big =

middle_cannot_be_normalized =
unable to determine layout for `{$ty}` because `{$failure_ty}` cannot be normalized

middle_strict_coherence_needs_negative_coherence =
to use `strict_coherence` on this trait, the `with_negative_coherence` feature must be enabled
.label = due to this attribute
16 changes: 10 additions & 6 deletions compiler/rustc_hir/src/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,12 +410,7 @@ pub trait Visitor<'v>: Sized {
walk_inf(self, inf);
}
fn visit_generic_arg(&mut self, generic_arg: &'v GenericArg<'v>) {
match generic_arg {
GenericArg::Lifetime(lt) => self.visit_lifetime(lt),
GenericArg::Type(ty) => self.visit_ty(ty),
GenericArg::Const(ct) => self.visit_anon_const(&ct.value),
GenericArg::Infer(inf) => self.visit_infer(inf),
}
walk_generic_arg(self, generic_arg);
}
fn visit_lifetime(&mut self, lifetime: &'v Lifetime) {
walk_lifetime(self, lifetime)
Expand Down Expand Up @@ -480,6 +475,15 @@ pub fn walk_label<'v, V: Visitor<'v>>(visitor: &mut V, label: &'v Label) {
visitor.visit_ident(label.ident);
}

pub fn walk_generic_arg<'v, V: Visitor<'v>>(visitor: &mut V, generic_arg: &'v GenericArg<'v>) {
match generic_arg {
GenericArg::Lifetime(lt) => visitor.visit_lifetime(lt),
GenericArg::Type(ty) => visitor.visit_ty(ty),
GenericArg::Const(ct) => visitor.visit_anon_const(&ct.value),
GenericArg::Infer(inf) => visitor.visit_infer(inf),
}
}

pub fn walk_lifetime<'v, V: Visitor<'v>>(visitor: &mut V, lifetime: &'v Lifetime) {
visitor.visit_id(lifetime.hir_id);
match lifetime.name {
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_middle/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,12 @@ pub struct ConstEvalNonIntError {
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic)]
#[diag(middle_strict_coherence_needs_negative_coherence)]
pub(crate) struct StrictCoherenceNeedsNegativeCoherence {
#[primary_span]
pub span: Span,
#[label]
pub attr_span: Option<Span>,
}
17 changes: 15 additions & 2 deletions compiler/rustc_middle/src/traits/specialization_graph.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::error::StrictCoherenceNeedsNegativeCoherence;
use crate::ty::fast_reject::SimplifiedType;
use crate::ty::visit::TypeVisitable;
use crate::ty::{self, TyCtxt};
Expand Down Expand Up @@ -65,9 +66,21 @@ impl OverlapMode {

if with_negative_coherence {
if strict_coherence { OverlapMode::Strict } else { OverlapMode::WithNegative }
} else if strict_coherence {
bug!("To use strict_coherence you need to set with_negative_coherence feature flag");
} else {
if strict_coherence {
let attr_span = trait_id
.as_local()
.into_iter()
.flat_map(|local_def_id| {
tcx.hir().attrs(tcx.hir().local_def_id_to_hir_id(local_def_id))
})
.find(|attr| attr.has_name(sym::rustc_strict_coherence))
.map(|attr| attr.span);
tcx.sess.emit_err(StrictCoherenceNeedsNegativeCoherence {
span: tcx.def_span(trait_id),
attr_span,
});
}
OverlapMode::Stable
}
}
Expand Down
18 changes: 8 additions & 10 deletions compiler/rustc_mir_build/src/thir/pattern/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ impl<'tcx> Visitor<'tcx> for MatchVisitor<'_, '_, 'tcx> {
intravisit::walk_local(self, loc);
let els = loc.els;
if let Some(init) = loc.init && els.is_some() {
self.check_let(&loc.pat, init, loc.span);
// Build a span without the else { ... } as we don't want to underline
// the entire else block in the IDE setting.
let span = loc.span.with_hi(init.span.hi());
self.check_let(&loc.pat, init, span);
}

let (msg, sp) = match loc.source {
Expand Down Expand Up @@ -630,11 +633,6 @@ fn irrefutable_let_patterns(
count: usize,
span: Span,
) {
let span = match source {
LetSource::LetElse(span) => span,
_ => span,
};

macro_rules! emit_diag {
(
$lint:expr,
Expand Down Expand Up @@ -680,7 +678,7 @@ fn irrefutable_let_patterns(
"removing the guard and adding a `let` inside the match arm"
);
}
LetSource::LetElse(..) => {
LetSource::LetElse => {
emit_diag!(
lint,
"`let...else`",
Expand Down Expand Up @@ -1127,7 +1125,7 @@ pub enum LetSource {
GenericLet,
IfLet,
IfLetGuard,
LetElse(Span),
LetElse,
WhileLet,
}

Expand Down Expand Up @@ -1156,8 +1154,8 @@ fn let_source_parent(tcx: TyCtxt<'_>, parent: HirId, pat_id: Option<HirId>) -> L
let parent_parent = hir.get_parent_node(parent);
let parent_parent_node = hir.get(parent_parent);
match parent_parent_node {
hir::Node::Stmt(hir::Stmt { kind: hir::StmtKind::Local(_), span, .. }) => {
return LetSource::LetElse(*span);
hir::Node::Stmt(hir::Stmt { kind: hir::StmtKind::Local(_), .. }) => {
return LetSource::LetElse;
}
hir::Node::Arm(hir::Arm { guard: Some(hir::Guard::If(_)), .. }) => {
return LetSource::IfLetGuard;
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_transmute/src/layout/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ pub(crate) mod rustc {
}

ty::Array(ty, len) => {
let len = len.try_eval_usize(tcx, ParamEnv::reveal_all()).unwrap();
let len =
len.try_eval_usize(tcx, ParamEnv::reveal_all()).ok_or(Err::Unspecified)?;
let elt = Tree::from_ty(*ty, tcx)?;
Ok(std::iter::repeat(elt)
.take(len as usize)
Expand Down
3 changes: 3 additions & 0 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,7 @@ impl Step for RustdocGUI {
.arg("doc")
.arg("--target-dir")
.arg(&out_dir)
.env("RUSTC_BOOTSTRAP", "1")
.env("RUSTDOC", builder.rustdoc(self.compiler))
.env("RUSTC", builder.rustc(self.compiler))
.current_dir(path);
Expand Down Expand Up @@ -1725,6 +1726,8 @@ impl BookTest {

let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
let path = builder.src.join(&self.path);
// Books often have feature-gated example text.
rustbook_cmd.env("RUSTC_BOOTSTRAP", "1");
rustbook_cmd.env("PATH", new_path).arg("test").arg(path);
builder.add_rust_test_threads(&mut rustbook_cmd);
builder.info(&format!("Testing rustbook {}", self.path.display()));
Expand Down
6 changes: 4 additions & 2 deletions src/doc/rustc/src/codegen-options/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,10 @@ platforms. Possible values are:
debug information. On other Unix platforms this means that `*.dwo` files will
contain debug information.

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

## strip

Expand Down
37 changes: 22 additions & 15 deletions src/librustdoc/formats/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,21 +316,28 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
let desc = item.doc_value().map_or_else(String::new, |x| {
short_markdown_summary(x.as_str(), &item.link_names(self.cache))
});
self.cache.search_index.push(IndexItem {
ty: item.type_(),
name: s.to_string(),
path: join_with_double_colon(path),
desc,
parent,
parent_idx: None,
search_type: get_function_type_for_search(
&item,
self.tcx,
clean_impl_generics(self.cache.parent_stack.last()).as_ref(),
self.cache,
),
aliases: item.attrs.get_doc_aliases(),
});
let ty = item.type_();
let name = s.to_string();
if ty != ItemType::StructField || u16::from_str_radix(&name, 10).is_err() {
// In case this is a field from a tuple struct, we don't add it into
// the search index because its name is something like "0", which is
// not useful for rustdoc search.
self.cache.search_index.push(IndexItem {
ty,
name,
path: join_with_double_colon(path),
desc,
parent,
parent_idx: None,
search_type: get_function_type_for_search(
&item,
self.tcx,
clean_impl_generics(self.cache.parent_stack.last()).as_ref(),
self.cache,
),
aliases: item.attrs.get_doc_aliases(),
});
}
}
}
(Some(parent), None) if is_inherent_impl_item => {
Expand Down
14 changes: 8 additions & 6 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -1968,24 +1968,26 @@ in storage.js
}
}

.method-toggle > summary,
.implementors-toggle > summary,
.impl,
#implementors-list > .docblock,
.impl-items > section,
.methods > section
.impl-items > .rustdoc-toggle > summary,
.methods > section,
.methods > .rustdoc-toggle > summary
{
margin-bottom: 0.75em;
}

.method-toggle[open]:not(:last-child),
.impl-items > .rustdoc-toggle[open]:not(:last-child),
.methods > .rustdoc-toggle[open]:not(:last-child),
.implementors-toggle[open]:not(:last-child) {
margin-bottom: 2em;
}

#trait-implementations-list .method-toggle:not(:last-child),
#synthetic-implementations-list .method-toggle:not(:last-child),
#blanket-implementations-list .method-toggle:not(:last-child) {
#trait-implementations-list .impl-items > .rustdoc-toggle:not(:last-child),
#synthetic-implementations-list .impl-items > .rustdoc-toggle:not(:last-child),
#blanket-implementations-list .impl-items > .rustdoc-toggle:not(:last-child) {
margin-bottom: 1em;
}

Expand Down
17 changes: 17 additions & 0 deletions src/test/rustdoc-gui/method-margins.goml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
goto: "file://" + |DOC_PATH| + "/test_docs/trait_members/struct.HasTrait.html#impl-TraitMembers-for-HasTrait"

assert-count: ("#trait-implementations-list > .rustdoc-toggle", 1)

compare-elements-css: (
// compare margin on type with margin on method
"#trait-implementations-list .impl-items > .rustdoc-toggle:nth-child(1) > summary",
"#trait-implementations-list .impl-items > .rustdoc-toggle:nth-child(2) > summary",
["margin"]
)

compare-elements-css: (
// compare margin on type with margin on method
"#trait-implementations-list .impl-items > .rustdoc-toggle:nth-child(1)",
"#trait-implementations-list .impl-items > .rustdoc-toggle:nth-child(2)",
["margin"]
)
17 changes: 17 additions & 0 deletions src/test/rustdoc-gui/src/test_docs/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,3 +416,20 @@ pub trait TraitWithoutGenerics {

fn foo();
}

pub mod trait_members {
pub trait TraitMembers {
/// Some type
type Type;
/// Some function
fn function();
/// Some other function
fn function2();
}
pub struct HasTrait;
impl TraitMembers for HasTrait {
type Type = u8;
fn function() {}
fn function2() {}
}
}
18 changes: 18 additions & 0 deletions src/test/rustdoc/no-unit-struct-field.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// This test ensures that the tuple struct fields are not generated in the
// search index.

// @!hasraw search-index.js '"0"'
// @!hasraw search-index.js '"1"'
// @hasraw search-index.js '"foo_a"'
// @hasraw search-index.js '"bar_a"'

pub struct Bar(pub u32, pub u8);
pub struct Foo {
pub foo_a: u8,
}
pub enum Enum {
Foo(u8),
Bar {
bar_a: u8,
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![feature(rustc_attrs)]

#[rustc_strict_coherence]
trait Foo {}
//~^ ERROR to use `strict_coherence` on this trait, the `with_negative_coherence` feature must be enabled

fn main() {}
Loading