Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 8321f00

Browse files
committed
Auto merge of rust-lang#135678 - matthiaskrgr:rollup-psuyzpn, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#134455 (cleanup promoteds move check) - rust-lang#135421 (Make tidy warn on unrecognized directives) - rust-lang#135611 (Remove unnecessary assertion for reference error) - rust-lang#135620 (ci: improve github action name) - rust-lang#135639 (new solver: prefer trivial builtin impls) - rust-lang#135654 (add src/librustdoc and src/rustdoc-json-types to RUSTC_IF_UNCHANGED_ALLOWED_PATHS) r? `@ghost` `@rustbot` modify labels: rollup
2 parents bd62a45 + e873695 commit 8321f00

File tree

17 files changed

+134
-52
lines changed

17 files changed

+134
-52
lines changed

.github/workflows/ghcr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# for PR jobs, because forks can't access secrets.
1010
# That's why we use ghcr.io: it has no rate limit and it doesn't require authentication.
1111

12-
name: GHCR
12+
name: GHCR image mirroring
1313

1414
on:
1515
workflow_dispatch:

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4259,6 +4259,7 @@ dependencies = [
42594259
"rustc_serialize",
42604260
"rustc_type_ir",
42614261
"rustc_type_ir_macros",
4262+
"smallvec",
42624263
"tracing",
42634264
]
42644265

compiler/rustc_borrowck/src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,6 @@ fn do_mir_borrowck<'tcx>(
182182
let location_table = PoloniusLocationTable::new(body);
183183

184184
let move_data = MoveData::gather_moves(body, tcx, |_| true);
185-
let promoted_move_data = promoted
186-
.iter_enumerated()
187-
.map(|(idx, body)| (idx, MoveData::gather_moves(body, tcx, |_| true)));
188185

189186
let flow_inits = MaybeInitializedPlaces::new(tcx, body, &move_data)
190187
.iterate_to_fixpoint(tcx, body, Some("borrowck"))
@@ -242,10 +239,14 @@ fn do_mir_borrowck<'tcx>(
242239
false
243240
};
244241

245-
for (idx, move_data) in promoted_move_data {
242+
// While promoteds should mostly be correct by construction, we need to check them for
243+
// invalid moves to detect moving out of arrays:`struct S; fn main() { &([S][0]); }`.
244+
for promoted_body in &promoted {
246245
use rustc_middle::mir::visit::Visitor;
247-
248-
let promoted_body = &promoted[idx];
246+
// This assumes that we won't use some of the fields of the `promoted_mbcx`
247+
// when detecting and reporting move errors. While it would be nice to move
248+
// this check out of `MirBorrowckCtxt`, actually doing so is far from trivial.
249+
let move_data = MoveData::gather_moves(promoted_body, tcx, |_| true);
249250
let mut promoted_mbcx = MirBorrowckCtxt {
250251
infcx: &infcx,
251252
body: promoted_body,
@@ -270,9 +271,6 @@ fn do_mir_borrowck<'tcx>(
270271
move_errors: Vec::new(),
271272
diags_buffer,
272273
};
273-
MoveVisitor { ctxt: &mut promoted_mbcx }.visit_body(promoted_body);
274-
promoted_mbcx.report_move_errors();
275-
276274
struct MoveVisitor<'a, 'b, 'infcx, 'tcx> {
277275
ctxt: &'a mut MirBorrowckCtxt<'b, 'infcx, 'tcx>,
278276
}
@@ -284,6 +282,8 @@ fn do_mir_borrowck<'tcx>(
284282
}
285283
}
286284
}
285+
MoveVisitor { ctxt: &mut promoted_mbcx }.visit_body(promoted_body);
286+
promoted_mbcx.report_move_errors();
287287
}
288288

289289
let mut mbcx = MirBorrowckCtxt {

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1637,7 +1637,6 @@ fn check_type_alias_type_params_are_used<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalD
16371637
let ty = tcx.type_of(def_id).instantiate_identity();
16381638
if ty.references_error() {
16391639
// If there is already another error, do not emit an error for not using a type parameter.
1640-
assert!(tcx.dcx().has_errors().is_some());
16411640
return;
16421641
}
16431642

compiler/rustc_next_trait_solver/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ rustc_macros = { path = "../rustc_macros", optional = true }
1313
rustc_serialize = { path = "../rustc_serialize", optional = true }
1414
rustc_type_ir = { path = "../rustc_type_ir", default-features = false }
1515
rustc_type_ir_macros = { path = "../rustc_type_ir_macros" }
16+
smallvec = "1.8.1"
1617
tracing = "0.1"
1718
# tidy-alphabetical-end
1819

compiler/rustc_next_trait_solver/src/solve/trait_goals.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_type_ir::lang_items::TraitSolverLangItem;
88
use rustc_type_ir::solve::CanonicalResponse;
99
use rustc_type_ir::visit::TypeVisitableExt as _;
1010
use rustc_type_ir::{self as ty, Interner, TraitPredicate, TypingMode, Upcast as _, elaborate};
11+
use smallvec::SmallVec;
1112
use tracing::{instrument, trace};
1213

1314
use crate::delegate::SolverDelegate;
@@ -225,7 +226,7 @@ where
225226
}
226227

227228
ecx.probe_and_evaluate_goal_for_constituent_tys(
228-
CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),
229+
CandidateSource::BuiltinImpl(BuiltinImplSource::Trivial),
229230
goal,
230231
structural_traits::instantiate_constituent_tys_for_sized_trait,
231232
)
@@ -1194,7 +1195,30 @@ where
11941195
};
11951196
}
11961197

1197-
// FIXME: prefer trivial builtin impls
1198+
// We prefer trivial builtin candidates, i.e. builtin impls without any
1199+
// nested requirements, over all others. This is a fix for #53123 and
1200+
// prevents where-bounds from accidentally extending the lifetime of a
1201+
// variable.
1202+
if candidates
1203+
.iter()
1204+
.any(|c| matches!(c.source, CandidateSource::BuiltinImpl(BuiltinImplSource::Trivial)))
1205+
{
1206+
let trivial_builtin_impls: SmallVec<[_; 1]> = candidates
1207+
.iter()
1208+
.filter(|c| {
1209+
matches!(c.source, CandidateSource::BuiltinImpl(BuiltinImplSource::Trivial))
1210+
})
1211+
.map(|c| c.result)
1212+
.collect();
1213+
// There should only ever be a single trivial builtin candidate
1214+
// as they would otherwise overlap.
1215+
assert_eq!(trivial_builtin_impls.len(), 1);
1216+
return if let Some(response) = self.try_merge_responses(&trivial_builtin_impls) {
1217+
Ok((response, Some(TraitGoalProvenVia::Misc)))
1218+
} else {
1219+
Ok((self.bail_with_ambiguity(&trivial_builtin_impls), None))
1220+
};
1221+
}
11981222

11991223
// If there are non-global where-bounds, prefer where-bounds
12001224
// (including global ones) over everything else.

compiler/rustc_trait_selection/src/traits/project.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
991991
Err(ErrorGuaranteed { .. }) => true,
992992
}
993993
}
994-
ImplSource::Builtin(BuiltinImplSource::Misc, _) => {
994+
ImplSource::Builtin(BuiltinImplSource::Misc | BuiltinImplSource::Trivial, _) => {
995995
// While a builtin impl may be known to exist, the associated type may not yet
996996
// be known. Any type with multiple potential associated types is therefore
997997
// not eligible.
@@ -1296,7 +1296,7 @@ fn confirm_select_candidate<'cx, 'tcx>(
12961296
) -> Progress<'tcx> {
12971297
match impl_source {
12981298
ImplSource::UserDefined(data) => confirm_impl_candidate(selcx, obligation, data),
1299-
ImplSource::Builtin(BuiltinImplSource::Misc, data) => {
1299+
ImplSource::Builtin(BuiltinImplSource::Misc | BuiltinImplSource::Trivial, data) => {
13001300
let tcx = selcx.tcx();
13011301
let trait_def_id = obligation.predicate.trait_def_id(tcx);
13021302
if tcx.is_lang_item(trait_def_id, LangItem::Coroutine) {

compiler/rustc_ty_utils/src/instance.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ fn resolve_associated_item<'tcx>(
248248
})
249249
}
250250
}
251-
traits::ImplSource::Builtin(BuiltinImplSource::Misc, _) => {
251+
traits::ImplSource::Builtin(BuiltinImplSource::Misc | BuiltinImplSource::Trivial, _) => {
252252
if tcx.is_lang_item(trait_ref.def_id, LangItem::Clone) {
253253
// FIXME(eddyb) use lang items for methods instead of names.
254254
let name = tcx.item_name(trait_item_id);

compiler/rustc_type_ir/src/solve/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ pub enum CandidateSource<I: Interner> {
169169
#[derive(Clone, Copy, Hash, PartialEq, Eq, Debug)]
170170
#[cfg_attr(feature = "nightly", derive(HashStable_NoContext, TyEncodable, TyDecodable))]
171171
pub enum BuiltinImplSource {
172+
/// A built-in impl that is considered trivial, without any nested requirements. They
173+
/// are preferred over where-clauses, and we want to track them explicitly.
174+
Trivial,
172175
/// Some built-in impl we don't need to differentiate. This should be used
173176
/// unless more specific information is necessary.
174177
Misc,

src/bootstrap/src/core/config/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ use crate::utils::helpers::{self, exe, output, t};
4242
#[rustfmt::skip] // We don't want rustfmt to oneline this list
4343
pub(crate) const RUSTC_IF_UNCHANGED_ALLOWED_PATHS: &[&str] = &[
4444
":!src/tools",
45+
":!src/librustdoc",
46+
":!src/rustdoc-json-types",
4547
":!tests",
4648
":!triagebot.toml",
4749
];

0 commit comments

Comments
 (0)