Skip to content

Commit c3202af

Browse files
committed
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
2 parents e3029d2 + 5347652 commit c3202af

File tree

9 files changed

+94
-36
lines changed

9 files changed

+94
-36
lines changed

compiler/rustc_lint/src/reference_casting.rs

+7
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,13 @@ fn is_cast_to_bigger_memory_layout<'tcx>(
199199
let e_alloc = cx.expr_or_init(e);
200200
let e_alloc =
201201
if let ExprKind::AddrOf(_, _, inner_expr) = e_alloc.kind { inner_expr } else { e_alloc };
202+
203+
// if the current expr looks like this `&mut expr[index]` then just looking
204+
// at `expr[index]` won't give us the underlying allocation, so we just skip it
205+
if let ExprKind::Index(..) = e_alloc.kind {
206+
return None;
207+
}
208+
202209
let alloc_ty = cx.typeck_results().node_type(e_alloc.hir_id);
203210

204211
// if we do not find it we bail out, as this may not be UB

compiler/rustc_middle/src/ty/layout.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,22 @@ impl<'tcx> SizeSkeleton<'tcx> {
333333
match *ty.kind() {
334334
ty::Ref(_, pointee, _) | ty::RawPtr(pointee, _) => {
335335
let non_zero = !ty.is_unsafe_ptr();
336-
let tail = tcx.struct_tail_erasing_lifetimes(pointee, param_env);
336+
337+
let tail = tcx.struct_tail_with_normalize(
338+
pointee,
339+
|ty| match tcx.try_normalize_erasing_regions(param_env, ty) {
340+
Ok(ty) => ty,
341+
Err(_e) => {
342+
if let Some(guar) = tcx.dcx().has_errors() {
343+
Ty::new_error(tcx, guar)
344+
} else {
345+
bug!("normalization failed, but no errors reported");
346+
}
347+
}
348+
},
349+
|| {},
350+
);
351+
337352
match tail.kind() {
338353
ty::Param(_) | ty::Alias(ty::Projection | ty::Inherent, _) => {
339354
debug_assert!(tail.has_non_region_param());

src/librustdoc/clean/inline.rs

+19-28
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_hir::Mutability;
1414
use rustc_metadata::creader::{CStore, LoadedMacro};
1515
use rustc_middle::ty::fast_reject::SimplifiedType;
1616
use rustc_middle::ty::{self, TyCtxt};
17+
use rustc_span::def_id::LOCAL_CRATE;
1718
use rustc_span::hygiene::MacroKind;
1819
use rustc_span::symbol::{kw, sym, Symbol};
1920

@@ -444,24 +445,24 @@ pub(crate) fn build_impl(
444445

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

448+
// Do not inline compiler-internal items unless we're a compiler-internal crate.
449+
let is_compiler_internal = |did| {
450+
tcx.lookup_stability(did)
451+
.is_some_and(|stab| stab.is_unstable() && stab.feature == sym::rustc_private)
452+
};
453+
let document_compiler_internal = is_compiler_internal(LOCAL_CRATE.as_def_id());
454+
let is_directly_public = |cx: &mut DocContext<'_>, did| {
455+
cx.cache.effective_visibilities.is_directly_public(tcx, did)
456+
&& (document_compiler_internal || !is_compiler_internal(did))
457+
};
458+
447459
// Only inline impl if the implemented trait is
448460
// reachable in rustdoc generated documentation
449461
if !did.is_local()
450462
&& let Some(traitref) = associated_trait
463+
&& !is_directly_public(cx, traitref.def_id)
451464
{
452-
let did = traitref.def_id;
453-
if !cx.cache.effective_visibilities.is_directly_public(tcx, did) {
454-
return;
455-
}
456-
457-
if !tcx.features().rustc_private && !cx.render_options.force_unstable_if_unmarked {
458-
if let Some(stab) = tcx.lookup_stability(did)
459-
&& stab.is_unstable()
460-
&& stab.feature == sym::rustc_private
461-
{
462-
return;
463-
}
464-
}
465+
return;
465466
}
466467

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

485486
// Only inline impl if the implementing type is
486487
// reachable in rustdoc generated documentation
487-
if !did.is_local() {
488-
if let Some(did) = for_.def_id(&cx.cache) {
489-
if !cx.cache.effective_visibilities.is_directly_public(tcx, did) {
490-
return;
491-
}
492-
493-
if !tcx.features().rustc_private && !cx.render_options.force_unstable_if_unmarked {
494-
if let Some(stab) = tcx.lookup_stability(did)
495-
&& stab.is_unstable()
496-
&& stab.feature == sym::rustc_private
497-
{
498-
return;
499-
}
500-
}
501-
}
488+
if !did.is_local()
489+
&& let Some(did) = for_.def_id(&cx.cache)
490+
&& !is_directly_public(cx, did)
491+
{
492+
return;
502493
}
503494

504495
let document_hidden = cx.render_options.document_hidden;

src/librustdoc/config.rs

-4
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,6 @@ pub(crate) struct RenderOptions {
285285
pub(crate) no_emit_shared: bool,
286286
/// If `true`, HTML source code pages won't be generated.
287287
pub(crate) html_no_source: bool,
288-
/// Whether `-Zforce-unstable-if-unmarked` unstable option is set
289-
pub(crate) force_unstable_if_unmarked: bool,
290288
}
291289

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

354352
let codegen_options = CodegenOptions::build(early_dcx, matches);
355353
let unstable_opts = UnstableOptions::build(early_dcx, matches);
356-
let force_unstable_if_unmarked = unstable_opts.force_unstable_if_unmarked;
357354

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

@@ -790,7 +787,6 @@ impl Options {
790787
call_locations,
791788
no_emit_shared: false,
792789
html_no_source,
793-
force_unstable_if_unmarked,
794790
};
795791
Some((options, render_options))
796792
}
+4-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
//@ aux-build:issue-76736-1.rs
22
//@ aux-build:issue-76736-2.rs
33

4+
// https://github.com/rust-lang/rust/issues/124635
5+
46
#![crate_name = "foo"]
57
#![feature(rustc_private)]
68

79
extern crate issue_76736_1;
810
extern crate issue_76736_2;
911

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

1416
// @has foo/struct.Bar.html
15-
// @has - '//*[@class="impl"]//h3[@class="code-header"]' 'MaybeResult'
17+
// @!has - '//*[@class="impl"]//h3[@class="code-header"]' 'MaybeResult'
1618
pub use issue_76736_2::Bar;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//@ aux-build:issue-76736-1.rs
2+
//@ aux-build:issue-76736-2.rs
3+
4+
// https://github.com/rust-lang/rust/issues/124635
5+
6+
#![crate_name = "foo"]
7+
#![feature(rustc_private, staged_api)]
8+
#![unstable(feature = "rustc_private", issue = "none")]
9+
10+
extern crate issue_76736_1;
11+
extern crate issue_76736_2;
12+
13+
// @has foo/struct.Foo.html
14+
// @has - '//*[@class="impl"]//h3[@class="code-header"]' 'MaybeResult'
15+
pub struct Foo;
16+
17+
// @has foo/struct.Bar.html
18+
// @has - '//*[@class="impl"]//h3[@class="code-header"]' 'MaybeResult'
19+
pub use issue_76736_2::Bar;

tests/ui/lint/reference_casting.rs

+8
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,14 @@ unsafe fn bigger_layout() {
247247
unsafe fn from_ref(this: &i32) -> &i64 {
248248
&*(this as *const i32 as *const i64)
249249
}
250+
251+
// https://github.com/rust-lang/rust/issues/124685
252+
unsafe fn slice_index(array: &mut [u8], offset: usize) {
253+
let a1 = &mut array[offset];
254+
let a2 = a1 as *mut u8;
255+
let a3 = a2 as *mut u64;
256+
unsafe { *a3 = 3 };
257+
}
250258
}
251259

252260
const RAW_PTR: *mut u8 = 1 as *mut u8;

tests/crashes/113272.rs tests/ui/structs/ice-struct-tail-normalization-113272.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
//@ known-bug: #113272
21
trait Trait {
32
type RefTarget;
43
}
54

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

89
struct Other {
910
data: <() as Trait>::RefTarget,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0412]: cannot find type `Missing` in this scope
2+
--> $DIR/ice-struct-tail-normalization-113272.rs:5:25
3+
|
4+
LL | impl Trait for () where Missing: Trait {}
5+
| ^^^^^^^ not found in this scope
6+
7+
error[E0046]: not all trait items implemented, missing: `RefTarget`
8+
--> $DIR/ice-struct-tail-normalization-113272.rs:5:1
9+
|
10+
LL | type RefTarget;
11+
| -------------- `RefTarget` from trait
12+
...
13+
LL | impl Trait for () where Missing: Trait {}
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `RefTarget` in implementation
15+
16+
error: aborting due to 2 previous errors
17+
18+
Some errors have detailed explanations: E0046, E0412.
19+
For more information about an error, try `rustc --explain E0046`.

0 commit comments

Comments
 (0)