Skip to content

Commit 2550243

Browse files
committed
auto merge of #17466 : nikomatsakis/rust/oibt, r=pcwalton
Moves the vast majority of builtin bound checking out of type contents and into the trait system. This is a preliminary step for a lot of follow-on work: - opt-in builtin types, obviously - generalized where clauses, because TypeContents has this notion that a type parameter has a single set of builtin kinds, but with where clauses it depends on context - generalized coherence, because this adds support for recursive trait selection Unfortunately I wasn't able to completely remove Type Contents from the front-end checking in this PR. It's still used by EUV to decide what gets moved and what doesn't. r? @pcwalton
2 parents 3be6a2f + 6473909 commit 2550243

Some content is hidden

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

47 files changed

+1194
-1112
lines changed

mk/crates.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ CRATES := $(TARGET_CRATES) $(HOST_CRATES)
5959
TOOLS := compiletest rustdoc rustc
6060

6161
DEPS_core :=
62+
DEPS_libc := core
6263
DEPS_rlibc := core
6364
DEPS_unicode := core
6465
DEPS_alloc := core libc native:jemalloc

src/doc/guide-unsafe.md

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ fn start(_argc: int, _argv: *const *const u8) -> int {
466466
// provided by libstd.
467467
#[lang = "stack_exhausted"] extern fn stack_exhausted() {}
468468
#[lang = "eh_personality"] extern fn eh_personality() {}
469-
#[lang = "sized"] trait Sized { }
469+
#[lang = "fail_fmt"] fn fail_fmt() -> ! { loop {} }
470470
# // fn main() {} tricked you, rustdoc!
471471
```
472472

@@ -489,32 +489,28 @@ pub extern fn main(argc: int, argv: *const *const u8) -> int {
489489
490490
#[lang = "stack_exhausted"] extern fn stack_exhausted() {}
491491
#[lang = "eh_personality"] extern fn eh_personality() {}
492-
#[lang = "sized"] trait Sized { }
492+
#[lang = "fail_fmt"] fn fail_fmt() -> ! { loop {} }
493493
# // fn main() {} tricked you, rustdoc!
494494
```
495495

496496

497497
The compiler currently makes a few assumptions about symbols which are available
498498
in the executable to call. Normally these functions are provided by the standard
499-
xlibrary, but without it you must define your own.
499+
library, but without it you must define your own.
500500

501-
The first of these two functions, `stack_exhausted`, is invoked whenever stack
501+
The first of these three functions, `stack_exhausted`, is invoked whenever stack
502502
overflow is detected. This function has a number of restrictions about how it
503503
can be called and what it must do, but if the stack limit register is not being
504504
maintained then a task always has an "infinite stack" and this function
505505
shouldn't get triggered.
506506

507-
The second of these two functions, `eh_personality`, is used by the failure
508-
mechanisms of the compiler. This is often mapped to GCC's personality function
509-
(see the [libstd implementation](std/rt/unwind/index.html) for more
510-
information), but crates which do not trigger failure can be assured that this
511-
function is never called.
512-
513-
The final item in the example is a trait called `Sized`. This a trait
514-
that represents data of a known static size: it is integral to the
515-
Rust type system, and so the compiler expects the standard library to
516-
provide it. Since you are not using the standard library, you have to
517-
provide it yourself.
507+
The second of these three functions, `eh_personality`, is used by the
508+
failure mechanisms of the compiler. This is often mapped to GCC's
509+
personality function (see the
510+
[libstd implementation](std/rt/unwind/index.html) for more
511+
information), but crates which do not trigger failure can be assured
512+
that this function is never called. The final function, `fail_fmt`, is
513+
also used by the failure mechanisms of the compiler.
518514

519515
## Using libcore
520516

@@ -694,7 +690,7 @@ fn main(argc: int, argv: *const *const u8) -> int {
694690
695691
#[lang = "stack_exhausted"] extern fn stack_exhausted() {}
696692
#[lang = "eh_personality"] extern fn eh_personality() {}
697-
#[lang = "sized"] trait Sized {}
693+
#[lang = "fail_fmt"] fn fail_fmt() -> ! { loop {} }
698694
```
699695

700696
Note the use of `abort`: the `exchange_malloc` lang item is assumed to

src/libcore/kinds.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ pub use self::Sync as Share;
2525

2626
/// Types able to be transferred across task boundaries.
2727
#[lang="send"]
28-
pub trait Send {
28+
pub trait Send for Sized? {
2929
// empty.
3030
}
3131

3232
/// Types with a constant size known at compile-time.
3333
#[lang="sized"]
34-
pub trait Sized {
34+
pub trait Sized for Sized? {
3535
// Empty.
3636
}
3737

3838
/// Types that can be copied by simply copying bits (i.e. `memcpy`).
3939
#[lang="copy"]
40-
pub trait Copy {
40+
pub trait Copy for Sized? {
4141
// Empty.
4242
}
4343

@@ -87,7 +87,7 @@ pub trait Copy {
8787
/// reference; not doing this is undefined behaviour (for example,
8888
/// `transmute`-ing from `&T` to `&mut T` is illegal).
8989
#[lang="sync"]
90-
pub trait Sync {
90+
pub trait Sync for Sized? {
9191
// Empty
9292
}
9393

src/liblibc/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@
7979
#![allow(missing_doc)]
8080
#![allow(non_snake_case)]
8181

82+
extern crate core;
83+
8284
#[cfg(test)] extern crate std;
8385
#[cfg(test)] extern crate test;
8486
#[cfg(test)] extern crate native;

src/librustc/diagnostics.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ register_diagnostics!(
5858
E0039,
5959
E0040,
6060
E0041,
61-
E0042,
62-
E0043,
6361
E0044,
6462
E0045,
6563
E0046,
@@ -92,7 +90,6 @@ register_diagnostics!(
9290
E0075,
9391
E0076,
9492
E0077,
95-
E0078,
9693
E0079,
9794
E0080,
9895
E0081,
@@ -130,7 +127,6 @@ register_diagnostics!(
130127
E0121,
131128
E0122,
132129
E0124,
133-
E0125,
134130
E0126,
135131
E0127,
136132
E0128,
@@ -147,12 +143,6 @@ register_diagnostics!(
147143
E0139,
148144
E0140,
149145
E0141,
150-
E0143,
151-
E0144,
152-
E0145,
153-
E0146,
154-
E0148,
155-
E0151,
156146
E0152,
157147
E0153,
158148
E0154,

src/librustc/driver/driver.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use lint;
1717
use llvm::{ContextRef, ModuleRef};
1818
use metadata::common::LinkMeta;
1919
use metadata::creader;
20-
use middle::{trans, stability, kind, ty, typeck, reachable};
20+
use middle::{trans, stability, ty, typeck, reachable};
2121
use middle::dependency_format;
2222
use middle;
2323
use plugin::load::Plugins;
@@ -462,8 +462,12 @@ pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
462462
time(time_passes, "rvalue checking", (), |_|
463463
middle::check_rvalues::check_crate(&ty_cx, krate));
464464

465-
time(time_passes, "kind checking", (), |_|
466-
kind::check_crate(&ty_cx));
465+
// Avoid overwhelming user with errors if type checking failed.
466+
// I'm not sure how helpful this is, to be honest, but it avoids a
467+
// lot of annoying errors in the compile-fail tests (basically,
468+
// lint warnings and so on -- kindck used to do this abort, but
469+
// kindck is gone now). -nmatsakis
470+
ty_cx.sess.abort_if_errors();
467471

468472
let reachable_map =
469473
time(time_passes, "reachability checking", (), |_|

src/librustc/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ pub mod middle {
9595
pub mod expr_use_visitor;
9696
pub mod graph;
9797
pub mod intrinsicck;
98-
pub mod kind;
9998
pub mod lang_items;
10099
pub mod liveness;
101100
pub mod mem_categorization;

0 commit comments

Comments
 (0)