From c47bb6debdea0ad69287328e5d578138fe14b32d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sat, 18 Apr 2020 20:51:11 -0700 Subject: [PATCH 1/7] On `FnDef` type annotation suggestion, use fn-pointer output Partly addresses #71209. --- .../infer/error_reporting/need_type_info.rs | 8 +++++++- .../fn-needing-specified-return-type-param.rs | 5 +++++ .../fn-needing-specified-return-type-param.stderr | 11 +++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/suggestions/fn-needing-specified-return-type-param.rs create mode 100644 src/test/ui/suggestions/fn-needing-specified-return-type-param.stderr diff --git a/src/librustc_infer/infer/error_reporting/need_type_info.rs b/src/librustc_infer/infer/error_reporting/need_type_info.rs index bb6e5700ccad4..2b4aeb2138240 100644 --- a/src/librustc_infer/infer/error_reporting/need_type_info.rs +++ b/src/librustc_infer/infer/error_reporting/need_type_info.rs @@ -247,7 +247,13 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { None }; printer.name_resolver = Some(Box::new(&getter)); - let _ = ty.print(printer); + let _ = if let ty::FnDef(..) = ty.kind { + // We don't want the regular output for `fn`s because it inscludes its path in + // invalid pseduo-syntax, we want the `fn`-pointer output instead. + ty.fn_sig(self.tcx).print(printer) + } else { + ty.print(printer) + }; s }; diff --git a/src/test/ui/suggestions/fn-needing-specified-return-type-param.rs b/src/test/ui/suggestions/fn-needing-specified-return-type-param.rs new file mode 100644 index 0000000000000..2f140f823afb9 --- /dev/null +++ b/src/test/ui/suggestions/fn-needing-specified-return-type-param.rs @@ -0,0 +1,5 @@ +fn f() -> A { unimplemented!() } +fn foo() { + let _ = f; //~ ERROR type annotations needed for `fn() -> A` +} +fn main() {} diff --git a/src/test/ui/suggestions/fn-needing-specified-return-type-param.stderr b/src/test/ui/suggestions/fn-needing-specified-return-type-param.stderr new file mode 100644 index 0000000000000..b59a3818e7042 --- /dev/null +++ b/src/test/ui/suggestions/fn-needing-specified-return-type-param.stderr @@ -0,0 +1,11 @@ +error[E0282]: type annotations needed for `fn() -> A` + --> $DIR/fn-needing-specified-return-type-param.rs:3:13 + | +LL | let _ = f; + | - ^ cannot infer type for type parameter `A` declared on the function `f` + | | + | consider giving this pattern the explicit type `fn() -> A`, where the type parameter `A` is specified + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0282`. From 7bafb5704d9727b3897f086d9f159e62bc40ce42 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 23 Apr 2020 18:14:01 -0300 Subject: [PATCH 2/7] normalize field projection ty to fix broken MIR issue --- src/librustc_mir/borrow_check/type_check/mod.rs | 1 + src/test/ui/consts/issue-70773-mir-typeck-lt-norm.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/librustc_mir/borrow_check/type_check/mod.rs b/src/librustc_mir/borrow_check/type_check/mod.rs index 796efd2bab976..8ed5993acbbfb 100644 --- a/src/librustc_mir/borrow_check/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/type_check/mod.rs @@ -686,6 +686,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> { let fty = self.sanitize_type(place, fty); match self.field_ty(place, base, field, location) { Ok(ty) => { + let ty = self.cx.normalize(ty, location); if let Err(terr) = self.cx.eq_types( ty, fty, diff --git a/src/test/ui/consts/issue-70773-mir-typeck-lt-norm.rs b/src/test/ui/consts/issue-70773-mir-typeck-lt-norm.rs index 07af83104241c..9d44aa1361cfc 100644 --- a/src/test/ui/consts/issue-70773-mir-typeck-lt-norm.rs +++ b/src/test/ui/consts/issue-70773-mir-typeck-lt-norm.rs @@ -7,6 +7,7 @@ fn init_hash(_: &mut [u8; HASH_LEN]) {} fn foo<'a>() -> &'a () { Hash([0; HASH_LEN]); init_hash(&mut [0; HASH_LEN]); + let (_array,) = ([0; HASH_LEN],); &() } From e82056aedc2ec8fcd133f5106232f8eb5e0792f2 Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Sun, 26 Apr 2020 15:57:38 +0200 Subject: [PATCH 3/7] remove obsolete comment --- src/librustc_mir/util/elaborate_drops.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/librustc_mir/util/elaborate_drops.rs b/src/librustc_mir/util/elaborate_drops.rs index 8286793b53230..43fa7b9922d74 100644 --- a/src/librustc_mir/util/elaborate_drops.rs +++ b/src/librustc_mir/util/elaborate_drops.rs @@ -835,13 +835,6 @@ where } } - /// Returns a basic block that drop a place using the context - /// and path in `c`. If `mode` is something, also clear `c` - /// according to it. - /// - /// if FLAG(self.path) - /// if let Some(mode) = mode: FLAG(self.path)[mode] = false - /// drop(self.place) fn complete_drop( &mut self, drop_mode: Option, From 230e40644b5c112228a0b43d07fda552133f00b8 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 24 Apr 2020 01:03:20 -0300 Subject: [PATCH 4/7] Fix off by one error for delay_span_bug delay_span_bug bumps error_count after checking treat_err_as_bug --- src/librustc_errors/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 151241fdb0b5f..e4a560e434aaa 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -869,7 +869,10 @@ impl HandlerInner { } fn delay_span_bug(&mut self, sp: impl Into, msg: &str) { - if self.treat_err_as_bug() { + // This is technically `self.treat_err_as_bug()` but `delay_span_bug` is called before + // incrementing `err_count` by one, so we need to +1 the comparing. + // FIXME: Would be nice to increment err_count in a more coherent way. + if self.flags.treat_err_as_bug.map(|c| self.err_count() + 1 >= c).unwrap_or(false) { // FIXME: don't abort here if report_delayed_bugs is off self.span_bug(sp, msg); } From 3fe280451bcc7dc2a2debf71a4d5747df0f0e0fd Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 24 Apr 2020 16:08:22 -0300 Subject: [PATCH 5/7] Add test for delay_span_bug and -Ztrear-err-as-bug --- src/test/run-make-fulldeps/treat-err-as-bug/Makefile | 2 ++ src/test/run-make-fulldeps/treat-err-as-bug/delay_span_bug.rs | 4 ++++ 2 files changed, 6 insertions(+) create mode 100644 src/test/run-make-fulldeps/treat-err-as-bug/delay_span_bug.rs diff --git a/src/test/run-make-fulldeps/treat-err-as-bug/Makefile b/src/test/run-make-fulldeps/treat-err-as-bug/Makefile index 9b3bcef2faf32..57cac76aec2a5 100644 --- a/src/test/run-make-fulldeps/treat-err-as-bug/Makefile +++ b/src/test/run-make-fulldeps/treat-err-as-bug/Makefile @@ -3,3 +3,5 @@ all: $(RUSTC) err.rs -Z treat-err-as-bug 2>&1 \ | $(CGREP) "panicked at 'aborting due to \`-Z treat-err-as-bug=1\`'" + $(RUSTC) delay_span_bug.rs -Z treat-err-as-bug 2>&1 \ + | $(CGREP) "panicked at 'aborting due to \`-Z treat-err-as-bug=1\`'" diff --git a/src/test/run-make-fulldeps/treat-err-as-bug/delay_span_bug.rs b/src/test/run-make-fulldeps/treat-err-as-bug/delay_span_bug.rs new file mode 100644 index 0000000000000..dad33e498b52f --- /dev/null +++ b/src/test/run-make-fulldeps/treat-err-as-bug/delay_span_bug.rs @@ -0,0 +1,4 @@ +#![feature(rustc_attrs)] + +#[rustc_error(delay_span_bug_from_inside_query)] +fn main() {} From 432ab343f8c75e657d25713addc2ee0cd5110542 Mon Sep 17 00:00:00 2001 From: Esteban Kuber Date: Mon, 27 Apr 2020 10:59:44 -0700 Subject: [PATCH 6/7] fix typo Co-Authored-By: varkor --- src/librustc_infer/infer/error_reporting/need_type_info.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_infer/infer/error_reporting/need_type_info.rs b/src/librustc_infer/infer/error_reporting/need_type_info.rs index 2b4aeb2138240..2ec16408465ef 100644 --- a/src/librustc_infer/infer/error_reporting/need_type_info.rs +++ b/src/librustc_infer/infer/error_reporting/need_type_info.rs @@ -248,7 +248,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { }; printer.name_resolver = Some(Box::new(&getter)); let _ = if let ty::FnDef(..) = ty.kind { - // We don't want the regular output for `fn`s because it inscludes its path in + // We don't want the regular output for `fn`s because it includes its path in // invalid pseduo-syntax, we want the `fn`-pointer output instead. ty.fn_sig(self.tcx).print(printer) } else { From 4d67c8da5563f7398dd7373b24bccd46c96ebb77 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Tue, 28 Apr 2020 13:02:58 +0300 Subject: [PATCH 7/7] Revert "Rollup merge of #71372 - ayushmishra2005:shebang_stripping, r=estebank" This reverts commit 46a8dcef5c9e4de0d412c6ac3c4765cb4aef4f7f, reversing changes made to f28e3873c55eb4bdcfc496e1f300b97aeb0d189c. --- src/librustc_lexer/src/lib.rs | 7 +------ src/librustc_lexer/src/tests.rs | 18 ------------------ 2 files changed, 1 insertion(+), 24 deletions(-) diff --git a/src/librustc_lexer/src/lib.rs b/src/librustc_lexer/src/lib.rs index be85a34bd395a..5ccfc1b276bfa 100644 --- a/src/librustc_lexer/src/lib.rs +++ b/src/librustc_lexer/src/lib.rs @@ -236,17 +236,12 @@ pub enum Base { /// (e.g. "#![deny(missing_docs)]"). pub fn strip_shebang(input: &str) -> Option { debug_assert!(!input.is_empty()); - let s: &str = &remove_whitespace(input); - if !s.starts_with("#!") || s.starts_with("#![") { + if !input.starts_with("#!") || input.starts_with("#![") { return None; } Some(input.find('\n').unwrap_or(input.len())) } -fn remove_whitespace(s: &str) -> String { - s.chars().filter(|c| !c.is_whitespace()).collect() -} - /// Parses the first token from the provided input string. pub fn first_token(input: &str) -> Token { debug_assert!(!input.is_empty()); diff --git a/src/librustc_lexer/src/tests.rs b/src/librustc_lexer/src/tests.rs index 065e8f3f646fb..06fc159fe2516 100644 --- a/src/librustc_lexer/src/tests.rs +++ b/src/librustc_lexer/src/tests.rs @@ -145,22 +145,4 @@ mod tests { }), ); } - - #[test] - fn test_valid_shebang() { - // https://github.com/rust-lang/rust/issues/70528 - let input = "#!/usr/bin/rustrun"; - let actual = strip_shebang(input); - let expected: Option = Some(18); - assert_eq!(expected, actual); - } - - #[test] - fn test_invalid_shebang_valid_rust_syntax() { - // https://github.com/rust-lang/rust/issues/70528 - let input = "#! [bad_attribute]"; - let actual = strip_shebang(input); - let expected: Option = None; - assert_eq!(expected, actual); - } }