Skip to content

Commit

Permalink
Auto merge of #103009 - Dylan-DPC:rollup-9c2tng6, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 6 pull requests

Successful merges:

 - #102765 (Suggest `==` to the first expr which has `ExprKind::Assign` kind)
 - #102854 (openbsd: don't reallocate a guard page on the stack.)
 - #102904 (Print return-position `impl Trait` in trait verbosely if `-Zverbose`)
 - #102947 (Sort elaborated existential predicates in `object_ty_for_trait`)
 - #102956 (Use `full_res` instead of `expect_full_res`)
 - #102999 (Delay `is_intrinsic` query until after we've determined the callee is a function)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Oct 13, 2022
2 parents 4891d57 + 0f12b40 commit 6b3ede3
Show file tree
Hide file tree
Showing 13 changed files with 164 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -909,8 +909,6 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
return;
}

let is_intrinsic = tcx.is_intrinsic(callee);

if !tcx.is_const_fn_raw(callee) {
if !tcx.is_const_default_method(callee) {
// To get to here we must have already found a const impl for the
Expand Down Expand Up @@ -970,7 +968,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
// We do not use `const` modifiers for intrinsic "functions", as intrinsics are
// `extern` functions, and these have no way to get marked `const`. So instead we
// use `rustc_const_(un)stable` attributes to mean that the intrinsic is `const`
if self.ccx.is_const_stable_const_fn() || is_intrinsic {
if self.ccx.is_const_stable_const_fn() || tcx.is_intrinsic(callee) {
self.check_op(ops::FnCallUnstable(callee, None));
return;
}
Expand Down
12 changes: 12 additions & 0 deletions compiler/rustc_hir_analysis/src/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1051,8 +1051,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
rhs_expr,
) = lhs.kind
{
// if x == 1 && y == 2 { .. }
// +
let actual_lhs_ty = self.check_expr(&rhs_expr);
(Applicability::MaybeIncorrect, self.can_coerce(rhs_ty, actual_lhs_ty))
} else if let ExprKind::Binary(
Spanned { node: hir::BinOpKind::And | hir::BinOpKind::Or, .. },
lhs_expr,
_,
) = rhs.kind
{
// if x == 1 && y == 2 { .. }
// +
let actual_rhs_ty = self.check_expr(&lhs_expr);
(Applicability::MaybeIncorrect, self.can_coerce(actual_rhs_ty, lhs_ty))
} else {
(Applicability::MaybeIncorrect, false)
};
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,9 @@ pub trait PrettyPrinter<'tcx>:
p!(print_def_path(def_id, &[]));
}
ty::Projection(ref data) => {
if self.tcx().def_kind(data.item_def_id) == DefKind::ImplTraitPlaceholder {
if !(self.tcx().sess.verbose() || NO_QUERIES.with(|q| q.get()))
&& self.tcx().def_kind(data.item_def_id) == DefKind::ImplTraitPlaceholder
{
return self.pretty_print_opaque_impl_type(data.item_def_id, data.substs);
} else {
p!(print(data))
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1969,7 +1969,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
None
}
})
.map(|res| res.expect_full_res())
.and_then(|res| res.full_res())
.filter(|res| {
// Permit the types that unambiguously always
// result in the same type constructor being used
Expand Down
29 changes: 18 additions & 11 deletions compiler/rustc_trait_selection/src/traits/object_safety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,17 +581,24 @@ fn object_ty_for_trait<'tcx>(
});
debug!(?trait_predicate);

let elaborated_predicates = elaborate_trait_ref(tcx, trait_ref).filter_map(|obligation| {
debug!(?obligation);
let pred = obligation.predicate.to_opt_poly_projection_pred()?;
Some(pred.map_bound(|p| {
ty::ExistentialPredicate::Projection(ty::ExistentialProjection {
item_def_id: p.projection_ty.item_def_id,
substs: p.projection_ty.substs,
term: p.term,
})
}))
});
let mut elaborated_predicates: Vec<_> = elaborate_trait_ref(tcx, trait_ref)
.filter_map(|obligation| {
debug!(?obligation);
let pred = obligation.predicate.to_opt_poly_projection_pred()?;
Some(pred.map_bound(|p| {
ty::ExistentialPredicate::Projection(ty::ExistentialProjection {
item_def_id: p.projection_ty.item_def_id,
substs: p.projection_ty.substs,
term: p.term,
})
}))
})
.collect();
// NOTE: Since #37965, the existential predicates list has depended on the
// list of predicates to be sorted. This is mostly to enforce that the primary
// predicate comes first.
elaborated_predicates.sort_by(|a, b| a.skip_binder().stable_cmp(tcx, &b.skip_binder()));
elaborated_predicates.dedup();

let existential_predicates = tcx
.mk_poly_existential_predicates(iter::once(trait_predicate).chain(elaborated_predicates));
Expand Down
10 changes: 10 additions & 0 deletions library/std/src/sys/unix/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,16 @@ pub mod guard {
const GUARD_PAGES: usize = 1;
let guard = guardaddr..guardaddr + GUARD_PAGES * page_size;
Some(guard)
} else if cfg!(target_os = "openbsd") {
// OpenBSD stack already includes a guard page, and stack is
// immutable.
//
// We'll just note where we expect rlimit to start
// faulting, so our handler can report "stack overflow", and
// trust that the kernel's own stack guard will work.
let stackptr = get_stack_start_aligned()?;
let stackaddr = stackptr.addr();
Some(stackaddr - page_size..stackaddr)
} else {
// Reallocate the last page of the stack.
// This ensures SIGBUS will be raised on
Expand Down
25 changes: 25 additions & 0 deletions src/test/ui/object-safety/issue-102933.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// check-pass

use std::future::Future;

pub trait Service {
type Response;
type Future: Future<Output = Self::Response>;
}

pub trait A1: Service<Response = i32> {}

pub trait A2: Service<Future = Box<dyn Future<Output = i32>>> + A1 {
fn foo(&self) {}
}

pub trait B1: Service<Future = Box<dyn Future<Output = i32>>> {}

pub trait B2: Service<Response = i32> + B1 {
fn foo(&self) {}
}

fn main() {
let x: &dyn A2 = todo!();
let x: &dyn B2 = todo!();
}
7 changes: 7 additions & 0 deletions src/test/ui/resolve/issue-102946.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
impl Error for str::Utf8Error {
//~^ ERROR cannot find trait `Error` in this scope
//~| ERROR ambiguous associated type
fn description(&self) {}
}

fn main() {}
26 changes: 26 additions & 0 deletions src/test/ui/resolve/issue-102946.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
error[E0405]: cannot find trait `Error` in this scope
--> $DIR/issue-102946.rs:1:6
|
LL | impl Error for str::Utf8Error {
| ^^^^^ not found in this scope
|
help: consider importing this trait
|
LL | use std::error::Error;
|

error[E0223]: ambiguous associated type
--> $DIR/issue-102946.rs:1:16
|
LL | impl Error for str::Utf8Error {
| ^^^^^^^^^^^^^^
|
help: you are looking for the module in `std`, not the primitive type
|
LL | impl Error for std::str::Utf8Error {
| +++++

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0223, E0405.
For more information about an error, try `rustc --explain E0223`.
11 changes: 11 additions & 0 deletions src/test/ui/rfc-2632-const-trait-impl/issue-102985.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#![feature(const_trait_impl)]

struct Bug {
inner: [(); match || 1 {
n => n(),
//~^ ERROR the trait bound
//~| ERROR cannot call non-const fn `Bug::inner::{constant#0}::{closure#0}` in constants
}],
}

fn main() {}
26 changes: 26 additions & 0 deletions src/test/ui/rfc-2632-const-trait-impl/issue-102985.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
error[E0277]: the trait bound `[closure@$DIR/issue-102985.rs:4:23: 4:25]: ~const Fn<()>` is not satisfied
--> $DIR/issue-102985.rs:5:14
|
LL | n => n(),
| ^^^ expected an `Fn<()>` closure, found `[closure@$DIR/issue-102985.rs:4:23: 4:25]`
|
= help: the trait `~const Fn<()>` is not implemented for closure `[closure@$DIR/issue-102985.rs:4:23: 4:25]`
note: the trait `Fn<()>` is implemented for `[closure@$DIR/issue-102985.rs:4:23: 4:25]`, but that implementation is not `const`
--> $DIR/issue-102985.rs:5:14
|
LL | n => n(),
| ^^^
= note: wrap the `[closure@$DIR/issue-102985.rs:4:23: 4:25]` in a closure with no arguments: `|| { /* code */ }`

error[E0015]: cannot call non-const fn `Bug::inner::{constant#0}::{closure#0}` in constants
--> $DIR/issue-102985.rs:5:14
|
LL | n => n(),
| ^^^
|
= note: calls in constants are limited to constant functions, tuple structs and tuple variants

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0015, E0277.
For more information about an error, try `rustc --explain E0015`.
6 changes: 6 additions & 0 deletions src/test/ui/type/type-check/assignment-in-if.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,10 @@ fn main() {
//~| ERROR mismatched types
println!("{}", x);
}

if x = 1 && x == 1 {
//~^ ERROR mismatched types
//~| ERROR mismatched types
println!("{}", x);
}
}
19 changes: 18 additions & 1 deletion src/test/ui/type/type-check/assignment-in-if.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,23 @@ help: you might have meant to compare for equality
LL | if x == x && x == x && x == x {
| +

error: aborting due to 11 previous errors
error[E0308]: mismatched types
--> $DIR/assignment-in-if.rs:57:12
|
LL | if x = 1 && x == 1 {
| ^ expected `bool`, found integer

error[E0308]: mismatched types
--> $DIR/assignment-in-if.rs:57:8
|
LL | if x = 1 && x == 1 {
| ^^^^^^^^^^^^^^^ expected `bool`, found `()`
|
help: you might have meant to compare for equality
|
LL | if x == 1 && x == 1 {
| +

error: aborting due to 13 previous errors

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

0 comments on commit 6b3ede3

Please sign in to comment.