From 90f891d8ae9073623769fac18f00c4f1031fcb59 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 3 Nov 2019 14:58:01 +0300 Subject: syntax: Avoid span arithmetics for delimiter tokens --- src/libsyntax/parse/parser.rs | 4 ++-- src/libsyntax/tokenstream.rs | 20 +++++--------------- 2 files changed, 7 insertions(+), 17 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 6ead1ce811d..bce36d259ac 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -210,12 +210,12 @@ impl TokenCursor { loop { let tree = if !self.frame.open_delim { self.frame.open_delim = true; - TokenTree::open_tt(self.frame.span.open, self.frame.delim) + TokenTree::open_tt(self.frame.span, self.frame.delim) } else if let Some(tree) = self.frame.tree_cursor.next() { tree } else if !self.frame.close_delim { self.frame.close_delim = true; - TokenTree::close_tt(self.frame.span.close, self.frame.delim) + TokenTree::close_tt(self.frame.span, self.frame.delim) } else if let Some(frame) = self.stack.pop() { self.frame = frame; continue diff --git a/src/libsyntax/tokenstream.rs b/src/libsyntax/tokenstream.rs index 0559f224f1f..7e0582797c7 100644 --- a/src/libsyntax/tokenstream.rs +++ b/src/libsyntax/tokenstream.rs @@ -15,7 +15,7 @@ use crate::parse::token::{self, DelimToken, Token, TokenKind}; -use syntax_pos::{BytePos, Span, DUMMY_SP}; +use syntax_pos::{Span, DUMMY_SP}; #[cfg(target_arch = "x86_64")] use rustc_data_structures::static_assert_size; use rustc_data_structures::sync::Lrc; @@ -110,23 +110,13 @@ impl TokenTree { } /// Returns the opening delimiter as a token tree. - pub fn open_tt(span: Span, delim: DelimToken) -> TokenTree { - let open_span = if span.is_dummy() { - span - } else { - span.with_hi(span.lo() + BytePos(delim.len() as u32)) - }; - TokenTree::token(token::OpenDelim(delim), open_span) + pub fn open_tt(span: DelimSpan, delim: DelimToken) -> TokenTree { + TokenTree::token(token::OpenDelim(delim), span.open) } /// Returns the closing delimiter as a token tree. - pub fn close_tt(span: Span, delim: DelimToken) -> TokenTree { - let close_span = if span.is_dummy() { - span - } else { - span.with_lo(span.hi() - BytePos(delim.len() as u32)) - }; - TokenTree::token(token::CloseDelim(delim), close_span) + pub fn close_tt(span: DelimSpan, delim: DelimToken) -> TokenTree { + TokenTree::token(token::CloseDelim(delim), span.close) } } -- cgit 1.4.1-3-g733a5 From d06a4ded13b948a6a5b546514ccc7009097f145a Mon Sep 17 00:00:00 2001 From: Andy Russell Date: Sun, 3 Nov 2019 12:04:01 -0500 Subject: use silent emitter for rustdoc highlighting pass --- src/librustc_errors/emitter.rs | 8 ++++ src/librustc_interface/interface.rs | 14 +------ src/librustdoc/html/highlight.rs | 4 +- src/libsyntax/sess.rs | 8 +++- src/test/rustdoc-ui/invalid-syntax.stderr | 64 ------------------------------- 5 files changed, 19 insertions(+), 79 deletions(-) (limited to 'src/libsyntax') diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index b153f0f0e82..5f74df13fae 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -424,6 +424,14 @@ impl Emitter for EmitterWriter { } } +/// An emitter that does nothing when emitting a diagnostic. +pub struct SilentEmitter; + +impl Emitter for SilentEmitter { + fn source_map(&self) -> Option<&Lrc> { None } + fn emit_diagnostic(&mut self, _: &Diagnostic) {} +} + /// maximum number of lines we will print for each error; arbitrary. pub const MAX_HIGHLIGHT_LINES: usize = 6; /// maximum number of suggestions to be shown diff --git a/src/librustc_interface/interface.rs b/src/librustc_interface/interface.rs index e014e4ed0fd..4e4d6d982fb 100644 --- a/src/librustc_interface/interface.rs +++ b/src/librustc_interface/interface.rs @@ -17,10 +17,9 @@ use std::sync::{Arc, Mutex}; use syntax::{self, parse}; use syntax::ast::{self, MetaItemKind}; use syntax::parse::token; -use syntax::source_map::{FileName, FilePathMapping, FileLoader, SourceMap}; +use syntax::source_map::{FileName, FileLoader, SourceMap}; use syntax::sess::ParseSess; use syntax_pos::edition; -use rustc_errors::{Diagnostic, emitter::Emitter, Handler, SourceMapperDyn}; pub type Result = result::Result; @@ -63,18 +62,9 @@ impl Compiler { /// Converts strings provided as `--cfg [cfgspec]` into a `crate_cfg`. pub fn parse_cfgspecs(cfgspecs: Vec) -> FxHashSet<(String, Option)> { - struct NullEmitter; - impl Emitter for NullEmitter { - fn emit_diagnostic(&mut self, _: &Diagnostic) {} - fn source_map(&self) -> Option<&Lrc> { None } - } - syntax::with_default_globals(move || { let cfg = cfgspecs.into_iter().map(|s| { - - let cm = Lrc::new(SourceMap::new(FilePathMapping::empty())); - let handler = Handler::with_emitter(false, None, Box::new(NullEmitter)); - let sess = ParseSess::with_span_handler(handler, cm); + let sess = ParseSess::with_silent_emitter(); let filename = FileName::cfg_spec_source_code(&s); let mut parser = parse::new_parser_from_source_str(&sess, filename, s.to_string()); diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs index 30c9453a643..88ba13f2796 100644 --- a/src/librustdoc/html/highlight.rs +++ b/src/librustdoc/html/highlight.rs @@ -11,7 +11,7 @@ use std::fmt::Display; use std::io; use std::io::prelude::*; -use syntax::source_map::{SourceMap, FilePathMapping}; +use syntax::source_map::SourceMap; use syntax::parse::lexer; use syntax::parse::token::{self, Token}; use syntax::sess::ParseSess; @@ -33,7 +33,7 @@ pub fn render_with_highlighting( class, tooltip).unwrap(); } - let sess = ParseSess::new(FilePathMapping::empty()); + let sess = ParseSess::with_silent_emitter(); let fm = sess.source_map().new_source_file( FileName::Custom(String::from("rustdoc-highlighting")), src.to_owned(), diff --git a/src/libsyntax/sess.rs b/src/libsyntax/sess.rs index 28a0868d5dd..2251c3961db 100644 --- a/src/libsyntax/sess.rs +++ b/src/libsyntax/sess.rs @@ -6,7 +6,7 @@ use crate::early_buffered_lints::{BufferedEarlyLint, BufferedEarlyLintId}; use crate::source_map::{SourceMap, FilePathMapping}; use crate::feature_gate::UnstableFeatures; -use errors::{Applicability, Handler, ColorConfig, DiagnosticBuilder}; +use errors::{Applicability, emitter::SilentEmitter, Handler, ColorConfig, DiagnosticBuilder}; use rustc_data_structures::fx::{FxHashSet, FxHashMap}; use rustc_data_structures::sync::{Lrc, Lock, Once}; use syntax_pos::{Symbol, Span, MultiSpan}; @@ -104,6 +104,12 @@ impl ParseSess { } } + pub fn with_silent_emitter() -> Self { + let cm = Lrc::new(SourceMap::new(FilePathMapping::empty())); + let handler = Handler::with_emitter(false, None, Box::new(SilentEmitter)); + ParseSess::with_span_handler(handler, cm) + } + #[inline] pub fn source_map(&self) -> &SourceMap { &self.source_map diff --git a/src/test/rustdoc-ui/invalid-syntax.stderr b/src/test/rustdoc-ui/invalid-syntax.stderr index 8ec4338e13f..84c10028fd1 100644 --- a/src/test/rustdoc-ui/invalid-syntax.stderr +++ b/src/test/rustdoc-ui/invalid-syntax.stderr @@ -222,67 +222,3 @@ warning: could not parse code block as Rust code LL | /// \____/ | ^^^^^^ -error: unknown start of token: \ - --> :1:1 - | -1 | \____/ - | ^ - -error: unknown start of token: \ - --> :1:1 - | -1 | \_ - | ^ - -error: unknown start of token: \ - --> :1:1 - | -1 | \_ - | ^ - -error: unknown start of token: ` - --> :1:1 - | -1 | ``` - | ^ - | -help: Unicode character '`' (Grave Accent) looks like ''' (Single Quote), but it is not - | -1 | '`` - | ^ - -error: unknown start of token: \ - --> :2:1 - | -2 | \_ - | ^ - -error: unknown start of token: \ - --> :1:1 - | -1 | \_ - | ^ - -error: unknown start of token: \ - --> :1:1 - | -1 | \_ - | ^ - -error: unknown start of token: ` - --> :3:30 - | -3 | | ^^^^^^ did you mean `baz::foobar`? - | ^ - | -help: Unicode character '`' (Grave Accent) looks like ''' (Single Quote), but it is not - | -3 | | ^^^^^^ did you mean 'baz::foobar`? - | ^ - -error: unknown start of token: \ - --> :1:1 - | -1 | \__________pkt->size___________/ \_result->size_/ \__pkt->size__/ - | ^ - -- cgit 1.4.1-3-g733a5 From 3bbfc7320ba0f23541f94a84cf5281a210a546cd Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Mon, 4 Nov 2019 16:19:55 -0800 Subject: Detect `::` -> `:` typo when involving turbofish --- src/libsyntax/parse/parser/diagnostics.rs | 3 ++- src/libsyntax/parse/parser/stmt.rs | 1 + .../ui/suggestions/type-ascription-instead-of-path-2.rs | 5 +++++ .../ui/suggestions/type-ascription-instead-of-path-2.stderr | 13 +++++++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/suggestions/type-ascription-instead-of-path-2.rs create mode 100644 src/test/ui/suggestions/type-ascription-instead-of-path-2.stderr (limited to 'src/libsyntax') diff --git a/src/libsyntax/parse/parser/diagnostics.rs b/src/libsyntax/parse/parser/diagnostics.rs index ab2b4519cb7..ad479e6278b 100644 --- a/src/libsyntax/parse/parser/diagnostics.rs +++ b/src/libsyntax/parse/parser/diagnostics.rs @@ -354,7 +354,7 @@ impl<'a> Parser<'a> { } pub fn maybe_annotate_with_ascription( - &self, + &mut self, err: &mut DiagnosticBuilder<'_>, maybe_expected_semicolon: bool, ) { @@ -395,6 +395,7 @@ impl<'a> Parser<'a> { err.note("for more information, see \ https://github.com/rust-lang/rust/issues/23416"); } + self.last_type_ascription = None; } } diff --git a/src/libsyntax/parse/parser/stmt.rs b/src/libsyntax/parse/parser/stmt.rs index 4f51fefe66f..12c530f3cbb 100644 --- a/src/libsyntax/parse/parser/stmt.rs +++ b/src/libsyntax/parse/parser/stmt.rs @@ -397,6 +397,7 @@ impl<'a> Parser<'a> { } let stmt = match self.parse_full_stmt(false) { Err(mut err) => { + self.maybe_annotate_with_ascription(&mut err, false); err.emit(); self.recover_stmt_(SemiColonMode::Ignore, BlockMode::Ignore); Some(Stmt { diff --git a/src/test/ui/suggestions/type-ascription-instead-of-path-2.rs b/src/test/ui/suggestions/type-ascription-instead-of-path-2.rs new file mode 100644 index 00000000000..220fd1eebda --- /dev/null +++ b/src/test/ui/suggestions/type-ascription-instead-of-path-2.rs @@ -0,0 +1,5 @@ +fn main() -> Result<(), ()> { + vec![Ok(2)].into_iter().collect:,_>>()?; + //~^ ERROR expected `::`, found `(` + Ok(()) +} diff --git a/src/test/ui/suggestions/type-ascription-instead-of-path-2.stderr b/src/test/ui/suggestions/type-ascription-instead-of-path-2.stderr new file mode 100644 index 00000000000..191c4f631c4 --- /dev/null +++ b/src/test/ui/suggestions/type-ascription-instead-of-path-2.stderr @@ -0,0 +1,13 @@ +error: expected `::`, found `(` + --> $DIR/type-ascription-instead-of-path-2.rs:2:55 + | +LL | vec![Ok(2)].into_iter().collect:,_>>()?; + | - ^ expected `::` + | | + | tried to parse a type due to this type ascription + | + = note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `: ` + = note: for more information, see https://github.com/rust-lang/rust/issues/23416 + +error: aborting due to previous error + -- cgit 1.4.1-3-g733a5 From 7d7fbcb3015521412ab17a814680cd1d9bb6cde9 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Mon, 28 Oct 2019 12:40:12 +0100 Subject: Remove `PartialEq` and `Eq` from the `SpecialDerives`. --- src/librustc/hir/lowering/item.rs | 9 +-------- src/librustc_resolve/lib.rs | 2 -- src/libsyntax/expand/mod.rs | 2 -- src/libsyntax_ext/deriving/cmp/eq.rs | 3 --- src/libsyntax_ext/deriving/cmp/partial_eq.rs | 3 --- 5 files changed, 1 insertion(+), 18 deletions(-) (limited to 'src/libsyntax') diff --git a/src/librustc/hir/lowering/item.rs b/src/librustc/hir/lowering/item.rs index 9da87090c79..f1b999cdd6f 100644 --- a/src/librustc/hir/lowering/item.rs +++ b/src/librustc/hir/lowering/item.rs @@ -18,7 +18,6 @@ use smallvec::SmallVec; use syntax::attr; use syntax::ast::*; use syntax::visit::{self, Visitor}; -use syntax::expand::SpecialDerives; use syntax::source_map::{respan, DesugaringKind, Spanned}; use syntax::symbol::{kw, sym}; use syntax_pos::Span; @@ -227,13 +226,7 @@ impl LoweringContext<'_> { pub fn lower_item(&mut self, i: &Item) -> Option { let mut ident = i.ident; let mut vis = self.lower_visibility(&i.vis, None); - let mut attrs = self.lower_attrs_extendable(&i.attrs); - if self.resolver.has_derives(i.id, SpecialDerives::PARTIAL_EQ | SpecialDerives::EQ) { - // Add `#[structural_match]` if the item derived both `PartialEq` and `Eq`. - let ident = Ident::new(sym::structural_match, i.span); - attrs.push(attr::mk_attr_outer(attr::mk_word_item(ident))); - } - let attrs = attrs.into(); + let attrs = self.lower_attrs(&i.attrs); if let ItemKind::MacroDef(ref def) = i.kind { if !def.legacy || attr::contains_name(&i.attrs, sym::macro_export) { diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index b45eb356bdb..ca450544558 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -937,8 +937,6 @@ pub struct Resolver<'a> { /// Some built-in derives mark items they are applied to so they are treated specially later. /// Derive macros cannot modify the item themselves and have to store the markers in the global /// context, so they attach the markers to derive container IDs using this resolver table. - /// FIXME: Find a way for `PartialEq` and `Eq` to emulate `#[structural_match]` - /// by marking the produced impls rather than the original items. special_derives: FxHashMap, /// Parent scopes in which the macros were invoked. /// FIXME: `derives` are missing in these parent scopes and need to be taken from elsewhere. diff --git a/src/libsyntax/expand/mod.rs b/src/libsyntax/expand/mod.rs index 038f60287be..35729508197 100644 --- a/src/libsyntax/expand/mod.rs +++ b/src/libsyntax/expand/mod.rs @@ -9,8 +9,6 @@ bitflags::bitflags! { /// Built-in derives that need some extra tracking beyond the usual macro functionality. #[derive(Default)] pub struct SpecialDerives: u8 { - const PARTIAL_EQ = 1 << 0; - const EQ = 1 << 1; const COPY = 1 << 2; } } diff --git a/src/libsyntax_ext/deriving/cmp/eq.rs b/src/libsyntax_ext/deriving/cmp/eq.rs index eddf8eea1db..41189de7fa2 100644 --- a/src/libsyntax_ext/deriving/cmp/eq.rs +++ b/src/libsyntax_ext/deriving/cmp/eq.rs @@ -3,7 +3,6 @@ use crate::deriving::generic::*; use crate::deriving::generic::ty::*; use syntax::ast::{self, Ident, Expr, MetaItem, GenericArg}; -use syntax::expand::SpecialDerives; use syntax::ptr::P; use syntax::symbol::{sym, Symbol}; use syntax_expand::base::{Annotatable, ExtCtxt}; @@ -14,8 +13,6 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt<'_>, mitem: &MetaItem, item: &Annotatable, push: &mut dyn FnMut(Annotatable)) { - cx.resolver.add_derives(cx.current_expansion.id.expn_data().parent, SpecialDerives::EQ); - let inline = cx.meta_word(span, sym::inline); let hidden = syntax::attr::mk_nested_word_item(Ident::new(sym::hidden, span)); let doc = syntax::attr::mk_list_item(Ident::new(sym::doc, span), vec![hidden]); diff --git a/src/libsyntax_ext/deriving/cmp/partial_eq.rs b/src/libsyntax_ext/deriving/cmp/partial_eq.rs index 2e2be91de8a..19562e350dd 100644 --- a/src/libsyntax_ext/deriving/cmp/partial_eq.rs +++ b/src/libsyntax_ext/deriving/cmp/partial_eq.rs @@ -3,7 +3,6 @@ use crate::deriving::generic::*; use crate::deriving::generic::ty::*; use syntax::ast::{BinOpKind, Expr, MetaItem}; -use syntax::expand::SpecialDerives; use syntax::ptr::P; use syntax::symbol::sym; use syntax_expand::base::{Annotatable, ExtCtxt}; @@ -14,8 +13,6 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt<'_>, mitem: &MetaItem, item: &Annotatable, push: &mut dyn FnMut(Annotatable)) { - cx.resolver.add_derives(cx.current_expansion.id.expn_data().parent, SpecialDerives::PARTIAL_EQ); - // structures are equal if all fields are equal, and non equal, if // any fields are not equal or if the enum variants are different fn cs_op(cx: &mut ExtCtxt<'_>, -- cgit 1.4.1-3-g733a5 From 0dfe0ed8e1b2b8596a8cabee0afdae23e343ee69 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Wed, 30 Oct 2019 11:13:00 +0100 Subject: Review feedback: Remove more stuff! Simplify simplify simplify! --- src/librustc/hir/lowering.rs | 3 --- src/librustc_resolve/lib.rs | 17 +++-------------- src/librustc_resolve/macros.rs | 9 ++++----- src/libsyntax/expand/mod.rs | 8 -------- src/libsyntax_expand/base.rs | 5 ++--- src/libsyntax_expand/expand.rs | 2 +- src/libsyntax_ext/deriving/clone.rs | 3 +-- src/libsyntax_ext/deriving/generic/mod.rs | 7 ++----- 8 files changed, 13 insertions(+), 41 deletions(-) (limited to 'src/libsyntax') diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 6b6032516ca..c6acdf53de3 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -65,7 +65,6 @@ use syntax::ast; use syntax::ptr::P as AstP; use syntax::ast::*; use syntax::errors; -use syntax::expand::SpecialDerives; use syntax::print::pprust; use syntax::parse::token::{self, Nonterminal, Token}; use syntax::tokenstream::{TokenStream, TokenTree}; @@ -184,8 +183,6 @@ pub trait Resolver { ns: Namespace, ) -> (ast::Path, Res); - fn has_derives(&self, node_id: NodeId, derives: SpecialDerives) -> bool; - fn lint_buffer(&mut self) -> &mut lint::LintBuffer; } diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index ca450544558..17b62b3bda2 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -36,7 +36,6 @@ use rustc_metadata::creader::CrateLoader; use rustc_metadata::cstore::CStore; use syntax::{struct_span_err, unwrap_or}; -use syntax::expand::SpecialDerives; use syntax::ast::{self, Name, NodeId, Ident, FloatTy, IntTy, UintTy}; use syntax::ast::{CRATE_NODE_ID, Crate}; use syntax::ast::{ItemKind, Path}; @@ -934,10 +933,10 @@ pub struct Resolver<'a> { multi_segment_macro_resolutions: Vec<(Vec, Span, MacroKind, ParentScope<'a>, Option)>, builtin_attrs: Vec<(Ident, ParentScope<'a>)>, - /// Some built-in derives mark items they are applied to so they are treated specially later. + /// `derive(Copy)` marks items they are applied to so they are treated specially later. /// Derive macros cannot modify the item themselves and have to store the markers in the global /// context, so they attach the markers to derive container IDs using this resolver table. - special_derives: FxHashMap, + copy_derives: FxHashSet, /// Parent scopes in which the macros were invoked. /// FIXME: `derives` are missing in these parent scopes and need to be taken from elsewhere. invocation_parent_scopes: FxHashMap>, @@ -1076,12 +1075,6 @@ impl<'a> hir::lowering::Resolver for Resolver<'a> { &mut self.definitions } - fn has_derives(&self, node_id: NodeId, derives: SpecialDerives) -> bool { - let def_id = self.definitions.local_def_id(node_id); - let expn_id = self.definitions.expansion_that_defined(def_id.index); - self.has_derives(expn_id, derives) - } - fn lint_buffer(&mut self) -> &mut lint::LintBuffer { &mut self.lint_buffer } @@ -1226,7 +1219,7 @@ impl<'a> Resolver<'a> { single_segment_macro_resolutions: Default::default(), multi_segment_macro_resolutions: Default::default(), builtin_attrs: Default::default(), - special_derives: Default::default(), + copy_derives: Default::default(), active_features: features.declared_lib_features.iter().map(|(feat, ..)| *feat) .chain(features.declared_lang_features.iter().map(|(feat, ..)| *feat)) @@ -1312,10 +1305,6 @@ impl<'a> Resolver<'a> { } } - fn has_derives(&self, expn_id: ExpnId, markers: SpecialDerives) -> bool { - self.special_derives.get(&expn_id).map_or(false, |m| m.contains(markers)) - } - /// Entry point to crate resolution. pub fn resolve_crate(&mut self, krate: &Crate) { let _prof_timer = diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 84d3d3a48b0..9997d0f946a 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -14,7 +14,6 @@ use rustc::{ty, lint, span_bug}; use syntax::ast::{self, NodeId, Ident}; use syntax::attr::StabilityLevel; use syntax::edition::Edition; -use syntax::expand::SpecialDerives; use syntax::feature_gate::{emit_feature_err, is_builtin_attr_name}; use syntax::feature_gate::GateIssue; use syntax::print::pprust; @@ -255,12 +254,12 @@ impl<'a> base::Resolver for Resolver<'a> { } } - fn has_derives(&self, expn_id: ExpnId, derives: SpecialDerives) -> bool { - self.has_derives(expn_id, derives) + fn has_derive_copy(&self, expn_id: ExpnId) -> bool { + self.copy_derives.contains(&expn_id) } - fn add_derives(&mut self, expn_id: ExpnId, derives: SpecialDerives) { - *self.special_derives.entry(expn_id).or_default() |= derives; + fn add_derive_copy(&mut self, expn_id: ExpnId) { + self.copy_derives.insert(expn_id); } } diff --git a/src/libsyntax/expand/mod.rs b/src/libsyntax/expand/mod.rs index 35729508197..03b30fda745 100644 --- a/src/libsyntax/expand/mod.rs +++ b/src/libsyntax/expand/mod.rs @@ -5,14 +5,6 @@ use syntax_pos::symbol::sym; pub mod allocator; -bitflags::bitflags! { - /// Built-in derives that need some extra tracking beyond the usual macro functionality. - #[derive(Default)] - pub struct SpecialDerives: u8 { - const COPY = 1 << 2; - } -} - pub fn is_proc_macro_attr(attr: &Attribute) -> bool { [sym::proc_macro, sym::proc_macro_attribute, sym::proc_macro_derive] .iter().any(|kind| attr.check_name(*kind)) diff --git a/src/libsyntax_expand/base.rs b/src/libsyntax_expand/base.rs index d79b6910587..6cc7b7da53b 100644 --- a/src/libsyntax_expand/base.rs +++ b/src/libsyntax_expand/base.rs @@ -13,7 +13,6 @@ use syntax::symbol::{kw, sym, Ident, Symbol}; use syntax::{ThinVec, MACRO_ARGUMENTS}; use syntax::tokenstream::{self, TokenStream}; use syntax::visit::Visitor; -crate use syntax::expand::SpecialDerives; use errors::{DiagnosticBuilder, DiagnosticId}; use smallvec::{smallvec, SmallVec}; @@ -860,8 +859,8 @@ pub trait Resolver { fn check_unused_macros(&mut self); - fn has_derives(&self, expn_id: ExpnId, derives: SpecialDerives) -> bool; - fn add_derives(&mut self, expn_id: ExpnId, derives: SpecialDerives); + fn has_derive_copy(&self, expn_id: ExpnId) -> bool; + fn add_derive_copy(&mut self, expn_id: ExpnId); } #[derive(Clone)] diff --git a/src/libsyntax_expand/expand.rs b/src/libsyntax_expand/expand.rs index bdb50dbfb4f..da70fdbb0f3 100644 --- a/src/libsyntax_expand/expand.rs +++ b/src/libsyntax_expand/expand.rs @@ -432,7 +432,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { // can be in scope for all code produced by that container's expansion. item.visit_with(&mut MarkAttrs(&helper_attrs)); if has_copy { - self.cx.resolver.add_derives(invoc.expansion_data.id, SpecialDerives::COPY); + self.cx.resolver.add_derive_copy(invoc.expansion_data.id); } let mut derive_placeholders = Vec::with_capacity(derives.len()); diff --git a/src/libsyntax_ext/deriving/clone.rs b/src/libsyntax_ext/deriving/clone.rs index 061afa379c6..c056d03614d 100644 --- a/src/libsyntax_ext/deriving/clone.rs +++ b/src/libsyntax_ext/deriving/clone.rs @@ -3,7 +3,6 @@ use crate::deriving::generic::*; use crate::deriving::generic::ty::*; use syntax::ast::{self, Expr, GenericArg, Generics, ItemKind, MetaItem, VariantData}; -use syntax::expand::SpecialDerives; use syntax_expand::base::{Annotatable, ExtCtxt}; use syntax::ptr::P; use syntax::symbol::{kw, sym, Symbol}; @@ -37,7 +36,7 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt<'_>, ItemKind::Struct(_, Generics { ref params, .. }) | ItemKind::Enum(_, Generics { ref params, .. }) => { let container_id = cx.current_expansion.id.expn_data().parent; - if cx.resolver.has_derives(container_id, SpecialDerives::COPY) && + if cx.resolver.has_derive_copy(container_id) && !params.iter().any(|param| match param.kind { ast::GenericParamKind::Type { .. } => true, _ => false, diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index c04b65245e1..2e5ae235893 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -186,7 +186,6 @@ use rustc_target::spec::abi::Abi; use syntax::ast::{self, BinOpKind, EnumDef, Expr, Generics, Ident, PatKind}; use syntax::ast::{VariantData, GenericParamKind, GenericArg}; use syntax::attr; -use syntax::expand::SpecialDerives; use syntax::source_map::respan; use syntax::util::map_in_place::MapInPlace; use syntax::ptr::P; @@ -427,10 +426,8 @@ impl<'a> TraitDef<'a> { } }; let container_id = cx.current_expansion.id.expn_data().parent; - let is_always_copy = - cx.resolver.has_derives(container_id, SpecialDerives::COPY) && - has_no_type_params; - let use_temporaries = is_packed && is_always_copy; + let always_copy = has_no_type_params && cx.resolver.has_derive_copy(container_id); + let use_temporaries = is_packed && always_copy; let newitem = match item.kind { ast::ItemKind::Struct(ref struct_def, ref generics) => { -- cgit 1.4.1-3-g733a5 From a8ccbf5f2fa75007ce0effe58caef4e342859a4f Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Tue, 5 Nov 2019 10:29:54 -0800 Subject: Account for typo in turbofish and suggest `::` --- src/libsyntax/parse/parser/diagnostics.rs | 14 ++++++++++---- .../suggestions/type-ascription-instead-of-path-2.stderr | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/parse/parser/diagnostics.rs b/src/libsyntax/parse/parser/diagnostics.rs index ad479e6278b..fc2b10f2260 100644 --- a/src/libsyntax/parse/parser/diagnostics.rs +++ b/src/libsyntax/parse/parser/diagnostics.rs @@ -358,7 +358,7 @@ impl<'a> Parser<'a> { err: &mut DiagnosticBuilder<'_>, maybe_expected_semicolon: bool, ) { - if let Some((sp, likely_path)) = self.last_type_ascription { + if let Some((sp, likely_path)) = self.last_type_ascription.take() { let sm = self.sess.source_map(); let next_pos = sm.lookup_char_pos(self.token.span.lo()); let op_pos = sm.lookup_char_pos(sp.hi()); @@ -395,7 +395,6 @@ impl<'a> Parser<'a> { err.note("for more information, see \ https://github.com/rust-lang/rust/issues/23416"); } - self.last_type_ascription = None; } } @@ -1083,8 +1082,15 @@ impl<'a> Parser<'a> { } pub(super) fn could_ascription_be_path(&self, node: &ast::ExprKind) -> bool { - self.token.is_ident() && - if let ast::ExprKind::Path(..) = node { true } else { false } && + (self.token == token::Lt && // `foo: true, + _ => false, + } && !self.token.is_reserved_ident() && // v `foo:bar(baz)` self.look_ahead(1, |t| t == &token::OpenDelim(token::Paren)) || self.look_ahead(1, |t| t == &token::Lt) && // `foo:bar,_>>()?; | - ^ expected `::` | | - | tried to parse a type due to this type ascription + | help: maybe write a path separator here: `::` | = note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `: ` = note: for more information, see https://github.com/rust-lang/rust/issues/23416 -- cgit 1.4.1-3-g733a5