Skip to content

Commit 4ecd70d

Browse files
committed
Auto merge of #137611 - fmease:rollup-ln673ux, r=fmease
Rollup of 6 pull requests Successful merges: - #135480 (Don't require method impls for methods with `Self:Sized` bounds for impls for unsized types) - #137360 (Use `as_chunks` in `analyze_source_file_sse2`) - #137460 (downgrade bootstrap `cc`) - #137515 (Update `compiler-builtins` to 0.1.148) - #137522 (use stage 2 on cargo and clippy tests when possible) - #137597 (Revert accidental cargo submodule update) r? `@ghost` `@rustbot` modify labels: rollup
2 parents c51b9b6 + fb9ae4c commit 4ecd70d

23 files changed

+222
-43
lines changed

compiler/rustc_codegen_cranelift/patches/0029-stdlib-Disable-f16-and-f128-in-compiler-builtins.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ index 7165c3e48af..968552ad435 100644
1616

1717
[dependencies]
1818
core = { path = "../core", public = true }
19-
-compiler_builtins = { version = "=0.1.147", features = ['rustc-dep-of-std'] }
20-
+compiler_builtins = { version = "=0.1.147", features = ['rustc-dep-of-std', 'no-f16-f128'] }
19+
-compiler_builtins = { version = "=0.1.148", features = ['rustc-dep-of-std'] }
20+
+compiler_builtins = { version = "=0.1.148", features = ['rustc-dep-of-std', 'no-f16-f128'] }
2121

2222
[dev-dependencies]
2323
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }

compiler/rustc_hir_analysis/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,8 @@ hir_analysis_unused_generic_parameter_adt_no_phantom_data_help =
605605
hir_analysis_unused_generic_parameter_ty_alias_help =
606606
consider removing `{$param_name}` or referring to it in the body of the type alias
607607
608+
hir_analysis_useless_impl_item = this item cannot be used as its where bounds are not satisfied for the `Self` type
609+
608610
hir_analysis_value_of_associated_struct_already_specified =
609611
the value of the associated type `{$item_name}` in trait `{$def_path}` is already specified
610612
.label = re-bound here

compiler/rustc_hir_analysis/src/check/check.rs

+40-1
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,32 @@ fn check_impl_items_against_trait<'tcx>(
992992

993993
let trait_def = tcx.trait_def(trait_ref.def_id);
994994

995+
let infcx = tcx.infer_ctxt().ignoring_regions().build(TypingMode::non_body_analysis());
996+
997+
let ocx = ObligationCtxt::new_with_diagnostics(&infcx);
998+
let cause = ObligationCause::misc(tcx.def_span(impl_id), impl_id);
999+
let param_env = tcx.param_env(impl_id);
1000+
1001+
let self_is_guaranteed_unsized = match tcx
1002+
.struct_tail_raw(
1003+
trait_ref.self_ty(),
1004+
|ty| {
1005+
ocx.structurally_normalize_ty(&cause, param_env, ty).unwrap_or_else(|_| {
1006+
Ty::new_error_with_message(
1007+
tcx,
1008+
tcx.def_span(impl_id),
1009+
"struct tail should be computable",
1010+
)
1011+
})
1012+
},
1013+
|| (),
1014+
)
1015+
.kind()
1016+
{
1017+
ty::Dynamic(_, _, ty::DynKind::Dyn) | ty::Slice(_) | ty::Str => true,
1018+
_ => false,
1019+
};
1020+
9951021
for &impl_item in impl_item_refs {
9961022
let ty_impl_item = tcx.associated_item(impl_item);
9971023
let ty_trait_item = if let Some(trait_item_id) = ty_impl_item.trait_item_def_id {
@@ -1021,6 +1047,15 @@ fn check_impl_items_against_trait<'tcx>(
10211047
}
10221048
}
10231049

1050+
if self_is_guaranteed_unsized && tcx.generics_require_sized_self(ty_trait_item.def_id) {
1051+
tcx.emit_node_span_lint(
1052+
rustc_lint_defs::builtin::DEAD_CODE,
1053+
tcx.local_def_id_to_hir_id(ty_impl_item.def_id.expect_local()),
1054+
tcx.def_span(ty_impl_item.def_id),
1055+
errors::UselessImplItem,
1056+
)
1057+
}
1058+
10241059
check_specialization_validity(
10251060
tcx,
10261061
trait_def,
@@ -1044,7 +1079,11 @@ fn check_impl_items_against_trait<'tcx>(
10441079
.as_ref()
10451080
.is_some_and(|node_item| node_item.item.defaultness(tcx).has_value());
10461081

1047-
if !is_implemented && tcx.defaultness(impl_id).is_final() {
1082+
if !is_implemented
1083+
&& tcx.defaultness(impl_id).is_final()
1084+
// unsized types don't need to implement methods that have `Self: Sized` bounds.
1085+
&& !(self_is_guaranteed_unsized && tcx.generics_require_sized_self(trait_item_id))
1086+
{
10481087
missing_items.push(tcx.associated_item(trait_item_id));
10491088
}
10501089

compiler/rustc_hir_analysis/src/errors.rs

+4
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,10 @@ pub(crate) enum ImplNotMarkedDefault {
908908
},
909909
}
910910

911+
#[derive(LintDiagnostic)]
912+
#[diag(hir_analysis_useless_impl_item)]
913+
pub(crate) struct UselessImplItem;
914+
911915
#[derive(Diagnostic)]
912916
#[diag(hir_analysis_missing_trait_item, code = E0046)]
913917
pub(crate) struct MissingTraitItem {

compiler/rustc_span/src/analyze_source_file.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,18 @@ cfg_match! {
6868

6969
const CHUNK_SIZE: usize = 16;
7070

71-
let src_bytes = src.as_bytes();
72-
73-
let chunk_count = src.len() / CHUNK_SIZE;
71+
let (chunks, tail) = src.as_bytes().as_chunks::<CHUNK_SIZE>();
7472

7573
// This variable keeps track of where we should start decoding a
7674
// chunk. If a multi-byte character spans across chunk boundaries,
7775
// we need to skip that part in the next chunk because we already
7876
// handled it.
7977
let mut intra_chunk_offset = 0;
8078

81-
for chunk_index in 0..chunk_count {
82-
let ptr = src_bytes.as_ptr() as *const __m128i;
79+
for (chunk_index, chunk) in chunks.iter().enumerate() {
8380
// We don't know if the pointer is aligned to 16 bytes, so we
8481
// use `loadu`, which supports unaligned loading.
85-
let chunk = unsafe { _mm_loadu_si128(ptr.add(chunk_index)) };
82+
let chunk = unsafe { _mm_loadu_si128(chunk.as_ptr() as *const __m128i) };
8683

8784
// For character in the chunk, see if its byte value is < 0, which
8885
// indicates that it's part of a UTF-8 char.
@@ -123,7 +120,7 @@ cfg_match! {
123120
}
124121

125122
// There might still be a tail left to analyze
126-
let tail_start = chunk_count * CHUNK_SIZE + intra_chunk_offset;
123+
let tail_start = src.len() - tail.len() + intra_chunk_offset;
127124
if tail_start < src.len() {
128125
analyze_source_file_generic(
129126
&src[tail_start..],

compiler/rustc_span/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#![feature(round_char_boundary)]
3232
#![feature(rustc_attrs)]
3333
#![feature(rustdoc_internals)]
34+
#![feature(slice_as_chunks)]
3435
#![warn(unreachable_pub)]
3536
// tidy-alphabetical-end
3637

library/Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ dependencies = [
6161

6262
[[package]]
6363
name = "compiler_builtins"
64-
version = "0.1.147"
64+
version = "0.1.148"
6565
source = "registry+https://github.com/rust-lang/crates.io-index"
66-
checksum = "7170335a76fbcba350c3ea795c15df3b2c02934e35e502e82c4dd7837d4d0161"
66+
checksum = "26137996631d90d2727b905b480fdcf8c4479fdbce7afd7f8e3796d689b33cc2"
6767
dependencies = [
6868
"cc",
6969
"rustc-std-workspace-core",

library/alloc/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ edition = "2021"
1212

1313
[dependencies]
1414
core = { path = "../core", public = true }
15-
compiler_builtins = { version = "=0.1.147", features = ['rustc-dep-of-std'] }
15+
compiler_builtins = { version = "=0.1.148", features = ['rustc-dep-of-std'] }
1616

1717
[dev-dependencies]
1818
rand = { version = "0.9.0", default-features = false, features = ["alloc"] }

library/std/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] }
1818
panic_unwind = { path = "../panic_unwind", optional = true }
1919
panic_abort = { path = "../panic_abort" }
2020
core = { path = "../core", public = true }
21-
compiler_builtins = { version = "=0.1.147" }
21+
compiler_builtins = { version = "=0.1.148" }
2222
unwind = { path = "../unwind" }
2323
hashbrown = { version = "0.15", default-features = false, features = [
2424
'rustc-dep-of-std',

src/bootstrap/Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ dependencies = [
8888

8989
[[package]]
9090
name = "cc"
91-
version = "1.2.0"
91+
version = "1.1.22"
9292
source = "registry+https://github.com/rust-lang/crates.io-index"
93-
checksum = "1aeb932158bd710538c73702db6945cb68a8fb08c519e6e12706b94263b36db8"
93+
checksum = "9540e661f81799159abee814118cc139a2004b3a3aa3ea37724a1b66530b90e0"
9494
dependencies = [
9595
"shlex",
9696
]

src/bootstrap/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ test = false
3737
# Most of the time updating these dependencies requires modifications to the
3838
# bootstrap codebase(e.g., https://github.com/rust-lang/rust/issues/124565);
3939
# otherwise, some targets will fail. That's why these dependencies are explicitly pinned.
40-
cc = "=1.2.0"
40+
#
41+
# Do not upgrade this crate unless https://github.com/rust-lang/cc-rs/issues/1317 is fixed.
42+
cc = "=1.1.22"
4143
cmake = "=0.1.48"
4244

4345
build_helper = { path = "../build_helper" }

src/bootstrap/src/core/build_steps/test.rs

+24-6
Original file line numberDiff line numberDiff line change
@@ -293,17 +293,27 @@ impl Step for Cargo {
293293
}
294294

295295
fn make_run(run: RunConfig<'_>) {
296-
run.builder.ensure(Cargo { stage: run.builder.top_stage, host: run.target });
296+
// If stage is explicitly set or not lower than 2, keep it. Otherwise, make sure it's at least 2
297+
// as tests for this step don't work with a lower stage.
298+
let stage = if run.builder.config.is_explicit_stage() || run.builder.top_stage >= 2 {
299+
run.builder.top_stage
300+
} else {
301+
2
302+
};
303+
304+
run.builder.ensure(Cargo { stage, host: run.target });
297305
}
298306

299307
/// Runs `cargo test` for `cargo` packaged with Rust.
300308
fn run(self, builder: &Builder<'_>) {
301-
if self.stage < 2 {
302-
eprintln!("WARNING: cargo tests on stage {} may not behave well.", self.stage);
309+
let stage = self.stage;
310+
311+
if stage < 2 {
312+
eprintln!("WARNING: cargo tests on stage {stage} may not behave well.");
303313
eprintln!("HELP: consider using stage 2");
304314
}
305315

306-
let compiler = builder.compiler(self.stage, self.host);
316+
let compiler = builder.compiler(stage, self.host);
307317

308318
let cargo = builder.ensure(tool::Cargo { compiler, target: self.host });
309319
let compiler = cargo.build_compiler;
@@ -340,7 +350,7 @@ impl Step for Cargo {
340350
crates: vec!["cargo".into()],
341351
target: self.host.triple.to_string(),
342352
host: self.host.triple.to_string(),
343-
stage: self.stage,
353+
stage,
344354
},
345355
builder,
346356
);
@@ -739,7 +749,15 @@ impl Step for Clippy {
739749
}
740750

741751
fn make_run(run: RunConfig<'_>) {
742-
run.builder.ensure(Clippy { stage: run.builder.top_stage, host: run.target });
752+
// If stage is explicitly set or not lower than 2, keep it. Otherwise, make sure it's at least 2
753+
// as tests for this step don't work with a lower stage.
754+
let stage = if run.builder.config.is_explicit_stage() || run.builder.top_stage >= 2 {
755+
run.builder.top_stage
756+
} else {
757+
2
758+
};
759+
760+
run.builder.ensure(Clippy { stage, host: run.target });
743761
}
744762

745763
/// Runs `cargo test` for clippy.

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

+14
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ pub struct Config {
218218
pub stderr_is_tty: bool,
219219

220220
pub on_fail: Option<String>,
221+
pub explicit_stage_from_cli: bool,
222+
pub explicit_stage_from_config: bool,
221223
pub stage: u32,
222224
pub keep_stage: Vec<u32>,
223225
pub keep_stage_std: Vec<u32>,
@@ -2323,6 +2325,14 @@ impl Config {
23232325
config.compiletest_diff_tool = compiletest_diff_tool;
23242326

23252327
let download_rustc = config.download_rustc_commit.is_some();
2328+
config.explicit_stage_from_cli = flags.stage.is_some();
2329+
config.explicit_stage_from_config = test_stage.is_some()
2330+
|| build_stage.is_some()
2331+
|| doc_stage.is_some()
2332+
|| dist_stage.is_some()
2333+
|| install_stage.is_some()
2334+
|| check_stage.is_some()
2335+
|| bench_stage.is_some();
23262336
// See https://github.com/rust-lang/compiler-team/issues/326
23272337
config.stage = match config.cmd {
23282338
Subcommand::Check { .. } => flags.stage.or(check_stage).unwrap_or(0),
@@ -2392,6 +2402,10 @@ impl Config {
23922402
}
23932403
}
23942404

2405+
pub fn is_explicit_stage(&self) -> bool {
2406+
self.explicit_stage_from_cli || self.explicit_stage_from_config
2407+
}
2408+
23952409
/// Runs a command, printing out nice contextual information if it fails.
23962410
/// Exits if the command failed to execute at all, otherwise returns its
23972411
/// `status.success()`.

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

+61
Original file line numberDiff line numberDiff line change
@@ -454,3 +454,64 @@ fn check_rustc_if_unchanged_paths() {
454454
assert!(config.src.join(p).exists(), "{p} doesn't exist.");
455455
}
456456
}
457+
458+
#[test]
459+
fn test_explicit_stage() {
460+
let config = Config::parse_inner(
461+
Flags::parse(&["check".to_owned(), "--config=/does/not/exist".to_owned()]),
462+
|&_| {
463+
toml::from_str(
464+
r#"
465+
[build]
466+
test-stage = 1
467+
"#,
468+
)
469+
},
470+
);
471+
472+
assert!(!config.explicit_stage_from_cli);
473+
assert!(config.explicit_stage_from_config);
474+
assert!(config.is_explicit_stage());
475+
476+
let config = Config::parse_inner(
477+
Flags::parse(&[
478+
"check".to_owned(),
479+
"--stage=2".to_owned(),
480+
"--config=/does/not/exist".to_owned(),
481+
]),
482+
|&_| toml::from_str(""),
483+
);
484+
485+
assert!(config.explicit_stage_from_cli);
486+
assert!(!config.explicit_stage_from_config);
487+
assert!(config.is_explicit_stage());
488+
489+
let config = Config::parse_inner(
490+
Flags::parse(&[
491+
"check".to_owned(),
492+
"--stage=2".to_owned(),
493+
"--config=/does/not/exist".to_owned(),
494+
]),
495+
|&_| {
496+
toml::from_str(
497+
r#"
498+
[build]
499+
test-stage = 1
500+
"#,
501+
)
502+
},
503+
);
504+
505+
assert!(config.explicit_stage_from_cli);
506+
assert!(config.explicit_stage_from_config);
507+
assert!(config.is_explicit_stage());
508+
509+
let config = Config::parse_inner(
510+
Flags::parse(&["check".to_owned(), "--config=/does/not/exist".to_owned()]),
511+
|&_| toml::from_str(""),
512+
);
513+
514+
assert!(!config.explicit_stage_from_cli);
515+
assert!(!config.explicit_stage_from_config);
516+
assert!(!config.is_explicit_stage());
517+
}

src/tools/cargo

Submodule cargo updated 45 files

tests/ui/did_you_mean/recursion_limit_deref.stderr

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
error: reached the recursion limit finding the struct tail for `K`
2+
|
3+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "20"]`
4+
15
error: reached the recursion limit finding the struct tail for `Bottom`
26
|
37
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "20"]`
@@ -21,7 +25,7 @@ LL | let x: &Bottom = &t;
2125
= note: expected reference `&Bottom`
2226
found reference `&Top`
2327

24-
error: aborting due to 3 previous errors
28+
error: aborting due to 4 previous errors
2529

2630
Some errors have detailed explanations: E0055, E0308.
2731
For more information about an error, try `rustc --explain E0055`.

tests/ui/invalid/issue-114435-layout-type-err.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
//@ build-fail
1+
//@ check-fail
22
//@ compile-flags: --crate-type lib -Cdebuginfo=2
3-
//@ error-pattern: the type has an unknown layout
3+
//@ error-pattern: recursion limit
44

55
#![recursion_limit = "10"]
66
macro_rules! link {
@@ -28,7 +28,6 @@ impl Bottom {
2828
}
2929
}
3030

31-
3231
link!(A, B);
3332
link!(B, C);
3433
link!(C, D);
@@ -41,4 +40,4 @@ link!(I, J);
4140
link!(J, K);
4241
link!(K, Bottom);
4342

44-
fn main() { }
43+
fn main() {}

tests/ui/invalid/issue-114435-layout-type-err.stderr

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,5 @@ error: reached the recursion limit finding the struct tail for `Bottom`
22
|
33
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "20"]`
44

5-
error: the type has an unknown layout
6-
7-
error: aborting due to 2 previous errors
5+
error: aborting due to 1 previous error
86

0 commit comments

Comments
 (0)