Skip to content

Link error in stage1 #2

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
jokade opened this issue Nov 12, 2014 · 8 comments
Closed

Link error in stage1 #2

jokade opened this issue Nov 12, 2014 · 8 comments

Comments

@jokade
Copy link

jokade commented Nov 12, 2014

Hi, I tried to compile your branch avr-support with

./configure --prefix=/opt/local/avrrust && make

which results in a link error (for stage1?):

error: linking with `cc` failed: exit code: 1
note: cc '-m64' '-L' '/Volumes/JKDATA/dev/tmp/avr-rust/x86_64-apple-darwin/stage0/lib/rustlib/x86_64-apple-darwin/lib' '-o' 'x86_64-apple-darwin/stage0/lib/rustlib/x86_64-apple-darwin/lib/librustc-4e7c5e5c.dylib' 'x86_64-apple-darwin/stage0/lib/rustlib/x86_64-apple-darwin/lib/rustc-4e7c5e5c.o' '-Wl,-force_load,/Volumes/JKDATA/dev/tmp/avr-rust/x86_64-apple-darwin/stage0/lib/rustlib/x86_64-apple-darwin/lib/libmorestack.a' 'x86_64-apple-darwin/stage0/lib/rustlib/x86_64-apple-darwin/lib/rustc-4e7c5e5c.metadata.o' '-fno-lto' '-Wl,-dead_strip' '-nodefaultlibs' '-L' '/Volumes/JKDATA/dev/tmp/avr-rust/x86_64-apple-darwin/stage0/lib/rustlib/x86_64-apple-darwin/lib' '-lgraphviz-4e7c5e5c' '-L' '/Volumes/JKDATA/dev/tmp/avr-rust/x86_64-apple-darwin/stage0/lib/rustlib/x86_64-apple-darwin/lib' '-lgetopts-4e7c5e5c' '-L' '/Volumes/JKDATA/dev/tmp/avr-rust/x86_64-apple-darwin/stage0/lib/rustlib/x86_64-apple-darwin/lib' '-lrustc_llvm-4e7c5e5c' '-L' '/Volumes/JKDATA/dev/tmp/avr-rust/x86_64-apple-darwin/stage0/lib/rustlib/x86_64-apple-darwin/lib' '-lrustc_back-4e7c5e5c' '-L' '/Volumes/JKDATA/dev/tmp/avr-rust/x86_64-apple-darwin/stage0/lib/rustlib/x86_64-apple-darwin/lib' '-lsyntax-4e7c5e5c' '-L' '/Volumes/JKDATA/dev/tmp/avr-rust/x86_64-apple-darwin/stage0/lib/rustlib/x86_64-apple-darwin/lib' '-lterm-4e7c5e5c' '-L' '/Volumes/JKDATA/dev/tmp/avr-rust/x86_64-apple-darwin/stage0/lib/rustlib/x86_64-apple-darwin/lib' '-lfmt_macros-4e7c5e5c' '-L' '/Volumes/JKDATA/dev/tmp/avr-rust/x86_64-apple-darwin/stage0/lib/rustlib/x86_64-apple-darwin/lib' '-larena-4e7c5e5c' '-L' '/Volumes/JKDATA/dev/tmp/avr-rust/x86_64-apple-darwin/stage0/lib/rustlib/x86_64-apple-darwin/lib' '-lrbml-4e7c5e5c' '-L' '/Volumes/JKDATA/dev/tmp/avr-rust/x86_64-apple-darwin/stage0/lib/rustlib/x86_64-apple-darwin/lib' '-ltime-4e7c5e5c' '-L' '/Volumes/JKDATA/dev/tmp/avr-rust/x86_64-apple-darwin/stage0/lib/rustlib/x86_64-apple-darwin/lib' '-lserialize-4e7c5e5c' '-L' '/Volumes/JKDATA/dev/tmp/avr-rust/x86_64-apple-darwin/stage0/lib/rustlib/x86_64-apple-darwin/lib' '-llog-4e7c5e5c' '-L' '/Volumes/JKDATA/dev/tmp/avr-rust/x86_64-apple-darwin/stage0/lib/rustlib/x86_64-apple-darwin/lib' '-lregex-4e7c5e5c' '-L' '/Volumes/JKDATA/dev/tmp/avr-rust/x86_64-apple-darwin/stage0/lib/rustlib/x86_64-apple-darwin/lib' '-lflate-4e7c5e5c' '-L' '/Volumes/JKDATA/dev/tmp/avr-rust/x86_64-apple-darwin/stage0/lib/rustlib/x86_64-apple-darwin/lib' '-lstd-4e7c5e5c' '-L' '/Volumes/JKDATA/dev/tmp/avr-rust/x86_64-apple-darwin/stage0/lib/rustlib/x86_64-apple-darwin/lib' '-lsync-4e7c5e5c' '-L' '/Volumes/JKDATA/dev/tmp/avr-rust/x86_64-apple-darwin/stage0/lib/rustlib/x86_64-apple-darwin/lib' '-lrustrt-4e7c5e5c' '-L' 'x86_64-apple-darwin/rt' '-L' '/Volumes/JKDATA/dev/tmp/avr-rust/x86_64-apple-darwin/llvm/Release+Asserts/lib' '-L' '.' '-L' '/Volumes/JKDATA/dev/tmp/avr-rust/.rust' '-L' '/Volumes/JKDATA/dev/tmp/avr-rust' '-lpthread' '-ledit' '-lm' '-lc++' '-lSystem' '-lpthread' '-lc' '-lm' '-dynamiclib' '-Wl,-dylib' '-lcompiler-rt'
note: ld: warning: directory not found for option '-L/Volumes/JKDATA/dev/tmp/avr-rust/.rust'
Undefined symbols for architecture x86_64:
  "_LLVMInitializeAVRTargetInfo", referenced from:
      back::write::configure_llvm::closure.105122 in rustc-4e7c5e5c.o
  "_LLVMInitializeAVRTarget", referenced from:
      back::write::configure_llvm::closure.105122 in rustc-4e7c5e5c.o
  "_LLVMInitializeAVRTargetMC", referenced from:
      back::write::configure_llvm::closure.105122 in rustc-4e7c5e5c.o
  "_LLVMInitializeAVRAsmPrinter", referenced from:
      back::write::configure_llvm::closure.105122 in rustc-4e7c5e5c.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

error: aborting due to previous error
make: *** [x86_64-apple-darwin/stage0/lib/rustlib/x86_64-apple-darwin/lib/stamp.rustc] Error 101

Do I need addtional config flags? thx

@dylanmckay
Copy link
Member

Ah yes, I was intending to fix this but it slipped my mind.

Rust knows about all of those functions, and calls them, but it isn't linking to the static libraries (libLLVMAVRCodeGen.a, etc).

A quick fix is to add these lines to rust/src/librustc_llvm/llvmdeps.rs" and recompile

#[link(name = "LLVMAVRCodeGen", kind = "static")]
#[link(name = "LLVMAVRDesc", kind = "static")]
#[link(name = "LLVMAVRInfo", kind = "static")]
#[link(name = "LLVMAVRAsmPrinter", kind = "static")]

I believe the fix for this is to add avr to the LLVM_COMPONENTS variable in rust/mk/main.mk here, which I will do now. It used to be there, but it would cause an error (LLVM_COMPONENTS is passed to the llvm-config program which then outputs all of the libraries which are needed to be linked against for all of the components. It used to say unknown component: avr or something to that effect.

@dylanmckay
Copy link
Member

I have now added avr to LLVM_COMPONENTS and am waiting for Rust to compile afresh before I push the change. Note that my laptop is fairly low-end, and Rust doesn't have particularly fast compilation times, so give it an hour or two, perhaps three :)

@jokade
Copy link
Author

jokade commented Nov 12, 2014

Great, rust now compiles with your fix :-)
However, how do I set the target architecture to avr? Don't I need to compile the rust libraries for target avr (it seems to me, that without further config flags, all libraries are built for my host architecture)?
When I try to compile a rust file with

rust test.rs

I get a link error:

error: linking with `cc` failed: exit code: 1
note: cc '-m64' '-L' '/opt/local/avrrust/lib/rustlib/x86_64-apple-darwin/lib' '-o' 'test' 'test.o' '-Wl,-force_load,/opt/local/avrrust/lib/rustlib/x86_64-apple-darwin/lib/libmorestack.a' '-fno-lto' '-Wl,-dead_strip' '-nodefaultlibs' '/opt/local/avrrust/lib/rustlib/x86_64-apple-darwin/lib/libnative-4e7c5e5c.rlib' '/opt/local/avrrust/lib/rustlib/x86_64-apple-darwin/lib/libstd-4e7c5e5c.rlib' '/opt/local/avrrust/lib/rustlib/x86_64-apple-darwin/lib/libsync-4e7c5e5c.rlib' '/opt/local/avrrust/lib/rustlib/x86_64-apple-darwin/lib/librustrt-4e7c5e5c.rlib' '/opt/local/avrrust/lib/rustlib/x86_64-apple-darwin/lib/librand-4e7c5e5c.rlib' '/opt/local/avrrust/lib/rustlib/x86_64-apple-darwin/lib/libcollections-4e7c5e5c.rlib' '/opt/local/avrrust/lib/rustlib/x86_64-apple-darwin/lib/libunicode-4e7c5e5c.rlib' '/opt/local/avrrust/lib/rustlib/x86_64-apple-darwin/lib/liballoc-4e7c5e5c.rlib' '/opt/local/avrrust/lib/rustlib/x86_64-apple-darwin/lib/liblibc-4e7c5e5c.rlib' '/opt/local/avrrust/lib/rustlib/x86_64-apple-darwin/lib/libcore-4e7c5e5c.rlib' '-L' '/Volumes/JKDATA/dev/tmp/rust/.rust' '-L' '/Volumes/JKDATA/dev/tmp/rust' '-lSystem' '-lpthread' '-lc' '-lm' '-lcompiler-rt'
note: ld: warning: directory not found for option '-L/Volumes/JKDATA/dev/tmp/rust/.rust'
ld: can't open output file for writing: test, errno=21 for architecture x86_64

@dylanmckay
Copy link
Member

Take a look at README.md, and the example source enclosed within. Basically:

To set the target architecture to AVR, pass --target=avr-none (none being the OS by the way). Because currently only outputting assembly is possible, pass --emit asm as well. Also, to get around a bug (#1), optimization must also be turned on: pass -O

For example:

rustc hello_world.rs --target=avr-none -O --emit asm

Good luck!

@dylanmckay
Copy link
Member

Note that the quick fix should no longer be necessary after deleting the old /rust/src/librustc_llvm/llvmdeps.rs and reconfiguring and rebuilding, or simply just recloning the repository and compiling with the latest commit.

@jokade
Copy link
Author

jokade commented Nov 12, 2014

Sorry, I didn't notice that you've updated the README...
It works fine now... Thanks!

@dylanmckay
Copy link
Member

You are right about the standard library not being built for AVR. Obviously a portion of it will not be possible (io/mutexes/etc), but hopefully the libraries are structured in such a way to make porting to Rust a tractable problem.

I have very recently created a new repo which aims to catalog details about the hordes of AVR variants. I have already written a tool to parse the Atmel io/io___.h headers for register information for each board, and generate a JSON format description of it. Currently, the Atmega328p exists in it. I also have another repo which provides a Rust API for reading the JSON register information, which I am to use to generate Rust source files which define all of the available registers for each CPU.

Imagine:

// io/atmega328p.rs
const DDRB: *mut u8 = 0x04;
const PORTB: *mut u8 = 0x05;

Once that exists, it would be easy to write various abstractions over CPUs. After I have written this, I will then endeavor to get the standard library (well, as much as I can) working for AVR.

I haven't had access to an AVR for several days and so avr-rust is untested in the purest sense of the word, so keep me updated!

@dylanmckay
Copy link
Member

Let's move discussion to #3

dylanmckay pushed a commit that referenced this issue Aug 11, 2015
shepmaster pushed a commit that referenced this issue Feb 14, 2017
For a given file

```rust
trait A { fn foo(&self) {} }
trait B : A { fn foo(&self) {} }

fn bar<T: B>(a: &T) {
  a.foo()
}
```

provide the following output

```
error[E0034]: multiple applicable items in scope
 --> file.rs:6:5
  |
6 |   a.foo(1)
  |     ^^^ multiple `foo` found
  |
note: candidate #1 is defined in the trait `A`
 --> file.rs:2:11
  |
2 | trait A { fn foo(&self, a: usize) {} }
  |           ^^^^^^^^^^^^^^^^^^^^^^^^^^
help: to use it here write `A::foo(&a, 1)` instead
 --> file.rs:6:5
  |
6 |   a.foo(1)
  |     ^^^
note: candidate #2 is defined in the trait `B`
 --> file.rs:3:15
  |
3 | trait B : A { fn foo(&self, a: usize) {} }
  |               ^^^^^^^^^^^^^^^^^^^^^^^^^^
help: to use it here write `B::foo(&a, 1)` instead
 --> file.rs:6:5
  |
6 |   a.foo(1)
  |     ^^^
```
shepmaster pushed a commit that referenced this issue Feb 14, 2017
E0034: provide disambiguated syntax for candidates

For a given file

```rust
trait A { fn foo(&self) {} }
trait B : A { fn foo(&self) {} }

fn bar<T: B>(a: &T) {
  a.foo()
}
```

provide the following output

```
error[E0034]: multiple applicable items in scope
 --> file.rs:6:5
  |
6 |   a.foo(1)
  |     ^^^ multiple `foo` found
  |
note: candidate #1 is defined in the trait `A`
 --> file.rs:2:11
  |
2 | trait A { fn foo(&self, a: usize) {} }
  |           ^^^^^^^^^^^^^^^^^^^^^^^^^^
help: to use it here write `A::foo(&a, 1)` instead
 --> file.rs:6:5
  |
6 |   a.foo(1)
  |     ^^^
note: candidate #2 is defined in the trait `B`
 --> file.rs:3:15
  |
3 | trait B : A { fn foo(&self, a: usize) {} }
  |               ^^^^^^^^^^^^^^^^^^^^^^^^^^
help: to use it here write `B::foo(&a, 1)` instead
 --> file.rs:6:5
  |
6 |   a.foo(1)
  |     ^^^
```

Fix rust-lang#37767.
shepmaster pushed a commit that referenced this issue Feb 14, 2017
LeakSanitizer, ThreadSanitizer, AddressSanitizer and MemorySanitizer support

```
$ cargo new --bin leak && cd $_

$ edit Cargo.toml && tail -n3 $_
```

``` toml
[profile.dev]
opt-level = 1
```

```
$ edit src/main.rs && cat $_
```

``` rust
use std::mem;

fn main() {
    let xs = vec![0, 1, 2, 3];
    mem::forget(xs);
}
```

```
$ RUSTFLAGS="-Z sanitizer=leak" cargo run --target x86_64-unknown-linux-gnu; echo $?
    Finished dev [optimized + debuginfo] target(s) in 0.0 secs
     Running `target/debug/leak`

=================================================================
==10848==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 16 byte(s) in 1 object(s) allocated from:
    #0 0x557c3488db1f in __interceptor_malloc /shared/rust/checkouts/lsan/src/compiler-rt/lib/lsan/lsan_interceptors.cc:55
    #1 0x557c34888aaa in alloc::heap::exchange_malloc::h68f3f8b376a0da42 /shared/rust/checkouts/lsan/src/liballoc/heap.rs:138
    #2 0x557c34888afc in leak::main::hc56ab767de6d653a $PWD/src/main.rs:4
    #3 0x557c348c0806 in __rust_maybe_catch_panic ($PWD/target/debug/leak+0x3d806)

SUMMARY: LeakSanitizer: 16 byte(s) leaked in 1 allocation(s).
23
```

```
$ cargo new --bin racy && cd $_

$ edit src/main.rs && cat $_
```

``` rust
use std::thread;

static mut ANSWER: i32 = 0;

fn main() {
    let t1 = thread::spawn(|| unsafe { ANSWER = 42 });
    unsafe {
        ANSWER = 24;
    }
    t1.join().ok();
}
```

```
$ RUSTFLAGS="-Z sanitizer=thread" cargo run --target x86_64-unknown-linux-gnu; echo $?
==================
WARNING: ThreadSanitizer: data race (pid=12019)
  Write of size 4 at 0x562105989bb4 by thread T1:
    #0 racy::main::_$u7b$$u7b$closure$u7d$$u7d$::hbe13ea9e8ac73f7e $PWD/src/main.rs:6 (racy+0x000000010e3f)
    #1 _$LT$std..panic..AssertUnwindSafe$LT$F$GT$$u20$as$u20$core..ops..FnOnce$LT$$LP$$RP$$GT$$GT$::call_once::h2e466a92accacc78 /shared/rust/checkouts/lsan/src/libstd/panic.rs:296 (racy+0x000000010cc5)
    #2 std::panicking::try::do_call::h7f4d2b38069e4042 /shared/rust/checkouts/lsan/src/libstd/panicking.rs:460 (racy+0x00000000c8f2)
    #3 __rust_maybe_catch_panic <null> (racy+0x0000000b4e56)
    #4 std::panic::catch_unwind::h31ca45621ad66d5a /shared/rust/checkouts/lsan/src/libstd/panic.rs:361 (racy+0x00000000b517)
    #5 std::thread::Builder::spawn::_$u7b$$u7b$closure$u7d$$u7d$::hccfc37175dea0b01 /shared/rust/checkouts/lsan/src/libstd/thread/mod.rs:357 (racy+0x00000000c226)
    #6 _$LT$F$u20$as$u20$alloc..boxed..FnBox$LT$A$GT$$GT$::call_box::hd880bbf91561e033 /shared/rust/checkouts/lsan/src/liballoc/boxed.rs:605 (racy+0x00000000f27e)
    #7 std::sys::imp::thread::Thread::new::thread_start::hebdfc4b3d17afc85 <null> (racy+0x0000000abd40)

  Previous write of size 4 at 0x562105989bb4 by main thread:
    #0 racy::main::h23e6e5ca46d085c3 $PWD/src/main.rs:8 (racy+0x000000010d7c)
    #1 __rust_maybe_catch_panic <null> (racy+0x0000000b4e56)
    #2 __libc_start_main <null> (libc.so.6+0x000000020290)

  Location is global 'racy::ANSWER::h543d2b139f819b19' of size 4 at 0x562105989bb4 (racy+0x0000002f8bb4)

  Thread T1 (tid=12028, running) created by main thread at:
    #0 pthread_create /shared/rust/checkouts/lsan/src/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:902 (racy+0x00000001aedb)
    #1 std::sys::imp::thread::Thread::new::hce44187bf4a36222 <null> (racy+0x0000000ab9ae)
    #2 std::thread::spawn::he382608373eb667e /shared/rust/checkouts/lsan/src/libstd/thread/mod.rs:412 (racy+0x00000000b5aa)
    #3 racy::main::h23e6e5ca46d085c3 $PWD/src/main.rs:6 (racy+0x000000010d5c)
    #4 __rust_maybe_catch_panic <null> (racy+0x0000000b4e56)
    #5 __libc_start_main <null> (libc.so.6+0x000000020290)

SUMMARY: ThreadSanitizer: data race $PWD/src/main.rs:6 in racy::main::_$u7b$$u7b$closure$u7d$$u7d$::hbe13ea9e8ac73f7e
==================
ThreadSanitizer: reported 1 warnings
66
```

```
$ cargo new --bin oob && cd $_

$ edit src/main.rs && cat $_
```

``` rust
fn main() {
    let xs = [0, 1, 2, 3];
    let y = unsafe { *xs.as_ptr().offset(4) };
}
```

```
$ RUSTFLAGS="-Z sanitizer=address" cargo run --target x86_64-unknown-linux-gnu; echo $?
=================================================================
==13328==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fff29f3ecd0 at pc 0x55802dc6bf7e bp 0x7fff29f3ec90 sp 0x7fff29f3ec88
READ of size 4 at 0x7fff29f3ecd0 thread T0
    #0 0x55802dc6bf7d in oob::main::h0adc7b67e5feb2e7 $PWD/src/main.rs:3
    #1 0x55802dd60426 in __rust_maybe_catch_panic ($PWD/target/debug/oob+0xfe426)
    #2 0x55802dd58dd9 in std::rt::lang_start::hb2951fc8a59d62a7 ($PWD/target/debug/oob+0xf6dd9)
    #3 0x55802dc6c002 in main ($PWD/target/debug/oob+0xa002)
    #4 0x7fad8c3b3290 in __libc_start_main (/usr/lib/libc.so.6+0x20290)
    #5 0x55802dc6b719 in _start ($PWD/target/debug/oob+0x9719)

Address 0x7fff29f3ecd0 is located in stack of thread T0 at offset 48 in frame
    #0 0x55802dc6bd5f in oob::main::h0adc7b67e5feb2e7 $PWD/src/main.rs:1

  This frame has 1 object(s):
    [32, 48) 'xs' <== Memory access at offset 48 overflows this variable
HINT: this may be a false positive if your program uses some custom stack unwind mechanism or swapcontext
      (longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-overflow $PWD/src/main.rs:3 in oob::main::h0adc7b67e5feb2e7
Shadow bytes around the buggy address:
  0x1000653dfd40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1000653dfd50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1000653dfd60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1000653dfd70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1000653dfd80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x1000653dfd90: 00 00 00 00 f1 f1 f1 f1 00 00[f3]f3 00 00 00 00
  0x1000653dfda0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1000653dfdb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1000653dfdc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1000653dfdd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1000653dfde0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Heap right redzone:      fb
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack partial redzone:   f4
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==13328==ABORTING
1
```

```
$ cargo new --bin uninit && cd $_

$ edit src/main.rs && cat $_
```

``` rust
use std::mem;

fn main() {
    let xs: [u8; 4] = unsafe { mem::uninitialized() };
    let y = xs[0] + xs[1];
}
```

```
$ RUSTFLAGS="-Z sanitizer=memory" cargo run; echo $?
==30198==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x563f4b6867da in uninit::main::hc2731cd4f2ed48f8 $PWD/src/main.rs:5
    #1 0x563f4b7033b6 in __rust_maybe_catch_panic ($PWD/target/debug/uninit+0x873b6)
    #2 0x563f4b6fbd69 in std::rt::lang_start::hb2951fc8a59d62a7 ($PWD/target/debug/uninit+0x7fd69)
    #3 0x563f4b6868a9 in main ($PWD/target/debug/uninit+0xa8a9)
    #4 0x7fe844354290 in __libc_start_main (/usr/lib/libc.so.6+0x20290)
    #5 0x563f4b6864f9 in _start ($PWD/target/debug/uninit+0xa4f9)

SUMMARY: MemorySanitizer: use-of-uninitialized-value $PWD/src/main.rs:5 in uninit::main::hc2731cd4f2ed48f8
Exiting
77
```
shepmaster pushed a commit that referenced this issue Apr 19, 2017
Group "missing variable bind" spans in `or` matches and clarify wording
for the two possible cases: when a variable from the first pattern is
not in any of the subsequent patterns, and when a variable in any of the
other patterns is not in the first one.

Before:

```
error[E0408]: variable `a` from pattern #1 is not bound in pattern #2
  --> file.rs:10:23
   |
10 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
   |                       ^^^^^^^^^^^ pattern doesn't bind `a`

error[E0408]: variable `b` from pattern #2 is not bound in pattern #1
  --> file.rs:10:32
   |
10 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
   |                                ^ pattern doesn't bind `b`

error[E0408]: variable `a` from pattern #1 is not bound in pattern #3
  --> file.rs:10:37
   |
10 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
   |                                     ^^^^^^^^ pattern doesn't bind `a`

error[E0408]: variable `d` from pattern #1 is not bound in pattern #3
  --> file.rs:10:37
   |
10 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
   |                                     ^^^^^^^^ pattern doesn't bind `d`

error[E0408]: variable `c` from pattern #3 is not bound in pattern #1
  --> file.rs:10:43
   |
10 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
   |                                           ^ pattern doesn't bind `c`

error[E0408]: variable `d` from pattern #1 is not bound in pattern #4
  --> file.rs:10:48
   |
10 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
   |                                                ^^^^^^^^ pattern doesn't bind `d`

error: aborting due to 6 previous errors
```

After:

```
error[E0408]: variable `a` is not bound in all patterns
  --> file.rs:20:37
   |
20 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => {
intln!("{:?}", a); }
   |               -       ^^^^^^^^^^^   ^^^^^^^^         - variable
t in all patterns
   |               |       |             |
   |               |       |             pattern doesn't bind `a`
   |               |       pattern doesn't bind `a`
   |               variable not in all patterns

error[E0408]: variable `d` is not bound in all patterns
  --> file.rs:20:37
   |
20 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => {
intln!("{:?}", a); }
   |                  -          -       ^^^^^^^^   ^^^^^^^^ pattern
esn't bind `d`
   |                  |          |       |
   |                  |          |       pattern doesn't bind `d`
   |                  |          variable not in all patterns
   |                  variable not in all patterns

error[E0408]: variable `b` is not bound in all patterns
  --> file.rs:20:37
   |
20 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => {
intln!("{:?}", a); }
   |         ^^^^^^^^^^^            -    ^^^^^^^^   ^^^^^^^^ pattern
esn't bind `b`
   |         |                      |    |
   |         |                      |    pattern doesn't bind `b`
   |         |                      variable not in all patterns
   |         pattern doesn't bind `b`

error[E0408]: variable `c` is not bound in all patterns
  --> file.rs:20:48
   |
20 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => {
intln!("{:?}", a); }
   |         ^^^^^^^^^^^   ^^^^^^^^^^^         -    ^^^^^^^^ pattern
esn't bind `c`
   |         |             |                   |
   |         |             |                   variable not in all
tterns
   |         |             pattern doesn't bind `c`
   |         pattern doesn't bind `c`

error: aborting due to 4 previous errors
```

* Have only one presentation for binding consistency errors
* Point to same binding in multiple patterns when possible
* Check inconsistent bindings in all arms
* Simplify wording of diagnostic message
* Sort emition and spans of binding errors for deterministic output
shepmaster pushed a commit that referenced this issue Apr 19, 2017
Clean up "pattern doesn't bind x" messages

Group "missing variable bind" spans in `or` matches and clarify wording
for the two possible cases: when a variable from the first pattern is
not in any of the subsequent patterns, and when a variable in any of the
other patterns is not in the first one.

Before:

```rust
error[E0408]: variable `a` from pattern #1 is not bound in pattern #2
  --> file.rs:10:23
   |
10 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
   |                       ^^^^^^^^^^^ pattern doesn't bind `a`

error[E0408]: variable `b` from pattern #2 is not bound in pattern #1
  --> file.rs:10:32
   |
10 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
   |                                ^ pattern doesn't bind `b`

error[E0408]: variable `a` from pattern #1 is not bound in pattern #3
  --> file.rs:10:37
   |
10 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
   |                                     ^^^^^^^^ pattern doesn't bind `a`

error[E0408]: variable `d` from pattern #1 is not bound in pattern #3
  --> file.rs:10:37
   |
10 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
   |                                     ^^^^^^^^ pattern doesn't bind `d`

error[E0408]: variable `c` from pattern #3 is not bound in pattern #1
  --> file.rs:10:43
   |
10 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
   |                                           ^ pattern doesn't bind `c`

error[E0408]: variable `d` from pattern #1 is not bound in pattern #4
  --> file.rs:10:48
   |
10 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
   |                                                ^^^^^^^^ pattern doesn't bind `d`

error: aborting due to 6 previous errors
```

After:

```rust
error[E0408]: variable `d` is not bound in all patterns
  --> $DIR/issue-39698.rs:20:37
   |
20 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
   |                  -          -       ^^^^^^^^   ^^^^^^^^ pattern doesn't bind `d`
   |                  |          |       |
   |                  |          |       pattern doesn't bind `d`
   |                  |          variable not in all patterns
   |                  variable not in all patterns

error[E0408]: variable `c` is not bound in all patterns
  --> $DIR/issue-39698.rs:20:48
   |
20 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
   |         ^^^^^^^^^^^   ^^^^^^^^^^^         -    ^^^^^^^^ pattern doesn't bind `c`
   |         |             |                   |
   |         |             |                   variable not in all patterns
   |         |             pattern doesn't bind `c`
   |         pattern doesn't bind `c`

error[E0408]: variable `a` is not bound in all patterns
  --> $DIR/issue-39698.rs:20:37
   |
20 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
   |               -       ^^^^^^^^^^^   ^^^^^^^^         - variable not in all patterns
   |               |       |             |
   |               |       |             pattern doesn't bind `a`
   |               |       pattern doesn't bind `a`
   |               variable not in all patterns

error[E0408]: variable `b` is not bound in all patterns
  --> $DIR/issue-39698.rs:20:37
   |
20 |         T::T1(a, d) | T::T2(d, b) | T::T3(c) | T::T4(a) => { println!("{:?}", a); }
   |         ^^^^^^^^^^^            -    ^^^^^^^^   ^^^^^^^^ pattern doesn't bind `b`
   |         |                      |    |
   |         |                      |    pattern doesn't bind `b`
   |         |                      variable not in all patterns
   |         pattern doesn't bind `b`

error: aborting due to 4 previous errors
```

Fixes rust-lang#39698.
dylanmckay pushed a commit that referenced this issue Jun 9, 2019
Some review feedback and other misc tweaks
dylanmckay pushed a commit that referenced this issue Jun 9, 2019
…erister

Use arenas to avoid Lrc in queries #2

The `Remove subtle Default impl for Value` makes the compilation stop due earlier due to cycle errors, since there's no longer a default value to continue the compilation with.

Based on rust-lang#59540.
dylanmckay pushed a commit that referenced this issue Jun 9, 2019
Rollup of 6 pull requests

Successful merges:

 - rust-lang#59545 (Use arenas to avoid Lrc in queries #2)
 - rust-lang#61054 (Suggest dereferencing on assignment to mutable borrow)
 - rust-lang#61056 (tweak discriminant on non-nullary enum diagnostic)
 - rust-lang#61082 (fix dangling reference in Vec::append)
 - rust-lang#61086 (Box::into_unique: do the reborrow-to-raw *after* destroying the Box)
 - rust-lang#61098 (Fix overflowing literal lint in loops)

Failed merges:

r? @ghost
dylanmckay pushed a commit that referenced this issue Jun 9, 2020
fix comment


add newline for tidy fmt error...


edit suggestion message


change the suggestion message to better handle cases with binding modes


Apply suggestions from estebank code review

Co-authored-by: Esteban Kuber <[email protected]>
edits to address source review


Apply suggestions from estebank code review #2

Co-authored-by: Esteban Kuber <[email protected]>
update test files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants