cargo run
或cargo rebuild
会忽略任何程式码变更。
我有一个程序
fn main() {
println!("Hello, World!");
}
然后,我执行cargo run
,看到:
Compiling myproject v0.1.0 (/Volumes/.../myproject)
Finished dev [unoptimized + debuginfo] target(s) in 0.52s
Running `target/debug/myproject`
Hello, World!
然后我将代码更改为:
fn main() {
println!("Hello, Worldaefafeff!");
print!("22222412414");
}
cargo run
再次:
Compiling myproject v0.1.0 (/Volumes/.../myproject)
Finished dev [unoptimized + debuginfo] target(s) in 0.76s
Running `target/debug/myproject`
Hello, World!
即使我看到“Compiling”行,这意味着cargo
知道文件已经被更改,输出也是一样的。当我运行cargo build
时也会发生同样的情况。我需要每次都运行cargo clean
吗?
我看到很多人说我做错了,我在一个终端重复了我所有的步骤,是不是有什么问题?
Genychs-iMac:~ defake$ z /Volumes/MainBrain/Programming/Projects/Personal
Genychs-iMac:Personal defake$ cargo new notworking
Created binary (application) `notworking` package
Genychs-iMac:Personal defake$ cd notworking/
Genychs-iMac:notworking defake$ cargo run
Compiling notworking v0.1.0 (/Volumes/MainBrain/Programming/Projects/Personal/notworking)
Finished dev [unoptimized + debuginfo] target(s) in 0.55s
Running `target/debug/notworking`
Hello, world!
Genychs-iMac:notworking defake$ printf 'fn main() {' > src/main.rs
Genychs-iMac:notworking defake$ printf '\n\tprintln!("Other text");' >> src/main.rs
Genychs-iMac:notworking defake$ printf '\n}\n' >> src/main.rs
Genychs-iMac:notworking defake$ cargo run
Compiling notworking v0.1.0 (/Volumes/MainBrain/Programming/Projects/Personal/notworking)
Finished dev [unoptimized + debuginfo] target(s) in 0.33s
Running `target/debug/notworking`
Hello, world!
Genychs-iMac:notworking defake$ cd src
Genychs-iMac:src defake$ cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.00s
Running `/Volumes/MainBrain/Programming/Projects/Personal/notworking/target/debug/notworking`
Hello, world!
Genychs-iMac:src defake$ cat main.rs
fn main() {
println!("Other text");
}
Genychs-iMac:src defake$ cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.00s
Running `/Volumes/MainBrain/Programming/Projects/Personal/notworking/target/debug/notworking`
Hello, worlGenychs-iMac:src defake$ cargo clean
Genychs-iMac:src defake$ cargo run
Compiling notworking v0.1.0 (/Volumes/MainBrain/Programming/Projects/Personal/notworking)
Finished dev [unoptimized + debuginfo] target(s) in 0.48s
Running `/Volumes/MainBrain/Programming/Projects/Personal/notworking/target/debug/notworking`
Other text
Genychs-iMac:src defake$
“编译”发生了,但输出是一样的。第二次没有“编译”步骤。我显然不明白我做错了什么。
而且没有错,倒数第二个启动实际上显示“你好,世界”。我确实正确地复制了终端内容
Genychs-iMac:secondtry defake$ cargo run
Compiling secondtry v0.1.0 (/Volumes/MainBrain/Programming/Projects/Personal/secondtry)
Finished dev [unoptimized + debuginfo] target(s) in 1.13s
Running `target/debug/secondtry`
Other text 15
Genychs-iMac:secondtry defake$ ls -l target/debug/
total 776
drwxr-xr-x 0 defake staff 0 Jul 20 18:03 build
drwxr-xr-x 0 defake staff 4096 Jul 20 18:03 deps
drwxr-xr-x 0 defake staff 0 Jul 20 18:03 examples
drwxr-xr-x 0 defake staff 0 Jul 20 18:03 incremental
drwxr-xr-x 0 defake staff 0 Jul 20 18:03 native
-rwxr-xr-x 2 defake staff 291112 Jul 20 18:03 secondtry
-rw-r--r-- 1 defake staff 159 Jul 20 18:03 secondtry.d
lrwxr-xr-x 1 defake staff 0 Jul 20 18:03 secondtry.dSYM -> deps/secondtry-d4f28f61785f1e66.dSYM
然后更新代码
Genychs-iMac:secondtry defake$ cargo run
Compiling secondtry v0.1.0 (/Volumes/MainBrain/Programming/Projects/Personal/secondtry)
Finished dev [unoptimized + debuginfo] target(s) in 0.36s
Running `target/debug/secondtry`
Other text 15
Genychs-iMac:secondtry defake$ ls -l target/debug/
total 776
drwxr-xr-x 0 defake staff 0 Jul 20 18:03 build
drwxr-xr-x 0 defake staff 4096 Jul 20 18:04 deps
drwxr-xr-x 0 defake staff 0 Jul 20 18:03 examples
drwxr-xr-x 0 defake staff 0 Jul 20 18:03 incremental
drwxr-xr-x 0 defake staff 0 Jul 20 18:03 native
-rwxr-xr-x 2 defake staff 291112 Jul 20 18:04 secondtry
-rw-r--r-- 1 defake staff 159 Jul 20 18:04 secondtry.d
lrwxr-xr-x 1 defake staff 0 Jul 20 18:03 secondtry.dSYM -> deps/secondtry-d4f28f61785f1e66.dSYM
Genychs-iMac:secondtry defake$ strings target/debug/secondtry
Other text 15
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
<... and possibly more>RUST_BACKTRACE0full : -
<unknown>
at .: at
main
called `Option::unwrap()` on a `None` valuesrc/libcore/option.rscalled `Result::unwrap()` on an `Err` valuefailed to get environment variable ``: src/libstd/env.rs
src/libstd/sync/once.rsassertion failed: state & STATE_MASK == RUNNINGOnce instance has previously been poisoned
assertion failed: `(left == right)`
left: ``,
right: ``memory allocation of bytes failed
<unnamed>' panicked at '',
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
thread panicked while processing panic. aborting.
thread panicked while panicking. aborting.
failed to initiate panic, error
src/libstd/sys/unix/os.rsstrerror_r failure
src/libstd/sys/unix/rwlock.rsrwlock maximum reader count exceededrwlock read lock would result in deadlock
Box<Any>thread '...
called `Option::unwrap()` on a `None` valuesrc/libcore/option.rsfailed to write the buffered data
stack overflowsrc/libstd/sys/unix/stack_overflow.rsfailed to allocate an alternative stack
called `Option::unwrap()` on a `None` valuesrc/libcore/option.rscalled `Result::unwrap()` on an `Err` valueuse of std::thread::current() is not possible after the thread's local data has been destroyedsrc/libstd/thread/mod.rsinconsistent park stateassertion failed: `(left == right)`
left: ``,
right: ``: park state changed unexpectedly
failed to generate unique thread ID: bitspace exhaustedthread name may not contain interior null bytesinconsistent state in unpark
data provided contains a nul byteunexpected end of fileother os erroroperation interruptedwrite zerotimed outinvalid datainvalid input parameteroperation would blockentity already existsbroken pipeaddress not availableaddress in usenot connectedconnection abortedconnection refusedpermission denied
(os error )
connection resetentity not found
already borrowed
: src/libcore/result.rs
cannot access stdout during shutdownfailed printing to src/libstd/io/stdio.rsstdout
failed to write whole bufferformatter errorsrc/libstd/sys_common/at_exit_imp.rsassertion failed: queue != DONE
src/libstd/sys/unix/mod.rsassertion failed: signal(libc::SIGPIPE, libc::SIG_IGN) != libc::SIG_ERR
src/libcore/slice/mod.rsassertion failed: `(left == right)`
left: ``,
right: ``: destination and source slices have different lengths
src/libstd/sync/condvar.rsattempted to use a condition variable with two mutexes
SomeNoneinternal error: entered unreachable codesrc/liballoc/raw_vec.rsTried to shrink to a larger capacity
/private/tmp/rust-20190704-90201-o56ua9/rustc-1.36.0-src/src/libcore/str/pattern.rs
attempt to calculate the remainder with a divisor of zero
src/liballoc/vec.rsassertion failed: end <= len
__rust_begin_short_backtracePoisonError { inner: .. }failed to allocate libbacktrace state
src/libstd/sys/unix/thread.rsassertion failed: PAGE_SIZE != 0
src/libstd/sys/unix/thread.rsfailed to allocate a guard pagefailed to protect the guard page
failed to write whole bufferformatter error
unexpected return value while unwinding:
src/libstd/sys/unix/backtrace/tracing/gcc_s.rs
UnwindError
NulErrorkind
/private/tmp/rust-20190704-90201-o56ua9/rustc-1.36.0-src/src/libcore/str/pattern.rsalready mutably borrowedcalled `Option::unwrap()` on a `None` valuesrc/libcore/option.rs
AccessError
cannot access a TLS value during or after it is destroyed
__rust_begin_short_backtrace
src/libstd/sys_common/thread_info.rsassertion failed: c.borrow().is_none()fatal runtime error:
thread '' has overflowed its stack
<unknown>StringErroralready borrowedcalled `Option::unwrap()` on a `None` valuesrc/libcore/option.rs
/private/tmp/rust-20190704-90201-o56ua9/rustc-1.36.0-src/src/libcore/str/pattern.rscalled `Option::unwrap()` on a `None` valuesrc/libcore/option.rscalled `Result::unwrap()` on an `Err` value.llvm.
E._ZNZN::_$.@*&<>()$C$,$u7e$~$u20$ $u27$'$u3d$=$u5b$[$u5d$]$u7b${$u7d$}$u3b$;$u2b$+$u22$"
__ZN$SP$$BP$$RF$$LT$$GT$$LP$$RP$
: src/libcore/result.rs_URC_FAILURE_URC_CONTINUE_UNWIND_URC_INSTALL_CONTEXT_URC_HANDLER_FOUND_URC_END_OF_STACK_URC_FATAL_PHASE1_ERROR_URC_FATAL_PHASE2_ERROR_URC_FOREIGN_EXCEPTION_CAUGHT_URC_NO_REASON
_URC_NORMAL_STOPsrc/liballoc/raw_vec.rscapacity overflow0x00010203040506070809101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
src/libcore/option.rs
, { } }(
5556
:index out of bounds: the len is but the index is called `Option::unwrap()` on a `None` valuesrc/libcore/option.rs
./?\]_
)147:;=IJ]
)14:;EFIJ^de
)EIWde
EIde
INOWY^_
FGNOXZ\^~
/_&./
NOZ[
no7=?BE
';>NO
6=>V
67VW
)14:EFIJNOdeZ\
;>fi
:?EQ
#%&(38:HJLPSUVXZ\^`cefksx}
?qr{^"{
PI73
<dS
t
Y'
ParseIntErrorUnderflowInvalidDigitEmpty
ZeroOverflow
) when slicing `
BorrowError
BorrowMutErrorcalled `Option::unwrap()` on a `None` valuesrc/libcore/option.rs
src/libcore/slice/mod.rsindex out of range for slice of length slice index starts at but ends at attempted to index slice up to maximum usize
src/libcore/str/mod.rs[...]byte index is out of bounds of ``begin <= end ( is not a char boundary; it is inside ) of `
Utf8Errorvalid_up_toerror_len <= (bytes called `Option::unwrap()` on a `None` valuesrc/libcore/option.rssrc/libcore/fmt/mod.rs
src/libcore/str/pattern.rs
src/libcore/unicode/bool_trie.rs
malloc
realloc
.debug_info
unrecognized DWARF version
DWARF underflow
%s in %s at %d
abbrev offset out of range
.debug_abbrev
LEB128 overflows uint64_t
invalid abbreviation code
DW_FORM_strp out of range
unrecognized DWARF form
unrecognized address size
signed LEB128 overflows uint64_t
ranges offset out of range
.debug_ranges
unit line offset out of range
.debug_line
unsupported line number version
invalid directory index in line number program header
invalid directory index in line number program
invalid file number in line number program
invalid file number in DW_AT_call_file attribute
abstract origin or specification out of range
invalid abstract origin or specification
function ranges offset out of range
failed to read executable information
/proc/self/exe
/proc/curproc/file
/proc/%ld/object/a.out
libbacktrace could not find executable to open
close
lseek
read
file too short
backtrace library does not support threads
executable file contains out of range command offset
executable file is missing an identifying UUID
__TEXT
executable is missing __TEXT segment
dSYM file contains out of range string table index
dSYM file contains unterminated string
dSYM file is missing an identifying uuid
dSYM file contains out of range command offset
__DWARF
/Contents/Resources/DWARF
could not open DWARF directory in dSYM
executable file is not loaded
could not open directory containing executable
.dSYM
__debug_info
__debug_line
__debug_abbrev
__debug_ranges
__debug_str
no debug info in Mach-O executable
no symbol table in Mach-O executable
"#$%&
,-./0
>?@ABCDEF
我注意到,如果我运行target/debug/secondtry
,输出是过时的,但如果我运行target/debug/deps/secondtry-8f71784d4f2f1e66
,我会得到正确的输出。
3条答案
按热度按时间7fhtutme1#
结果没有人回答这个问题,所以我将它关闭。
我想这个问题是与货物fs操作和mac与外部硬盘工作的结合有关。正如我在评论中所写的,它在mac的SSD上工作,在我迁移到一个新的笔记本电脑后,这个问题对我来说不再是实际的了。
如果有人再次遇到同一个恶作剧鬼,请尝试使用不同的磁盘来存储项目。
r1wp621o2#
print!
不会立即刷新。默认情况下,stdout通常是行缓冲的,因此可能需要使用
io::stdout().flush()
来确保立即发出输出。6kkfgxo03#
当我遇到这个问题时,我做错了什么,我添加了一个main.rs到项目根目录,而不是
/project_name/src/
文件夹。当你第一次运行
cargo new project_name
时,它会为你创建目录结构,并添加一个包含main.rs
的/src/
,这是你应该工作的地方。