mirror of https://github.com/rust-lang/rust.git
Auto merge of #124890 - matthiaskrgr:rollup-25iq88h, r=matthiaskrgr
Rollup of 3 pull requests Successful merges: - #124548 (Handle normalization failure in `struct_tail_erasing_lifetimes`) - #124761 (Fix insufficient logic when searching for the underlying allocation) - #124864 (rustdoc: use stability, instead of features, to decide what to show) r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
c3202afa28
|
@ -199,6 +199,13 @@ fn is_cast_to_bigger_memory_layout<'tcx>(
|
||||||
let e_alloc = cx.expr_or_init(e);
|
let e_alloc = cx.expr_or_init(e);
|
||||||
let e_alloc =
|
let e_alloc =
|
||||||
if let ExprKind::AddrOf(_, _, inner_expr) = e_alloc.kind { inner_expr } else { 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);
|
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
|
// if we do not find it we bail out, as this may not be UB
|
||||||
|
|
|
@ -333,7 +333,22 @@ impl<'tcx> SizeSkeleton<'tcx> {
|
||||||
match *ty.kind() {
|
match *ty.kind() {
|
||||||
ty::Ref(_, pointee, _) | ty::RawPtr(pointee, _) => {
|
ty::Ref(_, pointee, _) | ty::RawPtr(pointee, _) => {
|
||||||
let non_zero = !ty.is_unsafe_ptr();
|
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() {
|
match tail.kind() {
|
||||||
ty::Param(_) | ty::Alias(ty::Projection | ty::Inherent, _) => {
|
ty::Param(_) | ty::Alias(ty::Projection | ty::Inherent, _) => {
|
||||||
debug_assert!(tail.has_non_region_param());
|
debug_assert!(tail.has_non_region_param());
|
||||||
|
|
|
@ -14,6 +14,7 @@ use rustc_hir::Mutability;
|
||||||
use rustc_metadata::creader::{CStore, LoadedMacro};
|
use rustc_metadata::creader::{CStore, LoadedMacro};
|
||||||
use rustc_middle::ty::fast_reject::SimplifiedType;
|
use rustc_middle::ty::fast_reject::SimplifiedType;
|
||||||
use rustc_middle::ty::{self, TyCtxt};
|
use rustc_middle::ty::{self, TyCtxt};
|
||||||
|
use rustc_span::def_id::LOCAL_CRATE;
|
||||||
use rustc_span::hygiene::MacroKind;
|
use rustc_span::hygiene::MacroKind;
|
||||||
use rustc_span::symbol::{kw, sym, Symbol};
|
use rustc_span::symbol::{kw, sym, Symbol};
|
||||||
|
|
||||||
|
@ -444,24 +445,24 @@ pub(crate) fn build_impl(
|
||||||
|
|
||||||
let associated_trait = tcx.impl_trait_ref(did).map(ty::EarlyBinder::skip_binder);
|
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
|
// Only inline impl if the implemented trait is
|
||||||
// reachable in rustdoc generated documentation
|
// reachable in rustdoc generated documentation
|
||||||
if !did.is_local()
|
if !did.is_local()
|
||||||
&& let Some(traitref) = associated_trait
|
&& let Some(traitref) = associated_trait
|
||||||
|
&& !is_directly_public(cx, traitref.def_id)
|
||||||
{
|
{
|
||||||
let did = traitref.def_id;
|
return;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let impl_item = match did.as_local() {
|
let impl_item = match did.as_local() {
|
||||||
|
@ -484,21 +485,11 @@ pub(crate) fn build_impl(
|
||||||
|
|
||||||
// Only inline impl if the implementing type is
|
// Only inline impl if the implementing type is
|
||||||
// reachable in rustdoc generated documentation
|
// reachable in rustdoc generated documentation
|
||||||
if !did.is_local() {
|
if !did.is_local()
|
||||||
if let Some(did) = for_.def_id(&cx.cache) {
|
&& let Some(did) = for_.def_id(&cx.cache)
|
||||||
if !cx.cache.effective_visibilities.is_directly_public(tcx, did) {
|
&& !is_directly_public(cx, did)
|
||||||
return;
|
{
|
||||||
}
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let document_hidden = cx.render_options.document_hidden;
|
let document_hidden = cx.render_options.document_hidden;
|
||||||
|
|
|
@ -285,8 +285,6 @@ pub(crate) struct RenderOptions {
|
||||||
pub(crate) no_emit_shared: bool,
|
pub(crate) no_emit_shared: bool,
|
||||||
/// If `true`, HTML source code pages won't be generated.
|
/// If `true`, HTML source code pages won't be generated.
|
||||||
pub(crate) html_no_source: bool,
|
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)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||||
|
@ -353,7 +351,6 @@ impl Options {
|
||||||
|
|
||||||
let codegen_options = CodegenOptions::build(early_dcx, matches);
|
let codegen_options = CodegenOptions::build(early_dcx, matches);
|
||||||
let unstable_opts = UnstableOptions::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);
|
let dcx = new_dcx(error_format, None, diagnostic_width, &unstable_opts);
|
||||||
|
|
||||||
|
@ -790,7 +787,6 @@ impl Options {
|
||||||
call_locations,
|
call_locations,
|
||||||
no_emit_shared: false,
|
no_emit_shared: false,
|
||||||
html_no_source,
|
html_no_source,
|
||||||
force_unstable_if_unmarked,
|
|
||||||
};
|
};
|
||||||
Some((options, render_options))
|
Some((options, render_options))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
//@ aux-build:issue-76736-1.rs
|
//@ aux-build:issue-76736-1.rs
|
||||||
//@ aux-build:issue-76736-2.rs
|
//@ aux-build:issue-76736-2.rs
|
||||||
|
|
||||||
|
// https://github.com/rust-lang/rust/issues/124635
|
||||||
|
|
||||||
#![crate_name = "foo"]
|
#![crate_name = "foo"]
|
||||||
#![feature(rustc_private)]
|
#![feature(rustc_private)]
|
||||||
|
|
||||||
|
@ -8,9 +10,9 @@ extern crate issue_76736_1;
|
||||||
extern crate issue_76736_2;
|
extern crate issue_76736_2;
|
||||||
|
|
||||||
// @has foo/struct.Foo.html
|
// @has foo/struct.Foo.html
|
||||||
// @has - '//*[@class="impl"]//h3[@class="code-header"]' 'MaybeResult'
|
// @!has - '//*[@class="impl"]//h3[@class="code-header"]' 'MaybeResult'
|
||||||
pub struct Foo;
|
pub struct Foo;
|
||||||
|
|
||||||
// @has foo/struct.Bar.html
|
// @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;
|
pub use issue_76736_2::Bar;
|
||||||
|
|
|
@ -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;
|
|
@ -247,6 +247,14 @@ unsafe fn bigger_layout() {
|
||||||
unsafe fn from_ref(this: &i32) -> &i64 {
|
unsafe fn from_ref(this: &i32) -> &i64 {
|
||||||
&*(this as *const i32 as *const 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;
|
const RAW_PTR: *mut u8 = 1 as *mut u8;
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
//@ known-bug: #113272
|
|
||||||
trait Trait {
|
trait Trait {
|
||||||
type RefTarget;
|
type RefTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Trait for () where Missing: Trait {}
|
impl Trait for () where Missing: Trait {}
|
||||||
|
//~^ ERROR cannot find type `Missing` in this scope
|
||||||
|
//~| ERROR not all trait items implemented, missing: `RefTarget`
|
||||||
|
|
||||||
struct Other {
|
struct Other {
|
||||||
data: <() as Trait>::RefTarget,
|
data: <() as Trait>::RefTarget,
|
|
@ -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`.
|
Loading…
Reference in New Issue