From 53a870c5064b2fc31ec56dcdb74a7ad4e6c1736a Mon Sep 17 00:00:00 2001 From: Theodore Dubois Date: Fri, 8 Jul 2022 14:21:33 -0700 Subject: Stabilize backtrace --- compiler/rustc_errors/src/lib.rs | 1 - compiler/rustc_middle/src/lib.rs | 1 - 2 files changed, 2 deletions(-) (limited to 'compiler') diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index b173ac0e916..8640504835a 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -4,7 +4,6 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![feature(drain_filter)] -#![feature(backtrace)] #![feature(if_let_guard)] #![cfg_attr(bootstrap, feature(let_chains))] #![feature(let_else)] diff --git a/compiler/rustc_middle/src/lib.rs b/compiler/rustc_middle/src/lib.rs index 45c6468bc24..4e1254efd17 100644 --- a/compiler/rustc_middle/src/lib.rs +++ b/compiler/rustc_middle/src/lib.rs @@ -26,7 +26,6 @@ #![feature(allocator_api)] #![feature(array_windows)] #![feature(assert_matches)] -#![feature(backtrace)] #![feature(box_patterns)] #![feature(core_intrinsics)] #![feature(discriminant_kind)] -- cgit 1.4.1-3-g733a5 From 6d85bb953521039350a915a73033a2e46e1a8665 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Wed, 10 Aug 2022 02:29:28 +0900 Subject: suggest a missing semicolon before an array --- compiler/rustc_parse/src/parser/expr.rs | 42 ++++++++++++++++++++++ ...o-not-suggest-suggest-semicolon-before-array.rs | 8 +++++ ...t-suggest-suggest-semicolon-before-array.stderr | 10 ++++++ .../suggest-suggest-semicolon-before-array.fixed | 11 ++++++ .../suggest-suggest-semicolon-before-array.rs | 11 ++++++ .../suggest-suggest-semicolon-before-array.stderr | 13 +++++++ 6 files changed, 95 insertions(+) create mode 100644 src/test/ui/parser/do-not-suggest-suggest-semicolon-before-array.rs create mode 100644 src/test/ui/parser/do-not-suggest-suggest-semicolon-before-array.stderr create mode 100644 src/test/ui/parser/suggest-suggest-semicolon-before-array.fixed create mode 100644 src/test/ui/parser/suggest-suggest-semicolon-before-array.rs create mode 100644 src/test/ui/parser/suggest-suggest-semicolon-before-array.stderr (limited to 'compiler') diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index e473f4d30cf..b8bd960a5b3 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -1258,8 +1258,11 @@ impl<'a> Parser<'a> { /// Parse an indexing expression `expr[...]`. fn parse_index_expr(&mut self, lo: Span, base: P) -> PResult<'a, P> { + let prev_span = self.prev_token.span; + let open_delim_span = self.token.span; self.bump(); // `[` let index = self.parse_expr()?; + self.suggest_missing_semicolon_before_array(prev_span, open_delim_span)?; self.expect(&token::CloseDelim(Delimiter::Bracket))?; Ok(self.mk_expr(lo.to(self.prev_token.span), self.mk_index(base, index), AttrVec::new())) } @@ -2056,6 +2059,45 @@ impl<'a> Parser<'a> { } } + fn suggest_missing_semicolon_before_array( + &self, + prev_span: Span, + open_delim_span: Span, + ) -> PResult<'a, ()> { + if self.token.kind == token::Comma { + let mut snapshot = self.create_snapshot_for_diagnostic(); + snapshot.bump(); + match snapshot.parse_seq_to_before_end( + &token::CloseDelim(Delimiter::Bracket), + SeqSep::trailing_allowed(token::Comma), + |p| p.parse_expr(), + ) { + Ok(_) + // When the close delim is `)`, `token.kind` is expected to be `token::CloseDelim(Delimiter::Parenthesis)`, + // but the actual `token.kind` is `token::CloseDelim(Delimiter::Bracket)`. + // This is because the `token.kind` of the close delim is treated as the same as + // that of the open delim in `TokenTreesReader::parse_token_tree`, even if the delimiters of them are different. + // Therefore, `token.kind` should not be compared here. + if snapshot + .span_to_snippet(snapshot.token.span) + .map_or(false, |snippet| snippet == "]") => + { + let mut err = self.struct_span_err(open_delim_span, "expected `;`, found `[`"); + err.span_suggestion_verbose( + prev_span.shrink_to_hi(), + "consider adding `;` here", + ';', + Applicability::MaybeIncorrect, + ); + return Err(err); + } + Ok(_) => (), + Err(err) => err.cancel(), + } + } + Ok(()) + } + /// Parses a block or unsafe block. pub(super) fn parse_block_expr( &mut self, diff --git a/src/test/ui/parser/do-not-suggest-suggest-semicolon-before-array.rs b/src/test/ui/parser/do-not-suggest-suggest-semicolon-before-array.rs new file mode 100644 index 00000000000..7ebf3f6b0d8 --- /dev/null +++ b/src/test/ui/parser/do-not-suggest-suggest-semicolon-before-array.rs @@ -0,0 +1,8 @@ +fn foo() {} + +fn bar() -> [u8; 2] { + foo() + [1, 3) //~ ERROR expected one of `.`, `?`, `]`, or an operator, found `,` +} + +fn main() {} diff --git a/src/test/ui/parser/do-not-suggest-suggest-semicolon-before-array.stderr b/src/test/ui/parser/do-not-suggest-suggest-semicolon-before-array.stderr new file mode 100644 index 00000000000..d6e8db80329 --- /dev/null +++ b/src/test/ui/parser/do-not-suggest-suggest-semicolon-before-array.stderr @@ -0,0 +1,10 @@ +error: expected one of `.`, `?`, `]`, or an operator, found `,` + --> $DIR/do-not-suggest-suggest-semicolon-before-array.rs:5:5 + | +LL | [1, 3) + | ^ ^ help: `]` may belong here + | | + | unclosed delimiter + +error: aborting due to previous error + diff --git a/src/test/ui/parser/suggest-suggest-semicolon-before-array.fixed b/src/test/ui/parser/suggest-suggest-semicolon-before-array.fixed new file mode 100644 index 00000000000..a06b58b2740 --- /dev/null +++ b/src/test/ui/parser/suggest-suggest-semicolon-before-array.fixed @@ -0,0 +1,11 @@ +// run-rustfix +#![allow(dead_code)] + +fn foo() {} + +fn bar() -> [u8; 2] { + foo(); + [1, 3] //~ ERROR expected `;`, found `[` +} + +fn main() {} diff --git a/src/test/ui/parser/suggest-suggest-semicolon-before-array.rs b/src/test/ui/parser/suggest-suggest-semicolon-before-array.rs new file mode 100644 index 00000000000..f601ca2aef5 --- /dev/null +++ b/src/test/ui/parser/suggest-suggest-semicolon-before-array.rs @@ -0,0 +1,11 @@ +// run-rustfix +#![allow(dead_code)] + +fn foo() {} + +fn bar() -> [u8; 2] { + foo() + [1, 3] //~ ERROR expected `;`, found `[` +} + +fn main() {} diff --git a/src/test/ui/parser/suggest-suggest-semicolon-before-array.stderr b/src/test/ui/parser/suggest-suggest-semicolon-before-array.stderr new file mode 100644 index 00000000000..bf86b43554d --- /dev/null +++ b/src/test/ui/parser/suggest-suggest-semicolon-before-array.stderr @@ -0,0 +1,13 @@ +error: expected `;`, found `[` + --> $DIR/suggest-suggest-semicolon-before-array.rs:8:5 + | +LL | [1, 3] + | ^ + | +help: consider adding `;` here + | +LL | foo(); + | + + +error: aborting due to previous error + -- cgit 1.4.1-3-g733a5 From fda5144ceb2be07501febbbccc10172b4ea737cd Mon Sep 17 00:00:00 2001 From: Daniel Paoliello Date: Tue, 2 Aug 2022 10:33:27 -0700 Subject: Add error if link_ordinal used without raw-dylib --- compiler/rustc_metadata/src/native_libs.rs | 26 +++++++++++++++++++++- .../link-ordinal-unsupported-link-kind.rs | 18 +++++++++++++++ .../link-ordinal-unsupported-link-kind.stderr | 23 +++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/rfc-2627-raw-dylib/link-ordinal-unsupported-link-kind.rs create mode 100644 src/test/ui/rfc-2627-raw-dylib/link-ordinal-unsupported-link-kind.stderr (limited to 'compiler') diff --git a/compiler/rustc_metadata/src/native_libs.rs b/compiler/rustc_metadata/src/native_libs.rs index 9f6079ecba4..c5e39507d7e 100644 --- a/compiler/rustc_metadata/src/native_libs.rs +++ b/compiler/rustc_metadata/src/native_libs.rs @@ -328,7 +328,31 @@ impl<'tcx> Collector<'tcx> { .map(|child_item| self.build_dll_import(abi, child_item)) .collect() } - _ => Vec::new(), + _ => { + for child_item in foreign_mod_items { + if self.tcx.def_kind(child_item.id.def_id).has_codegen_attrs() + && self + .tcx + .codegen_fn_attrs(child_item.id.def_id) + .link_ordinal + .is_some() + { + let link_ordinal_attr = self + .tcx + .hir() + .attrs(self.tcx.hir().local_def_id_to_hir_id(child_item.id.def_id)) + .iter() + .find(|a| a.has_name(sym::link_ordinal)) + .unwrap(); + sess.span_err( + link_ordinal_attr.span, + "`#[link_ordinal]` is only supported if link kind is `raw-dylib`", + ); + } + } + + Vec::new() + } }; self.libs.push(NativeLib { name: name.map(|(name, _)| name), diff --git a/src/test/ui/rfc-2627-raw-dylib/link-ordinal-unsupported-link-kind.rs b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-unsupported-link-kind.rs new file mode 100644 index 00000000000..99f317399d7 --- /dev/null +++ b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-unsupported-link-kind.rs @@ -0,0 +1,18 @@ +#![feature(raw_dylib)] +//~^ WARN the feature `raw_dylib` is incomplete + +#[link(name = "foo")] +extern "C" { + #[link_ordinal(3)] + //~^ ERROR `#[link_ordinal]` is only supported if link kind is `raw-dylib` + fn foo(); +} + +#[link(name = "bar", kind = "static")] +extern "C" { + #[link_ordinal(3)] + //~^ ERROR `#[link_ordinal]` is only supported if link kind is `raw-dylib` + fn bar(); +} + +fn main() {} diff --git a/src/test/ui/rfc-2627-raw-dylib/link-ordinal-unsupported-link-kind.stderr b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-unsupported-link-kind.stderr new file mode 100644 index 00000000000..f1eeb22da59 --- /dev/null +++ b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-unsupported-link-kind.stderr @@ -0,0 +1,23 @@ +warning: the feature `raw_dylib` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/link-ordinal-unsupported-link-kind.rs:1:12 + | +LL | #![feature(raw_dylib)] + | ^^^^^^^^^ + | + = note: `#[warn(incomplete_features)]` on by default + = note: see issue #58713 for more information + +error: `#[link_ordinal]` is only supported if link kind is `raw-dylib` + --> $DIR/link-ordinal-unsupported-link-kind.rs:6:5 + | +LL | #[link_ordinal(3)] + | ^^^^^^^^^^^^^^^^^^ + +error: `#[link_ordinal]` is only supported if link kind is `raw-dylib` + --> $DIR/link-ordinal-unsupported-link-kind.rs:13:5 + | +LL | #[link_ordinal(3)] + | ^^^^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors; 1 warning emitted + -- cgit 1.4.1-3-g733a5 From 457ff7c56cedbf67e7716d88762595ed73d75077 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 9 Aug 2022 16:33:19 -0300 Subject: Iterate def_ids map backwards to try first the latest mappings (it's a stack) --- compiler/rustc_ast_lowering/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'compiler') diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 0562f7b88a3..46f2a435669 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -220,7 +220,7 @@ impl ResolverAstLoweringExt for ResolverAstLowering { } fn get_remapped_def_id(&self, mut local_def_id: LocalDefId) -> LocalDefId { - for map in &self.generics_def_id_map { + for map in self.generics_def_id_map.iter().rev() { if let Some(r) = map.get(&local_def_id) { debug!("def_id_remapper: remapping from `{local_def_id:?}` to `{r:?}`"); local_def_id = *r; -- cgit 1.4.1-3-g733a5 From 750a04ea7fabd46b6156e32b1e910a06daf8c33c Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 9 Aug 2022 16:39:02 -0300 Subject: Add docs for get_remapped_def_id --- compiler/rustc_ast_lowering/src/lib.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'compiler') diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 46f2a435669..38d30d0ffde 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -220,6 +220,19 @@ impl ResolverAstLoweringExt for ResolverAstLowering { } fn get_remapped_def_id(&self, mut local_def_id: LocalDefId) -> LocalDefId { + // `generics_def_id_map` is a stack of mappings. As we go deeper in impl traits nesting we + // push new mappings so we need to try first the latest mappings, hence `iter().rev()`. + // + // Consider: + // + // `fn test<'a, 'b>() -> impl Trait<&'a u8, Ty = impl Sized + 'b> {}` + // + // We would end with a generics_def_id_map like: + // + // `[[fn#'b -> impl_trait#'b], [fn#'b -> impl_sized#'b]]` + // + // for the opaque type generated on `impl Sized + 'b`, We want the result to be: + // impl_sized#'b, so iterating forward is the wrong thing to do. for map in self.generics_def_id_map.iter().rev() { if let Some(r) = map.get(&local_def_id) { debug!("def_id_remapper: remapping from `{local_def_id:?}` to `{r:?}`"); -- cgit 1.4.1-3-g733a5