Skip to content
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

Missing context lines for errors and warnings #57054

Closed
mqudsi opened this issue Dec 21, 2018 · 8 comments
Closed

Missing context lines for errors and warnings #57054

mqudsi opened this issue Dec 21, 2018 · 8 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-proc-macros Area: Procedural macros C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@mqudsi
Copy link
Contributor

mqudsi commented Dec 21, 2018

I'm working on a non-trivial project building with rustc 1.33.0-nightly (93c2f055b 2018-12-15) with a thumbv7em-none-eabi target, and I've run into an issue where something in the code breaks the compiler output (in both -v and regular modes) such that it emits neither the location/line number of some errors nor the context in which the error occurred, but only for some errors:

mqudsi@Blitzkrieg /m/d/G/remoterelay> make
env -u RUSTFLAGS -u CC -u CXX -u CFLAGS -u CXXFLAGS -u CPPFLAGS cargo build --release --target thumbv7em-none-eabi
   Compiling resetplug v0.1.0 (/mnt/d/GIT/remoterelay)
warning: unused imports: `SleepMode`, `sleep`
 --> src/rfm69.rs:2:21
  |
2 | use crate::cortex::{sleep, SleepMode};
  |                     ^^^^^  ^^^^^^^^^
  |
  = note: #[warn(unused_imports)] on by default

warning: unused import: `cortex_m::Peripherals`
  --> src/timer.rs:11:5
   |
11 | use cortex_m::Peripherals;
   |     ^^^^^^^^^^^^^^^^^^^^^

warning: unused import: `cortex_m::peripheral::SYST`
  --> src/timer.rs:12:5
   |
12 | use cortex_m::peripheral::SYST;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: unused import: `self::cortex::*`
  --> src/main.rs:31:5
   |
31 | use self::cortex::*;
   |     ^^^^^^^^^^^^^^^

warning: unused import: `panic_semihosting`
  --> src/main.rs:40:5
   |
40 | use panic_semihosting;
   |     ^^^^^^^^^^^^^^^^^

warning: unnecessary parentheses around assigned value
  |
  = note: #[warn(unused_parens)] on by default

warning: unnecessary parentheses around assigned value

error[E0308]: mismatched types
  |
  = note: expected type `()`
             found type `core::result::Result<(), stm32f103xx_hal::spi::Error>`

warning: unreachable statement
   --> src/rfm69.rs:615:13
    |
615 | /             for _ in 0..3 {
616 | |                 // debug!("ms: {}", Self::milliseconds());
617 | |                 let status = self.get_status()?;
618 | |                 let mode = self.get_mode()?;
...   |
632 | |                 }
633 | |             }
    | |_____________^
    |
    = note: #[warn(unreachable_code)] on by default

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
error: Could not compile `resetplug`.

To learn more, run the command again with --verbose.
Makefile:7: recipe for target 'all' failed
make: *** [all] Error 101

As you can see, while some of the warnings correctly show where they occurred, I have both warnings and error messages that are devoid of any context to help pin them down, e.g.

warning: unnecessary parentheses around assigned value
  |
  = note: #[warn(unused_parens)] on by default

warning: unnecessary parentheses around assigned value

and more worryingly

error[E0308]: mismatched types
  |
  = note: expected type `()`
             found type `core::result::Result<(), stm32f103xx_hal::spi::Error>`

I'm not able to reproduce this behavior in an MVP.

For reference, rustc is ultimately invoked as follows:

rustc --edition=2018 --crate-name resetplug src/main.rs --color always --crate-type bin --emit=dep-info,link -C opt-level=3 -C debuginfo=2 -C metadata=1e2eb267bde647f6 -C extra-filename=-1e2eb267bde647f6 --out-dir /mnt/d/GIT/remoterelay/target/thumbv7em-none-eabi/release/deps --target thumbv7em-none-eabi -L dependency=/mnt/d/GIT/remoterelay/target/thumbv7em-none-eabi/release/deps -L dependency=/mnt/d/GIT/remoterelay/target/release/deps --extern arrayvec=/mnt/d/GIT/remoterelay/target/thumbv7em-none-eabi/release/deps/libarrayvec-26146b813587c3c2.rlib --extern bitfield=/mnt/d/GIT/remoterelay/target/thumbv7em-none-eabi/release/deps/libbitfield-997032c56c0315d9.rlib --extern bitflags=/mnt/d/GIT/remoterelay/target/thumbv7em-none-eabi/release/deps/libbitflags-d86d85ee8fa2114a.rlib --extern cortex_m=/mnt/d/GIT/remoterelay/target/thumbv7em-none-eabi/release/deps/libcortex_m-40f83b831cae7928.rlib --extern cortex_m_rt=/mnt/d/GIT/remoterelay/target/thumbv7em-none-eabi/release/deps/libcortex_m_rt-e20c4e09525d2181.rlib --extern cortex_m_semihosting=/mnt/d/GIT/remoterelay/target/thumbv7em-none-eabi/release/deps/libcortex_m_semihosting-9650c89d0a9a08a6.rlib --extern embedded_hal=/mnt/d/GIT/remoterelay/target/thumbv7em-none-eabi/release/deps/libembedded_hal-e7949b13f3dd68af.rlib --extern generic_array=/mnt/d/GIT/remoterelay/target/thumbv7em-none-eabi/release/deps/libgeneric_array-6efd9bb5e3345cca.rlib --extern panic_semihosting=/mnt/d/GIT/remoterelay/target/thumbv7em-none-eabi/release/deps/libpanic_semihosting-6e573ccd50b870ae.rlib --extern stm32f103xx_hal=/mnt/d/GIT/remoterelay/target/thumbv7em-none-eabi/release/deps/libstm32f103xx_hal-c88e35dd2872e6d7.rlib --extern typenum=/mnt/d/GIT/remoterelay/target/thumbv7em-none-eabi/release/deps/libtypenum-9af09db0d0907f97.rlib -Z external-macro-backtrace -C link-arg=-Tlink.x -L /mnt/d/GIT/remoterelay/target/thumbv7em-none-eabi/release/build/cortex-m-rt-703d7c131cf138a6/out -L /mnt/d/GIT/remoterelay/target/thumbv7em-none-eabi/release/build/cortex-m-semihosting-c616a089e2dd4d11/out -L /mnt/d/GIT/remoterelay/target/thumbv7em-none-eabi/release/build/stm32f103xx-hal-62c503a0a996e381/out

@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints O-Arm Target: 32-bit Arm processors (armv6, armv7, thumb...), including 64-bit Arm in AArch32 state T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 22, 2018
@anlumo
Copy link

anlumo commented Jan 2, 2019

I just started seeing the same here on a wasm32-unknown-unknown library after the latest nightly update.

Compiler: rustc 1.33.0-nightly (9eac38634 2018-12-31)

Happens both on warnings and errors, but not all of them.

@anlumo
Copy link

anlumo commented Jan 3, 2019

So, I was able to isolate this issue with my code. I don't know whether it's the same problem as @mqudsi is seeing, since it's related to web-sys.

I went back in the nightlies as far as to nightly-2018-08-14, but still had the same issue, so I investigated whether a concurrent change triggered this, and found something. I have the following code in an impl (with all irrelevant lines already removed):

    pub fn push_operations(&mut self, operations: &Array) {
        operations.for_each(&mut |operation, index, array| {
        });
    }

The Array type here is js_sys::Array. When the for_each-line is in my code, I get the following type of messages from rustc:

error[E0308]: mismatched types

error[E0308]: mismatched types
help: you can cast an `u32` to `f64`, producing the floating point representation of the integer
  |
1 | .into()#![feature(try_from)]
  | ^^^^^^^

error[E0277]: cannot subtract `euclid::size::TypedSize2D<f64, MapUnit>` from `euclid::point::TypedPoint2D<f64, MapUnit>`
  |
  = help: the trait `std::ops::Sub<euclid::size::TypedSize2D<f64, MapUnit>>` is not implemented for `euclid::point::TypedPoint2D<f64, MapUnit>`

error[E0308]: mismatched types
  |
  = note: expected type `&str`
             found type `std::string::String`

error[E0308]: mismatched types
  |
  = note: expected type `&tile::Tile`
             found type `tile::Tile`

error: aborting due to 5 previous errors

All messages here are valid, but are missing the file and line information. They're all located in the same file as fn push_operation, though. When I comment out the for_each call, I get messages like these:

error[E0308]: mismatched types
   --> src\lib.rs:106:32
    |
106 |         context.viewport(0, 0, canvas.width(), canvas.height());
    |                                ^^^^^^^^^^^^^^ expected i32, found u32

error[E0308]: mismatched types
   --> src\lib.rs:106:48
    |
106 |         context.viewport(0, 0, canvas.width(), canvas.height());
    |                                                ^^^^^^^^^^^^^^^ expected i32, found u32

error[E0308]: mismatched types
   --> src\lib.rs:126:37
    |
126 |         self.context.viewport(0, 0, width, height);
    |                                     ^^^^^ expected i32, found u32

error[E0308]: mismatched types
   --> src\lib.rs:126:44
    |
126 |         self.context.viewport(0, 0, width, height);
    |                                            ^^^^^^ expected i32, found u32
…

As you can see, it's the same messages, but with a file and line number.

So, it's the for_each function call on js_sys::Array that's causing this issue for the whole file.

@anlumo
Copy link

anlumo commented Jan 3, 2019

Here is a minimal demonstration of this behavior:

compiler-unhelpful.zip

Verified with rustc 1.33.0-nightly (b2b7a063a 2019-01-01).

$ cargo build
   Compiling proc-macro2 v0.4.24
   Compiling unicode-xid v0.1.0
   Compiling wasm-bindgen-shared v0.2.29
   Compiling cfg-if v0.1.6
   Compiling lazy_static v1.2.0
   Compiling wasm-bindgen v0.2.29
   Compiling log v0.4.6
   Compiling quote v0.6.10
   Compiling syn v0.15.23
   Compiling wasm-bindgen-backend v0.2.29
   Compiling wasm-bindgen-macro-support v0.2.29
   Compiling wasm-bindgen-macro v0.2.29
   Compiling js-sys v0.3.6
   Compiling compiler-unhelpful v0.1.0 (…\compiler-unhelpful)
warning: unused variable: `operation`
  |
  = note: #[warn(unused_variables)] on by default

warning: unused variable: `index`

warning: unused variable: `array`

warning: struct is never constructed: `Renderer`
 --> src\lib.rs:4:1
  |
4 | struct Renderer;
  | ^^^^^^^^^^^^^^^^
  |
  = note: #[warn(dead_code)] on by default

warning: method is never used: `push_operations`

    Finished dev [unoptimized + debuginfo] target(s) in 26.09s

@sanxiyn sanxiyn removed the O-Arm Target: 32-bit Arm processors (armv6, armv7, thumb...), including 64-bit Arm in AArch32 state label Mar 25, 2019
@TheNeikos
Copy link
Contributor

TheNeikos commented Sep 25, 2019

I have also encountered this issue, and after several hours of investigation: it seems to happen when a proc-macro is re-emitting tokens from a macro call.

This can be reproduced in the playground: https://play.rust-lang.org/?version=stable&mode=release&edition=2018&gist=a3c0361aeaaa7ed6257e79136f3aa6be

Anything put into the function body that was put in by the macro will not have any associated line number.

(This is also not limited to the wasm crate, but happens with any proc-macro as far as I noticed. The wasm crate is just available on the playground)

@jonas-schievink
Copy link
Contributor

This is probably caused by (and a duplicate of) #43081

@jonas-schievink jonas-schievink added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. labels Nov 9, 2019
@Aaron1011 Aaron1011 added the A-proc-macros Area: Procedural macros label May 21, 2020
@Aaron1011
Copy link
Member

This should be fixed by #72388

@Aaron1011
Copy link
Member

@mqudsi: Can you re-test on the latest nightly?

@mqudsi
Copy link
Contributor Author

mqudsi commented Jan 3, 2021

I finally had some time to revisit the project that was triggering this for me and was not able to reproduce in a week of use. 👍

@mqudsi mqudsi closed this as completed Jan 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-proc-macros Area: Procedural macros C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants