Skip to content

Commit

Permalink
Auto merge of #137611 - fmease:rollup-ln673ux, r=fmease
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Feb 25, 2025
2 parents c51b9b6 + fb9ae4c commit 4ecd70d
Show file tree
Hide file tree
Showing 23 changed files with 222 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ index 7165c3e48af..968552ad435 100644

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

[dev-dependencies]
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_hir_analysis/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,8 @@ hir_analysis_unused_generic_parameter_adt_no_phantom_data_help =
hir_analysis_unused_generic_parameter_ty_alias_help =
consider removing `{$param_name}` or referring to it in the body of the type alias
hir_analysis_useless_impl_item = this item cannot be used as its where bounds are not satisfied for the `Self` type
hir_analysis_value_of_associated_struct_already_specified =
the value of the associated type `{$item_name}` in trait `{$def_path}` is already specified
.label = re-bound here
Expand Down
41 changes: 40 additions & 1 deletion compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,32 @@ fn check_impl_items_against_trait<'tcx>(

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

let infcx = tcx.infer_ctxt().ignoring_regions().build(TypingMode::non_body_analysis());

let ocx = ObligationCtxt::new_with_diagnostics(&infcx);
let cause = ObligationCause::misc(tcx.def_span(impl_id), impl_id);
let param_env = tcx.param_env(impl_id);

let self_is_guaranteed_unsized = match tcx
.struct_tail_raw(
trait_ref.self_ty(),
|ty| {
ocx.structurally_normalize_ty(&cause, param_env, ty).unwrap_or_else(|_| {
Ty::new_error_with_message(
tcx,
tcx.def_span(impl_id),
"struct tail should be computable",
)
})
},
|| (),
)
.kind()
{
ty::Dynamic(_, _, ty::DynKind::Dyn) | ty::Slice(_) | ty::Str => true,
_ => false,
};

for &impl_item in impl_item_refs {
let ty_impl_item = tcx.associated_item(impl_item);
let ty_trait_item = if let Some(trait_item_id) = ty_impl_item.trait_item_def_id {
Expand Down Expand Up @@ -1021,6 +1047,15 @@ fn check_impl_items_against_trait<'tcx>(
}
}

if self_is_guaranteed_unsized && tcx.generics_require_sized_self(ty_trait_item.def_id) {
tcx.emit_node_span_lint(
rustc_lint_defs::builtin::DEAD_CODE,
tcx.local_def_id_to_hir_id(ty_impl_item.def_id.expect_local()),
tcx.def_span(ty_impl_item.def_id),
errors::UselessImplItem,
)
}

check_specialization_validity(
tcx,
trait_def,
Expand All @@ -1044,7 +1079,11 @@ fn check_impl_items_against_trait<'tcx>(
.as_ref()
.is_some_and(|node_item| node_item.item.defaultness(tcx).has_value());

if !is_implemented && tcx.defaultness(impl_id).is_final() {
if !is_implemented
&& tcx.defaultness(impl_id).is_final()
// unsized types don't need to implement methods that have `Self: Sized` bounds.
&& !(self_is_guaranteed_unsized && tcx.generics_require_sized_self(trait_item_id))
{
missing_items.push(tcx.associated_item(trait_item_id));
}

Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_hir_analysis/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,10 @@ pub(crate) enum ImplNotMarkedDefault {
},
}

#[derive(LintDiagnostic)]
#[diag(hir_analysis_useless_impl_item)]
pub(crate) struct UselessImplItem;

#[derive(Diagnostic)]
#[diag(hir_analysis_missing_trait_item, code = E0046)]
pub(crate) struct MissingTraitItem {
Expand Down
11 changes: 4 additions & 7 deletions compiler/rustc_span/src/analyze_source_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,18 @@ cfg_match! {

const CHUNK_SIZE: usize = 16;

let src_bytes = src.as_bytes();

let chunk_count = src.len() / CHUNK_SIZE;
let (chunks, tail) = src.as_bytes().as_chunks::<CHUNK_SIZE>();

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

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

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

// There might still be a tail left to analyze
let tail_start = chunk_count * CHUNK_SIZE + intra_chunk_offset;
let tail_start = src.len() - tail.len() + intra_chunk_offset;
if tail_start < src.len() {
analyze_source_file_generic(
&src[tail_start..],
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#![feature(round_char_boundary)]
#![feature(rustc_attrs)]
#![feature(rustdoc_internals)]
#![feature(slice_as_chunks)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end

Expand Down
4 changes: 2 additions & 2 deletions library/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ dependencies = [

[[package]]
name = "compiler_builtins"
version = "0.1.147"
version = "0.1.148"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7170335a76fbcba350c3ea795c15df3b2c02934e35e502e82c4dd7837d4d0161"
checksum = "26137996631d90d2727b905b480fdcf8c4479fdbce7afd7f8e3796d689b33cc2"
dependencies = [
"cc",
"rustc-std-workspace-core",
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ edition = "2021"

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

[dev-dependencies]
rand = { version = "0.9.0", default-features = false, features = ["alloc"] }
Expand Down
2 changes: 1 addition & 1 deletion library/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] }
panic_unwind = { path = "../panic_unwind", optional = true }
panic_abort = { path = "../panic_abort" }
core = { path = "../core", public = true }
compiler_builtins = { version = "=0.1.147" }
compiler_builtins = { version = "=0.1.148" }
unwind = { path = "../unwind" }
hashbrown = { version = "0.15", default-features = false, features = [
'rustc-dep-of-std',
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ dependencies = [

[[package]]
name = "cc"
version = "1.2.0"
version = "1.1.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1aeb932158bd710538c73702db6945cb68a8fb08c519e6e12706b94263b36db8"
checksum = "9540e661f81799159abee814118cc139a2004b3a3aa3ea37724a1b66530b90e0"
dependencies = [
"shlex",
]
Expand Down
4 changes: 3 additions & 1 deletion src/bootstrap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ test = false
# Most of the time updating these dependencies requires modifications to the
# bootstrap codebase(e.g., https://github.com/rust-lang/rust/issues/124565);
# otherwise, some targets will fail. That's why these dependencies are explicitly pinned.
cc = "=1.2.0"
#
# Do not upgrade this crate unless https://github.com/rust-lang/cc-rs/issues/1317 is fixed.
cc = "=1.1.22"
cmake = "=0.1.48"

build_helper = { path = "../build_helper" }
Expand Down
30 changes: 24 additions & 6 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,17 +293,27 @@ impl Step for Cargo {
}

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

run.builder.ensure(Cargo { stage, host: run.target });
}

/// Runs `cargo test` for `cargo` packaged with Rust.
fn run(self, builder: &Builder<'_>) {
if self.stage < 2 {
eprintln!("WARNING: cargo tests on stage {} may not behave well.", self.stage);
let stage = self.stage;

if stage < 2 {
eprintln!("WARNING: cargo tests on stage {stage} may not behave well.");
eprintln!("HELP: consider using stage 2");
}

let compiler = builder.compiler(self.stage, self.host);
let compiler = builder.compiler(stage, self.host);

let cargo = builder.ensure(tool::Cargo { compiler, target: self.host });
let compiler = cargo.build_compiler;
Expand Down Expand Up @@ -340,7 +350,7 @@ impl Step for Cargo {
crates: vec!["cargo".into()],
target: self.host.triple.to_string(),
host: self.host.triple.to_string(),
stage: self.stage,
stage,
},
builder,
);
Expand Down Expand Up @@ -739,7 +749,15 @@ impl Step for Clippy {
}

fn make_run(run: RunConfig<'_>) {
run.builder.ensure(Clippy { stage: run.builder.top_stage, host: run.target });
// If stage is explicitly set or not lower than 2, keep it. Otherwise, make sure it's at least 2
// as tests for this step don't work with a lower stage.
let stage = if run.builder.config.is_explicit_stage() || run.builder.top_stage >= 2 {
run.builder.top_stage
} else {
2
};

run.builder.ensure(Clippy { stage, host: run.target });
}

/// Runs `cargo test` for clippy.
Expand Down
14 changes: 14 additions & 0 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ pub struct Config {
pub stderr_is_tty: bool,

pub on_fail: Option<String>,
pub explicit_stage_from_cli: bool,
pub explicit_stage_from_config: bool,
pub stage: u32,
pub keep_stage: Vec<u32>,
pub keep_stage_std: Vec<u32>,
Expand Down Expand Up @@ -2323,6 +2325,14 @@ impl Config {
config.compiletest_diff_tool = compiletest_diff_tool;

let download_rustc = config.download_rustc_commit.is_some();
config.explicit_stage_from_cli = flags.stage.is_some();
config.explicit_stage_from_config = test_stage.is_some()
|| build_stage.is_some()
|| doc_stage.is_some()
|| dist_stage.is_some()
|| install_stage.is_some()
|| check_stage.is_some()
|| bench_stage.is_some();
// See https://github.com/rust-lang/compiler-team/issues/326
config.stage = match config.cmd {
Subcommand::Check { .. } => flags.stage.or(check_stage).unwrap_or(0),
Expand Down Expand Up @@ -2392,6 +2402,10 @@ impl Config {
}
}

pub fn is_explicit_stage(&self) -> bool {
self.explicit_stage_from_cli || self.explicit_stage_from_config
}

/// Runs a command, printing out nice contextual information if it fails.
/// Exits if the command failed to execute at all, otherwise returns its
/// `status.success()`.
Expand Down
61 changes: 61 additions & 0 deletions src/bootstrap/src/core/config/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,3 +454,64 @@ fn check_rustc_if_unchanged_paths() {
assert!(config.src.join(p).exists(), "{p} doesn't exist.");
}
}

#[test]
fn test_explicit_stage() {
let config = Config::parse_inner(
Flags::parse(&["check".to_owned(), "--config=/does/not/exist".to_owned()]),
|&_| {
toml::from_str(
r#"
[build]
test-stage = 1
"#,
)
},
);

assert!(!config.explicit_stage_from_cli);
assert!(config.explicit_stage_from_config);
assert!(config.is_explicit_stage());

let config = Config::parse_inner(
Flags::parse(&[
"check".to_owned(),
"--stage=2".to_owned(),
"--config=/does/not/exist".to_owned(),
]),
|&_| toml::from_str(""),
);

assert!(config.explicit_stage_from_cli);
assert!(!config.explicit_stage_from_config);
assert!(config.is_explicit_stage());

let config = Config::parse_inner(
Flags::parse(&[
"check".to_owned(),
"--stage=2".to_owned(),
"--config=/does/not/exist".to_owned(),
]),
|&_| {
toml::from_str(
r#"
[build]
test-stage = 1
"#,
)
},
);

assert!(config.explicit_stage_from_cli);
assert!(config.explicit_stage_from_config);
assert!(config.is_explicit_stage());

let config = Config::parse_inner(
Flags::parse(&["check".to_owned(), "--config=/does/not/exist".to_owned()]),
|&_| toml::from_str(""),
);

assert!(!config.explicit_stage_from_cli);
assert!(!config.explicit_stage_from_config);
assert!(!config.is_explicit_stage());
}
2 changes: 1 addition & 1 deletion src/tools/cargo
Submodule cargo updated 45 files
+26 −0 .github/renovate.json5
+1 −1 .github/workflows/main.yml
+9 −9 Cargo.lock
+10 −10 Cargo.toml
+4 −1 ci/validate-version-bump.sh
+2 −2 crates/cargo-test-macro/Cargo.toml
+2 −2 crates/cargo-test-support/Cargo.toml
+0 −2 crates/cargo-test-support/src/paths.rs
+2 −2 crates/cargo-util-schemas/Cargo.toml
+2 −2 crates/cargo-util/Cargo.toml
+1 −1 crates/cargo-util/src/process_builder.rs
+6 −0 crates/cargo-util/src/registry.rs
+2 −2 crates/crates-io/Cargo.toml
+33 −14 crates/xtask-bump-check/src/xtask.rs
+2 −2 credential/cargo-credential-libsecret/Cargo.toml
+2 −2 credential/cargo-credential-macos-keychain/Cargo.toml
+2 −2 credential/cargo-credential-wincred/Cargo.toml
+1 −1 src/cargo/core/resolver/types.rs
+38 −29 src/cargo/ops/cargo_add/mod.rs
+2 −1 src/cargo/ops/cargo_package/mod.rs
+7 −7 src/cargo/ops/fix.rs
+6 −6 src/cargo/sources/registry/index/mod.rs
+118 −33 src/cargo/util/toml/embedded.rs
+1 −1 src/doc/man/cargo-publish.md
+6 −9 src/doc/man/generated_txt/cargo-publish.txt
+150 −5 src/doc/src/CHANGELOG.md
+6 −7 src/doc/src/commands/cargo-publish.md
+26 −0 src/doc/src/reference/unstable.md
+1 −1 src/doc/src/reference/workspaces.md
+5 −4 src/etc/man/cargo-publish.1
+51 −0 tests/testsuite/cargo_add/features_error_activated_over_limit/in/Cargo.toml
+0 −0 tests/testsuite/cargo_add/features_error_activated_over_limit/in/src/lib.rs
+35 −0 tests/testsuite/cargo_add/features_error_activated_over_limit/mod.rs
+51 −0 tests/testsuite/cargo_add/features_error_activated_over_limit/out/Cargo.toml
+40 −0 tests/testsuite/cargo_add/features_error_activated_over_limit/stderr.term.svg
+12 −0 tests/testsuite/cargo_add/features_error_deactivated_over_limit/in/Cargo.toml
+0 −0 tests/testsuite/cargo_add/features_error_deactivated_over_limit/in/src/lib.rs
+35 −0 tests/testsuite/cargo_add/features_error_deactivated_over_limit/mod.rs
+12 −0 tests/testsuite/cargo_add/features_error_deactivated_over_limit/out/Cargo.toml
+36 −0 tests/testsuite/cargo_add/features_error_deactivated_over_limit/stderr.term.svg
+2 −0 tests/testsuite/cargo_add/mod.rs
+1 −1 tests/testsuite/features2.rs
+2 −14 tests/testsuite/global_cache_tracker.rs
+62 −0 tests/testsuite/package.rs
+1 −1 tests/testsuite/workspaces.rs
6 changes: 5 additions & 1 deletion tests/ui/did_you_mean/recursion_limit_deref.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
error: reached the recursion limit finding the struct tail for `K`
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "20"]`

error: reached the recursion limit finding the struct tail for `Bottom`
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "20"]`
Expand All @@ -21,7 +25,7 @@ LL | let x: &Bottom = &t;
= note: expected reference `&Bottom`
found reference `&Top`

error: aborting due to 3 previous errors
error: aborting due to 4 previous errors

Some errors have detailed explanations: E0055, E0308.
For more information about an error, try `rustc --explain E0055`.
7 changes: 3 additions & 4 deletions tests/ui/invalid/issue-114435-layout-type-err.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ build-fail
//@ check-fail
//@ compile-flags: --crate-type lib -Cdebuginfo=2
//@ error-pattern: the type has an unknown layout
//@ error-pattern: recursion limit

#![recursion_limit = "10"]
macro_rules! link {
Expand Down Expand Up @@ -28,7 +28,6 @@ impl Bottom {
}
}


link!(A, B);
link!(B, C);
link!(C, D);
Expand All @@ -41,4 +40,4 @@ link!(I, J);
link!(J, K);
link!(K, Bottom);

fn main() { }
fn main() {}
4 changes: 1 addition & 3 deletions tests/ui/invalid/issue-114435-layout-type-err.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@ error: reached the recursion limit finding the struct tail for `Bottom`
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "20"]`

error: the type has an unknown layout

error: aborting due to 2 previous errors
error: aborting due to 1 previous error

Loading

0 comments on commit 4ecd70d

Please sign in to comment.