Skip to content

Commit 96bd50d

Browse files
committed
Auto merge of #109581 - matthiaskrgr:rollup-e8fi2vi, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #109355 (Fix bad suggestion for clone/is_some in field init shorthand) - #109484 (Bugfix: avoid panic on invalid json output from libtest) - #109539 (Refactor `find_*_stability` functions) - #109542 (rustdoc: clean up `storage.js`) - #109545 (Deeply check well-formedness of return-position `impl Trait` in trait) - #109568 (miri: fix raw pointer dyn receivers) - #109570 (Add GUI test for "Auto-hide item methods' documentation" setting) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents b72e896 + beac95a commit 96bd50d

File tree

18 files changed

+627
-442
lines changed

18 files changed

+627
-442
lines changed

Diff for: compiler/rustc_attr/src/builtin.rs

+297-294
Large diffs are not rendered by default.

Diff for: compiler/rustc_const_eval/src/interpret/terminator.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,15 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
539539
let mut receiver = args[0].clone();
540540
let receiver_place = loop {
541541
match receiver.layout.ty.kind() {
542-
ty::Ref(..) | ty::RawPtr(..) => break self.deref_operand(&receiver)?,
542+
ty::Ref(..) | ty::RawPtr(..) => {
543+
// We do *not* use `deref_operand` here: we don't want to conceptually
544+
// create a place that must be dereferenceable, since the receiver might
545+
// be a raw pointer and (for `*const dyn Trait`) we don't need to
546+
// actually access memory to resolve this method.
547+
// Also see <https://github.com/rust-lang/miri/issues/2786>.
548+
let val = self.read_immediate(&receiver)?;
549+
break self.ref_to_mplace(&val)?;
550+
}
543551
ty::Dynamic(.., ty::Dyn) => break receiver.assert_mem_place(), // no immediate unsized values
544552
ty::Dynamic(.., ty::DynStar) => {
545553
// Not clear how to handle this, so far we assume the receiver is always a pointer.

Diff for: compiler/rustc_expand/src/base.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,9 @@ impl SyntaxExtension {
793793
)
794794
})
795795
.unwrap_or_else(|| (None, helper_attrs));
796-
let (stability, const_stability, body_stability) = attr::find_stability(&sess, attrs, span);
796+
let stability = attr::find_stability(&sess, attrs, span);
797+
let const_stability = attr::find_const_stability(&sess, attrs, span);
798+
let body_stability = attr::find_body_stability(&sess, attrs);
797799
if let Some((_, sp)) = const_stability {
798800
sess.emit_err(errors::MacroConstStability {
799801
span: sp,

Diff for: compiler/rustc_hir_analysis/src/check/wfcheck.rs

+72-33
Original file line numberDiff line numberDiff line change
@@ -1544,42 +1544,81 @@ fn check_return_position_impl_trait_in_trait_bounds<'tcx>(
15441544
span: Span,
15451545
) {
15461546
let tcx = wfcx.tcx();
1547-
if let Some(assoc_item) = tcx.opt_associated_item(fn_def_id.to_def_id())
1548-
&& assoc_item.container == ty::AssocItemContainer::TraitContainer
1549-
{
1550-
// FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty): Even with the new lowering
1551-
// strategy, we can't just call `check_associated_item` on the new RPITITs,
1552-
// because tests like `tests/ui/async-await/in-trait/implied-bounds.rs` will fail.
1553-
// That's because we need to check that the bounds of the RPITIT hold using
1554-
// the special substs that we create during opaque type lowering, otherwise we're
1555-
// getting a bunch of early bound and free regions mixed up... Haven't looked too
1556-
// deep into this, though.
1557-
for arg in fn_output.walk() {
1558-
if let ty::GenericArgKind::Type(ty) = arg.unpack()
1559-
// RPITITs are always eagerly normalized into opaques, so always look for an
1560-
// opaque here.
1561-
&& let ty::Alias(ty::Opaque, opaque_ty) = ty.kind()
1562-
&& let Some(opaque_def_id) = opaque_ty.def_id.as_local()
1563-
&& let opaque = tcx.hir().expect_item(opaque_def_id).expect_opaque_ty()
1564-
&& let hir::OpaqueTyOrigin::FnReturn(source) | hir::OpaqueTyOrigin::AsyncFn(source) = opaque.origin
1565-
&& source == fn_def_id
1547+
let Some(assoc_item) = tcx.opt_associated_item(fn_def_id.to_def_id()) else {
1548+
return;
1549+
};
1550+
if assoc_item.container != ty::AssocItemContainer::TraitContainer {
1551+
return;
1552+
}
1553+
fn_output.visit_with(&mut ImplTraitInTraitFinder {
1554+
wfcx,
1555+
fn_def_id,
1556+
depth: ty::INNERMOST,
1557+
seen: FxHashSet::default(),
1558+
});
1559+
}
1560+
1561+
// FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty): Even with the new lowering
1562+
// strategy, we can't just call `check_associated_item` on the new RPITITs,
1563+
// because tests like `tests/ui/async-await/in-trait/implied-bounds.rs` will fail.
1564+
// That's because we need to check that the bounds of the RPITIT hold using
1565+
// the special substs that we create during opaque type lowering, otherwise we're
1566+
// getting a bunch of early bound and free regions mixed up... Haven't looked too
1567+
// deep into this, though.
1568+
struct ImplTraitInTraitFinder<'a, 'tcx> {
1569+
wfcx: &'a WfCheckingCtxt<'a, 'tcx>,
1570+
fn_def_id: LocalDefId,
1571+
depth: ty::DebruijnIndex,
1572+
seen: FxHashSet<DefId>,
1573+
}
1574+
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitFinder<'_, 'tcx> {
1575+
type BreakTy = !;
1576+
1577+
fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<!> {
1578+
let tcx = self.wfcx.tcx();
1579+
if let ty::Alias(ty::Opaque, unshifted_opaque_ty) = *ty.kind()
1580+
&& self.seen.insert(unshifted_opaque_ty.def_id)
1581+
&& let Some(opaque_def_id) = unshifted_opaque_ty.def_id.as_local()
1582+
&& let opaque = tcx.hir().expect_item(opaque_def_id).expect_opaque_ty()
1583+
&& let hir::OpaqueTyOrigin::FnReturn(source) | hir::OpaqueTyOrigin::AsyncFn(source) = opaque.origin
1584+
&& source == self.fn_def_id
1585+
{
1586+
let opaque_ty = tcx.fold_regions(unshifted_opaque_ty, |re, depth| {
1587+
if let ty::ReLateBound(index, bv) = re.kind() {
1588+
if depth != ty::INNERMOST {
1589+
return tcx.mk_re_error_with_message(
1590+
DUMMY_SP,
1591+
"we shouldn't walk non-predicate binders with `impl Trait`...",
1592+
);
1593+
}
1594+
tcx.mk_re_late_bound(index.shifted_out_to_binder(self.depth), bv)
1595+
} else {
1596+
re
1597+
}
1598+
});
1599+
for (bound, bound_span) in tcx
1600+
.bound_explicit_item_bounds(opaque_ty.def_id)
1601+
.subst_iter_copied(tcx, opaque_ty.substs)
15661602
{
1567-
let span = tcx.def_span(opaque_ty.def_id);
1568-
let bounds = wfcx.tcx().explicit_item_bounds(opaque_ty.def_id);
1569-
let wf_obligations = bounds.iter().flat_map(|&(bound, bound_span)| {
1570-
let bound = ty::EarlyBinder(bound).subst(tcx, opaque_ty.substs);
1571-
let normalized_bound = wfcx.normalize(span, None, bound);
1572-
traits::wf::predicate_obligations(
1573-
wfcx.infcx,
1574-
wfcx.param_env,
1575-
wfcx.body_def_id,
1576-
normalized_bound,
1577-
bound_span,
1578-
)
1579-
});
1580-
wfcx.register_obligations(wf_obligations);
1603+
let bound = self.wfcx.normalize(bound_span, None, bound);
1604+
self.wfcx.register_obligations(traits::wf::predicate_obligations(
1605+
self.wfcx.infcx,
1606+
self.wfcx.param_env,
1607+
self.wfcx.body_def_id,
1608+
bound,
1609+
bound_span,
1610+
));
1611+
// Set the debruijn index back to innermost here, since we already eagerly
1612+
// shifted the substs that we use to generate these bounds. This is unfortunately
1613+
// subtly different behavior than the `ImplTraitInTraitFinder` we use in `param_env`,
1614+
// but that function doesn't actually need to normalize the bound it's visiting
1615+
// (whereas we have to do so here)...
1616+
let old_depth = std::mem::replace(&mut self.depth, ty::INNERMOST);
1617+
bound.visit_with(self);
1618+
self.depth = old_depth;
15811619
}
15821620
}
1621+
ty.super_visit_with(self)
15831622
}
15841623
}
15851624

Diff for: compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+19-10
Original file line numberDiff line numberDiff line change
@@ -983,13 +983,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
983983
)
984984
.must_apply_modulo_regions()
985985
{
986-
diag.span_suggestion_verbose(
987-
expr.span.shrink_to_hi(),
988-
"consider using clone here",
989-
".clone()",
990-
Applicability::MachineApplicable,
991-
);
992-
return true;
986+
let suggestion = match self.maybe_get_struct_pattern_shorthand_field(expr) {
987+
Some(ident) => format!(": {}.clone()", ident),
988+
None => ".clone()".to_string()
989+
};
990+
991+
diag.span_suggestion_verbose(
992+
expr.span.shrink_to_hi(),
993+
"consider using clone here",
994+
suggestion,
995+
Applicability::MachineApplicable,
996+
);
997+
return true;
993998
}
994999
false
9951000
}
@@ -1150,13 +1155,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11501155
return false;
11511156
}
11521157

1153-
diag.span_suggestion(
1158+
let suggestion = match self.maybe_get_struct_pattern_shorthand_field(expr) {
1159+
Some(ident) => format!(": {}.is_some()", ident),
1160+
None => ".is_some()".to_string(),
1161+
};
1162+
1163+
diag.span_suggestion_verbose(
11541164
expr.span.shrink_to_hi(),
11551165
"use `Option::is_some` to test if the `Option` has a value",
1156-
".is_some()",
1166+
suggestion,
11571167
Applicability::MachineApplicable,
11581168
);
1159-
11601169
true
11611170
}
11621171

Diff for: compiler/rustc_passes/src/stability.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
159159
return;
160160
}
161161

162-
let (stab, const_stab, body_stab) = attr::find_stability(&self.tcx.sess, attrs, item_sp);
162+
let stab = attr::find_stability(&self.tcx.sess, attrs, item_sp);
163+
let const_stab = attr::find_const_stability(&self.tcx.sess, attrs, item_sp);
164+
let body_stab = attr::find_body_stability(&self.tcx.sess, attrs);
163165
let mut const_span = None;
164166

165167
let const_stab = const_stab.map(|(const_stab, const_span_node)| {
@@ -742,8 +744,8 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> {
742744
let features = self.tcx.features();
743745
if features.staged_api {
744746
let attrs = self.tcx.hir().attrs(item.hir_id());
745-
let (stab, const_stab, _) =
746-
attr::find_stability(&self.tcx.sess, attrs, item.span);
747+
let stab = attr::find_stability(&self.tcx.sess, attrs, item.span);
748+
let const_stab = attr::find_const_stability(&self.tcx.sess, attrs, item.span);
747749

748750
// If this impl block has an #[unstable] attribute, give an
749751
// error if all involved types and traits are stable, because

Diff for: src/bootstrap/render_tests.rs

+7-12
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,13 @@ impl<'a> Renderer<'a> {
100100
break;
101101
}
102102

103-
let trimmed = line.trim();
104-
if trimmed.starts_with("{") && trimmed.ends_with("}") {
105-
self.render_message(match serde_json::from_str(&trimmed) {
106-
Ok(parsed) => parsed,
107-
Err(err) => {
108-
panic!("failed to parse libtest json output; error: {err}, line: {line:?}");
109-
}
110-
});
111-
} else {
112-
// Handle non-JSON output, for example when --nocapture is passed.
113-
print!("{line}");
114-
let _ = std::io::stdout().flush();
103+
match serde_json::from_str(&line) {
104+
Ok(parsed) => self.render_message(parsed),
105+
Err(_err) => {
106+
// Handle non-JSON output, for example when --nocapture is passed.
107+
print!("{line}");
108+
let _ = std::io::stdout().flush();
109+
}
115110
}
116111
}
117112
}

Diff for: src/librustdoc/html/static/css/rustdoc.css

+1-16
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,6 @@
8787
box-sizing: border-box;
8888
}
8989

90-
/* This part handles the "default" theme being used depending on the system one. */
91-
html {
92-
content: "";
93-
}
94-
@media (prefers-color-scheme: light) {
95-
html {
96-
content: "light";
97-
}
98-
}
99-
@media (prefers-color-scheme: dark) {
100-
html {
101-
content: "dark";
102-
}
103-
}
104-
10590
/* General structure and fonts */
10691

10792
body {
@@ -1538,7 +1523,7 @@ However, it's not needed with smaller screen width because the doc/code block is
15381523
/*
15391524
WARNING: RUSTDOC_MOBILE_BREAKPOINT MEDIA QUERY
15401525
If you update this line, then you also need to update the line with the same warning
1541-
in storage.js
1526+
in main.js
15421527
*/
15431528
@media (max-width: 700px) {
15441529
/* When linking to an item with an `id` (for instance, by clicking a link in the sidebar,

Diff for: src/librustdoc/html/static/js/main.js

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
"use strict";
66

7+
// WARNING: RUSTDOC_MOBILE_BREAKPOINT MEDIA QUERY
8+
// If you update this line, then you also need to update the media query with the same
9+
// warning in rustdoc.css
10+
window.RUSTDOC_MOBILE_BREAKPOINT = 700;
11+
712
// Given a basename (e.g. "storage") and an extension (e.g. ".js"), return a URL
813
// for a resource under the root-path, with the resource-suffix.
914
function resourcePath(basename, extension) {

0 commit comments

Comments
 (0)