Skip to content

Debug asserts aren't enabled by default in optimized build #17124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 65 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
4a096f6
Enabled by default the debug assert in non optimzed mode
Sep 9, 2014
42b6548
Debug asserts aren't enabled by default in optimized build
Sep 9, 2014
07b9f3b
Disabled debug asserts in optimized builds
Sep 9, 2014
aafb29e
Inlines contains in bitflags!
Sep 12, 2014
5090841
Add note about string indexing.
steveklabnik Aug 28, 2014
69402c4
Revamp doc index
steveklabnik Aug 28, 2014
251b2cf
Fixes type range issue during linting (#16684)
Aug 26, 2014
2606d73
Add ICE regression test for issue #16218.
nathantypanski Sep 7, 2014
c215328
Add regression test for issue #10766
nathantypanski Sep 7, 2014
f2673ca
Fix vector/array/slice terminology in manual.
steveklabnik Aug 28, 2014
955b68e
Relicense shootout-reverse-complement.rs to the shootout license.
TeXitoi Sep 7, 2014
d2e7174
Relicense shootout-nbody.rs to the shootout license
TeXitoi Sep 7, 2014
5c82bc5
Flip arguments to `std::iter::iterate`.
treeman Sep 7, 2014
8cd98ef
enable jemalloc debugging in unoptimized builds
thestinger Sep 7, 2014
8d3b00e
Fix casts in constant expressions
Sep 7, 2014
8ace7d6
Allow Rust to be built with LLVM trunk (3.6).
DanAlbert Sep 7, 2014
d036c5b
rustdoc: Don't strip #-lines if notrust
alexcrichton Sep 7, 2014
5bdcf63
libnative/io: generic retry() for Unix 64 bit read/write().
nodakai Sep 5, 2014
ced6575
Add ICE regression test with unboxed closures
nathantypanski Sep 8, 2014
af156fb
Relicense shootout-chameneos-redux.rs to the shootout license.
TeXitoi Sep 8, 2014
f25f8d1
rand: inform the optimiser that indexing is never out-of-bounds.
huonw Sep 8, 2014
5fe41fe
Update LLVM to fix a crash in the MergeFunc pass
dotdash Sep 8, 2014
5e3e2bb
librustc: Make sure lifetimes in `for` loop heads outlive the `for` loop
pcwalton Sep 8, 2014
a4ec18b
librustc: Feature gate subslice matching in non-tail positions.
pcwalton Sep 6, 2014
bba9b29
quote: Explicitly borrow the ExtCtxt
kmcallister Sep 6, 2014
ed14a27
Check traits for built-in bounds in impls
nrc Sep 5, 2014
6067613
guide: Remove reference to uninitialized bindings
steveklabnik Sep 8, 2014
713054a
librustc: Change the syntax of subslice matching to use postfix `..`
pcwalton Sep 6, 2014
389c1e4
Decoding json now defaults Option<_> to None.
treeman Sep 9, 2014
1054461
Handle `Sized?` in `type` items.
nrc Sep 9, 2014
8c206b1
Remove some test warnings.
treeman Sep 9, 2014
4d87e75
ignore uninitialized submodules when checking if ./configure should b…
spernsteiner Sep 9, 2014
46a664c
fixes for Box<[T]>
thestinger Sep 8, 2014
5994471
Decouple string and argument pieces
pczarn Aug 21, 2014
b04613e
Optimize for the most common cases of `format!`
pczarn Aug 25, 2014
d5a9278
coretest: Ensure that pointer formatting flags are cleaned up
pczarn Aug 25, 2014
02352c0
Add links to forums in README.md, including discuss.rust-lang.org
brson Aug 22, 2014
4081361
Test fixes from the rollup
alexcrichton Sep 9, 2014
817482f
Fix snapshot.py for win64
brson Sep 8, 2014
b42f118
Fix naming of windows installer
brson Sep 9, 2014
ab456e6
Implement tuple and tuple struct indexing
ftxqxd Aug 10, 2014
e7acf9c
Avoid ever constructing cyclic types in the first place, rather than …
nikomatsakis Sep 9, 2014
d582645
Be explicit with rustdoc.
steveklabnik Sep 8, 2014
28faebd
Add section about Str trait
steveklabnik Aug 28, 2014
abdd054
Prefer lualatex, xelatex, pdflatex, in that order. #12804
brson Sep 9, 2014
7648e4b
librustc: Obsolete the old external crate renaming syntax.
pcwalton Sep 6, 2014
fe7bccd
Don't ICE on macros with -Z show-span
sfackler Sep 10, 2014
a44560f
micro-optimize dynamic allocation alignment
thestinger Sep 8, 2014
eb93b03
implement sized deallocation
thestinger Sep 5, 2014
c674000
reintroduce manual link in doc index
steveklabnik Sep 10, 2014
cbeff11
Fix vector terminology in the manual.
steveklabnik Sep 10, 2014
f5d986f
Register snapshots
brson Sep 10, 2014
d11c9de
Remove dependency on GCC's LTO linker plugin, since Rust does its' ow…
vadimcn Sep 3, 2014
ebd4996
Append target-specific tools directory ($(RUST)/bin/rustlib/<triple>/…
vadimcn Sep 3, 2014
3dee14c
Update license notice.
vadimcn Sep 11, 2014
3d044d7
Package rustc's mingw dependencies into Windows installer.
vadimcn Sep 2, 2014
d44d4f6
Replace the Tutorial with the Guide.
steveklabnik Aug 21, 2014
f123698
only deprecate the guide rather than :fire: :fire: :fire:
steveklabnik Aug 21, 2014
9199396
Handle always-unsized structs
nrc Sep 9, 2014
9e17776
Fix bug in padding unicode, #17105.
ahmedcharles Sep 12, 2014
0f3fe34
New lint : unused_extern_crate. #10385
elinorbgr Sep 11, 2014
ff596a3
Removing unused extern crates.
elinorbgr Sep 12, 2014
4ef60a5
Remove largely unused context from Visitor.
eddyb Sep 12, 2014
482ba0e
Track the visited AST's lifetime throughout Visitor.
eddyb Sep 9, 2014
ef35dc1
Inline contains in bitflags!
Sep 12, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#
# * `VERBOSE=1` - Print all commands. Use this to see what's going on.
# * `RUSTFLAGS=...` - Add compiler flags to all `rustc` invocations
# * `JEMALLOC_FLAGS=...` - Pass flags to jemalloc's configure script
#
# * `TESTNAME=...` - Specify the name of tests to run
# * `CHECK_IGNORED=1` - Run normally-ignored tests
Expand Down
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ documentation.
## Quick Start

1. Download a [binary installer][installer] for your platform.
2. Read the [tutorial].
2. Read the [guide].
3. Enjoy!

> ***Note:*** Windows users can read the detailed
> [getting started][wiki-start] notes on the wiki.

[installer]: http://www.rust-lang.org/install.html
[tutorial]: http://doc.rust-lang.org/tutorial.html
[guide]: http://doc.rust-lang.org/guide.html
[wiki-start]: https://github.com/rust-lang/rust/wiki/Note-getting-started-developing-Rust
[win-wiki]: https://github.com/rust-lang/rust/wiki/Using-Rust-on-Windows

Expand Down Expand Up @@ -54,7 +54,7 @@ documentation.
When complete, `make install` will place several programs into
`/usr/local/bin`: `rustc`, the Rust compiler, and `rustdoc`, the
API-documentation tool.
3. Read the [tutorial].
3. Read the [guide].
4. Enjoy!

### Building on Windows
Expand All @@ -76,7 +76,7 @@ To easily build on windows we can use [MSYS2](http://sourceforge.net/projects/ms

[repo]: https://github.com/rust-lang/rust
[tarball]: https://static.rust-lang.org/dist/rust-nightly.tar.gz
[tutorial]: http://doc.rust-lang.org/tutorial.html
[guide]: http://doc.rust-lang.org/guide.html

## Notes

Expand All @@ -101,6 +101,18 @@ There is a lot more documentation in the [wiki].

[wiki]: https://github.com/rust-lang/rust/wiki

## Getting help and getting involved

The Rust community congregates in a few places:

* [StackOverflow] - Get help here.
* [/r/rust] - General discussion.
* [discuss.rust-lang.org] - For development of the Rust language itself.

[StackOverflow]: http://stackoverflow.com/questions/tagged/rust
[/r/rust]: http://reddit.com/r/rust
[discuss.rust-lang.org]: http://discuss.rust-lang.org/

## License

Rust is primarily distributed under the terms of both the MIT license
Expand Down
2 changes: 1 addition & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ then
| cut -d ' ' -f 2)

case $CFG_CLANG_VERSION in
(3.0svn | 3.0 | 3.1* | 3.2* | 3.3* | 3.4* | 3.5* )
(3.0svn | 3.0 | 3.1* | 3.2* | 3.3* | 3.4* | 3.5* | 3.6*)
step_msg "found ok version of CLANG: $CFG_CLANG_VERSION"
if [ -z "$CC" ]
then
Expand Down
4 changes: 2 additions & 2 deletions mk/dist.mk
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ distcheck-tar-src: dist-tar-src

ifdef CFG_ISCC

PKG_EXE = dist/$(PKG_NAME)-install.exe
PKG_EXE = dist/$(PKG_NAME)-$(CFG_BUILD).exe

%.iss: $(S)src/etc/pkg/%.iss
cp $< $@
Expand All @@ -123,7 +123,7 @@ PKG_EXE = dist/$(PKG_NAME)-install.exe
$(PKG_EXE): rust.iss modpath.iss upgrade.iss LICENSE.txt rust-logo.ico \
$(CSREQ3_T_$(CFG_BUILD)_H_$(CFG_BUILD)) \
dist-prepare-win
$(CFG_PYTHON) $(S)src/etc/copy-runtime-deps.py tmp/dist/win/bin
$(CFG_PYTHON) $(S)src/etc/make-win-dist.py tmp/dist/win $(CFG_BUILD)
@$(call E, ISCC: $@)
$(Q)"$(CFG_ISCC)" $<

Expand Down
37 changes: 25 additions & 12 deletions mk/docs.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
# except according to those terms.

######################################################################
# The various pieces of standalone documentation: guides, tutorial,
# manual etc.
# The various pieces of standalone documentation: guides, manual, etc
#
# The DOCS variable is their names (with no file extension).
#
Expand All @@ -32,7 +31,7 @@ DOCS := index intro tutorial guide guide-ffi guide-macros guide-lifetimes \
complement-lang-faq complement-design-faq complement-project-faq rust \
rustdoc guide-unsafe guide-strings

PDF_DOCS := tutorial rust
PDF_DOCS := guide rust

RUSTDOC_DEPS_rust := doc/full-toc.inc
RUSTDOC_FLAGS_rust := --html-in-header=doc/full-toc.inc
Expand Down Expand Up @@ -76,21 +75,22 @@ endif

# Check for the various external utilities for the EPUB/PDF docs:

ifeq ($(CFG_PDFLATEX),)
$(info cfg: no pdflatex found, deferring to xelatex)
ifeq ($(CFG_LUALATEX),)
$(info cfg: no lualatex found, deferring to xelatex)
ifeq ($(CFG_XELATEX),)
$(info cfg: no xelatex found, deferring to lualatex)
ifeq ($(CFG_LUALATEX),)
$(info cfg: no lualatex found, disabling LaTeX docs)
$(info cfg: no xelatex found, deferring to pdflatex)
ifeq ($(CFG_PDFLATEX),)
$(info cfg: no pdflatex found, disabling LaTeX docs)
NO_PDF_DOCS = 1
else
CFG_LATEX := $(CFG_LUALATEX)
CFG_LATEX := $(CFG_PDFLATEX)
endif
else
CFG_LATEX := $(CFG_XELATEX)
XELATEX = 1
endif
else
CFG_LATEX := $(CFG_PDFLATEX)
CFG_LATEX := $(CFG_LUALATEX)
endif


Expand Down Expand Up @@ -187,12 +187,25 @@ doc/$(1).tex: $$(D)/$(1).md doc/footer.tex doc/version.tex | doc/
ifneq ($(NO_PDF_DOCS),1)
ifeq ($$(SHOULD_BUILD_PDF_DOC_$(1)),1)
DOC_TARGETS += doc/$(1).pdf
ifneq ($(XELATEX),1)
doc/$(1).pdf: doc/$(1).tex
@$$(call E, latex compiler: $$@)
$$(Q)$$(CFG_LATEX) \
-interaction=batchmode \
-output-directory=doc \
$$<
else
# The version of xelatex on the snap bots seemingly ingores -output-directory
# So we'll output to . and move to the doc directory manually.
# This will leave some intermediate files in the build directory.
doc/$(1).pdf: doc/$(1).tex
@$$(call E, latex compiler: $$@)
$$(Q)$$(CFG_LATEX) \
-interaction=batchmode \
-output-directory=. \
$$<
$$(Q)mv ./$(1).pdf $$@
endif # XELATEX
endif # SHOULD_BUILD_PDF_DOCS_$(1)
endif # NO_PDF_DOCS

Expand All @@ -212,7 +225,7 @@ $(foreach docname,$(DOCS),$(eval $(call DEF_DOC,$(docname))))
#
# As such, I've attempted to get it working as much as possible (and
# switching from pandoc to rustdoc), but preserving the old behaviour
# (e.g. only running on the tutorial)
# (e.g. only running on the guide)
.PHONY: l10n-mds
l10n-mds: $(D)/po4a.conf \
$(foreach lang,$(L10N_LANG),$(D)/po/$(lang)/*.md.po)
Expand All @@ -230,7 +243,7 @@ doc/l10n/$(1)/$(2).html: l10n-mds $$(HTML_DEPS) $$(RUSTDOC_DEPS_$(2))
$$(RUSTDOC) $$(RUSTDOC_HTML_OPTS) $$(RUSTDOC_FLAGS_$(1)) doc/l10n/$(1)/$(2).md
endef

$(foreach lang,$(L10N_LANGS),$(eval $(call DEF_L10N_DOC,$(lang),tutorial)))
$(foreach lang,$(L10N_LANGS),$(eval $(call DEF_L10N_DOC,$(lang),guide)))


######################################################################
Expand Down
4 changes: 4 additions & 0 deletions mk/main.mk
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,19 @@ endif
CFG_RUSTC_FLAGS := $(RUSTFLAGS)
CFG_GCCISH_CFLAGS :=
CFG_GCCISH_LINK_FLAGS :=
CFG_JEMALLOC_FLAGS :=

ifdef CFG_DISABLE_OPTIMIZE
$(info cfg: disabling rustc optimization (CFG_DISABLE_OPTIMIZE))
CFG_RUSTC_FLAGS +=
CFG_JEMALLOC_FLAGS += --enable-debug
else
# The rtopt cfg turns off runtime sanity checks
CFG_RUSTC_FLAGS += -O --cfg rtopt
endif

CFG_JEMALLOC_FLAGS += $(JEMALLOC_FLAGS)

ifdef CFG_DISABLE_DEBUG
CFG_RUSTC_FLAGS += --cfg ndebug
CFG_GCCISH_CFLAGS += -DRUST_NDEBUG
Expand Down
6 changes: 5 additions & 1 deletion mk/reconfig.mk
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) \

ifndef CFG_DISABLE_MANAGE_SUBMODULES
# This is a pretty expensive operation but I don't see any way to avoid it
NEED_GIT_RECONFIG=$(shell cd "$(CFG_SRC_DIR)" && "$(CFG_GIT)" submodule status | grep -c '^\(+\|-\)')
# NB: This only looks for '+' status (wrong commit checked out), not '-' status
# (nothing checked out at all). `./configure --{llvm,jemalloc,libuv}-root`
# will explicitly deinitialize the corresponding submodules, and we don't
# want to force constant rebuilds in that case.
NEED_GIT_RECONFIG=$(shell cd "$(CFG_SRC_DIR)" && "$(CFG_GIT)" submodule status | grep -c '^+')
else
NEED_GIT_RECONFIG=0
endif
Expand Down
2 changes: 1 addition & 1 deletion mk/rt.mk
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ JEMALLOC_LOCAL_$(1) := $$(JEMALLOC_BUILD_DIR_$(1))/lib/$$(JEMALLOC_REAL_NAME_$(1
$$(JEMALLOC_LOCAL_$(1)): $$(JEMALLOC_DEPS) $$(MKFILE_DEPS)
@$$(call E, make: jemalloc)
cd "$$(JEMALLOC_BUILD_DIR_$(1))"; "$(S)src/jemalloc/configure" \
$$(JEMALLOC_ARGS_$(1)) --with-jemalloc-prefix=je_ \
$$(JEMALLOC_ARGS_$(1)) --with-jemalloc-prefix=je_ $(CFG_JEMALLOC_FLAGS) \
--build=$(CFG_BUILD) --host=$(1) \
CC="$$(CC_$(1))" \
AR="$$(AR_$(1))" \
Expand Down
89 changes: 86 additions & 3 deletions src/doc/guide-strings.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,33 @@ fn foo(s: String) {
```

If you have good reason. It's not polite to hold on to ownership you don't
need, and it can make your lifetimes more complex. Furthermore, you can pass
either kind of string into `foo` by using `.as_slice()` on any `String` you
need to pass in, so the `&str` version is more flexible.
need, and it can make your lifetimes more complex.

## Generic functions

To write a function that's generic over types of strings, use [the `Str`
trait](http://doc.rust-lang.org/std/str/trait.Str.html):

```{rust}
fn some_string_length<T: Str>(x: T) -> uint {
x.as_slice().len()
}

fn main() {
let s = "Hello, world";

println!("{}", some_string_length(s));

let s = "Hello, world".to_string();

println!("{}", some_string_length(s));
}
```

Both of these lines will print `12`.

The only method that the `Str` trait has is `as_slice()`, which gives you
access to a `&str` value from the underlying string.

## Comparisons

Expand All @@ -121,6 +145,65 @@ fn compare(string: String) {
Converting a `String` to a `&str` is cheap, but converting the `&str` to a
`String` involves an allocation.

## Indexing strings

You may be tempted to try to access a certain character of a `String`, like
this:

```{rust,ignore}
let s = "hello".to_string();

println!("{}", s[0]);
```

This does not compile. This is on purpose. In the world of UTF-8, direct
indexing is basically never what you want to do. The reason is that each
character can be a variable number of bytes. This means that you have to iterate
through the characters anyway, which is a O(n) operation.

To iterate over a string, use the `graphemes()` method on `&str`:

```{rust}
let s = "αἰθήρ";

for l in s.graphemes(true) {
println!("{}", l);
}
```

Note that `l` has the type `&str` here, since a single grapheme can consist of
multiple codepoints, so a `char` wouldn't be appropriate.

This will print out each character in turn, as you'd expect: first "α", then
"ἰ", etc. You can see that this is different than just the individual bytes.
Here's a version that prints out each byte:

```{rust}
let s = "αἰθήρ";

for l in s.bytes() {
println!("{}", l);
}
```

This will print:

```{notrust,ignore}
206
177
225
188
176
206
184
206
174
207
129
```

Many more bytes than graphemes!

# Other Documentation

* [the `&str` API documentation](/std/str/index.html)
Expand Down
Loading