From 1d9481fdc80ecc7a33f703684ec0b6cbe56a79b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=C4=9Fuz=20A=C4=9Fcayaz=C4=B1?= Date: Wed, 11 Oct 2023 12:44:59 +0300 Subject: [PATCH 1/6] implement get_filename/lines for span --- compiler/rustc_smir/src/rustc_smir/mod.rs | 32 ++++++++++++++++++++++- compiler/stable_mir/src/lib.rs | 17 ++++++++---- compiler/stable_mir/src/ty.rs | 23 +++++++++++++++- 3 files changed, 65 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_smir/src/rustc_smir/mod.rs b/compiler/rustc_smir/src/rustc_smir/mod.rs index 2a265fc1f5bc0..0bf6dabc75e7e 100644 --- a/compiler/rustc_smir/src/rustc_smir/mod.rs +++ b/compiler/rustc_smir/src/rustc_smir/mod.rs @@ -18,7 +18,7 @@ use rustc_span::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc_target::abi::FieldIdx; use stable_mir::mir::{CopyNonOverlapping, Statement, UserTypeProjection, VariantIdx}; use stable_mir::ty::{FloatTy, GenericParamDef, IntTy, Movability, RigidTy, Span, TyKind, UintTy}; -use stable_mir::{self, opaque, Context}; +use stable_mir::{self, opaque, Context, Filename}; use tracing::debug; mod alloc; @@ -54,6 +54,36 @@ impl<'tcx> Context for Tables<'tcx> { self.tcx.sess.source_map().span_to_diagnostic_string(self[span]) } + fn get_filename(&self, span: &Span) -> Filename { + opaque( + &self + .tcx + .sess + .source_map() + .span_to_filename(self[*span]) + .display(rustc_span::FileNameDisplayPreference::Short) + .to_string(), + ) + } + + fn get_lines(&self, span: &Span) -> Vec { + let lines = &self + .tcx + .sess + .source_map() + .span_to_lines(self[*span]) + .unwrap() + .lines + .iter() + .map(|line| stable_mir::ty::LineInfo { + line_index: line.line_index + 1, + start_col: line.start_col.0 + 1, + end_col: line.end_col.0 + 1, + }) + .collect::>(); + lines.to_vec() + } + fn def_kind(&mut self, def_id: stable_mir::DefId) -> stable_mir::DefKind { self.tcx.def_kind(self[def_id]).stable(self) } diff --git a/compiler/stable_mir/src/lib.rs b/compiler/stable_mir/src/lib.rs index f371f46204fe4..8ff2f16327a87 100644 --- a/compiler/stable_mir/src/lib.rs +++ b/compiler/stable_mir/src/lib.rs @@ -22,8 +22,8 @@ use std::fmt; use std::fmt::Debug; use self::ty::{ - GenericPredicates, Generics, ImplDef, ImplTrait, IndexedVal, Span, TraitDecl, TraitDef, Ty, - TyKind, + GenericPredicates, Generics, ImplDef, ImplTrait, IndexedVal, LineInfo, Span, TraitDecl, + TraitDef, Ty, TyKind, }; #[macro_use] @@ -108,6 +108,7 @@ pub struct Crate { } pub type DefKind = Opaque; +pub type Filename = Opaque; /// Holds information about an item in the crate. /// For now, it only stores the item DefId. Use functions inside `rustc_internal` module to @@ -196,13 +197,19 @@ pub trait Context { /// Find a crate with the given name. fn find_crates(&self, name: &str) -> Vec; - /// Prints the name of given `DefId` + /// Returns the name of given `DefId` fn name_of_def_id(&self, def_id: DefId) -> String; - /// Prints a human readable form of `Span` + /// Returns printable, human readable form of `Span` fn print_span(&self, span: Span) -> String; - /// Prints the kind of given `DefId` + /// Return filename from given `Span`, for diagnostic purposes + fn get_filename(&self, span: &Span) -> Filename; + + /// Return lines corresponding to this `Span` + fn get_lines(&self, span: &Span) -> Vec; + + /// Returns the `kind` of given `DefId` fn def_kind(&mut self, def_id: DefId) -> DefKind; /// `Span` of an item diff --git a/compiler/stable_mir/src/ty.rs b/compiler/stable_mir/src/ty.rs index 691af15da8ca8..83d1fc5bc4f36 100644 --- a/compiler/stable_mir/src/ty.rs +++ b/compiler/stable_mir/src/ty.rs @@ -3,7 +3,7 @@ use super::{ mir::{Body, Mutability}, with, AllocId, DefId, Symbol, }; -use crate::Opaque; +use crate::{Filename, Opaque}; use std::fmt::{self, Debug, Formatter}; #[derive(Copy, Clone)] @@ -86,6 +86,27 @@ impl Debug for Span { } } +impl Span { + /// Return filename for diagnostic purposes + pub fn get_filename(&self) -> Filename { + with(|c| c.get_filename(self)) + } + + /// Return lines that corespond to this `Span` + pub fn get_lines(&self) -> Vec { + with(|c| c.get_lines(&self)) + } +} + +#[derive(Clone, Copy, Debug)] +/// Information you get from `Span` in a struct form. +/// Line and col start from 1. +pub struct LineInfo { + pub line_index: usize, + pub start_col: usize, + pub end_col: usize, +} + impl IndexedVal for Span { fn to_val(index: usize) -> Self { Span(index) From 71bc63c3968f6f5d048a0033fa8000297a488c90 Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Thu, 12 Oct 2023 00:34:09 +0300 Subject: [PATCH 2/6] remove outdated bootstrap FIXME Signed-off-by: onur-ozkan --- src/bootstrap/test.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index ba030f0f5251d..0447d5652d9e8 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -2940,10 +2940,6 @@ impl Step for TestHelpers { let _guard = builder.msg_unstaged(Kind::Build, "test helpers", target); t!(fs::create_dir_all(&dst)); let mut cfg = cc::Build::new(); - // FIXME: Workaround for https://github.com/emscripten-core/emscripten/issues/9013 - if target.contains("emscripten") { - cfg.pic(false); - } // We may have found various cross-compilers a little differently due to our // extra configuration, so inform cc of these compilers. Note, though, that From d6a55d3409e9e875e6d65ad5daecee4c7ea8449b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=C4=9Fuz=20A=C4=9Fcayaz=C4=B1?= Date: Fri, 13 Oct 2023 11:44:38 +0300 Subject: [PATCH 3/6] change fn name, return loc info, local name --- compiler/rustc_smir/src/rustc_smir/mod.rs | 27 +++++++---------------- compiler/stable_mir/src/lib.rs | 4 ++-- compiler/stable_mir/src/ty.rs | 7 +++--- 3 files changed, 14 insertions(+), 24 deletions(-) diff --git a/compiler/rustc_smir/src/rustc_smir/mod.rs b/compiler/rustc_smir/src/rustc_smir/mod.rs index 0bf6dabc75e7e..f26d18ad38f23 100644 --- a/compiler/rustc_smir/src/rustc_smir/mod.rs +++ b/compiler/rustc_smir/src/rustc_smir/mod.rs @@ -17,7 +17,9 @@ use rustc_middle::ty::{self, Ty, TyCtxt, Variance}; use rustc_span::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc_target::abi::FieldIdx; use stable_mir::mir::{CopyNonOverlapping, Statement, UserTypeProjection, VariantIdx}; -use stable_mir::ty::{FloatTy, GenericParamDef, IntTy, Movability, RigidTy, Span, TyKind, UintTy}; +use stable_mir::ty::{ + FloatTy, GenericParamDef, IntTy, LineInfo, Movability, RigidTy, Span, TyKind, UintTy, +}; use stable_mir::{self, opaque, Context, Filename}; use tracing::debug; @@ -50,7 +52,7 @@ impl<'tcx> Context for Tables<'tcx> { self.tcx.def_path_str(self[def_id]) } - fn print_span(&self, span: stable_mir::ty::Span) -> String { + fn span_to_string(&self, span: stable_mir::ty::Span) -> String { self.tcx.sess.source_map().span_to_diagnostic_string(self[span]) } @@ -61,27 +63,14 @@ impl<'tcx> Context for Tables<'tcx> { .sess .source_map() .span_to_filename(self[*span]) - .display(rustc_span::FileNameDisplayPreference::Short) + .display(rustc_span::FileNameDisplayPreference::Local) .to_string(), ) } - fn get_lines(&self, span: &Span) -> Vec { - let lines = &self - .tcx - .sess - .source_map() - .span_to_lines(self[*span]) - .unwrap() - .lines - .iter() - .map(|line| stable_mir::ty::LineInfo { - line_index: line.line_index + 1, - start_col: line.start_col.0 + 1, - end_col: line.end_col.0 + 1, - }) - .collect::>(); - lines.to_vec() + fn get_lines(&self, span: &Span) -> LineInfo { + let lines = &self.tcx.sess.source_map().span_to_location_info(self[*span]); + LineInfo { start_line: lines.1, start_col: lines.2, end_line: lines.3, end_col: lines.4 } } fn def_kind(&mut self, def_id: stable_mir::DefId) -> stable_mir::DefKind { diff --git a/compiler/stable_mir/src/lib.rs b/compiler/stable_mir/src/lib.rs index 8ff2f16327a87..a3b05f2435eb6 100644 --- a/compiler/stable_mir/src/lib.rs +++ b/compiler/stable_mir/src/lib.rs @@ -201,13 +201,13 @@ pub trait Context { fn name_of_def_id(&self, def_id: DefId) -> String; /// Returns printable, human readable form of `Span` - fn print_span(&self, span: Span) -> String; + fn span_to_string(&self, span: Span) -> String; /// Return filename from given `Span`, for diagnostic purposes fn get_filename(&self, span: &Span) -> Filename; /// Return lines corresponding to this `Span` - fn get_lines(&self, span: &Span) -> Vec; + fn get_lines(&self, span: &Span) -> LineInfo; /// Returns the `kind` of given `DefId` fn def_kind(&mut self, def_id: DefId) -> DefKind; diff --git a/compiler/stable_mir/src/ty.rs b/compiler/stable_mir/src/ty.rs index 83d1fc5bc4f36..003045a4696d5 100644 --- a/compiler/stable_mir/src/ty.rs +++ b/compiler/stable_mir/src/ty.rs @@ -81,7 +81,7 @@ impl Debug for Span { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { f.debug_struct("Span") .field("id", &self.0) - .field("repr", &with(|cx| cx.print_span(*self))) + .field("repr", &with(|cx| cx.span_to_string(*self))) .finish() } } @@ -93,7 +93,7 @@ impl Span { } /// Return lines that corespond to this `Span` - pub fn get_lines(&self) -> Vec { + pub fn get_lines(&self) -> LineInfo { with(|c| c.get_lines(&self)) } } @@ -102,8 +102,9 @@ impl Span { /// Information you get from `Span` in a struct form. /// Line and col start from 1. pub struct LineInfo { - pub line_index: usize, + pub start_line: usize, pub start_col: usize, + pub end_line: usize, pub end_col: usize, } From eae6e02ebaf5a6c257dd72985bdb6079448b3c33 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Fri, 13 Oct 2023 12:57:38 +0000 Subject: [PATCH 4/6] Fix a comment --- compiler/rustc_hir_analysis/src/collect/predicates_of.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs index 1298c08608716..b5b9cf5ae6cfd 100644 --- a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs @@ -180,7 +180,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen // // default impl Foo for Bar { .. } // - // we add a default where clause `Foo: Bar`. We do a similar thing for traits + // we add a default where clause `Bar: Foo`. We do a similar thing for traits // (see below). Recall that a default impl is not itself an impl, but rather a // set of defaults that can be incorporated into another impl. if let Some(trait_ref) = is_default_impl_trait { From 6b59f6fbeaacf066ee0167f6cf48aa8eab467659 Mon Sep 17 00:00:00 2001 From: Caio Date: Fri, 13 Oct 2023 10:22:33 -0300 Subject: [PATCH 5/6] Misc improvements --- compiler/rustc_ast/src/token.rs | 27 ++++++++++++++++++++++++ compiler/rustc_builtin_macros/src/lib.rs | 14 ++++++------ 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_ast/src/token.rs b/compiler/rustc_ast/src/token.rs index 300b1486f9ba0..04baed15a37ed 100644 --- a/compiler/rustc_ast/src/token.rs +++ b/compiler/rustc_ast/src/token.rs @@ -229,35 +229,61 @@ fn ident_can_begin_type(name: Symbol, span: Span, is_raw: bool) -> bool { #[derive(PartialEq, Encodable, Decodable, Debug, HashStable_Generic)] pub enum TokenKind { /* Expression-operator symbols. */ + /// `=` Eq, + /// `<` Lt, + /// `<=` Le, + /// `==` EqEq, + /// `!=` Ne, + /// `>` Ge, + /// `>=` Gt, + /// `&&` AndAnd, + /// `||` OrOr, + /// `!` Not, + /// `~` Tilde, BinOp(BinOpToken), BinOpEq(BinOpToken), /* Structural symbols */ + /// `@` At, + /// `.` Dot, + /// `..` DotDot, + /// `...` DotDotDot, + /// `..=` DotDotEq, + /// `,` Comma, + /// `;` Semi, + /// `:` Colon, + /// `::` ModSep, + /// `->` RArrow, + /// `<-` LArrow, + /// `=>` FatArrow, + /// `#` Pound, + /// `$` Dollar, + /// `?` Question, /// Used by proc macros for representing lifetimes, not generated by lexer right now. SingleQuote, @@ -296,6 +322,7 @@ pub enum TokenKind { /// similarly to symbols in string literal tokens. DocComment(CommentKind, ast::AttrStyle, Symbol), + /// End Of File Eof, } diff --git a/compiler/rustc_builtin_macros/src/lib.rs b/compiler/rustc_builtin_macros/src/lib.rs index ebf1448f55c99..35b615697f73b 100644 --- a/compiler/rustc_builtin_macros/src/lib.rs +++ b/compiler/rustc_builtin_macros/src/lib.rs @@ -71,33 +71,35 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) { } register_bang! { + // tidy-alphabetical-start asm: asm::expand_asm, assert: assert::expand_assert, cfg: cfg::expand_cfg, column: source_util::expand_column, compile_error: compile_error::expand_compile_error, + concat: concat::expand_concat, concat_bytes: concat_bytes::expand_concat_bytes, concat_idents: concat_idents::expand_concat_idents, - concat: concat::expand_concat, + const_format_args: format::expand_format_args, + core_panic: edition_panic::expand_panic, env: env::expand_env, file: source_util::expand_file, - format_args_nl: format::expand_format_args_nl, format_args: format::expand_format_args, - const_format_args: format::expand_format_args, + format_args_nl: format::expand_format_args_nl, global_asm: asm::expand_global_asm, + include: source_util::expand_include, include_bytes: source_util::expand_include_bytes, include_str: source_util::expand_include_str, - include: source_util::expand_include, line: source_util::expand_line, log_syntax: log_syntax::expand_log_syntax, module_path: source_util::expand_mod, option_env: env::expand_option_env, - core_panic: edition_panic::expand_panic, std_panic: edition_panic::expand_panic, - unreachable: edition_panic::expand_unreachable, stringify: source_util::expand_stringify, trace_macros: trace_macros::expand_trace_macros, type_ascribe: type_ascribe::expand_type_ascribe, + unreachable: edition_panic::expand_unreachable, + // tidy-alphabetical-end } register_attr! { From 362b75badfca2515ccbfdad7c0738017e449c1c0 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 13 Oct 2023 19:11:16 +0000 Subject: [PATCH 6/6] Fix AFIT lint message to mention pitfall --- compiler/rustc_lint/messages.ftl | 2 +- tests/ui/async-await/in-trait/warn.stderr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_lint/messages.ftl b/compiler/rustc_lint/messages.ftl index fa4b8e4c36b84..197fe6552d796 100644 --- a/compiler/rustc_lint/messages.ftl +++ b/compiler/rustc_lint/messages.ftl @@ -7,7 +7,7 @@ lint_array_into_iter = lint_async_fn_in_trait = use of `async fn` in public traits is discouraged as auto trait bounds cannot be specified .note = you can suppress this lint if you plan to use the trait only in your own code, or do not care about auto traits like `Send` on the `Future` - .suggestion = you can alternatively desugar to a normal `fn` that returns `impl Future` and add any desired bounds such as `Send` + .suggestion = you can alternatively desugar to a normal `fn` that returns `impl Future` and add any desired bounds such as `Send`, but these cannot be relaxed without a breaking API change lint_atomic_ordering_fence = memory fences cannot have `Relaxed` ordering .help = consider using ordering modes `Acquire`, `Release`, `AcqRel` or `SeqCst` diff --git a/tests/ui/async-await/in-trait/warn.stderr b/tests/ui/async-await/in-trait/warn.stderr index eac41a6e92425..7cc64dff4b609 100644 --- a/tests/ui/async-await/in-trait/warn.stderr +++ b/tests/ui/async-await/in-trait/warn.stderr @@ -10,7 +10,7 @@ note: the lint level is defined here | LL | #![deny(async_fn_in_trait)] | ^^^^^^^^^^^^^^^^^ -help: you can alternatively desugar to a normal `fn` that returns `impl Future` and add any desired bounds such as `Send` +help: you can alternatively desugar to a normal `fn` that returns `impl Future` and add any desired bounds such as `Send`, but these cannot be relaxed without a breaking API change | LL - async fn not_send(); LL + fn not_send() -> impl std::future::Future + Send;