Skip to content

Commit

Permalink
Auto merge of rust-lang#83149 - Dylan-DPC:rollup-ov70c5v, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 10 pull requests

Successful merges:

 - rust-lang#82989 (Custom error on literal names from other languages)
 - rust-lang#83054 (Validate rustc_layout_scalar_valid_range_{start,end} attributes)
 - rust-lang#83098 (Find more invalid doc attributes)
 - rust-lang#83108 (Remove unused `opt_local_def_id_to_hir_id` function)
 - rust-lang#83110 (Fix typos in `library/core/src/ptr/mod.rs` and `library/std/src/sys_common/thread_local_dtor.rs`)
 - rust-lang#83113 (Minor refactoring in try_index_step)
 - rust-lang#83127 (Introduce `proc_macro_back_compat` lint, and emit for `time-macros-impl`)
 - rust-lang#83132 (Don't encode file information for span with a dummy location)
 - rust-lang#83141 (:arrow_up: rust-analyzer)
 - rust-lang#83144 (Introduce `rustc_interface::interface::Config::parse_sess_created` callback)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Mar 15, 2021
2 parents 7a7bbdb + 2816c11 commit 2ccf063
Show file tree
Hide file tree
Showing 42 changed files with 687 additions and 159 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4247,6 +4247,7 @@ name = "rustc_passes"
version = "0.0.0"
dependencies = [
"rustc_ast",
"rustc_ast_pretty",
"rustc_attr",
"rustc_data_structures",
"rustc_errors",
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_ast/src/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ impl NestedMetaItem {
}

impl Attribute {
#[inline]
pub fn has_name(&self, name: Symbol) -> bool {
match self.kind {
AttrKind::Normal(ref item, _) => item.path == name,
Expand Down
50 changes: 1 addition & 49 deletions compiler/rustc_ast/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ use crate::tokenstream::TokenTree;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::sync::Lrc;
use rustc_macros::HashStable_Generic;
use rustc_span::hygiene::ExpnKind;
use rustc_span::source_map::SourceMap;
use rustc_span::symbol::{kw, sym};
use rustc_span::symbol::{Ident, Symbol};
use rustc_span::{self, edition::Edition, FileName, RealFileName, Span, DUMMY_SP};
use rustc_span::{self, edition::Edition, Span, DUMMY_SP};
use std::borrow::Cow;
use std::{fmt, mem};

Expand Down Expand Up @@ -813,52 +811,6 @@ impl Nonterminal {
}
false
}

// See issue #74616 for details
pub fn ident_name_compatibility_hack(
&self,
orig_span: Span,
source_map: &SourceMap,
) -> Option<(Ident, bool)> {
if let NtIdent(ident, is_raw) = self {
if let ExpnKind::Macro(_, macro_name) = orig_span.ctxt().outer_expn_data().kind {
let filename = source_map.span_to_filename(orig_span);
if let FileName::Real(RealFileName::Named(path)) = filename {
let matches_prefix = |prefix, filename| {
// Check for a path that ends with 'prefix*/src/<filename>'
let mut iter = path.components().rev();
iter.next().and_then(|p| p.as_os_str().to_str()) == Some(filename)
&& iter.next().and_then(|p| p.as_os_str().to_str()) == Some("src")
&& iter
.next()
.and_then(|p| p.as_os_str().to_str())
.map_or(false, |p| p.starts_with(prefix))
};

if (macro_name == sym::impl_macros
&& matches_prefix("time-macros-impl", "lib.rs"))
|| (macro_name == sym::arrays && matches_prefix("js-sys", "lib.rs"))
{
let snippet = source_map.span_to_snippet(orig_span);
if snippet.as_deref() == Ok("$name") {
return Some((*ident, *is_raw));
}
}

if macro_name == sym::tuple_from_req
&& (matches_prefix("actix-web", "extract.rs")
|| matches_prefix("actori-web", "extract.rs"))
{
let snippet = source_map.span_to_snippet(orig_span);
if snippet.as_deref() == Ok("$T") {
return Some((*ident, *is_raw));
}
}
}
}
}
None
}
}

impl PartialEq for Nonterminal {
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ fn run_compiler(
diagnostic_output,
stderr: None,
lint_caps: Default::default(),
parse_sess_created: None,
register_lints: None,
override_queries: None,
make_codegen_backend: make_codegen_backend.take().unwrap(),
Expand Down Expand Up @@ -298,6 +299,7 @@ fn run_compiler(
diagnostic_output,
stderr: None,
lint_caps: Default::default(),
parse_sess_created: None,
register_lints: None,
override_queries: None,
make_codegen_backend: make_codegen_backend.unwrap(),
Expand Down
70 changes: 66 additions & 4 deletions compiler/rustc_expand/src/proc_macro_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@ use crate::base::ExtCtxt;

use rustc_ast as ast;
use rustc_ast::token;
use rustc_ast::token::Nonterminal;
use rustc_ast::token::NtIdent;
use rustc_ast::tokenstream::{self, CanSynthesizeMissingTokens};
use rustc_ast::tokenstream::{DelimSpan, Spacing::*, TokenStream, TreeAndSpacing};
use rustc_ast_pretty::pprust;
use rustc_data_structures::sync::Lrc;
use rustc_errors::Diagnostic;
use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT;
use rustc_lint_defs::BuiltinLintDiagnostics;
use rustc_parse::lexer::nfc_normalize;
use rustc_parse::{nt_to_tokenstream, parse_stream_from_source_str};
use rustc_session::parse::ParseSess;
use rustc_span::hygiene::ExpnKind;
use rustc_span::symbol::{self, kw, sym, Symbol};
use rustc_span::{BytePos, FileName, MultiSpan, Pos, SourceFile, Span};
use rustc_span::{BytePos, FileName, MultiSpan, Pos, RealFileName, SourceFile, Span};

use pm::bridge::{server, TokenTree};
use pm::{Delimiter, Level, LineColumn, Spacing};
Expand Down Expand Up @@ -174,9 +179,7 @@ impl FromInternal<(TreeAndSpacing, &'_ ParseSess, &'_ mut Vec<Self>)>
}

Interpolated(nt) => {
if let Some((name, is_raw)) =
nt.ident_name_compatibility_hack(span, sess.source_map())
{
if let Some((name, is_raw)) = ident_name_compatibility_hack(&nt, span, sess) {
TokenTree::Ident(Ident::new(sess, name.name, is_raw, name.span))
} else {
let stream = nt_to_tokenstream(&nt, sess, CanSynthesizeMissingTokens::No);
Expand Down Expand Up @@ -711,3 +714,62 @@ impl server::Span for Rustc<'_> {
self.sess.source_map().span_to_snippet(span).ok()
}
}

// See issue #74616 for details
fn ident_name_compatibility_hack(
nt: &Nonterminal,
orig_span: Span,
sess: &ParseSess,
) -> Option<(rustc_span::symbol::Ident, bool)> {
if let NtIdent(ident, is_raw) = nt {
if let ExpnKind::Macro(_, macro_name) = orig_span.ctxt().outer_expn_data().kind {
let source_map = sess.source_map();
let filename = source_map.span_to_filename(orig_span);
if let FileName::Real(RealFileName::Named(path)) = filename {
let matches_prefix = |prefix, filename| {
// Check for a path that ends with 'prefix*/src/<filename>'
let mut iter = path.components().rev();
iter.next().and_then(|p| p.as_os_str().to_str()) == Some(filename)
&& iter.next().and_then(|p| p.as_os_str().to_str()) == Some("src")
&& iter
.next()
.and_then(|p| p.as_os_str().to_str())
.map_or(false, |p| p.starts_with(prefix))
};

let time_macros_impl =
macro_name == sym::impl_macros && matches_prefix("time-macros-impl", "lib.rs");
if time_macros_impl
|| (macro_name == sym::arrays && matches_prefix("js-sys", "lib.rs"))
{
let snippet = source_map.span_to_snippet(orig_span);
if snippet.as_deref() == Ok("$name") {
if time_macros_impl {
sess.buffer_lint_with_diagnostic(
&PROC_MACRO_BACK_COMPAT,
orig_span,
ast::CRATE_NODE_ID,
"using an old version of `time-macros-impl`",
BuiltinLintDiagnostics::ProcMacroBackCompat(
"the `time-macros-impl` crate will stop compiling in futures version of Rust. \
Please update to the latest version of the `time` crate to avoid breakage".to_string())
);
}
return Some((*ident, *is_raw));
}
}

if macro_name == sym::tuple_from_req
&& (matches_prefix("actix-web", "extract.rs")
|| matches_prefix("actori-web", "extract.rs"))
{
let snippet = source_map.span_to_snippet(orig_span);
if snippet.as_deref() == Ok("$T") {
return Some((*ident, *is_raw));
}
}
}
}
}
None
}
5 changes: 0 additions & 5 deletions compiler/rustc_hir/src/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,6 @@ impl Definitions {
self.def_id_to_hir_id[id].unwrap()
}

#[inline]
pub fn opt_local_def_id_to_hir_id(&self, id: LocalDefId) -> Option<hir::HirId> {
self.def_id_to_hir_id[id]
}

#[inline]
pub fn opt_hir_id_to_local_def_id(&self, hir_id: hir::HirId) -> Option<LocalDefId> {
self.hir_id_to_def_id.get(&hir_id).copied()
Expand Down
13 changes: 12 additions & 1 deletion compiler/rustc_interface/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ pub struct Config {

pub lint_caps: FxHashMap<lint::LintId, lint::Level>,

/// This is a callback from the driver that is called when [`ParseSess`] is created.
pub parse_sess_created: Option<Box<dyn FnOnce(&mut ParseSess) + Send>>,

/// This is a callback from the driver that is called when we're registering lints;
/// it is called during plugin registration when we have the LintStore in a non-shared state.
///
Expand All @@ -166,7 +169,7 @@ pub struct Config {

pub fn create_compiler_and_run<R>(config: Config, f: impl FnOnce(&Compiler) -> R) -> R {
let registry = &config.registry;
let (sess, codegen_backend) = util::create_session(
let (mut sess, codegen_backend) = util::create_session(
config.opts,
config.crate_cfg,
config.diagnostic_output,
Expand All @@ -177,6 +180,14 @@ pub fn create_compiler_and_run<R>(config: Config, f: impl FnOnce(&Compiler) -> R
registry.clone(),
);

if let Some(parse_sess_created) = config.parse_sess_created {
parse_sess_created(
&mut Lrc::get_mut(&mut sess)
.expect("create_session() should never share the returned session")
.parse_sess,
);
}

let compiler = Compiler {
sess,
codegen_backend,
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,9 @@ pub trait LintContext: Sized {
json
);
}
BuiltinLintDiagnostics::ProcMacroBackCompat(note) => {
db.note(&note);
}
}
// Rewrap `db`, and pass control to the user.
decorate(LintDiagnosticBuilder::new(db));
Expand Down
53 changes: 52 additions & 1 deletion compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! compiler code, rather than using their own custom pass. Those
//! lints are all available in `rustc_lint::builtin`.

use crate::{declare_lint, declare_lint_pass};
use crate::{declare_lint, declare_lint_pass, FutureBreakage};
use rustc_span::edition::Edition;

declare_lint! {
Expand Down Expand Up @@ -2955,6 +2955,7 @@ declare_lint_pass! {
SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
DISJOINT_CAPTURE_DROP_REORDER,
LEGACY_DERIVE_HELPERS,
PROC_MACRO_BACK_COMPAT,
]
}

Expand Down Expand Up @@ -3082,3 +3083,53 @@ declare_lint! {
edition: None,
};
}

declare_lint! {
/// The `proc_macro_back_compat` lint detects uses of old versions of certain
/// proc-macro crates, which have hardcoded workarounds in the compiler.
///
/// ### Example
///
/// ```rust,ignore (needs-dependency)
///
/// use time_macros_impl::impl_macros;
/// struct Foo;
/// impl_macros!(Foo);
/// ```
///
/// This will produce:
///
/// ```text
/// warning: using an old version of `time-macros-impl`
/// ::: $DIR/group-compat-hack.rs:27:5
/// |
/// LL | impl_macros!(Foo);
/// | ------------------ in this macro invocation
/// |
/// = note: `#[warn(proc_macro_back_compat)]` on by default
/// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
/// = note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
/// = note: the `time-macros-impl` crate will stop compiling in futures version of Rust. Please update to the latest version of the `time` crate to avoid breakage
/// = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
/// ```
///
/// ### Explanation
///
/// Eventually, the backwards-compatibility hacks present in the compiler will be removed,
/// causing older versions of certain crates to stop compiling.
/// This is a [future-incompatible] lint to ease the transition to an error.
/// See [issue #83125] for more details.
///
/// [issue #83125]: https://github.com/rust-lang/rust/issues/83125
/// [future-incompatible]: ../index.md#future-incompatible-lints
pub PROC_MACRO_BACK_COMPAT,
Warn,
"detects usage of old versions of certain proc-macro crates",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #83125 <https://github.com/rust-lang/rust/issues/83125>",
edition: None,
future_breakage: Some(FutureBreakage {
date: None
})
};
}
1 change: 1 addition & 0 deletions compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ pub enum BuiltinLintDiagnostics {
PatternsInFnsWithoutBody(Span, Ident),
LegacyDeriveHelpers(Span),
ExternDepSpec(String, ExternDepSpec),
ProcMacroBackCompat(String),
}

/// Lints that are buffered up early on in the `Session` before the
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_middle/src/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,6 @@ impl<'hir> Map<'hir> {
self.tcx.definitions.local_def_id_to_hir_id(def_id)
}

#[inline]
pub fn opt_local_def_id_to_hir_id(&self, def_id: LocalDefId) -> Option<HirId> {
self.tcx.definitions.opt_local_def_id_to_hir_id(def_id)
}

pub fn iter_local_def_id(&self) -> impl Iterator<Item = LocalDefId> + '_ {
self.tcx.definitions.iter_local_def_id()
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/ty/query/on_disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,12 +1045,12 @@ where
E: 'a + OpaqueEncoder,
{
fn encode(&self, s: &mut CacheEncoder<'a, 'tcx, E>) -> Result<(), E::Error> {
if *self == DUMMY_SP {
let span_data = self.data();
if self.is_dummy() {
TAG_PARTIAL_SPAN.encode(s)?;
return SyntaxContext::root().encode(s);
return span_data.ctxt.encode(s);
}

let span_data = self.data();
let pos = s.source_map.byte_pos_to_line_and_col(span_data.lo);
let partial_span = match &pos {
Some((file_lo, _, _)) => !file_lo.contains(span_data.hi),
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_mir_build/src/build/expr/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
block.unit()
}
ExprKind::Index { .. } | ExprKind::Deref { .. } | ExprKind::Field { .. } => {
debug_assert!(Category::of(&expr.kind) == Some(Category::Place));
debug_assert_eq!(Category::of(&expr.kind), Some(Category::Place));

// Create a "fake" temporary variable so that we check that the
// value is Sized. Usually, this is caught in type checking, but
Expand All @@ -436,8 +436,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
this.local_decls.push(LocalDecl::new(expr.ty, expr.span));
}

debug_assert!(Category::of(&expr.kind) == Some(Category::Place));

let place = unpack!(block = this.as_place(block, expr));
let rvalue = Rvalue::Use(this.consume_by_copy_or_move(place));
this.cfg.push_assign(block, source_info, destination, rvalue);
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_passes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ rustc_serialize = { path = "../rustc_serialize" }
rustc_span = { path = "../rustc_span" }
rustc_trait_selection = { path = "../rustc_trait_selection" }
rustc_lexer = { path = "../rustc_lexer" }
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
Loading

0 comments on commit 2ccf063

Please sign in to comment.