Skip to content

Commit 516a6d3

Browse files
committed
Auto merge of #109769 - JohnTitor:rollup-7n2bnpg, r=JohnTitor
Rollup of 7 pull requests Successful merges: - #106985 (Enhanced doucmentation of binary search methods for `slice` and `VecDeque` for unsorted instances) - #109509 (compiletest: Don't allow tests with overlapping prefix names) - #109719 (RELEASES: Add "Only support Android NDK 25 or newer" to 1.68.0) - #109748 (Don't ICE on `DiscriminantKind` projection in new solver) - #109749 (Canonicalize float var as float in new solver) - #109761 (Drop binutils on powerpc-unknown-freebsd) - #109766 (Fix title for openharmony.md) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8a7ca93 + 6519ca4 commit 516a6d3

File tree

20 files changed

+160
-44
lines changed

20 files changed

+160
-44
lines changed

RELEASES.md

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ Misc
9494
Compatibility Notes
9595
-------------------
9696

97+
- [Only support Android NDK 25 or newer](https://blog.rust-lang.org/2023/01/09/android-ndk-update-r25.html)
9798
- [Add `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` to future-incompat report](https://github.com/rust-lang/rust/pull/103418/)
9899
- [Only specify `--target` by default for `-Zgcc-ld=lld` on wasm](https://github.com/rust-lang/rust/pull/101792/)
99100
- [Bump `IMPLIED_BOUNDS_ENTAILMENT` to Deny + ReportNow](https://github.com/rust-lang/rust/pull/106465/)

compiler/rustc_trait_selection/src/solve/canonicalize.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'_, 'tcx> {
291291
if nt != t {
292292
return self.fold_ty(nt);
293293
} else {
294-
CanonicalVarKind::Ty(CanonicalTyVarKind::Int)
294+
CanonicalVarKind::Ty(CanonicalTyVarKind::Float)
295295
}
296296
}
297297
ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {

compiler/rustc_trait_selection/src/solve/project_goals.rs

+43-5
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,8 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
344344
LangItem::Sized,
345345
[ty::GenericArg::from(goal.predicate.self_ty())],
346346
));
347-
348347
ecx.add_goal(goal.with(tcx, sized_predicate));
349-
ecx.eq(goal.param_env, goal.predicate.term, tcx.types.unit.into())?;
350-
return ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes);
348+
tcx.types.unit
351349
}
352350

353351
ty::Adt(def, substs) if def.is_struct() => {
@@ -483,9 +481,49 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
483481
ecx: &mut EvalCtxt<'_, 'tcx>,
484482
goal: Goal<'tcx, Self>,
485483
) -> QueryResult<'tcx> {
486-
let discriminant = goal.predicate.self_ty().discriminant_ty(ecx.tcx());
484+
let self_ty = goal.predicate.self_ty();
485+
let discriminant_ty = match *self_ty.kind() {
486+
ty::Bool
487+
| ty::Char
488+
| ty::Int(..)
489+
| ty::Uint(..)
490+
| ty::Float(..)
491+
| ty::Array(..)
492+
| ty::RawPtr(..)
493+
| ty::Ref(..)
494+
| ty::FnDef(..)
495+
| ty::FnPtr(..)
496+
| ty::Closure(..)
497+
| ty::Infer(ty::IntVar(..) | ty::FloatVar(..))
498+
| ty::Generator(..)
499+
| ty::GeneratorWitness(..)
500+
| ty::GeneratorWitnessMIR(..)
501+
| ty::Never
502+
| ty::Foreign(..)
503+
| ty::Adt(_, _)
504+
| ty::Str
505+
| ty::Slice(_)
506+
| ty::Dynamic(_, _, _)
507+
| ty::Tuple(_)
508+
| ty::Error(_) => self_ty.discriminant_ty(ecx.tcx()),
509+
510+
// We do not call `Ty::discriminant_ty` on alias, param, or placeholder
511+
// types, which return `<self_ty as DiscriminantKind>::Discriminant`
512+
// (or ICE in the case of placeholders). Projecting a type to itself
513+
// is never really productive.
514+
ty::Alias(_, _) | ty::Param(_) | ty::Placeholder(..) => {
515+
return Err(NoSolution);
516+
}
517+
518+
ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_))
519+
| ty::Bound(..) => bug!(
520+
"unexpected self ty `{:?}` when normalizing `<T as DiscriminantKind>::Discriminant`",
521+
goal.predicate.self_ty()
522+
),
523+
};
524+
487525
ecx.probe(|ecx| {
488-
ecx.eq(goal.param_env, goal.predicate.term, discriminant.into())?;
526+
ecx.eq(goal.param_env, goal.predicate.term, discriminant_ty.into())?;
489527
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
490528
})
491529
}

library/alloc/src/collections/vec_deque/mod.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -2394,7 +2394,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
23942394
}
23952395

23962396
/// Binary searches this `VecDeque` for a given element.
2397-
/// This behaves similarly to [`contains`] if this `VecDeque` is sorted.
2397+
/// If the `VecDeque` is not sorted, the returned result is unspecified and
2398+
/// meaningless.
23982399
///
23992400
/// If the value is found then [`Result::Ok`] is returned, containing the
24002401
/// index of the matching element. If there are multiple matches, then any
@@ -2404,7 +2405,6 @@ impl<T, A: Allocator> VecDeque<T, A> {
24042405
///
24052406
/// See also [`binary_search_by`], [`binary_search_by_key`], and [`partition_point`].
24062407
///
2407-
/// [`contains`]: VecDeque::contains
24082408
/// [`binary_search_by`]: VecDeque::binary_search_by
24092409
/// [`binary_search_by_key`]: VecDeque::binary_search_by_key
24102410
/// [`partition_point`]: VecDeque::partition_point
@@ -2450,12 +2450,13 @@ impl<T, A: Allocator> VecDeque<T, A> {
24502450
}
24512451

24522452
/// Binary searches this `VecDeque` with a comparator function.
2453-
/// This behaves similarly to [`contains`] if this `VecDeque` is sorted.
24542453
///
2455-
/// The comparator function should implement an order consistent
2456-
/// with the sort order of the deque, returning an order code that
2457-
/// indicates whether its argument is `Less`, `Equal` or `Greater`
2458-
/// than the desired target.
2454+
/// The comparator function should return an order code that indicates
2455+
/// whether its argument is `Less`, `Equal` or `Greater` the desired
2456+
/// target.
2457+
/// If the `VecDeque` is not sorted or if the comparator function does not
2458+
/// implement an order consistent with the sort order of the underlying
2459+
/// `VecDeque`, the returned result is unspecified and meaningless.
24592460
///
24602461
/// If the value is found then [`Result::Ok`] is returned, containing the
24612462
/// index of the matching element. If there are multiple matches, then any
@@ -2465,7 +2466,6 @@ impl<T, A: Allocator> VecDeque<T, A> {
24652466
///
24662467
/// See also [`binary_search`], [`binary_search_by_key`], and [`partition_point`].
24672468
///
2468-
/// [`contains`]: VecDeque::contains
24692469
/// [`binary_search`]: VecDeque::binary_search
24702470
/// [`binary_search_by_key`]: VecDeque::binary_search_by_key
24712471
/// [`partition_point`]: VecDeque::partition_point
@@ -2505,10 +2505,11 @@ impl<T, A: Allocator> VecDeque<T, A> {
25052505
}
25062506

25072507
/// Binary searches this `VecDeque` with a key extraction function.
2508-
/// This behaves similarly to [`contains`] if this `VecDeque` is sorted.
25092508
///
25102509
/// Assumes that the deque is sorted by the key, for instance with
25112510
/// [`make_contiguous().sort_by_key()`] using the same key extraction function.
2511+
/// If the deque is not sorted by the key, the returned result is
2512+
/// unspecified and meaningless.
25122513
///
25132514
/// If the value is found then [`Result::Ok`] is returned, containing the
25142515
/// index of the matching element. If there are multiple matches, then any
@@ -2518,7 +2519,6 @@ impl<T, A: Allocator> VecDeque<T, A> {
25182519
///
25192520
/// See also [`binary_search`], [`binary_search_by`], and [`partition_point`].
25202521
///
2521-
/// [`contains`]: VecDeque::contains
25222522
/// [`make_contiguous().sort_by_key()`]: VecDeque::make_contiguous
25232523
/// [`binary_search`]: VecDeque::binary_search
25242524
/// [`binary_search_by`]: VecDeque::binary_search_by

library/core/src/slice/mod.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -2387,7 +2387,8 @@ impl<T> [T] {
23872387
}
23882388

23892389
/// Binary searches this slice for a given element.
2390-
/// This behaves similarly to [`contains`] if this slice is sorted.
2390+
/// If the slice is not sorted, the returned result is unspecified and
2391+
/// meaningless.
23912392
///
23922393
/// If the value is found then [`Result::Ok`] is returned, containing the
23932394
/// index of the matching element. If there are multiple matches, then any
@@ -2399,7 +2400,6 @@ impl<T> [T] {
23992400
///
24002401
/// See also [`binary_search_by`], [`binary_search_by_key`], and [`partition_point`].
24012402
///
2402-
/// [`contains`]: slice::contains
24032403
/// [`binary_search_by`]: slice::binary_search_by
24042404
/// [`binary_search_by_key`]: slice::binary_search_by_key
24052405
/// [`partition_point`]: slice::partition_point
@@ -2462,12 +2462,13 @@ impl<T> [T] {
24622462
}
24632463

24642464
/// Binary searches this slice with a comparator function.
2465-
/// This behaves similarly to [`contains`] if this slice is sorted.
24662465
///
2467-
/// The comparator function should implement an order consistent
2468-
/// with the sort order of the underlying slice, returning an
2469-
/// order code that indicates whether its argument is `Less`,
2470-
/// `Equal` or `Greater` the desired target.
2466+
/// The comparator function should return an order code that indicates
2467+
/// whether its argument is `Less`, `Equal` or `Greater` the desired
2468+
/// target.
2469+
/// If the slice is not sorted or if the comparator function does not
2470+
/// implement an order consistent with the sort order of the underlying
2471+
/// slice, the returned result is unspecified and meaningless.
24712472
///
24722473
/// If the value is found then [`Result::Ok`] is returned, containing the
24732474
/// index of the matching element. If there are multiple matches, then any
@@ -2479,7 +2480,6 @@ impl<T> [T] {
24792480
///
24802481
/// See also [`binary_search`], [`binary_search_by_key`], and [`partition_point`].
24812482
///
2482-
/// [`contains`]: slice::contains
24832483
/// [`binary_search`]: slice::binary_search
24842484
/// [`binary_search_by_key`]: slice::binary_search_by_key
24852485
/// [`partition_point`]: slice::partition_point
@@ -2548,10 +2548,11 @@ impl<T> [T] {
25482548
}
25492549

25502550
/// Binary searches this slice with a key extraction function.
2551-
/// This behaves similarly to [`contains`] if this slice is sorted.
25522551
///
25532552
/// Assumes that the slice is sorted by the key, for instance with
25542553
/// [`sort_by_key`] using the same key extraction function.
2554+
/// If the slice is not sorted by the key, the returned result is
2555+
/// unspecified and meaningless.
25552556
///
25562557
/// If the value is found then [`Result::Ok`] is returned, containing the
25572558
/// index of the matching element. If there are multiple matches, then any
@@ -2563,7 +2564,6 @@ impl<T> [T] {
25632564
///
25642565
/// See also [`binary_search`], [`binary_search_by`], and [`partition_point`].
25652566
///
2566-
/// [`contains`]: slice::contains
25672567
/// [`sort_by_key`]: slice::sort_by_key
25682568
/// [`binary_search`]: slice::binary_search
25692569
/// [`binary_search_by`]: slice::binary_search_by

src/bootstrap/llvm.rs

-5
Original file line numberDiff line numberDiff line change
@@ -434,11 +434,6 @@ impl Step for Llvm {
434434
}
435435
}
436436

437-
// Workaround for ppc32 lld limitation
438-
if target == "powerpc-unknown-freebsd" {
439-
ldflags.exe.push(" -fuse-ld=bfd");
440-
}
441-
442437
// https://llvm.org/docs/HowToCrossCompileLLVM.html
443438
if target != builder.config.build {
444439
let LlvmResult { llvm_config, .. } =

src/doc/rustc/src/platform-support/openharmony.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# `*-linux-ohos*`
1+
# `*-unknown-linux-ohos`
22

33
**Tier: 3**
44

src/tools/compiletest/src/main.rs

+35-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use build_helper::git::{get_git_modified_files, get_git_untracked_files};
1212
use core::panic;
1313
use getopts::Options;
1414
use lazycell::LazyCell;
15+
use std::collections::BTreeSet;
1516
use std::ffi::OsString;
1617
use std::fs;
1718
use std::io::{self, ErrorKind};
@@ -409,7 +410,9 @@ pub fn run_tests(config: Config) {
409410

410411
let mut tests = Vec::new();
411412
for c in &configs {
412-
make_tests(c, &mut tests);
413+
let mut found_paths = BTreeSet::new();
414+
make_tests(c, &mut tests, &mut found_paths);
415+
check_overlapping_tests(&found_paths);
413416
}
414417

415418
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 {
535538
}
536539
}
537540

538-
pub fn make_tests(config: &Config, tests: &mut Vec<test::TestDescAndFn>) {
541+
pub fn make_tests(
542+
config: &Config,
543+
tests: &mut Vec<test::TestDescAndFn>,
544+
found_paths: &mut BTreeSet<PathBuf>,
545+
) {
539546
debug!("making tests from {:?}", config.src_base.display());
540547
let inputs = common_inputs_stamp(config);
541548
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<test::TestDescAndFn>) {
547554
&PathBuf::new(),
548555
&inputs,
549556
tests,
557+
found_paths,
550558
&modified_tests,
551559
)
552560
.unwrap_or_else(|_| panic!("Could not read tests from {}", config.src_base.display()));
@@ -617,6 +625,7 @@ fn collect_tests_from_dir(
617625
relative_dir_path: &Path,
618626
inputs: &Stamp,
619627
tests: &mut Vec<test::TestDescAndFn>,
628+
found_paths: &mut BTreeSet<PathBuf>,
620629
modified_tests: &Vec<PathBuf>,
621630
) -> io::Result<()> {
622631
// Ignore directories that contain a file named `compiletest-ignore-dir`.
@@ -650,6 +659,8 @@ fn collect_tests_from_dir(
650659
let file_name = file.file_name();
651660
if is_test(&file_name) && (!config.only_modified || modified_tests.contains(&file_path)) {
652661
debug!("found test file: {:?}", file_path.display());
662+
let rel_test_path = relative_dir_path.join(file_path.file_stem().unwrap());
663+
found_paths.insert(rel_test_path);
653664
let paths =
654665
TestPaths { file: file_path, relative_dir: relative_dir_path.to_path_buf() };
655666

@@ -664,6 +675,7 @@ fn collect_tests_from_dir(
664675
&relative_file_path,
665676
inputs,
666677
tests,
678+
found_paths,
667679
modified_tests,
668680
)?;
669681
}
@@ -1079,3 +1091,24 @@ fn extract_lldb_version(full_version_line: &str) -> Option<(u32, bool)> {
10791091
fn not_a_digit(c: char) -> bool {
10801092
!c.is_digit(10)
10811093
}
1094+
1095+
fn check_overlapping_tests(found_paths: &BTreeSet<PathBuf>) {
1096+
let mut collisions = Vec::new();
1097+
for path in found_paths {
1098+
for ancestor in path.ancestors().skip(1) {
1099+
if found_paths.contains(ancestor) {
1100+
collisions.push((path, ancestor.clone()));
1101+
}
1102+
}
1103+
}
1104+
if !collisions.is_empty() {
1105+
let collisions: String = collisions
1106+
.into_iter()
1107+
.map(|(path, check_parent)| format!("test {path:?} clashes with {check_parent:?}\n"))
1108+
.collect();
1109+
panic!(
1110+
"{collisions}\n\
1111+
Tests cannot have overlapping names. Make sure they use unique prefixes."
1112+
);
1113+
}
1114+
}
File renamed without changes.

tests/ui/modules_and_files_visibility/mod_file_disambig_aux/compiletest-ignore-dir

Whitespace-only changes.

tests/ui/non_modrs_mods_and_inline_mods/x/y/z/compiletest-ignore-dir

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// compile-flags: -Ztrait-solver=next
2+
// check-pass
3+
4+
fn foo(x: f64) {
5+
let y = x + 1.0;
6+
}
7+
8+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// compile-flags: -Ztrait-solver=next
2+
// check-pass
3+
4+
fn foo<T>(x: T) {
5+
std::mem::discriminant(&x);
6+
}
7+
8+
fn main() {}

tests/ui/traits/new-solver/pointee.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@ use std::ptr::{DynMetadata, Pointee};
77
trait Trait<U> {}
88
struct MyDst<T: ?Sized>(T);
99

10-
fn works<T>() {
11-
let _: <T as Pointee>::Metadata = ();
12-
let _: <[T] as Pointee>::Metadata = 1_usize;
13-
let _: <str as Pointee>::Metadata = 1_usize;
14-
let _: <dyn Trait<T> as Pointee>::Metadata = give::<DynMetadata<dyn Trait<T>>>();
15-
let _: <MyDst<T> as Pointee>::Metadata = ();
16-
let _: <((((([u8],),),),),) as Pointee>::Metadata = 1_usize;
17-
}
10+
fn meta_is<T: Pointee<Metadata = U> + ?Sized, U>() {}
1811

19-
fn give<U>() -> U {
20-
loop {}
12+
fn works<T>() {
13+
meta_is::<T, ()>();
14+
meta_is::<[T], usize>();
15+
meta_is::<str, usize>();
16+
meta_is::<dyn Trait<T>, DynMetadata<dyn Trait<T>>>();
17+
meta_is::<MyDst<T>, ()>();
18+
meta_is::<((((([u8],),),),),), usize>();
2119
}
2220

2321
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// compile-flags: -Ztrait-solver=next
2+
3+
// Check that `<T::Assoc as DiscriminantKind>::Discriminant` doesn't normalize
4+
// to itself and cause overflow/ambiguity.
5+
6+
trait Foo {
7+
type Assoc;
8+
}
9+
10+
trait Bar {}
11+
fn needs_bar(_: impl Bar) {}
12+
13+
fn foo<T: Foo>(x: T::Assoc) {
14+
needs_bar(std::mem::discriminant(&x));
15+
//~^ ERROR the trait bound `Discriminant<<T as Foo>::Assoc>: Bar` is not satisfied
16+
}
17+
18+
fn main() {}

0 commit comments

Comments
 (0)