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 9 pull requests #125975

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d6d2ff0
Remove a stray comment that shouldn't be here.
nnethercote May 26, 2024
3607cee
Use let chains in `pretty_printing_compatibility_hack`.
nnethercote May 26, 2024
cf0c2c7
Convert `proc_macro_back_compat` lint to an unconditional error.
nnethercote May 26, 2024
6cc4b22
Manual rustfmt
oli-obk May 27, 2024
b6a8863
Show that it will pick up the entirely wrong function as a private ca…
oli-obk May 28, 2024
7253f07
Turn a delayed bug back into a normal bug by winnowing private method…
oli-obk May 27, 2024
2ba0330
Move tests to a more appropriate directory
oli-obk May 28, 2024
5dfabd1
Give test a more useful name
oli-obk May 28, 2024
575c86f
Add test description
oli-obk May 28, 2024
d392c50
Ignore `vec_deque_alloc_error::test_shrink_to_unwind` test on non-unw…
Veykril Jun 3, 2024
e9c4eb3
chore: update src/tools/rustc-perf
weihanglo May 31, 2024
9436fbe
Fix typo in the docs of `HashMap::raw_entry_mut`
its-the-shrimp Jun 3, 2024
47053d1
Update books
rustbot Jun 3, 2024
832b8b8
Update fuchsia maintainers
P1n3appl3 Jun 3, 2024
0a11dcf
feat(opt-dist): new flag `--benchmark-cargo-config`
weihanglo Jun 3, 2024
8f677e8
bootstrap: implement new feature `bootstrap-self-test`
onur-ozkan May 19, 2024
6a84995
Add function `core::iter::chain`
rossmacarthur Jun 4, 2024
fab2536
Rollup merge of #106186 - rossmacarthur:ft/iter-chain, r=Amanieu
compiler-errors Jun 4, 2024
7525590
Rollup merge of #125273 - onur-ozkan:bootstrap-self-test, r=albertlar…
compiler-errors Jun 4, 2024
e7cbcd3
Rollup merge of #125596 - nnethercote:rental-hard-error, r=estebank
compiler-errors Jun 4, 2024
d0f37fa
Rollup merge of #125622 - oli-obk:define_opaque_types15, r=compiler-e…
compiler-errors Jun 4, 2024
061c7ff
Rollup merge of #125927 - ferrocene:lw-alloc-unwind-test, r=pietroalbini
compiler-errors Jun 4, 2024
4e82d47
Rollup merge of #125930 - weihanglo:opt-dist-respect-cargo-config, r=…
compiler-errors Jun 4, 2024
e5c4ee3
Rollup merge of #125932 - schvv31n:patch-1, r=lqd
compiler-errors Jun 4, 2024
c94a2fa
Rollup merge of #125933 - rustbot:docs-update, r=ehuss
compiler-errors Jun 4, 2024
cee5d8e
Rollup merge of #125944 - P1n3appl3:fuchsia, r=lqd
compiler-errors Jun 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions compiler/rustc_expand/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ expand_not_a_meta_item =
expand_only_one_word =
must only be one word

expand_proc_macro_back_compat = using an old version of `{$crate_name}`
.note = older versions of the `{$crate_name}` crate no longer compile; please update to `{$crate_name}` v{$fixed_version}, or switch to one of the `{$crate_name}` alternatives

expand_proc_macro_derive_panicked =
proc-macro derive panicked
.help = message: {$message}
Expand Down
94 changes: 38 additions & 56 deletions compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::sync::{self, Lrc};
use rustc_errors::{DiagCtxt, ErrorGuaranteed, PResult};
use rustc_feature::Features;
use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT;
use rustc_lint_defs::{BufferedEarlyLint, BuiltinLintDiag, RegisteredTools};
use rustc_lint_defs::{BufferedEarlyLint, RegisteredTools};
use rustc_parse::{parser, MACRO_ARGUMENTS};
use rustc_session::config::CollapseMacroDebuginfo;
use rustc_session::{parse::ParseSess, Limit, Session};
Expand Down Expand Up @@ -1330,80 +1329,63 @@ pub fn parse_macro_name_and_helper_attrs(
Some((trait_ident.name, proc_attrs))
}

/// This nonterminal looks like some specific enums from
/// `proc-macro-hack` and `procedural-masquerade` crates.
/// We need to maintain some special pretty-printing behavior for them due to incorrect
/// asserts in old versions of those crates and their wide use in the ecosystem.
/// See issue #73345 for more details.
/// If this item looks like a specific enums from `rental`, emit a fatal error.
/// See #73345 and #83125 for more details.
/// FIXME(#73933): Remove this eventually.
fn pretty_printing_compatibility_hack(item: &Item, sess: &Session) -> bool {
fn pretty_printing_compatibility_hack(item: &Item, sess: &Session) {
let name = item.ident.name;
if name == sym::ProceduralMasqueradeDummyType {
if let ast::ItemKind::Enum(enum_def, _) = &item.kind {
if let [variant] = &*enum_def.variants {
if variant.ident.name == sym::Input {
let filename = sess.source_map().span_to_filename(item.ident.span);
if let FileName::Real(real) = filename {
if let Some(c) = real
.local_path()
.unwrap_or(Path::new(""))
.components()
.flat_map(|c| c.as_os_str().to_str())
.find(|c| c.starts_with("rental") || c.starts_with("allsorts-rental"))
{
let crate_matches = if c.starts_with("allsorts-rental") {
true
} else {
let mut version = c.trim_start_matches("rental-").split('.');
version.next() == Some("0")
&& version.next() == Some("5")
&& version
.next()
.and_then(|c| c.parse::<u32>().ok())
.is_some_and(|v| v < 6)
};

if crate_matches {
sess.psess.buffer_lint(
PROC_MACRO_BACK_COMPAT,
item.ident.span,
ast::CRATE_NODE_ID,
BuiltinLintDiag::ProcMacroBackCompat {
crate_name: "rental".to_string(),
fixed_version: "0.5.6".to_string(),
},
);
return true;
}
}
}
}
}
if name == sym::ProceduralMasqueradeDummyType
&& let ast::ItemKind::Enum(enum_def, _) = &item.kind
&& let [variant] = &*enum_def.variants
&& variant.ident.name == sym::Input
&& let FileName::Real(real) = sess.source_map().span_to_filename(item.ident.span)
&& let Some(c) = real
.local_path()
.unwrap_or(Path::new(""))
.components()
.flat_map(|c| c.as_os_str().to_str())
.find(|c| c.starts_with("rental") || c.starts_with("allsorts-rental"))
{
let crate_matches = if c.starts_with("allsorts-rental") {
true
} else {
let mut version = c.trim_start_matches("rental-").split('.');
version.next() == Some("0")
&& version.next() == Some("5")
&& version.next().and_then(|c| c.parse::<u32>().ok()).is_some_and(|v| v < 6)
};

if crate_matches {
// FIXME: make this translatable
#[allow(rustc::untranslatable_diagnostic)]
sess.psess.dcx.emit_fatal(errors::ProcMacroBackCompat {
crate_name: "rental".to_string(),
fixed_version: "0.5.6".to_string(),
});
}
}
false
}

pub(crate) fn ann_pretty_printing_compatibility_hack(ann: &Annotatable, sess: &Session) -> bool {
pub(crate) fn ann_pretty_printing_compatibility_hack(ann: &Annotatable, sess: &Session) {
let item = match ann {
Annotatable::Item(item) => item,
Annotatable::Stmt(stmt) => match &stmt.kind {
ast::StmtKind::Item(item) => item,
_ => return false,
_ => return,
},
_ => return false,
_ => return,
};
pretty_printing_compatibility_hack(item, sess)
}

pub(crate) fn nt_pretty_printing_compatibility_hack(nt: &Nonterminal, sess: &Session) -> bool {
pub(crate) fn nt_pretty_printing_compatibility_hack(nt: &Nonterminal, sess: &Session) {
let item = match nt {
Nonterminal::NtItem(item) => item,
Nonterminal::NtStmt(stmt) => match &stmt.kind {
ast::StmtKind::Item(item) => item,
_ => return false,
_ => return,
},
_ => return false,
_ => return,
};
pretty_printing_compatibility_hack(item, sess)
}
10 changes: 10 additions & 0 deletions compiler/rustc_expand/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,3 +440,13 @@ pub(crate) struct EmptyDelegationList {
#[primary_span]
pub span: Span,
}

// This used to be the `proc_macro_back_compat` lint (#83125). It was later
// turned into a hard error.
#[derive(Diagnostic)]
#[diag(expand_proc_macro_back_compat)]
#[note]
pub struct ProcMacroBackCompat {
pub crate_name: String,
pub fixed_version: String,
}
1 change: 0 additions & 1 deletion compiler/rustc_expand/src/mbe/transcribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ pub(super) fn transcribe<'a>(
// some of the unnecessary whitespace.
let ident = MacroRulesNormalizedIdent::new(original_ident);
if let Some(cur_matched) = lookup_cur_matched(ident, interp, &repeats) {
// njn: explain the use of alone here
let tt = match cur_matched {
MatchedSingle(ParseNtResult::Tt(tt)) => {
// `tt`s are emitted into the output stream directly as "raw tokens",
Expand Down
21 changes: 7 additions & 14 deletions compiler/rustc_expand/src/proc_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ use crate::proc_macro_server;

use rustc_ast as ast;
use rustc_ast::ptr::P;
use rustc_ast::token;
use rustc_ast::tokenstream::TokenStream;
use rustc_data_structures::sync::Lrc;
use rustc_errors::ErrorGuaranteed;
use rustc_parse::parser::ForceCollect;
use rustc_session::config::ProcMacroExecutionStrategy;
use rustc_span::profiling::SpannedEventArgRecorder;
use rustc_span::{Span, DUMMY_SP};
use rustc_span::Span;

struct MessagePipe<T> {
tx: std::sync::mpsc::SyncSender<T>,
Expand Down Expand Up @@ -120,18 +118,13 @@ impl MultiItemModifier for DeriveProcMacro {
// We need special handling for statement items
// (e.g. `fn foo() { #[derive(Debug)] struct Bar; }`)
let is_stmt = matches!(item, Annotatable::Stmt(..));
let hack = crate::base::ann_pretty_printing_compatibility_hack(&item, &ecx.sess);
let input = if hack {
let nt = match item {
Annotatable::Item(item) => token::NtItem(item),
Annotatable::Stmt(stmt) => token::NtStmt(stmt),
_ => unreachable!(),
};
TokenStream::token_alone(token::Interpolated(Lrc::new(nt)), DUMMY_SP)
} else {
item.to_tokens()
};

// We used to have an alternative behaviour for crates that needed it.
// We had a lint for a long time, but now we just emit a hard error.
// Eventually we might remove the special case hard error check
// altogether. See #73345.
crate::base::ann_pretty_printing_compatibility_hack(&item, &ecx.sess);
let input = item.to_tokens();
let stream = {
let _timer =
ecx.sess.prof.generic_activity_with_arg_recorder("expand_proc_macro", |recorder| {
Expand Down
29 changes: 14 additions & 15 deletions compiler/rustc_expand/src/proc_macro_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,21 +276,20 @@ impl FromInternal<(TokenStream, &mut Rustc<'_, '_>)> for Vec<TokenTree<TokenStre

Interpolated(nt) => {
let stream = TokenStream::from_nonterminal_ast(&nt);
// A hack used to pass AST fragments to attribute and derive
// macros as a single nonterminal token instead of a token
// stream. Such token needs to be "unwrapped" and not
// represented as a delimited group.
// FIXME: It needs to be removed, but there are some
// compatibility issues (see #73345).
if crate::base::nt_pretty_printing_compatibility_hack(&nt, rustc.ecx.sess) {
trees.extend(Self::from_internal((stream, rustc)));
} else {
trees.push(TokenTree::Group(Group {
delimiter: pm::Delimiter::None,
stream: Some(stream),
span: DelimSpan::from_single(span),
}))
}
// We used to have an alternative behaviour for crates that
// needed it: a hack used to pass AST fragments to
// attribute and derive macros as a single nonterminal
// token instead of a token stream. Such token needs to be
// "unwrapped" and not represented as a delimited group. We
// had a lint for a long time, but now we just emit a hard
// error. Eventually we might remove the special case hard
// error check altogether. See #73345.
crate::base::nt_pretty_printing_compatibility_hack(&nt, rustc.ecx.sess);
trees.push(TokenTree::Group(Group {
delimiter: pm::Delimiter::None,
stream: Some(stream),
span: DelimSpan::from_single(span),
}))
}

OpenDelim(..) | CloseDelim(..) => unreachable!(),
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ty::ImplContainer => {
if segments.len() == 1 {
// `<T>::assoc` will end up here, and so
// can `T::assoc`. It this came from an
// can `T::assoc`. If this came from an
// inherent impl, we need to record the
// `T` for posterity (see `UserSelfTy` for
// details).
Expand Down Expand Up @@ -1416,11 +1416,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) {
Ok(ok) => self.register_infer_ok_obligations(ok),
Err(_) => {
self.dcx().span_delayed_bug(
self.dcx().span_bug(
span,
format!(
"instantiate_value_path: (UFCS) {self_ty:?} was a subtype of {impl_ty:?} but now is not?",
),
"instantiate_value_path: (UFCS) {self_ty:?} was a subtype of {impl_ty:?} but now is not?",
),
);
}
}
Expand Down
28 changes: 21 additions & 7 deletions compiler/rustc_hir_typeck/src/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use rustc_trait_selection::traits::query::method_autoderef::{
use rustc_trait_selection::traits::query::CanonicalTyGoal;
use rustc_trait_selection::traits::ObligationCtxt;
use rustc_trait_selection::traits::{self, ObligationCause};
use std::cell::Cell;
use std::cell::RefCell;
use std::cmp::max;
use std::iter;
Expand Down Expand Up @@ -76,8 +77,12 @@ pub(crate) struct ProbeContext<'a, 'tcx> {
/// requested name (by edit distance)
allow_similar_names: bool,

/// List of potential private candidates. Will be trimmed to ones that
/// actually apply and then the result inserted into `private_candidate`
private_candidates: Vec<Candidate<'tcx>>,

/// Some(candidate) if there is a private candidate
private_candidate: Option<(DefKind, DefId)>,
private_candidate: Cell<Option<(DefKind, DefId)>>,

/// Collects near misses when the candidate functions are missing a `self` keyword and is only
/// used for error reporting
Expand Down Expand Up @@ -581,7 +586,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
orig_steps_var_values,
steps,
allow_similar_names: false,
private_candidate: None,
private_candidates: Vec::new(),
private_candidate: Cell::new(None),
static_candidates: RefCell::new(Vec::new()),
unsatisfied_predicates: RefCell::new(Vec::new()),
scope_expr_id,
Expand All @@ -593,7 +599,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
self.inherent_candidates.clear();
self.extension_candidates.clear();
self.impl_dups.clear();
self.private_candidate = None;
self.private_candidates.clear();
self.private_candidate.set(None);
self.static_candidates.borrow_mut().clear();
self.unsatisfied_predicates.borrow_mut().clear();
}
Expand All @@ -617,9 +624,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
} else {
self.extension_candidates.push(candidate);
}
} else if self.private_candidate.is_none() {
self.private_candidate =
Some((candidate.item.kind.as_def_kind(), candidate.item.def_id));
} else {
self.private_candidates.push(candidate);
}
}

Expand Down Expand Up @@ -1171,7 +1177,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
let mut possibly_unsatisfied_predicates = Vec::new();

for (kind, candidates) in
&[("inherent", &self.inherent_candidates), ("extension", &self.extension_candidates)]
[("inherent", &self.inherent_candidates), ("extension", &self.extension_candidates)]
{
debug!("searching {} candidates", kind);
let res = self.consider_candidates(
Expand All @@ -1185,6 +1191,14 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
}
}

if self.private_candidate.get().is_none() {
if let Some(Ok(pick)) =
self.consider_candidates(self_ty, &self.private_candidates, &mut vec![], None)
{
self.private_candidate.set(Some((pick.item.kind.as_def_kind(), pick.item.def_id)));
}
}

// `pick_method` may be called twice for the same self_ty if no stable methods
// match. Only extend once.
if unstable_candidates.is_some() {
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -635,9 +635,6 @@ lint_pattern_in_foreign = patterns aren't allowed in foreign function declaratio
lint_private_extern_crate_reexport =
extern crate `{$ident}` is private, and cannot be re-exported, consider declaring with `pub`

lint_proc_macro_back_compat = using an old version of `{$crate_name}`
.note = older versions of the `{$crate_name}` crate will stop compiling in future versions of Rust; please update to `{$crate_name}` v{$fixed_version}, or switch to one of the `{$crate_name}` alternatives

lint_proc_macro_derive_resolution_fallback = cannot find {$ns} `{$ident}` in this scope
.label = names from parent modules are not accessible without an explicit import

Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_lint/src/context/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,6 @@ pub(super) fn decorate_lint(sess: &Session, diagnostic: BuiltinLintDiag, diag: &
BuiltinLintDiag::LegacyDeriveHelpers(label_span) => {
lints::LegacyDeriveHelpers { span: label_span }.decorate_lint(diag);
}
BuiltinLintDiag::ProcMacroBackCompat { crate_name, fixed_version } => {
lints::ProcMacroBackCompat { crate_name, fixed_version }.decorate_lint(diag);
}
BuiltinLintDiag::OrPatternsBackCompat(suggestion_span, suggestion) => {
lints::OrPatternsBackCompat { span: suggestion_span, suggestion }.decorate_lint(diag);
}
Expand Down
8 changes: 0 additions & 8 deletions compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2649,14 +2649,6 @@ pub struct LegacyDeriveHelpers {
pub span: Span,
}

#[derive(LintDiagnostic)]
#[diag(lint_proc_macro_back_compat)]
#[note]
pub struct ProcMacroBackCompat {
pub crate_name: String,
pub fixed_version: String,
}

#[derive(LintDiagnostic)]
#[diag(lint_or_patterns_back_compat)]
pub struct OrPatternsBackCompat {
Expand Down
Loading
Loading