Skip to content

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

+1-1
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

+1
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

+9-9
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

-1
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

+1
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

+26-2
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

+2-2
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

+1-1
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

+3
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

+2
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
];

src/tools/compiletest/src/runtest.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::{ColorConfig, json, stamp_file_path};
3232
mod debugger;
3333

3434
// Helper modules that implement test running logic for each test suite.
35-
// tidy-alphabet-start
35+
// tidy-alphabetical-start
3636
mod assembly;
3737
mod codegen;
3838
mod codegen_units;
@@ -47,7 +47,7 @@ mod run_make;
4747
mod rustdoc;
4848
mod rustdoc_json;
4949
mod ui;
50-
// tidy-alphabet-end
50+
// tidy-alphabetical-end
5151

5252
#[cfg(test)]
5353
mod tests;

src/tools/tidy/src/style.rs

+66-28
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,21 @@ const ANNOTATIONS_TO_IGNORE: &[&str] = &[
7272
"//@ normalize-stderr",
7373
];
7474

75+
// If you edit this, also edit where it gets used in `check` (calling `contains_ignore_directives`)
76+
const CONFIGURABLE_CHECKS: [&str; 11] = [
77+
"cr",
78+
"undocumented-unsafe",
79+
"tab",
80+
"linelength",
81+
"filelength",
82+
"end-whitespace",
83+
"trailing-newlines",
84+
"leading-newlines",
85+
"copyright",
86+
"dbg",
87+
"odd-backticks",
88+
];
89+
7590
fn generate_problems<'a>(
7691
consts: &'a [u32],
7792
letter_digit: &'a FxHashMap<char, char>,
@@ -220,6 +235,7 @@ fn long_line_is_ok(extension: &str, is_error_code: bool, max_columns: usize, lin
220235
}
221236
}
222237

238+
#[derive(Clone, Copy)]
223239
enum Directive {
224240
/// By default, tidy always warns against style issues.
225241
Deny,
@@ -231,20 +247,28 @@ enum Directive {
231247
Ignore(bool),
232248
}
233249

234-
fn contains_ignore_directive(can_contain: bool, contents: &str, check: &str) -> Directive {
250+
// Use a fixed size array in the return type to catch mistakes with changing `CONFIGURABLE_CHECKS`
251+
// without changing the code in `check` easier.
252+
fn contains_ignore_directives<const N: usize>(
253+
can_contain: bool,
254+
contents: &str,
255+
checks: [&str; N],
256+
) -> [Directive; N] {
235257
if !can_contain {
236-
return Directive::Deny;
237-
}
238-
// Update `can_contain` when changing this
239-
if contents.contains(&format!("// ignore-tidy-{check}"))
240-
|| contents.contains(&format!("# ignore-tidy-{check}"))
241-
|| contents.contains(&format!("/* ignore-tidy-{check} */"))
242-
|| contents.contains(&format!("<!-- ignore-tidy-{check} -->"))
243-
{
244-
Directive::Ignore(false)
245-
} else {
246-
Directive::Deny
258+
return [Directive::Deny; N];
247259
}
260+
checks.map(|check| {
261+
// Update `can_contain` when changing this
262+
if contents.contains(&format!("// ignore-tidy-{check}"))
263+
|| contents.contains(&format!("# ignore-tidy-{check}"))
264+
|| contents.contains(&format!("/* ignore-tidy-{check} */"))
265+
|| contents.contains(&format!("<!-- ignore-tidy-{check} -->"))
266+
{
267+
Directive::Ignore(false)
268+
} else {
269+
Directive::Deny
270+
}
271+
})
248272
}
249273

250274
macro_rules! suppressible_tidy_err {
@@ -370,6 +394,7 @@ pub fn check(path: &Path, bad: &mut bool) {
370394
COLS
371395
};
372396

397+
// When you change this, also change the `directive_line_starts` variable below
373398
let can_contain = contents.contains("// ignore-tidy-")
374399
|| contents.contains("# ignore-tidy-")
375400
|| contents.contains("/* ignore-tidy-")
@@ -385,22 +410,19 @@ pub fn check(path: &Path, bad: &mut bool) {
385410
return;
386411
}
387412
}
388-
let mut skip_cr = contains_ignore_directive(can_contain, &contents, "cr");
389-
let mut skip_undocumented_unsafe =
390-
contains_ignore_directive(can_contain, &contents, "undocumented-unsafe");
391-
let mut skip_tab = contains_ignore_directive(can_contain, &contents, "tab");
392-
let mut skip_line_length = contains_ignore_directive(can_contain, &contents, "linelength");
393-
let mut skip_file_length = contains_ignore_directive(can_contain, &contents, "filelength");
394-
let mut skip_end_whitespace =
395-
contains_ignore_directive(can_contain, &contents, "end-whitespace");
396-
let mut skip_trailing_newlines =
397-
contains_ignore_directive(can_contain, &contents, "trailing-newlines");
398-
let mut skip_leading_newlines =
399-
contains_ignore_directive(can_contain, &contents, "leading-newlines");
400-
let mut skip_copyright = contains_ignore_directive(can_contain, &contents, "copyright");
401-
let mut skip_dbg = contains_ignore_directive(can_contain, &contents, "dbg");
402-
let mut skip_odd_backticks =
403-
contains_ignore_directive(can_contain, &contents, "odd-backticks");
413+
let [
414+
mut skip_cr,
415+
mut skip_undocumented_unsafe,
416+
mut skip_tab,
417+
mut skip_line_length,
418+
mut skip_file_length,
419+
mut skip_end_whitespace,
420+
mut skip_trailing_newlines,
421+
mut skip_leading_newlines,
422+
mut skip_copyright,
423+
mut skip_dbg,
424+
mut skip_odd_backticks,
425+
] = contains_ignore_directives(can_contain, &contents, CONFIGURABLE_CHECKS);
404426
let mut leading_new_lines = false;
405427
let mut trailing_new_lines = 0;
406428
let mut lines = 0;
@@ -474,6 +496,22 @@ pub fn check(path: &Path, bad: &mut bool) {
474496
suppressible_tidy_err!(err, skip_cr, "CR character");
475497
}
476498
if !is_this_file {
499+
let directive_line_starts = ["// ", "# ", "/* ", "<!-- "];
500+
let possible_line_start =
501+
directive_line_starts.into_iter().any(|s| line.starts_with(s));
502+
let contains_potential_directive =
503+
possible_line_start && (line.contains("-tidy") || line.contains("tidy-"));
504+
let has_recognized_ignore_directive =
505+
contains_ignore_directives(can_contain, line, CONFIGURABLE_CHECKS)
506+
.into_iter()
507+
.any(|directive| matches!(directive, Directive::Ignore(_)));
508+
let has_alphabetical_directive = line.contains("tidy-alphabetical-start")
509+
|| line.contains("tidy-alphabetical-end");
510+
let has_recognized_directive =
511+
has_recognized_ignore_directive || has_alphabetical_directive;
512+
if contains_potential_directive && (!has_recognized_directive) {
513+
err("Unrecognized tidy directive")
514+
}
477515
// Allow using TODO in diagnostic suggestions by marking the
478516
// relevant line with `// ignore-tidy-todo`.
479517
if trimmed.contains("TODO") && !trimmed.contains("ignore-tidy-todo") {

tests/crashes/135341.rs

-5
This file was deleted.

tests/ui/regions/issue-26448-1.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
//@ run-pass
1+
//@ revisions: current next
2+
//@ [next] compile-flags: -Znext-solver
3+
//@ ignore-compare-mode-next-solver (explicit revisions)
4+
//@ check-pass
25

36
pub trait Foo<T> {
47
fn foo(self) -> T;

tests/ui/regions/issue-26448-2.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//@ revisions: current next
2+
//@ [next] compile-flags: -Znext-solver
3+
//@ ignore-compare-mode-next-solver (explicit revisions)
14
//@ check-pass
25

36
pub struct Bar<T> {
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
type A<T> = B;
2+
type B = _; //~ ERROR the placeholder `_` is not allowed within types on item signatures for type aliases
3+
4+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for type aliases
2+
--> $DIR/ice-hir-wf-issue-135341.rs:2:10
3+
|
4+
LL | type B = _;
5+
| ^ not allowed in type signatures
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0121`.

0 commit comments

Comments
 (0)