Skip to content

Commit

Permalink
Auto merge of #117887 - matthiaskrgr:rollup-rgur03f, r=matthiaskrgr
Browse files Browse the repository at this point in the history
Rollup of 4 pull requests

Successful merges:

 - #114224 (rustc_llvm: Link to libkstat on Solaris/SPARC)
 - #117695 (Reorder checks to make sure potential missing expect on Option/Result…)
 - #117870 (`fn args_ref_X` to `fn args_X`)
 - #117879 (tests: update check for inferred nneg on zext)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Nov 13, 2023
2 parents 85b8450 + 6d5d509 commit ba7c7a3
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 14 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

// Use `||` to give these suggestions a precedence
let suggested = self.suggest_missing_parentheses(err, expr)
|| self.suggest_missing_unwrap_expect(err, expr, expected, expr_ty)
|| self.suggest_remove_last_method_call(err, expr, expected)
|| self.suggest_associated_const(err, expr, expected)
|| self.suggest_deref_ref_or_into(err, expr, expected, expr_ty, expected_ty_expr)
Expand All @@ -49,8 +50,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|| self.suggest_into(err, expr, expr_ty, expected)
|| self.suggest_floating_point_literal(err, expr, expected)
|| self.suggest_null_ptr_for_literal_zero_given_to_ptr_arg(err, expr, expected)
|| self.suggest_coercing_result_via_try_operator(err, expr, expected, expr_ty)
|| self.suggest_missing_unwrap_expect(err, expr, expected, expr_ty);
|| self.suggest_coercing_result_via_try_operator(err, expr, expected, expr_ty);

if !suggested {
self.note_source_of_type_mismatch_constraint(
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_llvm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ fn main() {
cmd.arg("--system-libs");
}

// We need libkstat for getHostCPUName on SPARC builds.
// See also: https://github.com/llvm/llvm-project/issues/64186
if target.starts_with("sparcv9") && target.contains("solaris") {
println!("cargo:rustc-link-lib=kstat");
}

if (target.starts_with("arm") && !target.contains("freebsd"))
|| target.starts_with("mips-")
|| target.starts_with("mipsel-")
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_middle/src/ty/fast_reject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,14 @@ pub struct DeepRejectCtxt {
}

impl DeepRejectCtxt {
pub fn args_refs_may_unify<'tcx>(
pub fn args_may_unify<'tcx>(
self,
obligation_args: GenericArgsRef<'tcx>,
impl_args: GenericArgsRef<'tcx>,
) -> bool {
iter::zip(obligation_args, impl_args).all(|(obl, imp)| {
match (obl.unpack(), imp.unpack()) {
// We don't fast reject based on regions for now.
// We don't fast reject based on regions.
(GenericArgKind::Lifetime(_), GenericArgKind::Lifetime(_)) => true,
(GenericArgKind::Type(obl), GenericArgKind::Type(imp)) => {
self.types_may_unify(obl, imp)
Expand Down Expand Up @@ -231,7 +231,7 @@ impl DeepRejectCtxt {
| ty::Never
| ty::Tuple(..)
| ty::FnPtr(..)
| ty::Foreign(..) => {}
| ty::Foreign(..) => debug_assert!(impl_ty.is_known_rigid()),
ty::FnDef(..)
| ty::Closure(..)
| ty::Coroutine(..)
Expand Down Expand Up @@ -260,7 +260,7 @@ impl DeepRejectCtxt {
},
ty::Adt(obl_def, obl_args) => match k {
&ty::Adt(impl_def, impl_args) => {
obl_def == impl_def && self.args_refs_may_unify(obl_args, impl_args)
obl_def == impl_def && self.args_may_unify(obl_args, impl_args)
}
_ => false,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
let goal_trait_ref = goal.predicate.projection_ty.trait_ref(tcx);
let impl_trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::ForLookup };
if !drcx.args_refs_may_unify(goal_trait_ref.args, impl_trait_ref.skip_binder().args) {
if !drcx.args_may_unify(goal_trait_ref.args, impl_trait_ref.skip_binder().args) {
return Err(NoSolution);
}

Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_trait_selection/src/solve/trait_goals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {

let impl_trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::ForLookup };
if !drcx
.args_refs_may_unify(goal.predicate.trait_ref.args, impl_trait_ref.skip_binder().args)
{
if !drcx.args_may_unify(goal.predicate.trait_ref.args, impl_trait_ref.skip_binder().args) {
return Err(NoSolution);
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_trait_selection/src/traits/coherence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub fn overlapping_impls(
let impl1_ref = tcx.impl_trait_ref(impl1_def_id);
let impl2_ref = tcx.impl_trait_ref(impl2_def_id);
let may_overlap = match (impl1_ref, impl2_ref) {
(Some(a), Some(b)) => drcx.args_refs_may_unify(a.skip_binder().args, b.skip_binder().args),
(Some(a), Some(b)) => drcx.args_may_unify(a.skip_binder().args, b.skip_binder().args),
(None, None) => {
let self_ty1 = tcx.type_of(impl1_def_id).skip_binder();
let self_ty2 = tcx.type_of(impl2_def_id).skip_binder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// consider a "quick reject". This avoids creating more types
// and so forth that we need to.
let impl_trait_ref = self.tcx().impl_trait_ref(impl_def_id).unwrap();
if !drcx.args_refs_may_unify(obligation_args, impl_trait_ref.skip_binder().args) {
if !drcx.args_may_unify(obligation_args, impl_trait_ref.skip_binder().args) {
return;
}
if self.reject_fn_ptr_impls(
Expand Down
4 changes: 2 additions & 2 deletions tests/codegen/unchecked_shifts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub unsafe fn unchecked_shl_unsigned_smaller(a: u16, b: u32) -> u16 {
#[no_mangle]
pub unsafe fn unchecked_shl_unsigned_bigger(a: u64, b: u32) -> u64 {
// CHECK-NOT: assume
// CHECK: %[[EXT:.+]] = zext i32 %b to i64
// CHECK: %[[EXT:.+]] = zext{{( nneg)?}} i32 %b to i64
// CHECK: shl i64 %a, %[[EXT]]
a.unchecked_shl(b)
}
Expand Down Expand Up @@ -63,7 +63,7 @@ pub unsafe fn unchecked_shr_signed_smaller(a: i16, b: u32) -> i16 {
#[no_mangle]
pub unsafe fn unchecked_shr_signed_bigger(a: i64, b: u32) -> i64 {
// CHECK-NOT: assume
// CHECK: %[[EXT:.+]] = zext i32 %b to i64
// CHECK: %[[EXT:.+]] = zext{{( nneg)?}} i32 %b to i64
// CHECK: ashr i64 %a, %[[EXT]]
a.unchecked_shr(b)
}
4 changes: 4 additions & 0 deletions tests/ui/suggestions/issue-117669.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() {
let abs: i32 = 3i32.checked_abs();
//~^ ERROR mismatched types
}
18 changes: 18 additions & 0 deletions tests/ui/suggestions/issue-117669.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error[E0308]: mismatched types
--> $DIR/issue-117669.rs:2:20
|
LL | let abs: i32 = 3i32.checked_abs();
| --- ^^^^^^^^^^^^^^^^^^ expected `i32`, found `Option<i32>`
| |
| expected due to this
|
= note: expected type `i32`
found enum `Option<i32>`
help: consider using `Option::expect` to unwrap the `Option<i32>` value, panicking if the value is an `Option::None`
|
LL | let abs: i32 = 3i32.checked_abs().expect("REASON");
| +++++++++++++++++

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.

0 comments on commit ba7c7a3

Please sign in to comment.