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); } 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 1986838e4016c..93c8e505697b4 100644 --- a/src/librustc_infer/infer/error_reporting/need_type_info.rs +++ b/src/librustc_infer/infer/error_reporting/need_type_info.rs @@ -257,7 +257,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 includes 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/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); - } } diff --git a/src/librustc_mir/borrow_check/type_check/mod.rs b/src/librustc_mir/borrow_check/type_check/mod.rs index d60ab2b81fd4d..7f554742777e2 100644 --- a/src/librustc_mir/borrow_check/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/type_check/mod.rs @@ -689,6 +689,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/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, 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() {} 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],); &() } 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`.