Skip to content

Commit

Permalink
Auto merge of rust-lang#109769 - JohnTitor:rollup-7n2bnpg, r=JohnTitor
Browse files Browse the repository at this point in the history
Rollup of 7 pull requests

Successful merges:

 - rust-lang#106985 (Enhanced doucmentation of binary search methods for `slice` and `VecDeque` for unsorted instances)
 - rust-lang#109509 (compiletest: Don't allow tests with overlapping prefix names)
 - rust-lang#109719 (RELEASES: Add "Only support Android NDK 25 or newer" to 1.68.0)
 - rust-lang#109748 (Don't ICE on `DiscriminantKind` projection in new solver)
 - rust-lang#109749 (Canonicalize float var as float in new solver)
 - rust-lang#109761 (Drop binutils on powerpc-unknown-freebsd)
 - rust-lang#109766 (Fix title for openharmony.md)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Mar 30, 2023
2 parents 8a7ca93 + 6519ca4 commit 516a6d3
Show file tree
Hide file tree
Showing 20 changed files with 160 additions and 44 deletions.
1 change: 1 addition & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_trait_selection/src/solve/canonicalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> 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(_)) => {
Expand Down
48 changes: 43 additions & 5 deletions compiler/rustc_trait_selection/src/solve/project_goals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() => {
Expand Down Expand Up @@ -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 `<self_ty as DiscriminantKind>::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 `<T as DiscriminantKind>::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)
})
}
Expand Down
20 changes: 10 additions & 10 deletions library/alloc/src/collections/vec_deque/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2394,7 +2394,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
}

/// 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
Expand All @@ -2404,7 +2405,6 @@ impl<T, A: Allocator> VecDeque<T, A> {
///
/// 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
Expand Down Expand Up @@ -2450,12 +2450,13 @@ impl<T, A: Allocator> VecDeque<T, A> {
}

/// 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
Expand All @@ -2465,7 +2466,6 @@ impl<T, A: Allocator> VecDeque<T, A> {
///
/// 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
Expand Down Expand Up @@ -2505,10 +2505,11 @@ impl<T, A: Allocator> VecDeque<T, A> {
}

/// 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
Expand All @@ -2518,7 +2519,6 @@ impl<T, A: Allocator> VecDeque<T, A> {
///
/// 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
Expand Down
20 changes: 10 additions & 10 deletions library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2387,7 +2387,8 @@ impl<T> [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
Expand All @@ -2399,7 +2400,6 @@ impl<T> [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
Expand Down Expand Up @@ -2462,12 +2462,13 @@ impl<T> [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
Expand All @@ -2479,7 +2480,6 @@ impl<T> [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
Expand Down Expand Up @@ -2548,10 +2548,11 @@ impl<T> [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
Expand All @@ -2563,7 +2564,6 @@ impl<T> [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
Expand Down
5 changes: 0 additions & 5 deletions src/bootstrap/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, .. } =
Expand Down
2 changes: 1 addition & 1 deletion src/doc/rustc/src/platform-support/openharmony.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `*-linux-ohos*`
# `*-unknown-linux-ohos`

**Tier: 3**

Expand Down
37 changes: 35 additions & 2 deletions src/tools/compiletest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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()));
Expand Down Expand Up @@ -535,7 +538,11 @@ pub fn test_opts(config: &Config) -> test::TestOpts {
}
}

pub fn make_tests(config: &Config, tests: &mut Vec<test::TestDescAndFn>) {
pub fn make_tests(
config: &Config,
tests: &mut Vec<test::TestDescAndFn>,
found_paths: &mut BTreeSet<PathBuf>,
) {
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| {
Expand All @@ -547,6 +554,7 @@ pub fn make_tests(config: &Config, tests: &mut Vec<test::TestDescAndFn>) {
&PathBuf::new(),
&inputs,
tests,
found_paths,
&modified_tests,
)
.unwrap_or_else(|_| panic!("Could not read tests from {}", config.src_base.display()));
Expand Down Expand Up @@ -617,6 +625,7 @@ fn collect_tests_from_dir(
relative_dir_path: &Path,
inputs: &Stamp,
tests: &mut Vec<test::TestDescAndFn>,
found_paths: &mut BTreeSet<PathBuf>,
modified_tests: &Vec<PathBuf>,
) -> io::Result<()> {
// Ignore directories that contain a file named `compiletest-ignore-dir`.
Expand Down Expand Up @@ -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() };

Expand All @@ -664,6 +675,7 @@ fn collect_tests_from_dir(
&relative_file_path,
inputs,
tests,
found_paths,
modified_tests,
)?;
}
Expand Down Expand Up @@ -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<PathBuf>) {
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."
);
}
}
File renamed without changes.
File renamed without changes.
Empty file.
Empty file.
8 changes: 8 additions & 0 deletions tests/ui/traits/new-solver/float-canonical.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// compile-flags: -Ztrait-solver=next
// check-pass

fn foo(x: f64) {
let y = x + 1.0;
}

fn main() {}
8 changes: 8 additions & 0 deletions tests/ui/traits/new-solver/param-discr-kind.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// compile-flags: -Ztrait-solver=next
// check-pass

fn foo<T>(x: T) {
std::mem::discriminant(&x);
}

fn main() {}
18 changes: 8 additions & 10 deletions tests/ui/traits/new-solver/pointee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@ use std::ptr::{DynMetadata, Pointee};
trait Trait<U> {}
struct MyDst<T: ?Sized>(T);

fn works<T>() {
let _: <T as Pointee>::Metadata = ();
let _: <[T] as Pointee>::Metadata = 1_usize;
let _: <str as Pointee>::Metadata = 1_usize;
let _: <dyn Trait<T> as Pointee>::Metadata = give::<DynMetadata<dyn Trait<T>>>();
let _: <MyDst<T> as Pointee>::Metadata = ();
let _: <((((([u8],),),),),) as Pointee>::Metadata = 1_usize;
}
fn meta_is<T: Pointee<Metadata = U> + ?Sized, U>() {}

fn give<U>() -> U {
loop {}
fn works<T>() {
meta_is::<T, ()>();
meta_is::<[T], usize>();
meta_is::<str, usize>();
meta_is::<dyn Trait<T>, DynMetadata<dyn Trait<T>>>();
meta_is::<MyDst<T>, ()>();
meta_is::<((((([u8],),),),),), usize>();
}

fn main() {}
18 changes: 18 additions & 0 deletions tests/ui/traits/new-solver/projection-discr-kind.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// compile-flags: -Ztrait-solver=next

// Check that `<T::Assoc as DiscriminantKind>::Discriminant` doesn't normalize
// to itself and cause overflow/ambiguity.

trait Foo {
type Assoc;
}

trait Bar {}
fn needs_bar(_: impl Bar) {}

fn foo<T: Foo>(x: T::Assoc) {
needs_bar(std::mem::discriminant(&x));
//~^ ERROR the trait bound `Discriminant<<T as Foo>::Assoc>: Bar` is not satisfied
}

fn main() {}
Loading

0 comments on commit 516a6d3

Please sign in to comment.