Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 11 pull requests #83145

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
1ba71ab
Inline Attribute::has_name
tmiasko Mar 11, 2021
4943190
Validate rustc_layout_scalar_valid_range_{start,end} attributes
tmiasko Mar 11, 2021
2eeddcc
Add reproduction test
oli-obk Mar 4, 2021
7154563
Use tracing instrumentation for better bug diagnosing
oli-obk Mar 5, 2021
b42e258
Make regression test succeed as long as it ICEs
oli-obk Mar 5, 2021
7a318ae
Delete non-revision ui test output file if revisions are used
oli-obk Mar 5, 2021
375e243
Replace `type_alias_impl_trait` by `min_type_alias_impl_trait` with n…
oli-obk Mar 12, 2021
ed4c2d1
Add a test showing how `impl_trait_in_bindings` is a breaking change
oli-obk Mar 12, 2021
bc9019f
Special case type aliases from impl trait in const/static types
oli-obk Mar 12, 2021
9a36840
Only allow tait defining uses in function and method return position
oli-obk Mar 12, 2021
6fb5716
🍼 for tidy
oli-obk Mar 12, 2021
c74fdf0
More precise spans for HIR paths
petrochenkov Mar 13, 2021
9613a88
Refactor `check_doc_attrs` body
camelid Mar 13, 2021
7189c05
Lint non-meta doc attributes
camelid Mar 13, 2021
7e972a3
Report error for each invalid nested attribute
camelid Mar 11, 2021
fe64970
Add another test case
camelid Mar 12, 2021
5134047
Add hyphen to "crate level"
camelid Mar 13, 2021
13884dc
Update `rustdoc-ui` versions of the `doc-attr` test
camelid Mar 14, 2021
e161a2f
Remove unused `opt_local_def_id_to_hir_id` function
jyn514 Mar 14, 2021
71a784d
Fix a typo in `swap_nonoverlapping_bytes`
hiyoko3m Mar 12, 2021
5ec0540
Fix a typo in thread_local_dtor.rs
hiyoko3m Mar 14, 2021
6ddd840
Minor refactoring in try_index_step
osa1 Mar 14, 2021
14038c7
Remove duplicate asserts, replace eq assert with assert_eq
osa1 Mar 14, 2021
13076f9
Tweak diagnostics
camelid Mar 14, 2021
8f40e11
Use pretty-printer instead of `span_to_snippet`
camelid Mar 14, 2021
7429c68
Don't encode file information for span with a dummy location
Aaron1011 Mar 14, 2021
f190bc4
Introduce `proc_macro_back_compat` lint, and emit for `time-macros-impl`
Aaron1011 Mar 14, 2021
4bc1434
Explain each variant of TAIT usage with examples
oli-obk Mar 15, 2021
ebe51cf
:arrow_up: rust-analyzer
lnicola Mar 15, 2021
5eae9af
Custom error on literal names from other languages
syvb Mar 15, 2021
239f32e
Rollup merge of #82898 - oli-obk:tait_🧊, r=nikomatsakis
Dylan-DPC Mar 15, 2021
b9f52df
Rollup merge of #82989 - Smittyvb:other-lang-literal-errors, r=varkor
Dylan-DPC Mar 15, 2021
c109e9e
Rollup merge of #83054 - tmiasko:rustc_layout_scalar_valid_range, r=d…
Dylan-DPC Mar 15, 2021
f49091d
Rollup merge of #83092 - petrochenkov:qspan, r=estebank
Dylan-DPC Mar 15, 2021
3ec47de
Rollup merge of #83098 - camelid:more-doc-attr-check, r=davidtwco
Dylan-DPC Mar 15, 2021
65474b2
Rollup merge of #83108 - jyn514:remove-unused, r=estebank
Dylan-DPC Mar 15, 2021
96e0c44
Rollup merge of #83110 - hyksm:fix-typo, r=jonas-schievink
Dylan-DPC Mar 15, 2021
1647646
Rollup merge of #83113 - osa1:refactor_try_index_step, r=jonas-schievink
Dylan-DPC Mar 15, 2021
ebba9a4
Rollup merge of #83127 - Aaron1011:time-macros-impl-warn, r=petrochenkov
Dylan-DPC Mar 15, 2021
99252bf
Rollup merge of #83132 - Aaron1011:fix/incr-cache-dummy, r=estebank
Dylan-DPC Mar 15, 2021
97423d5
Rollup merge of #83141 - lnicola:rust-analyzer-2021-03-15, r=jonas-sc…
Dylan-DPC Mar 15, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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
8 changes: 8 additions & 0 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,17 @@ impl PathSegment {
pub fn from_ident(ident: Ident) -> Self {
PathSegment { ident, id: DUMMY_NODE_ID, args: None }
}

pub fn path_root(span: Span) -> Self {
PathSegment::from_ident(Ident::new(kw::PathRoot, span))
}

pub fn span(&self) -> Span {
match &self.args {
Some(args) => self.ident.span.to(args.span()),
None => self.ident.span,
}
}
}

/// The arguments of a path segment.
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
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
ty,
ImplTraitContext::OtherOpaqueTy {
capturable_lifetimes: &mut FxHashSet::default(),
origin: hir::OpaqueTyOrigin::Misc,
origin: hir::OpaqueTyOrigin::TyAlias,
},
);
let generics = self.lower_generics(gen, ImplTraitContext::disallowed());
Expand Down Expand Up @@ -918,7 +918,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
ty,
ImplTraitContext::OtherOpaqueTy {
capturable_lifetimes: &mut FxHashSet::default(),
origin: hir::OpaqueTyOrigin::Misc,
origin: hir::OpaqueTyOrigin::TyAlias,
},
);
hir::ImplItemKind::TyAlias(ty)
Expand Down
13 changes: 8 additions & 5 deletions compiler/rustc_ast_lowering/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let partial_res =
self.resolver.get_partial_res(id).unwrap_or_else(|| PartialRes::new(Res::Err));

let path_span_lo = p.span.shrink_to_lo();
let proj_start = p.segments.len() - partial_res.unresolved_segments();
let path = self.arena.alloc(hir::Path {
res: self.lower_res(partial_res.base_res()),
Expand Down Expand Up @@ -108,7 +109,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
)
},
)),
span: p.span,
span: p.segments[..proj_start]
.last()
.map_or(path_span_lo, |segment| path_span_lo.to(segment.span())),
});

// Simple case, either no projections, or only fully-qualified.
Expand All @@ -127,7 +130,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// e.g., `Vec` in `Vec::new` or `<I as Iterator>::Item` in
// `<I as Iterator>::Item::default`.
let new_id = self.next_id();
self.arena.alloc(self.ty_path(new_id, p.span, hir::QPath::Resolved(qself, path)))
self.arena.alloc(self.ty_path(new_id, path.span, hir::QPath::Resolved(qself, path)))
};

// Anything after the base path are associated "extensions",
Expand All @@ -141,7 +144,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// 3. `<<std::vec::Vec<T>>::IntoIter>::Item`
// * final path is `<<<std::vec::Vec<T>>::IntoIter>::Item>::clone`
for (i, segment) in p.segments.iter().enumerate().skip(proj_start) {
let segment = self.arena.alloc(self.lower_path_segment(
let hir_segment = self.arena.alloc(self.lower_path_segment(
p.span,
segment,
param_mode,
Expand All @@ -150,7 +153,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
itctx.reborrow(),
None,
));
let qpath = hir::QPath::TypeRelative(ty, segment);
let qpath = hir::QPath::TypeRelative(ty, hir_segment);

// It's finished, return the extension of the right node type.
if i == p.segments.len() - 1 {
Expand All @@ -159,7 +162,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {

// Wrap the associated extension in another type node.
let new_id = self.next_id();
ty = self.arena.alloc(self.ty_path(new_id, p.span, qpath));
ty = self.arena.alloc(self.ty_path(new_id, path_span_lo.to(segment.span()), qpath));
}

// We should've returned in the for loop above.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ impl<'a> PostExpansionVisitor<'a> {
if let ast::TyKind::ImplTrait(..) = ty.kind {
gate_feature_post!(
&self.vis,
type_alias_impl_trait,
min_type_alias_impl_trait,
ty.span,
"`impl Trait` in type aliases is unstable"
);
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
}
4 changes: 4 additions & 0 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,9 @@ declare_features! (
/// Allows `pub` on `macro_rules` items.
(active, pub_macro_rules, "1.52.0", Some(78855), None),

/// Allows the use of type alias impl trait in function return positions
(active, min_type_alias_impl_trait, "1.52.0", Some(63063), None),

/// Allows associated types in inherent impls.
(active, inherent_associated_types, "1.52.0", Some(8995), None),

Expand Down Expand Up @@ -670,6 +673,7 @@ pub const INCOMPLETE_FEATURES: &[Symbol] = &[
sym::capture_disjoint_fields,
sym::const_generics_defaults,
sym::inherent_associated_types,
sym::type_alias_impl_trait,
];

/// Some features are not allowed to be used together at the same time, if
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_feature/src/removed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ declare_features! (
Some("subsumed by `.await` syntax")),
/// Allows defining `existential type`s.
(removed, existential_type, "1.38.0", Some(63063), None,
Some("removed in favor of `#![feature(type_alias_impl_trait)]`")),
Some("removed in favor of `#![feature(min_type_alias_impl_trait)]`")),
/// Allows using the macros:
/// + `__diagnostic_used`
/// + `__register_diagnostic`
Expand Down
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
6 changes: 4 additions & 2 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1809,7 +1809,7 @@ impl<'hir> QPath<'hir> {
pub fn span(&self) -> Span {
match *self {
QPath::Resolved(_, path) => path.span,
QPath::TypeRelative(_, ps) => ps.ident.span,
QPath::TypeRelative(qself, ps) => qself.span.to(ps.ident.span),
QPath::LangItem(_, span) => span,
}
}
Expand Down Expand Up @@ -2291,7 +2291,9 @@ pub enum OpaqueTyOrigin {
AsyncFn,
/// `let _: impl Trait = ...`
Binding,
/// Impl trait in type aliases, consts, statics, bounds.
/// type aliases: `type Foo = impl Trait;`
TyAlias,
/// Impl trait consts, statics, bounds.
Misc,
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/traits/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub fn report_object_safety_error(
<https://doc.rust-lang.org/reference/items/traits.html#object-safety>",
);

if tcx.sess.trait_methods_not_found.borrow().contains(&span) {
if tcx.sess.trait_methods_not_found.borrow().iter().any(|full_span| full_span.contains(span)) {
// Avoid emitting error caused by non-existing method (#58734)
err.cancel();
}
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
Loading