diff --git a/RELEASES.md b/RELEASES.md index e453b8d6891af..b923f87abfd47 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -94,6 +94,7 @@ Misc Compatibility Notes ------------------- +- [Only support Android NDK 25 or newer](https://blog.rust-lang.org/2023/01/09/android-ndk-update-r25.html) - [Add `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` to future-incompat report](https://github.com/rust-lang/rust/pull/103418/) - [Only specify `--target` by default for `-Zgcc-ld=lld` on wasm](https://github.com/rust-lang/rust/pull/101792/) - [Bump `IMPLIED_BOUNDS_ENTAILMENT` to Deny + ReportNow](https://github.com/rust-lang/rust/pull/106465/) diff --git a/compiler/rustc_trait_selection/src/solve/canonicalize.rs b/compiler/rustc_trait_selection/src/solve/canonicalize.rs index 7ee4f33230630..2e5a8b7debc51 100644 --- a/compiler/rustc_trait_selection/src/solve/canonicalize.rs +++ b/compiler/rustc_trait_selection/src/solve/canonicalize.rs @@ -291,7 +291,7 @@ impl<'tcx> TypeFolder> for Canonicalizer<'_, 'tcx> { if nt != t { return self.fold_ty(nt); } else { - CanonicalVarKind::Ty(CanonicalTyVarKind::Int) + CanonicalVarKind::Ty(CanonicalTyVarKind::Float) } } ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => { diff --git a/compiler/rustc_trait_selection/src/solve/project_goals.rs b/compiler/rustc_trait_selection/src/solve/project_goals.rs index 48f7d3e3e4023..fd2aa10caa23a 100644 --- a/compiler/rustc_trait_selection/src/solve/project_goals.rs +++ b/compiler/rustc_trait_selection/src/solve/project_goals.rs @@ -344,10 +344,8 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> { LangItem::Sized, [ty::GenericArg::from(goal.predicate.self_ty())], )); - ecx.add_goal(goal.with(tcx, sized_predicate)); - ecx.eq(goal.param_env, goal.predicate.term, tcx.types.unit.into())?; - return ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes); + tcx.types.unit } ty::Adt(def, substs) if def.is_struct() => { @@ -483,9 +481,49 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> { ecx: &mut EvalCtxt<'_, 'tcx>, goal: Goal<'tcx, Self>, ) -> QueryResult<'tcx> { - let discriminant = goal.predicate.self_ty().discriminant_ty(ecx.tcx()); + let self_ty = goal.predicate.self_ty(); + let discriminant_ty = match *self_ty.kind() { + ty::Bool + | ty::Char + | ty::Int(..) + | ty::Uint(..) + | ty::Float(..) + | ty::Array(..) + | ty::RawPtr(..) + | ty::Ref(..) + | ty::FnDef(..) + | ty::FnPtr(..) + | ty::Closure(..) + | ty::Infer(ty::IntVar(..) | ty::FloatVar(..)) + | ty::Generator(..) + | ty::GeneratorWitness(..) + | ty::GeneratorWitnessMIR(..) + | ty::Never + | ty::Foreign(..) + | ty::Adt(_, _) + | ty::Str + | ty::Slice(_) + | ty::Dynamic(_, _, _) + | ty::Tuple(_) + | ty::Error(_) => self_ty.discriminant_ty(ecx.tcx()), + + // We do not call `Ty::discriminant_ty` on alias, param, or placeholder + // types, which return `::Discriminant` + // (or ICE in the case of placeholders). Projecting a type to itself + // is never really productive. + ty::Alias(_, _) | ty::Param(_) | ty::Placeholder(..) => { + return Err(NoSolution); + } + + ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) + | ty::Bound(..) => bug!( + "unexpected self ty `{:?}` when normalizing `::Discriminant`", + goal.predicate.self_ty() + ), + }; + ecx.probe(|ecx| { - ecx.eq(goal.param_env, goal.predicate.term, discriminant.into())?; + ecx.eq(goal.param_env, goal.predicate.term, discriminant_ty.into())?; ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) }) } diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index 48e907e402ccf..05dbcdc904e05 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -2394,7 +2394,8 @@ impl VecDeque { } /// Binary searches this `VecDeque` for a given element. - /// This behaves similarly to [`contains`] if this `VecDeque` is sorted. + /// If the `VecDeque` is not sorted, the returned result is unspecified and + /// meaningless. /// /// If the value is found then [`Result::Ok`] is returned, containing the /// index of the matching element. If there are multiple matches, then any @@ -2404,7 +2405,6 @@ impl VecDeque { /// /// See also [`binary_search_by`], [`binary_search_by_key`], and [`partition_point`]. /// - /// [`contains`]: VecDeque::contains /// [`binary_search_by`]: VecDeque::binary_search_by /// [`binary_search_by_key`]: VecDeque::binary_search_by_key /// [`partition_point`]: VecDeque::partition_point @@ -2450,12 +2450,13 @@ impl VecDeque { } /// Binary searches this `VecDeque` with a comparator function. - /// This behaves similarly to [`contains`] if this `VecDeque` is sorted. /// - /// The comparator function should implement an order consistent - /// with the sort order of the deque, returning an order code that - /// indicates whether its argument is `Less`, `Equal` or `Greater` - /// than the desired target. + /// The comparator function should return an order code that indicates + /// whether its argument is `Less`, `Equal` or `Greater` the desired + /// target. + /// If the `VecDeque` is not sorted or if the comparator function does not + /// implement an order consistent with the sort order of the underlying + /// `VecDeque`, the returned result is unspecified and meaningless. /// /// If the value is found then [`Result::Ok`] is returned, containing the /// index of the matching element. If there are multiple matches, then any @@ -2465,7 +2466,6 @@ impl VecDeque { /// /// See also [`binary_search`], [`binary_search_by_key`], and [`partition_point`]. /// - /// [`contains`]: VecDeque::contains /// [`binary_search`]: VecDeque::binary_search /// [`binary_search_by_key`]: VecDeque::binary_search_by_key /// [`partition_point`]: VecDeque::partition_point @@ -2505,10 +2505,11 @@ impl VecDeque { } /// Binary searches this `VecDeque` with a key extraction function. - /// This behaves similarly to [`contains`] if this `VecDeque` is sorted. /// /// Assumes that the deque is sorted by the key, for instance with /// [`make_contiguous().sort_by_key()`] using the same key extraction function. + /// If the deque is not sorted by the key, the returned result is + /// unspecified and meaningless. /// /// If the value is found then [`Result::Ok`] is returned, containing the /// index of the matching element. If there are multiple matches, then any @@ -2518,7 +2519,6 @@ impl VecDeque { /// /// See also [`binary_search`], [`binary_search_by`], and [`partition_point`]. /// - /// [`contains`]: VecDeque::contains /// [`make_contiguous().sort_by_key()`]: VecDeque::make_contiguous /// [`binary_search`]: VecDeque::binary_search /// [`binary_search_by`]: VecDeque::binary_search_by diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 57b6e0ce4bb23..f541808a61836 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -2387,7 +2387,8 @@ impl [T] { } /// Binary searches this slice for a given element. - /// This behaves similarly to [`contains`] if this slice is sorted. + /// If the slice is not sorted, the returned result is unspecified and + /// meaningless. /// /// If the value is found then [`Result::Ok`] is returned, containing the /// index of the matching element. If there are multiple matches, then any @@ -2399,7 +2400,6 @@ impl [T] { /// /// See also [`binary_search_by`], [`binary_search_by_key`], and [`partition_point`]. /// - /// [`contains`]: slice::contains /// [`binary_search_by`]: slice::binary_search_by /// [`binary_search_by_key`]: slice::binary_search_by_key /// [`partition_point`]: slice::partition_point @@ -2462,12 +2462,13 @@ impl [T] { } /// Binary searches this slice with a comparator function. - /// This behaves similarly to [`contains`] if this slice is sorted. /// - /// The comparator function should implement an order consistent - /// with the sort order of the underlying slice, returning an - /// order code that indicates whether its argument is `Less`, - /// `Equal` or `Greater` the desired target. + /// The comparator function should return an order code that indicates + /// whether its argument is `Less`, `Equal` or `Greater` the desired + /// target. + /// If the slice is not sorted or if the comparator function does not + /// implement an order consistent with the sort order of the underlying + /// slice, the returned result is unspecified and meaningless. /// /// If the value is found then [`Result::Ok`] is returned, containing the /// index of the matching element. If there are multiple matches, then any @@ -2479,7 +2480,6 @@ impl [T] { /// /// See also [`binary_search`], [`binary_search_by_key`], and [`partition_point`]. /// - /// [`contains`]: slice::contains /// [`binary_search`]: slice::binary_search /// [`binary_search_by_key`]: slice::binary_search_by_key /// [`partition_point`]: slice::partition_point @@ -2548,10 +2548,11 @@ impl [T] { } /// Binary searches this slice with a key extraction function. - /// This behaves similarly to [`contains`] if this slice is sorted. /// /// Assumes that the slice is sorted by the key, for instance with /// [`sort_by_key`] using the same key extraction function. + /// If the slice is not sorted by the key, the returned result is + /// unspecified and meaningless. /// /// If the value is found then [`Result::Ok`] is returned, containing the /// index of the matching element. If there are multiple matches, then any @@ -2563,7 +2564,6 @@ impl [T] { /// /// See also [`binary_search`], [`binary_search_by`], and [`partition_point`]. /// - /// [`contains`]: slice::contains /// [`sort_by_key`]: slice::sort_by_key /// [`binary_search`]: slice::binary_search /// [`binary_search_by`]: slice::binary_search_by diff --git a/src/bootstrap/llvm.rs b/src/bootstrap/llvm.rs index a22f0f04b2e01..cc2b45a9bdb5c 100644 --- a/src/bootstrap/llvm.rs +++ b/src/bootstrap/llvm.rs @@ -434,11 +434,6 @@ impl Step for Llvm { } } - // Workaround for ppc32 lld limitation - if target == "powerpc-unknown-freebsd" { - ldflags.exe.push(" -fuse-ld=bfd"); - } - // https://llvm.org/docs/HowToCrossCompileLLVM.html if target != builder.config.build { let LlvmResult { llvm_config, .. } = diff --git a/src/doc/rustc/src/platform-support/openharmony.md b/src/doc/rustc/src/platform-support/openharmony.md index aa4debfd45a33..a8dcc6443461e 100644 --- a/src/doc/rustc/src/platform-support/openharmony.md +++ b/src/doc/rustc/src/platform-support/openharmony.md @@ -1,4 +1,4 @@ -# `*-linux-ohos*` +# `*-unknown-linux-ohos` **Tier: 3** diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs index bce61c55c3d0a..7048b0e08bbfd 100644 --- a/src/tools/compiletest/src/main.rs +++ b/src/tools/compiletest/src/main.rs @@ -12,6 +12,7 @@ use build_helper::git::{get_git_modified_files, get_git_untracked_files}; use core::panic; use getopts::Options; use lazycell::LazyCell; +use std::collections::BTreeSet; use std::ffi::OsString; use std::fs; use std::io::{self, ErrorKind}; @@ -409,7 +410,9 @@ pub fn run_tests(config: Config) { let mut tests = Vec::new(); for c in &configs { - make_tests(c, &mut tests); + let mut found_paths = BTreeSet::new(); + make_tests(c, &mut tests, &mut found_paths); + check_overlapping_tests(&found_paths); } tests.sort_by(|a, b| a.desc.name.as_slice().cmp(&b.desc.name.as_slice())); @@ -535,7 +538,11 @@ pub fn test_opts(config: &Config) -> test::TestOpts { } } -pub fn make_tests(config: &Config, tests: &mut Vec) { +pub fn make_tests( + config: &Config, + tests: &mut Vec, + found_paths: &mut BTreeSet, +) { debug!("making tests from {:?}", config.src_base.display()); let inputs = common_inputs_stamp(config); let modified_tests = modified_tests(config, &config.src_base).unwrap_or_else(|err| { @@ -547,6 +554,7 @@ pub fn make_tests(config: &Config, tests: &mut Vec) { &PathBuf::new(), &inputs, tests, + found_paths, &modified_tests, ) .unwrap_or_else(|_| panic!("Could not read tests from {}", config.src_base.display())); @@ -617,6 +625,7 @@ fn collect_tests_from_dir( relative_dir_path: &Path, inputs: &Stamp, tests: &mut Vec, + found_paths: &mut BTreeSet, modified_tests: &Vec, ) -> io::Result<()> { // Ignore directories that contain a file named `compiletest-ignore-dir`. @@ -650,6 +659,8 @@ fn collect_tests_from_dir( let file_name = file.file_name(); if is_test(&file_name) && (!config.only_modified || modified_tests.contains(&file_path)) { debug!("found test file: {:?}", file_path.display()); + let rel_test_path = relative_dir_path.join(file_path.file_stem().unwrap()); + found_paths.insert(rel_test_path); let paths = TestPaths { file: file_path, relative_dir: relative_dir_path.to_path_buf() }; @@ -664,6 +675,7 @@ fn collect_tests_from_dir( &relative_file_path, inputs, tests, + found_paths, modified_tests, )?; } @@ -1079,3 +1091,24 @@ fn extract_lldb_version(full_version_line: &str) -> Option<(u32, bool)> { fn not_a_digit(c: char) -> bool { !c.is_digit(10) } + +fn check_overlapping_tests(found_paths: &BTreeSet) { + let mut collisions = Vec::new(); + for path in found_paths { + for ancestor in path.ancestors().skip(1) { + if found_paths.contains(ancestor) { + collisions.push((path, ancestor.clone())); + } + } + } + if !collisions.is_empty() { + let collisions: String = collisions + .into_iter() + .map(|(path, check_parent)| format!("test {path:?} clashes with {check_parent:?}\n")) + .collect(); + panic!( + "{collisions}\n\ + Tests cannot have overlapping names. Make sure they use unique prefixes." + ); + } +} diff --git a/tests/rustdoc/primitive.rs b/tests/rustdoc/primitive/primitive.rs similarity index 100% rename from tests/rustdoc/primitive.rs rename to tests/rustdoc/primitive/primitive.rs diff --git a/tests/ui/impl-trait/multiple-lifetimes.rs b/tests/ui/impl-trait/multiple-lifetimes/multiple-lifetimes.rs similarity index 100% rename from tests/ui/impl-trait/multiple-lifetimes.rs rename to tests/ui/impl-trait/multiple-lifetimes/multiple-lifetimes.rs diff --git a/tests/ui/modules_and_files_visibility/mod_file_disambig_aux/compiletest-ignore-dir b/tests/ui/modules_and_files_visibility/mod_file_disambig_aux/compiletest-ignore-dir new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/tests/ui/non_modrs_mods_and_inline_mods/x/y/z/compiletest-ignore-dir b/tests/ui/non_modrs_mods_and_inline_mods/x/y/z/compiletest-ignore-dir new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/tests/ui/traits/new-solver/float-canonical.rs b/tests/ui/traits/new-solver/float-canonical.rs new file mode 100644 index 0000000000000..b8748cd433b18 --- /dev/null +++ b/tests/ui/traits/new-solver/float-canonical.rs @@ -0,0 +1,8 @@ +// compile-flags: -Ztrait-solver=next +// check-pass + +fn foo(x: f64) { + let y = x + 1.0; +} + +fn main() {} diff --git a/tests/ui/traits/new-solver/param-discr-kind.rs b/tests/ui/traits/new-solver/param-discr-kind.rs new file mode 100644 index 0000000000000..e319ddea106bc --- /dev/null +++ b/tests/ui/traits/new-solver/param-discr-kind.rs @@ -0,0 +1,8 @@ +// compile-flags: -Ztrait-solver=next +// check-pass + +fn foo(x: T) { + std::mem::discriminant(&x); +} + +fn main() {} diff --git a/tests/ui/traits/new-solver/pointee.rs b/tests/ui/traits/new-solver/pointee.rs index fa6ee2e2daf64..93c0542ace4bf 100644 --- a/tests/ui/traits/new-solver/pointee.rs +++ b/tests/ui/traits/new-solver/pointee.rs @@ -7,17 +7,15 @@ use std::ptr::{DynMetadata, Pointee}; trait Trait {} struct MyDst(T); -fn works() { - let _: ::Metadata = (); - let _: <[T] as Pointee>::Metadata = 1_usize; - let _: ::Metadata = 1_usize; - let _: as Pointee>::Metadata = give::>>(); - let _: as Pointee>::Metadata = (); - let _: <((((([u8],),),),),) as Pointee>::Metadata = 1_usize; -} +fn meta_is + ?Sized, U>() {} -fn give() -> U { - loop {} +fn works() { + meta_is::(); + meta_is::<[T], usize>(); + meta_is::(); + meta_is::, DynMetadata>>(); + meta_is::, ()>(); + meta_is::<((((([u8],),),),),), usize>(); } fn main() {} diff --git a/tests/ui/traits/new-solver/projection-discr-kind.rs b/tests/ui/traits/new-solver/projection-discr-kind.rs new file mode 100644 index 0000000000000..20296b287b17e --- /dev/null +++ b/tests/ui/traits/new-solver/projection-discr-kind.rs @@ -0,0 +1,18 @@ +// compile-flags: -Ztrait-solver=next + +// Check that `::Discriminant` doesn't normalize +// to itself and cause overflow/ambiguity. + +trait Foo { + type Assoc; +} + +trait Bar {} +fn needs_bar(_: impl Bar) {} + +fn foo(x: T::Assoc) { + needs_bar(std::mem::discriminant(&x)); + //~^ ERROR the trait bound `Discriminant<::Assoc>: Bar` is not satisfied +} + +fn main() {} diff --git a/tests/ui/traits/new-solver/projection-discr-kind.stderr b/tests/ui/traits/new-solver/projection-discr-kind.stderr new file mode 100644 index 0000000000000..03e28f993e25d --- /dev/null +++ b/tests/ui/traits/new-solver/projection-discr-kind.stderr @@ -0,0 +1,17 @@ +error[E0277]: the trait bound `Discriminant<::Assoc>: Bar` is not satisfied + --> $DIR/projection-discr-kind.rs:14:15 + | +LL | needs_bar(std::mem::discriminant(&x)); + | --------- ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `Discriminant<::Assoc>` + | | + | required by a bound introduced by this call + | +note: required by a bound in `needs_bar` + --> $DIR/projection-discr-kind.rs:11:22 + | +LL | fn needs_bar(_: impl Bar) {} + | ^^^ required by this bound in `needs_bar` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/use/use-mod.rs b/tests/ui/use/use-mod/use-mod.rs similarity index 100% rename from tests/ui/use/use-mod.rs rename to tests/ui/use/use-mod/use-mod.rs diff --git a/tests/ui/use/use-mod.stderr b/tests/ui/use/use-mod/use-mod.stderr similarity index 100% rename from tests/ui/use/use-mod.stderr rename to tests/ui/use/use-mod/use-mod.stderr diff --git a/tests/ui/use.rs b/tests/ui/use/use.rs similarity index 100% rename from tests/ui/use.rs rename to tests/ui/use/use.rs