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

Set CompilerDesugaring expn_info for all desugared expressions #39766

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
127 changes: 74 additions & 53 deletions src/librustc/hir/lowering.rs

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/librustc_errors/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,8 @@ impl EmitterWriter {
}
// Check to make sure we're not in any <*macros>
if !cm.span_to_filename(def_site).contains("macros>") &&
!trace.macro_decl_name.starts_with("#[") {
!trace.macro_decl_name.starts_with("#[") &&
!trace.macro_decl_name.starts_with("desugaring of") {
new_labels.push((trace.call_site,
"in this macro invocation".to_string()));
break;
Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/E0297.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ fn main() {
for Some(x) in xs {}
//~^ ERROR E0297
//~| NOTE pattern `None` not covered
//~| NOTE in this expansion of desugaring of `for`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nor this.

}
2 changes: 2 additions & 0 deletions src/test/compile-fail/if-let-arm-types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ fn main() {
//~^ expected (), found integral variable
//~| expected type `()`
//~| found type `{integer}`
//~| NOTE: in this expansion of desugaring of `if let`
//~| NOTE: in this expansion of desugaring of `if let`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I definitely think we should not be writing this to the output.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines are required by compiletest, but not shown in rustc output (see the second commit).

()
} else { //~ NOTE: `if let` arm with an incompatible type
1
Expand Down
3 changes: 2 additions & 1 deletion src/test/run-make/save-analysis/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
all: code
krate2: krate2.rs
$(RUSTC) $<
code: foo.rs krate2
code: foo.rs krate2 sugar.rs
$(RUSTC) foo.rs -Zsave-analysis-csv
$(RUSTC) foo.rs -Zsave-analysis
$(RUSTC) foo.rs -Zsave-analysis-api
$(RUSTC) sugar.rs -Zsave-analysis-csv
30 changes: 30 additions & 0 deletions src/test/run-make/save-analysis/sugar.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn main() {
let _ = foo();

for x in vec![1, 2, 3, 4] {
println!("{}", x);
}

while let Some(x) = Some(1) {
println!("{}", x);
}
}

fn foo() -> Result<(), ()> {
bar()?;
Ok(())
}

fn bar() -> Result<(), ()> {
Ok(())
}
26 changes: 26 additions & 0 deletions src/test/ui/compiler_desugaring.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// checks that errors on compiler-desugared spans don't have
// useless `in this macro invocation` notes.

fn main() {
let _ = foo();
}

fn foo() -> Result<(), ()> {
let _: i32 = bar()?; //~ ERROR E0308
Ok(())
}

fn bar() -> Result<(), ()> {
Ok(())
}

16 changes: 16 additions & 0 deletions src/test/ui/compiler_desugaring.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error[E0308]: match arms have incompatible types
--> $DIR/compiler_desugaring.rs:19:18
|
19 | let _: i32 = bar()?; //~ ERROR E0308
| ^^^^^^ expected i32, found ()
|
= note: expected type `i32`
found type `()`
note: match arm with an incompatible type
--> $DIR/compiler_desugaring.rs:19:18
|
19 | let _: i32 = bar()?; //~ ERROR E0308
| ^^^^^^

error: aborting due to previous error