Skip to content

Commit 022c148

Browse files
committed
Fix tests from rebase
1 parent 1db284e commit 022c148

File tree

100 files changed

+585
-481
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+585
-481
lines changed

compiler/rustc_middle/src/ty/sty.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,9 @@ impl<'tcx> ExistentialProjection<'tcx> {
15131513
/// then this function would return a `exists T. T: Iterator` existential trait
15141514
/// reference.
15151515
pub fn trait_ref(&self, tcx: TyCtxt<'_>) -> ty::ExistentialTraitRef<'tcx> {
1516-
// FIXME(generic_associated_types): truncate substs to have the right length.
1516+
// FIXME(generic_associated_types): substs is the substs of the
1517+
// associated type, which should be truncated to get the correct substs
1518+
// for the trait.
15171519
let def_id = tcx.associated_item(self.item_def_id).container.id();
15181520
ty::ExistentialTraitRef { def_id, substs: self.substs }
15191521
}

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -125,29 +125,34 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
125125
self.infcx.commit_unconditionally(|_| {
126126
let tcx = self.tcx();
127127

128-
let bound_self_ty = self.infcx.shallow_resolve(obligation.self_ty());
129-
let (def_id, substs) = match *bound_self_ty.skip_binder().kind() {
128+
let trait_predicate = self.infcx.shallow_resolve(obligation.predicate);
129+
let placeholder_trait_predicate =
130+
self.infcx().replace_bound_vars_with_placeholders(&trait_predicate);
131+
let placeholder_self_ty = placeholder_trait_predicate.self_ty();
132+
let (def_id, substs) = match *placeholder_self_ty.kind() {
130133
ty::Projection(proj) => (proj.item_def_id, proj.substs),
131134
ty::Opaque(def_id, substs) => (def_id, substs),
132-
_ => bug!("projection candidate for unexpected type: {:?}", bound_self_ty),
135+
_ => bug!("projection candidate for unexpected type: {:?}", placeholder_self_ty),
133136
};
134137

135138
let candidate_predicate = tcx.item_bounds(def_id)[idx].subst(tcx, substs);
136139
let candidate = candidate_predicate
137140
.to_opt_poly_trait_ref()
138141
.expect("projection candidate is not a trait predicate");
139-
let Normalized { value: candidate, mut obligations } = normalize_with_depth(
142+
let mut obligations = Vec::new();
143+
let candidate = normalize_with_depth_to(
140144
self,
141145
obligation.param_env,
142146
obligation.cause.clone(),
143147
obligation.recursion_depth + 1,
144148
&candidate,
149+
&mut obligations,
145150
);
146151

147152
obligations.extend(
148153
self.infcx
149154
.at(&obligation.cause, obligation.param_env)
150-
.sup(obligation.predicate.to_poly_trait_ref(), candidate)
155+
.sup(placeholder_trait_predicate.trait_ref.to_poly_trait_ref(), candidate)
151156
.map(|InferOk { obligations, .. }| obligations)
152157
.unwrap_or_else(|_| {
153158
bug!(
@@ -158,7 +163,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
158163
}),
159164
);
160165

161-
if let ty::Projection(..) = bound_self_ty.skip_binder().kind() {
166+
if let ty::Projection(..) = placeholder_self_ty.kind() {
162167
for predicate in tcx.predicates_of(def_id).instantiate_own(tcx, substs).predicates {
163168
let normalized = normalize_with_depth_to(
164169
self,

compiler/rustc_trait_selection/src/traits/select/mod.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -1204,22 +1204,18 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12041204
if let ty::PredicateAtom::Trait(pred, _) = bound.skip_binders() {
12051205
let bound = ty::Binder::bind(pred.trait_ref);
12061206
if self.infcx.probe(|_| {
1207-
if let Ok(normalized_trait) = self.match_projection(
1207+
match self.match_projection(
12081208
obligation,
12091209
bound,
12101210
placeholder_trait_predicate.trait_ref,
12111211
) {
1212-
match normalized_trait {
1213-
None => true,
1214-
Some(normalized_trait)
1215-
if distinct_normalized_bounds.insert(normalized_trait) =>
1216-
{
1217-
true
1218-
}
1219-
_ => false,
1212+
Ok(None) => true,
1213+
Ok(Some(normalized_trait))
1214+
if distinct_normalized_bounds.insert(normalized_trait) =>
1215+
{
1216+
true
12201217
}
1221-
} else {
1222-
false
1218+
_ => false,
12231219
}
12241220
}) {
12251221
return Some(idx);

compiler/rustc_traits/src/chalk/lowering.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,10 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_solve::rust_ir::QuantifiedInlineBound<Ru
767767
| ty::PredicateAtom::ClosureKind(..)
768768
| ty::PredicateAtom::Subtype(..)
769769
| ty::PredicateAtom::ConstEvaluatable(..)
770-
| ty::PredicateAtom::ConstEquate(..) => bug!("unexpected predicate {}", &self),
770+
| ty::PredicateAtom::ConstEquate(..)
771+
| ty::PredicateAtom::TypeWellFormedFromEnv(..) => {
772+
bug!("unexpected predicate {}", &self)
773+
}
771774
}
772775
}
773776
}

compiler/rustc_typeck/src/check/check.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ use super::compare_method::{compare_const_impl, compare_impl_method, compare_ty_
44
use super::*;
55

66
use rustc_attr as attr;
7-
use rustc_errors::Applicability;
7+
use rustc_errors::{Applicability, ErrorReported};
88
use rustc_hir as hir;
99
use rustc_hir::def_id::{DefId, LocalDefId, LOCAL_CRATE};
1010
use rustc_hir::lang_items::LangItem;
1111
use rustc_hir::{ItemKind, Node};
1212
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
13-
use rustc_infer::infer::RegionVariableOrigin;
13+
use rustc_infer::infer::{RegionVariableOrigin, TyCtxtInferExt};
1414
use rustc_middle::ty::fold::TypeFoldable;
1515
use rustc_middle::ty::subst::GenericArgKind;
1616
use rustc_middle::ty::util::{Discr, IntTypeExt, Representability};
@@ -19,6 +19,8 @@ use rustc_session::config::EntryFnType;
1919
use rustc_span::symbol::sym;
2020
use rustc_span::{self, MultiSpan, Span};
2121
use rustc_target::spec::abi::Abi;
22+
use rustc_trait_selection::opaque_types::InferCtxtExt as _;
23+
use rustc_trait_selection::traits::error_reporting::InferCtxtExt as _;
2224
use rustc_trait_selection::traits::{self, ObligationCauseCode};
2325

2426
pub fn check_wf_new(tcx: TyCtxt<'_>) {
@@ -386,7 +388,9 @@ pub(super) fn check_opaque<'tcx>(
386388
origin: &hir::OpaqueTyOrigin,
387389
) {
388390
check_opaque_for_inheriting_lifetimes(tcx, def_id, span);
389-
tcx.ensure().type_of(def_id);
391+
if tcx.type_of(def_id).references_error() {
392+
return;
393+
}
390394
if check_opaque_for_cycles(tcx, def_id, substs, span, origin).is_err() {
391395
return;
392396
}

compiler/rustc_typeck/src/collect.rs

+1
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::HirId) {
704704
hir::ItemKind::OpaqueTy(..) => {
705705
tcx.ensure().generics_of(def_id);
706706
tcx.ensure().predicates_of(def_id);
707+
tcx.ensure().explicit_item_bounds(def_id);
707708
}
708709
hir::ItemKind::TyAlias(..)
709710
| hir::ItemKind::Static(..)

src/test/mir-opt/issue_62289.test.ElaborateDrops.before.mir

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn test() -> Option<Box<u32>> {
6969

7070
bb5: {
7171
StorageDead(_9); // scope 2 at $DIR/issue-62289.rs:9:19: 9:20
72-
_0 = <Option<Box<u32>> as Try>::from_error(move _8) -> [return: bb6, unwind: bb12]; // scope 2 at $DIR/issue-62289.rs:9:19: 9:20
72+
_0 = <Option<Box<u32>> as Try>::from_error(move _8) -> [return: bb6, unwind: bb12]; // scope 2 at $DIR/issue-62289.rs:9:15: 9:20
7373
// mir::Constant
7474
// + span: $DIR/issue-62289.rs:9:15: 9:20
7575
// + literal: Const { ty: fn(<std::option::Option<std::boxed::Box<u32>> as std::ops::Try>::Error) -> std::option::Option<std::boxed::Box<u32>> {<std::option::Option<std::boxed::Box<u32>> as std::ops::Try>::from_error}, val: Value(Scalar(<ZST>)) }

src/test/mir-opt/simplify_arm.id_try.SimplifyArmIdentity.diff

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
- // MIR for `id_try` before SimplifyArmIdentity
22
+ // MIR for `id_try` after SimplifyArmIdentity
3-
3+
44
fn id_try(_1: std::result::Result<u8, i32>) -> std::result::Result<u8, i32> {
55
debug r => _1; // in scope 0 at $DIR/simplify-arm.rs:23:11: 23:12
66
let mut _0: std::result::Result<u8, i32>; // return place in scope 0 at $DIR/simplify-arm.rs:23:34: 23:49
@@ -29,7 +29,7 @@
2929
scope 8 {
3030
- debug v => _8; // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
3131
+ debug v => ((_0 as Err).0: i32); // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
32-
let mut _12: i32; // in scope 8 at $DIR/simplify-arm.rs:24:14: 24:15
32+
let mut _12: i32; // in scope 8 at $DIR/simplify-arm.rs:24:13: 24:15
3333
}
3434
}
3535
}
@@ -42,7 +42,7 @@
4242
scope 6 {
4343
debug self => _4; // in scope 6 at $SRC_DIR/core/src/result.rs:LL:COL
4444
}
45-
45+
4646
bb0: {
4747
StorageLive(_2); // scope 0 at $DIR/simplify-arm.rs:24:9: 24:10
4848
StorageLive(_3); // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
@@ -53,7 +53,7 @@
5353
_5 = discriminant(_3); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
5454
switchInt(move _5) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
5555
}
56-
56+
5757
bb1: {
5858
- StorageLive(_10); // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
5959
- _10 = ((_3 as Ok).0: u8); // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
@@ -69,11 +69,11 @@
6969
StorageDead(_2); // scope 0 at $DIR/simplify-arm.rs:26:1: 26:2
7070
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2
7171
}
72-
72+
7373
bb2: {
7474
unreachable; // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
7575
}
76-
76+
7777
bb3: {
7878
- StorageLive(_6); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
7979
- _6 = ((_3 as Err).0: i32); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
@@ -94,9 +94,9 @@
9494
StorageDead(_2); // scope 0 at $DIR/simplify-arm.rs:26:1: 26:2
9595
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2
9696
}
97-
97+
9898
bb4: {
9999
return; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2
100100
}
101101
}
102-
102+

src/test/mir-opt/simplify_arm.id_try.SimplifyBranchSame.diff

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
- // MIR for `id_try` before SimplifyBranchSame
22
+ // MIR for `id_try` after SimplifyBranchSame
3-
3+
44
fn id_try(_1: std::result::Result<u8, i32>) -> std::result::Result<u8, i32> {
55
debug r => _1; // in scope 0 at $DIR/simplify-arm.rs:23:11: 23:12
66
let mut _0: std::result::Result<u8, i32>; // return place in scope 0 at $DIR/simplify-arm.rs:23:34: 23:49
@@ -25,7 +25,7 @@
2525
}
2626
scope 8 {
2727
debug v => ((_0 as Err).0: i32); // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
28-
let mut _12: i32; // in scope 8 at $DIR/simplify-arm.rs:24:14: 24:15
28+
let mut _12: i32; // in scope 8 at $DIR/simplify-arm.rs:24:13: 24:15
2929
}
3030
}
3131
}
@@ -37,7 +37,7 @@
3737
scope 6 {
3838
debug self => _4; // in scope 6 at $SRC_DIR/core/src/result.rs:LL:COL
3939
}
40-
40+
4141
bb0: {
4242
StorageLive(_2); // scope 0 at $DIR/simplify-arm.rs:24:9: 24:10
4343
StorageLive(_3); // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
@@ -49,28 +49,28 @@
4949
- switchInt(move _5) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
5050
+ goto -> bb1; // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
5151
}
52-
52+
5353
bb1: {
5454
_0 = move _3; // scope 1 at $DIR/simplify-arm.rs:25:5: 25:10
5555
StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:24:15: 24:16
5656
StorageDead(_2); // scope 0 at $DIR/simplify-arm.rs:26:1: 26:2
5757
- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2
5858
+ goto -> bb2; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2
5959
}
60-
60+
6161
bb2: {
6262
- unreachable; // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
6363
- }
64-
-
64+
-
6565
- bb3: {
6666
- _0 = move _3; // scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
6767
- StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:24:15: 24:16
6868
- StorageDead(_2); // scope 0 at $DIR/simplify-arm.rs:26:1: 26:2
6969
- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2
7070
- }
71-
-
71+
-
7272
- bb4: {
7373
return; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2
7474
}
7575
}
76-
76+

src/test/ui/associated-type-bounds/assoc-type-eq-with-dyn-atb-fail.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,24 @@
1212

1313
fn main() {}
1414

15-
trait Bar { type Assoc; }
15+
trait Bar {
16+
type Assoc;
17+
}
1618

1719
trait Thing {
1820
type Out;
1921
fn func() -> Self::Out;
2022
}
2123

2224
struct AssocNoCopy;
23-
impl Bar for AssocNoCopy { type Assoc = String; }
25+
impl Bar for AssocNoCopy {
26+
type Assoc = String;
27+
}
2428

2529
impl Thing for AssocNoCopy {
2630
type Out = Box<dyn Bar<Assoc: Copy>>;
2731
//~^ ERROR the trait bound `String: Copy` is not satisfied
32+
//~| ERROR the trait bound `String: Copy` is not satisfied
2833

2934
fn func() -> Self::Out {
3035
Box::new(AssocNoCopy)
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
error[E0277]: the trait bound `String: Copy` is not satisfied
2-
--> $DIR/assoc-type-eq-with-dyn-atb-fail.rs:26:28
2+
--> $DIR/assoc-type-eq-with-dyn-atb-fail.rs:30:28
33
|
44
LL | type Out = Box<dyn Bar<Assoc: Copy>>;
55
| ^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
6+
7+
error[E0277]: the trait bound `String: Copy` is not satisfied
8+
--> $DIR/assoc-type-eq-with-dyn-atb-fail.rs:30:28
69
|
7-
= note: the return type of a function must have a statically known size
10+
LL | type Out = Box<dyn Bar<Assoc: Copy>>;
11+
| ^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
812

9-
error: aborting due to previous error
13+
error: aborting due to 2 previous errors
1014

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

src/test/ui/associated-type-bounds/bad-bounds-on-assoc-in-trait.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ impl<'a, 'b> Lam<&'a &'b u8> for L2 {
2424

2525
trait Case1 {
2626
type C: Clone + Iterator<Item: Send + Iterator<Item: for<'a> Lam<&'a u8, App: Debug>> + Sync>;
27-
//~^ ERROR `<<Self as Case1>::C as std::iter::Iterator>::Item` is not an iterator
28-
//~| ERROR `<<Self as Case1>::C as std::iter::Iterator>::Item` cannot be sent between threads safely
29-
//~| ERROR `<<Self as Case1>::C as std::iter::Iterator>::Item` cannot be shared between threads safely
27+
//~^ ERROR `<<Self as Case1>::C as Iterator>::Item` is not an iterator
28+
//~| ERROR `<<Self as Case1>::C as Iterator>::Item` cannot be sent between threads safely
29+
//~| ERROR `<<Self as Case1>::C as Iterator>::Item` cannot be shared between threads safely
3030
}
3131

3232
pub struct S1;

0 commit comments

Comments
 (0)