Skip to content

Commit

Permalink
Auto merge of rust-lang#124890 - matthiaskrgr:rollup-25iq88h, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 3 pull requests

Successful merges:

 - rust-lang#124548 (Handle normalization failure in `struct_tail_erasing_lifetimes`)
 - rust-lang#124761 (Fix insufficient logic when searching for the underlying allocation)
 - rust-lang#124864 (rustdoc: use stability, instead of features, to decide what to show)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed May 8, 2024
2 parents e3029d2 + 5347652 commit c3202af
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 36 deletions.
7 changes: 7 additions & 0 deletions compiler/rustc_lint/src/reference_casting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ fn is_cast_to_bigger_memory_layout<'tcx>(
let e_alloc = cx.expr_or_init(e);
let e_alloc =
if let ExprKind::AddrOf(_, _, inner_expr) = e_alloc.kind { inner_expr } else { e_alloc };

// if the current expr looks like this `&mut expr[index]` then just looking
// at `expr[index]` won't give us the underlying allocation, so we just skip it
if let ExprKind::Index(..) = e_alloc.kind {
return None;
}

let alloc_ty = cx.typeck_results().node_type(e_alloc.hir_id);

// if we do not find it we bail out, as this may not be UB
Expand Down
17 changes: 16 additions & 1 deletion compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,22 @@ impl<'tcx> SizeSkeleton<'tcx> {
match *ty.kind() {
ty::Ref(_, pointee, _) | ty::RawPtr(pointee, _) => {
let non_zero = !ty.is_unsafe_ptr();
let tail = tcx.struct_tail_erasing_lifetimes(pointee, param_env);

let tail = tcx.struct_tail_with_normalize(
pointee,
|ty| match tcx.try_normalize_erasing_regions(param_env, ty) {
Ok(ty) => ty,
Err(_e) => {
if let Some(guar) = tcx.dcx().has_errors() {
Ty::new_error(tcx, guar)
} else {
bug!("normalization failed, but no errors reported");
}
}
},
|| {},
);

match tail.kind() {
ty::Param(_) | ty::Alias(ty::Projection | ty::Inherent, _) => {
debug_assert!(tail.has_non_region_param());
Expand Down
47 changes: 19 additions & 28 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use rustc_hir::Mutability;
use rustc_metadata::creader::{CStore, LoadedMacro};
use rustc_middle::ty::fast_reject::SimplifiedType;
use rustc_middle::ty::{self, TyCtxt};
use rustc_span::def_id::LOCAL_CRATE;
use rustc_span::hygiene::MacroKind;
use rustc_span::symbol::{kw, sym, Symbol};

Expand Down Expand Up @@ -444,24 +445,24 @@ pub(crate) fn build_impl(

let associated_trait = tcx.impl_trait_ref(did).map(ty::EarlyBinder::skip_binder);

// Do not inline compiler-internal items unless we're a compiler-internal crate.
let is_compiler_internal = |did| {
tcx.lookup_stability(did)
.is_some_and(|stab| stab.is_unstable() && stab.feature == sym::rustc_private)
};
let document_compiler_internal = is_compiler_internal(LOCAL_CRATE.as_def_id());
let is_directly_public = |cx: &mut DocContext<'_>, did| {
cx.cache.effective_visibilities.is_directly_public(tcx, did)
&& (document_compiler_internal || !is_compiler_internal(did))
};

// Only inline impl if the implemented trait is
// reachable in rustdoc generated documentation
if !did.is_local()
&& let Some(traitref) = associated_trait
&& !is_directly_public(cx, traitref.def_id)
{
let did = traitref.def_id;
if !cx.cache.effective_visibilities.is_directly_public(tcx, did) {
return;
}

if !tcx.features().rustc_private && !cx.render_options.force_unstable_if_unmarked {
if let Some(stab) = tcx.lookup_stability(did)
&& stab.is_unstable()
&& stab.feature == sym::rustc_private
{
return;
}
}
return;
}

let impl_item = match did.as_local() {
Expand All @@ -484,21 +485,11 @@ pub(crate) fn build_impl(

// Only inline impl if the implementing type is
// reachable in rustdoc generated documentation
if !did.is_local() {
if let Some(did) = for_.def_id(&cx.cache) {
if !cx.cache.effective_visibilities.is_directly_public(tcx, did) {
return;
}

if !tcx.features().rustc_private && !cx.render_options.force_unstable_if_unmarked {
if let Some(stab) = tcx.lookup_stability(did)
&& stab.is_unstable()
&& stab.feature == sym::rustc_private
{
return;
}
}
}
if !did.is_local()
&& let Some(did) = for_.def_id(&cx.cache)
&& !is_directly_public(cx, did)
{
return;
}

let document_hidden = cx.render_options.document_hidden;
Expand Down
4 changes: 0 additions & 4 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,6 @@ pub(crate) struct RenderOptions {
pub(crate) no_emit_shared: bool,
/// If `true`, HTML source code pages won't be generated.
pub(crate) html_no_source: bool,
/// Whether `-Zforce-unstable-if-unmarked` unstable option is set
pub(crate) force_unstable_if_unmarked: bool,
}

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -353,7 +351,6 @@ impl Options {

let codegen_options = CodegenOptions::build(early_dcx, matches);
let unstable_opts = UnstableOptions::build(early_dcx, matches);
let force_unstable_if_unmarked = unstable_opts.force_unstable_if_unmarked;

let dcx = new_dcx(error_format, None, diagnostic_width, &unstable_opts);

Expand Down Expand Up @@ -790,7 +787,6 @@ impl Options {
call_locations,
no_emit_shared: false,
html_no_source,
force_unstable_if_unmarked,
};
Some((options, render_options))
}
Expand Down
6 changes: 4 additions & 2 deletions tests/rustdoc/inline_cross/issue-76736-2.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
//@ aux-build:issue-76736-1.rs
//@ aux-build:issue-76736-2.rs

// https://github.com/rust-lang/rust/issues/124635

#![crate_name = "foo"]
#![feature(rustc_private)]

extern crate issue_76736_1;
extern crate issue_76736_2;

// @has foo/struct.Foo.html
// @has - '//*[@class="impl"]//h3[@class="code-header"]' 'MaybeResult'
// @!has - '//*[@class="impl"]//h3[@class="code-header"]' 'MaybeResult'
pub struct Foo;

// @has foo/struct.Bar.html
// @has - '//*[@class="impl"]//h3[@class="code-header"]' 'MaybeResult'
// @!has - '//*[@class="impl"]//h3[@class="code-header"]' 'MaybeResult'
pub use issue_76736_2::Bar;
19 changes: 19 additions & 0 deletions tests/rustdoc/inline_cross/issue-76736-4.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//@ aux-build:issue-76736-1.rs
//@ aux-build:issue-76736-2.rs

// https://github.com/rust-lang/rust/issues/124635

#![crate_name = "foo"]
#![feature(rustc_private, staged_api)]
#![unstable(feature = "rustc_private", issue = "none")]

extern crate issue_76736_1;
extern crate issue_76736_2;

// @has foo/struct.Foo.html
// @has - '//*[@class="impl"]//h3[@class="code-header"]' 'MaybeResult'
pub struct Foo;

// @has foo/struct.Bar.html
// @has - '//*[@class="impl"]//h3[@class="code-header"]' 'MaybeResult'
pub use issue_76736_2::Bar;
8 changes: 8 additions & 0 deletions tests/ui/lint/reference_casting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,14 @@ unsafe fn bigger_layout() {
unsafe fn from_ref(this: &i32) -> &i64 {
&*(this as *const i32 as *const i64)
}

// https://github.com/rust-lang/rust/issues/124685
unsafe fn slice_index(array: &mut [u8], offset: usize) {
let a1 = &mut array[offset];
let a2 = a1 as *mut u8;
let a3 = a2 as *mut u64;
unsafe { *a3 = 3 };
}
}

const RAW_PTR: *mut u8 = 1 as *mut u8;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//@ known-bug: #113272
trait Trait {
type RefTarget;
}

impl Trait for () where Missing: Trait {}
//~^ ERROR cannot find type `Missing` in this scope
//~| ERROR not all trait items implemented, missing: `RefTarget`

struct Other {
data: <() as Trait>::RefTarget,
Expand Down
19 changes: 19 additions & 0 deletions tests/ui/structs/ice-struct-tail-normalization-113272.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0412]: cannot find type `Missing` in this scope
--> $DIR/ice-struct-tail-normalization-113272.rs:5:25
|
LL | impl Trait for () where Missing: Trait {}
| ^^^^^^^ not found in this scope

error[E0046]: not all trait items implemented, missing: `RefTarget`
--> $DIR/ice-struct-tail-normalization-113272.rs:5:1
|
LL | type RefTarget;
| -------------- `RefTarget` from trait
...
LL | impl Trait for () where Missing: Trait {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `RefTarget` in implementation

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0046, E0412.
For more information about an error, try `rustc --explain E0046`.

0 comments on commit c3202af

Please sign in to comment.