Skip to content

Commit 6b3ede3

Browse files
committed
Auto merge of #103009 - Dylan-DPC:rollup-9c2tng6, r=Dylan-DPC
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
2 parents 4891d57 + 0f12b40 commit 6b3ede3

File tree

13 files changed

+164
-17
lines changed

13 files changed

+164
-17
lines changed

compiler/rustc_const_eval/src/transform/check_consts/check.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -909,8 +909,6 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
909909
return;
910910
}
911911

912-
let is_intrinsic = tcx.is_intrinsic(callee);
913-
914912
if !tcx.is_const_fn_raw(callee) {
915913
if !tcx.is_const_default_method(callee) {
916914
// To get to here we must have already found a const impl for the
@@ -970,7 +968,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
970968
// We do not use `const` modifiers for intrinsic "functions", as intrinsics are
971969
// `extern` functions, and these have no way to get marked `const`. So instead we
972970
// use `rustc_const_(un)stable` attributes to mean that the intrinsic is `const`
973-
if self.ccx.is_const_stable_const_fn() || is_intrinsic {
971+
if self.ccx.is_const_stable_const_fn() || tcx.is_intrinsic(callee) {
974972
self.check_op(ops::FnCallUnstable(callee, None));
975973
return;
976974
}

compiler/rustc_hir_analysis/src/check/expr.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1051,8 +1051,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10511051
rhs_expr,
10521052
) = lhs.kind
10531053
{
1054+
// if x == 1 && y == 2 { .. }
1055+
// +
10541056
let actual_lhs_ty = self.check_expr(&rhs_expr);
10551057
(Applicability::MaybeIncorrect, self.can_coerce(rhs_ty, actual_lhs_ty))
1058+
} else if let ExprKind::Binary(
1059+
Spanned { node: hir::BinOpKind::And | hir::BinOpKind::Or, .. },
1060+
lhs_expr,
1061+
_,
1062+
) = rhs.kind
1063+
{
1064+
// if x == 1 && y == 2 { .. }
1065+
// +
1066+
let actual_rhs_ty = self.check_expr(&lhs_expr);
1067+
(Applicability::MaybeIncorrect, self.can_coerce(actual_rhs_ty, lhs_ty))
10561068
} else {
10571069
(Applicability::MaybeIncorrect, false)
10581070
};

compiler/rustc_middle/src/ty/print/pretty.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,9 @@ pub trait PrettyPrinter<'tcx>:
637637
p!(print_def_path(def_id, &[]));
638638
}
639639
ty::Projection(ref data) => {
640-
if self.tcx().def_kind(data.item_def_id) == DefKind::ImplTraitPlaceholder {
640+
if !(self.tcx().sess.verbose() || NO_QUERIES.with(|q| q.get()))
641+
&& self.tcx().def_kind(data.item_def_id) == DefKind::ImplTraitPlaceholder
642+
{
641643
return self.pretty_print_opaque_impl_type(data.item_def_id, data.substs);
642644
} else {
643645
p!(print(data))

compiler/rustc_resolve/src/late.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1969,7 +1969,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
19691969
None
19701970
}
19711971
})
1972-
.map(|res| res.expect_full_res())
1972+
.and_then(|res| res.full_res())
19731973
.filter(|res| {
19741974
// Permit the types that unambiguously always
19751975
// result in the same type constructor being used

compiler/rustc_trait_selection/src/traits/object_safety.rs

+18-11
Original file line numberDiff line numberDiff line change
@@ -581,17 +581,24 @@ fn object_ty_for_trait<'tcx>(
581581
});
582582
debug!(?trait_predicate);
583583

584-
let elaborated_predicates = elaborate_trait_ref(tcx, trait_ref).filter_map(|obligation| {
585-
debug!(?obligation);
586-
let pred = obligation.predicate.to_opt_poly_projection_pred()?;
587-
Some(pred.map_bound(|p| {
588-
ty::ExistentialPredicate::Projection(ty::ExistentialProjection {
589-
item_def_id: p.projection_ty.item_def_id,
590-
substs: p.projection_ty.substs,
591-
term: p.term,
592-
})
593-
}))
594-
});
584+
let mut elaborated_predicates: Vec<_> = elaborate_trait_ref(tcx, trait_ref)
585+
.filter_map(|obligation| {
586+
debug!(?obligation);
587+
let pred = obligation.predicate.to_opt_poly_projection_pred()?;
588+
Some(pred.map_bound(|p| {
589+
ty::ExistentialPredicate::Projection(ty::ExistentialProjection {
590+
item_def_id: p.projection_ty.item_def_id,
591+
substs: p.projection_ty.substs,
592+
term: p.term,
593+
})
594+
}))
595+
})
596+
.collect();
597+
// NOTE: Since #37965, the existential predicates list has depended on the
598+
// list of predicates to be sorted. This is mostly to enforce that the primary
599+
// predicate comes first.
600+
elaborated_predicates.sort_by(|a, b| a.skip_binder().stable_cmp(tcx, &b.skip_binder()));
601+
elaborated_predicates.dedup();
595602

596603
let existential_predicates = tcx
597604
.mk_poly_existential_predicates(iter::once(trait_predicate).chain(elaborated_predicates));

library/std/src/sys/unix/thread.rs

+10
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,16 @@ pub mod guard {
766766
const GUARD_PAGES: usize = 1;
767767
let guard = guardaddr..guardaddr + GUARD_PAGES * page_size;
768768
Some(guard)
769+
} else if cfg!(target_os = "openbsd") {
770+
// OpenBSD stack already includes a guard page, and stack is
771+
// immutable.
772+
//
773+
// We'll just note where we expect rlimit to start
774+
// faulting, so our handler can report "stack overflow", and
775+
// trust that the kernel's own stack guard will work.
776+
let stackptr = get_stack_start_aligned()?;
777+
let stackaddr = stackptr.addr();
778+
Some(stackaddr - page_size..stackaddr)
769779
} else {
770780
// Reallocate the last page of the stack.
771781
// This ensures SIGBUS will be raised on
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// check-pass
2+
3+
use std::future::Future;
4+
5+
pub trait Service {
6+
type Response;
7+
type Future: Future<Output = Self::Response>;
8+
}
9+
10+
pub trait A1: Service<Response = i32> {}
11+
12+
pub trait A2: Service<Future = Box<dyn Future<Output = i32>>> + A1 {
13+
fn foo(&self) {}
14+
}
15+
16+
pub trait B1: Service<Future = Box<dyn Future<Output = i32>>> {}
17+
18+
pub trait B2: Service<Response = i32> + B1 {
19+
fn foo(&self) {}
20+
}
21+
22+
fn main() {
23+
let x: &dyn A2 = todo!();
24+
let x: &dyn B2 = todo!();
25+
}

src/test/ui/resolve/issue-102946.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
impl Error for str::Utf8Error {
2+
//~^ ERROR cannot find trait `Error` in this scope
3+
//~| ERROR ambiguous associated type
4+
fn description(&self) {}
5+
}
6+
7+
fn main() {}
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error[E0405]: cannot find trait `Error` in this scope
2+
--> $DIR/issue-102946.rs:1:6
3+
|
4+
LL | impl Error for str::Utf8Error {
5+
| ^^^^^ not found in this scope
6+
|
7+
help: consider importing this trait
8+
|
9+
LL | use std::error::Error;
10+
|
11+
12+
error[E0223]: ambiguous associated type
13+
--> $DIR/issue-102946.rs:1:16
14+
|
15+
LL | impl Error for str::Utf8Error {
16+
| ^^^^^^^^^^^^^^
17+
|
18+
help: you are looking for the module in `std`, not the primitive type
19+
|
20+
LL | impl Error for std::str::Utf8Error {
21+
| +++++
22+
23+
error: aborting due to 2 previous errors
24+
25+
Some errors have detailed explanations: E0223, E0405.
26+
For more information about an error, try `rustc --explain E0223`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![feature(const_trait_impl)]
2+
3+
struct Bug {
4+
inner: [(); match || 1 {
5+
n => n(),
6+
//~^ ERROR the trait bound
7+
//~| ERROR cannot call non-const fn `Bug::inner::{constant#0}::{closure#0}` in constants
8+
}],
9+
}
10+
11+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error[E0277]: the trait bound `[closure@$DIR/issue-102985.rs:4:23: 4:25]: ~const Fn<()>` is not satisfied
2+
--> $DIR/issue-102985.rs:5:14
3+
|
4+
LL | n => n(),
5+
| ^^^ expected an `Fn<()>` closure, found `[closure@$DIR/issue-102985.rs:4:23: 4:25]`
6+
|
7+
= help: the trait `~const Fn<()>` is not implemented for closure `[closure@$DIR/issue-102985.rs:4:23: 4:25]`
8+
note: the trait `Fn<()>` is implemented for `[closure@$DIR/issue-102985.rs:4:23: 4:25]`, but that implementation is not `const`
9+
--> $DIR/issue-102985.rs:5:14
10+
|
11+
LL | n => n(),
12+
| ^^^
13+
= note: wrap the `[closure@$DIR/issue-102985.rs:4:23: 4:25]` in a closure with no arguments: `|| { /* code */ }`
14+
15+
error[E0015]: cannot call non-const fn `Bug::inner::{constant#0}::{closure#0}` in constants
16+
--> $DIR/issue-102985.rs:5:14
17+
|
18+
LL | n => n(),
19+
| ^^^
20+
|
21+
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
22+
23+
error: aborting due to 2 previous errors
24+
25+
Some errors have detailed explanations: E0015, E0277.
26+
For more information about an error, try `rustc --explain E0015`.

src/test/ui/type/type-check/assignment-in-if.rs

+6
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,10 @@ fn main() {
5353
//~| ERROR mismatched types
5454
println!("{}", x);
5555
}
56+
57+
if x = 1 && x == 1 {
58+
//~^ ERROR mismatched types
59+
//~| ERROR mismatched types
60+
println!("{}", x);
61+
}
5662
}

src/test/ui/type/type-check/assignment-in-if.stderr

+18-1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,23 @@ help: you might have meant to compare for equality
104104
LL | if x == x && x == x && x == x {
105105
| +
106106

107-
error: aborting due to 11 previous errors
107+
error[E0308]: mismatched types
108+
--> $DIR/assignment-in-if.rs:57:12
109+
|
110+
LL | if x = 1 && x == 1 {
111+
| ^ expected `bool`, found integer
112+
113+
error[E0308]: mismatched types
114+
--> $DIR/assignment-in-if.rs:57:8
115+
|
116+
LL | if x = 1 && x == 1 {
117+
| ^^^^^^^^^^^^^^^ expected `bool`, found `()`
118+
|
119+
help: you might have meant to compare for equality
120+
|
121+
LL | if x == 1 && x == 1 {
122+
| +
123+
124+
error: aborting due to 13 previous errors
108125

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

0 commit comments

Comments
 (0)