Skip to content

Commit e243158

Browse files
committed
rustc_typeck: make "global" WF requirements hard errors, in type aliases.
1 parent a333677 commit e243158

File tree

5 files changed

+24
-19
lines changed

5 files changed

+24
-19
lines changed

src/librustc_typeck/check/wfcheck.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,25 @@ pub fn check_item_well_formed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: Def
136136

137137
let def_id = fcx.tcx.hir.local_def_id(item.id);
138138
let ty = fcx.tcx.type_of(def_id);
139-
let item_ty = fcx.inh.normalize_associated_types_in(cause, fcx.param_env, &ty);
139+
let item_ty = fcx.inh.normalize_associated_types_in(
140+
cause.clone(),
141+
fcx.param_env,
142+
&ty,
143+
);
144+
145+
let wf_obligations = ty::wf::obligations(fcx,
146+
fcx.param_env,
147+
&cause,
148+
item_ty)
149+
.unwrap_or(vec![]);
140150

141-
fcx.register_wf_obligation(item_ty, hir_ty.span, code.clone());
151+
for mut obligation in wf_obligations {
152+
// Produce hard errors for monomorphic/"global" obligations.
153+
if obligation.predicate.is_global() {
154+
obligation.cause.code = ObligationCauseCode::MiscObligation;
155+
}
156+
fcx.register_predicate(obligation);
157+
}
142158

143159
check_where_clauses(tcx, fcx, item.span, def_id, None, code);
144160

src/test/ui/consts/const-eval/pub_const_err.stderr

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,14 @@ LL | pub type Foo = [i32; 0 - 1];
66
|
77
= note: #[deny(const_err)] on by default
88

9-
error: could not evaluate constant expression
9+
error[E0080]: could not evaluate constant expression
1010
--> $DIR/pub_const_err.rs:13:16
1111
|
1212
LL | pub type Foo = [i32; 0 - 1];
1313
| ^^^^^^-----^
1414
| |
1515
| attempt to subtract with overflow
16-
|
17-
= note: #[deny(type_alias_missing_bounds)] on by default
18-
= help: missing bounds in type aliases were previously allowed
19-
= help: this is a hard error in Rust 2018
2016

2117
error: aborting due to 2 previous errors
2218

19+
For more information about this error, try `rustc --explain E0080`.

src/test/ui/consts/const-eval/pub_const_err_bin.stderr

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,14 @@ LL | pub type Foo = [i32; 0 - 1];
66
|
77
= note: #[deny(const_err)] on by default
88

9-
error: could not evaluate constant expression
9+
error[E0080]: could not evaluate constant expression
1010
--> $DIR/pub_const_err_bin.rs:11:16
1111
|
1212
LL | pub type Foo = [i32; 0 - 1];
1313
| ^^^^^^-----^
1414
| |
1515
| attempt to subtract with overflow
16-
|
17-
= note: #[deny(type_alias_missing_bounds)] on by default
18-
= help: missing bounds in type aliases were previously allowed
19-
= help: this is a hard error in Rust 2018
2016

2117
error: aborting due to 2 previous errors
2218

19+
For more information about this error, try `rustc --explain E0080`.

src/test/ui/resolve/issue-3907-2.stderr

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ LL | type Foo = issue_3907::Foo+'static;
55
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `issue_3907::Foo` cannot be made into an object
66
|
77
= note: method `bar` has no receiver
8-
= help: missing bounds in type aliases were previously allowed
9-
= help: this is a hard error in Rust 2018
108

119
error[E0038]: the trait `issue_3907::Foo` cannot be made into an object
1210
--> $DIR/issue-3907-2.rs:21:1
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
error: the trait bound `NoClone: std::clone::Clone` is not satisfied
1+
error[E0277]: the trait bound `NoClone: std::clone::Clone` is not satisfied
22
--> $DIR/struct-path-alias-bounds.rs:16:10
33
|
44
LL | type A = S<NoClone>;
55
| ^^^^^^^^^^ the trait `std::clone::Clone` is not implemented for `NoClone`
6-
|
7-
= note: #[deny(type_alias_missing_bounds)] on by default
8-
= help: missing bounds in type aliases were previously allowed
9-
= help: this is a hard error in Rust 2018
106

117
error: aborting due to previous error
128

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

0 commit comments

Comments
 (0)