Skip to content

Rollup of 15 pull requests #138072

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

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
2c752bc
Undeprecate env::home_dir
arlosi Feb 20, 2025
812b1de
ref_pat_eat_one_layer_2024: add context and examples to the unstable …
dianne Feb 21, 2025
9323ba5
Remove MaybeForgetReturn suggestion
compiler-errors Feb 20, 2025
a7bd4a3
Add DWARF test case for non-C-like `repr128` enums
beetrees Feb 25, 2025
fb3aa33
Revert "Derive `Clone` on fewer THIR types."
skius Feb 27, 2025
b5f0c82
Add note to Thir struct about necessity of Clone derive
skius Feb 27, 2025
67cc82a
Inline VecDeque<u8> and BorrowedCursor methods
thaliaarchi Feb 15, 2025
41bdd2b
Override default Write methods for cursor-like types
thaliaarchi Feb 16, 2025
41dd80a
add test to reproduce #137662 (using ty decl macro fragment in an att…
jdonszelmann Feb 26, 2025
b119671
Tweak BufReader::peek() doctest to expose bug in Buffer::read_more()
wgwoods Mar 1, 2025
6d07144
Fix logic error in Buffer::read_more()
wgwoods Mar 1, 2025
adff091
Check dyn flavor before registering upcast goal on wide pointer cast …
compiler-errors Feb 25, 2025
133705c
[rustdoc] hide item that is not marked as doc(inline) and whose src i…
xizheyin Feb 27, 2025
ddd04d0
Add timestamp to unstable feature usage metrics
yaahc Feb 28, 2025
ab31129
Point of macro expansion from call expr if it involves macro var
compiler-errors Feb 24, 2025
e4dfca8
Point out macro expansion ident in resolver errors too
compiler-errors Feb 24, 2025
0607246
Fix associated type errors too
compiler-errors Feb 24, 2025
09e5846
Also note struct access, and fix macro expansion from foreign crates
compiler-errors Feb 24, 2025
e0b7577
linux x64: default to `-znostart-stop-gc`
lqd Feb 26, 2025
36efaf8
normalize away `-Wlinker-messages` wrappers from `rust-lld` rmake test
lqd Mar 5, 2025
cb7d687
Implement `&pin const self` and `&pin mut self` sugars
frank-king Jan 19, 2025
52cd874
Simplify `parse_self_param`
frank-king Mar 5, 2025
50d0f99
Simplify `rewrite_explicit_self`
frank-king Mar 5, 2025
40cc44e
Rollup merge of #135733 - frank-king:feature/pin-self-receiver, r=oli…
jieyouxu Mar 5, 2025
aa9a6cb
Rollup merge of #137107 - thaliaarchi:io-optional-methods/cursors, r=…
jieyouxu Mar 5, 2025
ea7630c
Rollup merge of #137303 - compiler-errors:maybe-forgor, r=cjgillot
jieyouxu Mar 5, 2025
56c69ac
Rollup merge of #137327 - arlosi:home-dir, r=Mark-Simulacrum
jieyouxu Mar 5, 2025
0b88627
Rollup merge of #137358 - dianne:new-match-ergonomics-examples, r=Nad…
jieyouxu Mar 5, 2025
c1c8f4b
Rollup merge of #137534 - xizheyin:issue-137342, r=GuillaumeGomez
jieyouxu Mar 5, 2025
8f557a0
Rollup merge of #137565 - compiler-errors:macro-ex, r=estebank
jieyouxu Mar 5, 2025
817028d
Rollup merge of #137637 - compiler-errors:dyn-cast-from-dyn-star, r=o…
jieyouxu Mar 5, 2025
f96dec2
Rollup merge of #137643 - beetrees:repr128-dwarf-variant-test, r=jiey…
jieyouxu Mar 5, 2025
aa7a3fc
Rollup merge of #137685 - lqd:nostart-stop-gc, r=petrochenkov
jieyouxu Mar 5, 2025
9af67eb
Rollup merge of #137744 - skius:master, r=Nadrieril
jieyouxu Mar 5, 2025
128a5ec
Rollup merge of #137758 - jdonszelmann:fix-137662, r=nnethercote
jieyouxu Mar 5, 2025
0f6565b
Rollup merge of #137827 - yaahc:timestamp-metrics, r=estebank
jieyouxu Mar 5, 2025
2df41b3
Rollup merge of #137832 - wgwoods:fix-bufreader-peek, r=joboet
jieyouxu Mar 5, 2025
97ae7d6
Rollup merge of #138052 - lqd:lld-linker-messages, r=jieyouxu
jieyouxu Mar 5, 2025
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
21 changes: 18 additions & 3 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2641,6 +2641,8 @@ pub enum SelfKind {
Value(Mutability),
/// `&'lt self`, `&'lt mut self`
Region(Option<Lifetime>, Mutability),
/// `&'lt pin const self`, `&'lt pin mut self`
Pinned(Option<Lifetime>, Mutability),
/// `self: TYPE`, `mut self: TYPE`
Explicit(P<Ty>, Mutability),
}
Expand All @@ -2650,6 +2652,8 @@ impl SelfKind {
match self {
SelfKind::Region(None, mutbl) => mutbl.ref_prefix_str().to_string(),
SelfKind::Region(Some(lt), mutbl) => format!("&{lt} {}", mutbl.prefix_str()),
SelfKind::Pinned(None, mutbl) => format!("&pin {}", mutbl.ptr_str()),
SelfKind::Pinned(Some(lt), mutbl) => format!("&{lt} pin {}", mutbl.ptr_str()),
SelfKind::Value(_) | SelfKind::Explicit(_, _) => {
unreachable!("if we had an explicit self, we wouldn't be here")
}
Expand All @@ -2666,11 +2670,13 @@ impl Param {
if ident.name == kw::SelfLower {
return match self.ty.kind {
TyKind::ImplicitSelf => Some(respan(self.pat.span, SelfKind::Value(mutbl))),
TyKind::Ref(lt, MutTy { ref ty, mutbl })
| TyKind::PinnedRef(lt, MutTy { ref ty, mutbl })
TyKind::Ref(lt, MutTy { ref ty, mutbl }) if ty.kind.is_implicit_self() => {
Some(respan(self.pat.span, SelfKind::Region(lt, mutbl)))
}
TyKind::PinnedRef(lt, MutTy { ref ty, mutbl })
if ty.kind.is_implicit_self() =>
{
Some(respan(self.pat.span, SelfKind::Region(lt, mutbl)))
Some(respan(self.pat.span, SelfKind::Pinned(lt, mutbl)))
}
_ => Some(respan(
self.pat.span.to(self.ty.span),
Expand Down Expand Up @@ -2712,6 +2718,15 @@ impl Param {
tokens: None,
}),
),
SelfKind::Pinned(lt, mutbl) => (
mutbl,
P(Ty {
id: DUMMY_NODE_ID,
kind: TyKind::PinnedRef(lt, MutTy { ty: infer_ty, mutbl }),
span,
tokens: None,
}),
),
};
Param {
attrs,
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1783,6 +1783,13 @@ impl<'a> State<'a> {
self.print_mutability(*m, false);
self.word("self")
}
SelfKind::Pinned(lt, m) => {
self.word("&");
self.print_opt_lifetime(lt);
self.word("pin ");
self.print_mutability(*m, true);
self.word("self")
}
SelfKind::Explicit(typ, m) => {
self.print_mutability(*m, false);
self.word("self");
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_attr_parsing/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,15 @@ impl<'a> MetaItemListParserContext<'a> {
{
self.inside_delimiters.next();
return Some(MetaItemOrLitParser::Lit(lit));
} else if let Some(TokenTree::Delimited(.., Delimiter::Invisible(_), inner_tokens)) =
self.inside_delimiters.peek()
{
self.inside_delimiters.next();
return MetaItemListParserContext {
inside_delimiters: inner_tokens.iter().peekable(),
dcx: self.dcx,
}
.next();
}

// or a path.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2120,8 +2120,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
//
// Note that other checks (such as denying `dyn Send` -> `dyn
// Debug`) are in `rustc_hir_typeck`.
if let ty::Dynamic(src_tty, _src_lt, _) = *src_tail.kind()
&& let ty::Dynamic(dst_tty, dst_lt, _) = *dst_tail.kind()
if let ty::Dynamic(src_tty, _src_lt, ty::Dyn) = *src_tail.kind()
&& let ty::Dynamic(dst_tty, dst_lt, ty::Dyn) = *dst_tail.kind()
&& src_tty.principal().is_some()
&& dst_tty.principal().is_some()
{
Expand Down
29 changes: 29 additions & 0 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3382,6 +3382,35 @@ fn add_lld_args(
// this, `wasm-component-ld`, which is overridden if this option is passed.
if !sess.target.is_like_wasm {
cmd.cc_arg("-fuse-ld=lld");

// On ELF platforms like at least x64 linux, GNU ld and LLD have opposite defaults on some
// section garbage-collection features. For example, the somewhat popular `linkme` crate and
// its dependents rely in practice on this difference: when using lld, they need `-z
// nostart-stop-gc` to prevent encapsulation symbols and sections from being
// garbage-collected.
//
// More information about all this can be found in:
// - https://maskray.me/blog/2021-01-31-metadata-sections-comdat-and-shf-link-order
// - https://lld.llvm.org/ELF/start-stop-gc
//
// So when using lld, we restore, for now, the traditional behavior to help migration, but
// will remove it in the future.
// Since this only disables an optimization, it shouldn't create issues, but is in theory
// slightly suboptimal. However, it:
// - doesn't have any visible impact on our benchmarks
// - reduces the need to disable lld for the crates that depend on this
//
// Note that lld can detect some cases where this difference is relied on, and emits a
// dedicated error to add this link arg. We could make use of this error to emit an FCW. As
// of writing this, we don't do it, because lld is already enabled by default on nightly
// without this mitigation: no working project would see the FCW, so we do this to help
// stabilization.
//
// FIXME: emit an FCW if linking fails due its absence, and then remove this link-arg in the
// future.
if sess.target.llvm_target == "x86_64-unknown-linux-gnu" {
cmd.link_arg("-znostart-stop-gc");
}
}

if !flavor.is_gnu() {
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,6 @@ pub enum StashKey {
MaybeFruTypo,
CallAssocMethod,
AssociatedTypeSuggestion,
MaybeForgetReturn,
/// Query cycle detected, stashing in favor of a better error.
Cycle,
UndeterminedMacroResolution,
Expand Down
16 changes: 15 additions & 1 deletion compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! List of the unstable feature gates.

use std::path::PathBuf;
use std::time::{SystemTime, UNIX_EPOCH};

use rustc_data_structures::fx::FxHashSet;
use rustc_span::{Span, Symbol, sym};
Expand Down Expand Up @@ -685,11 +686,13 @@ impl Features {
) -> Result<(), Box<dyn std::error::Error>> {
#[derive(serde::Serialize)]
struct LibFeature {
timestamp: u128,
symbol: String,
}

#[derive(serde::Serialize)]
struct LangFeature {
timestamp: u128,
symbol: String,
since: Option<String>,
}
Expand All @@ -703,10 +706,20 @@ impl Features {
let metrics_file = std::fs::File::create(metrics_path)?;
let metrics_file = std::io::BufWriter::new(metrics_file);

let now = || {
SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("system time should always be greater than the unix epoch")
.as_nanos()
};

let lib_features = self
.enabled_lib_features
.iter()
.map(|EnabledLibFeature { gate_name, .. }| LibFeature { symbol: gate_name.to_string() })
.map(|EnabledLibFeature { gate_name, .. }| LibFeature {
symbol: gate_name.to_string(),
timestamp: now(),
})
.collect();

let lang_features = self
Expand All @@ -715,6 +728,7 @@ impl Features {
.map(|EnabledLangFeature { gate_name, stable_since, .. }| LangFeature {
symbol: gate_name.to_string(),
since: stable_since.map(|since| since.to_string()),
timestamp: now(),
})
.collect();

Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_hir_analysis/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,8 @@ hir_analysis_variances_of = {$variances}
hir_analysis_where_clause_on_main = `main` function is not allowed to have a `where` clause
.label = `main` cannot have a `where` clause

hir_analysis_within_macro = due to this macro variable

hir_analysis_wrong_number_of_generic_arguments_to_intrinsic =
intrinsic has wrong number of {$descr} parameters: found {$found}, expected {$expected}
.label = expected {$expected} {$descr} {$expected ->
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_hir_analysis/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ pub(crate) struct AssocItemNotFound<'a> {
pub label: Option<AssocItemNotFoundLabel<'a>>,
#[subdiagnostic]
pub sugg: Option<AssocItemNotFoundSugg<'a>>,
#[label(hir_analysis_within_macro)]
pub within_macro_span: Option<Span>,
}

#[derive(Subdiagnostic)]
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
qself: &qself_str,
label: None,
sugg: None,
// Try to get the span of the identifier within the path's syntax context
// (if that's different).
within_macro_span: assoc_name.span.within_macro(span, tcx.sess.source_map()),
};

if is_dummy {
Expand Down
35 changes: 23 additions & 12 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3069,7 +3069,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
"ban_nonexisting_field: field={:?}, base={:?}, expr={:?}, base_ty={:?}",
ident, base, expr, base_ty
);
let mut err = self.no_such_field_err(ident, base_ty, base.hir_id);
let mut err = self.no_such_field_err(ident, base_ty, expr);

match *base_ty.peel_refs().kind() {
ty::Array(_, len) => {
Expand Down Expand Up @@ -3282,29 +3282,38 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
);
}

fn no_such_field_err(&self, field: Ident, expr_t: Ty<'tcx>, id: HirId) -> Diag<'_> {
fn no_such_field_err(
&self,
field: Ident,
base_ty: Ty<'tcx>,
expr: &hir::Expr<'tcx>,
) -> Diag<'_> {
let span = field.span;
debug!("no_such_field_err(span: {:?}, field: {:?}, expr_t: {:?})", span, field, expr_t);
debug!("no_such_field_err(span: {:?}, field: {:?}, expr_t: {:?})", span, field, base_ty);

let mut err = self.dcx().create_err(NoFieldOnType { span, ty: expr_t, field });
if expr_t.references_error() {
let mut err = self.dcx().create_err(NoFieldOnType { span, ty: base_ty, field });
if base_ty.references_error() {
err.downgrade_to_delayed_bug();
}

if let Some(within_macro_span) = span.within_macro(expr.span, self.tcx.sess.source_map()) {
err.span_label(within_macro_span, "due to this macro variable");
}

// try to add a suggestion in case the field is a nested field of a field of the Adt
let mod_id = self.tcx.parent_module(id).to_def_id();
let (ty, unwrap) = if let ty::Adt(def, args) = expr_t.kind()
let mod_id = self.tcx.parent_module(expr.hir_id).to_def_id();
let (ty, unwrap) = if let ty::Adt(def, args) = base_ty.kind()
&& (self.tcx.is_diagnostic_item(sym::Result, def.did())
|| self.tcx.is_diagnostic_item(sym::Option, def.did()))
&& let Some(arg) = args.get(0)
&& let Some(ty) = arg.as_type()
{
(ty, "unwrap().")
} else {
(expr_t, "")
(base_ty, "")
};
for (found_fields, args) in
self.get_field_candidates_considering_privacy_for_diag(span, ty, mod_id, id)
self.get_field_candidates_considering_privacy_for_diag(span, ty, mod_id, expr.hir_id)
{
let field_names = found_fields.iter().map(|field| field.name).collect::<Vec<_>>();
let mut candidate_fields: Vec<_> = found_fields
Expand All @@ -3317,7 +3326,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
args,
vec![],
mod_id,
id,
expr.hir_id,
)
})
.map(|mut field_path| {
Expand All @@ -3328,7 +3337,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
candidate_fields.sort();

let len = candidate_fields.len();
if len > 0 {
// Don't suggest `.field` if the base expr is from a different
// syntax context than the field.
if len > 0 && expr.span.eq_ctxt(field.span) {
err.span_suggestions(
field.span.shrink_to_lo(),
format!(
Expand Down Expand Up @@ -3963,7 +3974,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
_ => (),
};

self.no_such_field_err(field, container, expr.hir_id).emit();
self.no_such_field_err(field, container, expr).emit();

break;
}
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,12 +669,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

if !errors.is_empty() {
self.adjust_fulfillment_errors_for_expr_obligation(&mut errors);
let errors_causecode = errors
.iter()
.map(|e| (e.obligation.cause.span, e.root_obligation.cause.code().clone()))
.collect::<Vec<_>>();
self.err_ctxt().report_fulfillment_errors(errors);
self.collect_unused_stmts_for_coerce_return_ty(errors_causecode);
}
}

Expand Down
60 changes: 1 addition & 59 deletions compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ use std::{fmt, iter, mem};
use itertools::Itertools;
use rustc_data_structures::fx::FxIndexSet;
use rustc_errors::codes::*;
use rustc_errors::{
Applicability, Diag, ErrorGuaranteed, MultiSpan, StashKey, a_or_an, listify, pluralize,
};
use rustc_errors::{Applicability, Diag, ErrorGuaranteed, MultiSpan, a_or_an, listify, pluralize};
use rustc_hir::def::{CtorOf, DefKind, Res};
use rustc_hir::def_id::DefId;
use rustc_hir::intravisit::Visitor;
Expand Down Expand Up @@ -2193,62 +2191,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}

pub(super) fn collect_unused_stmts_for_coerce_return_ty(
&self,
errors_causecode: Vec<(Span, ObligationCauseCode<'tcx>)>,
) {
for (span, code) in errors_causecode {
self.dcx().try_steal_modify_and_emit_err(span, StashKey::MaybeForgetReturn, |err| {
if let Some(fn_sig) = self.body_fn_sig()
&& let ObligationCauseCode::WhereClauseInExpr(_, _, binding_hir_id, ..) = code
&& !fn_sig.output().is_unit()
{
let mut block_num = 0;
let mut found_semi = false;
for (hir_id, node) in self.tcx.hir_parent_iter(binding_hir_id) {
// Don't proceed into parent bodies
if hir_id.owner != binding_hir_id.owner {
break;
}
match node {
hir::Node::Stmt(stmt) => {
if let hir::StmtKind::Semi(expr) = stmt.kind {
let expr_ty = self.typeck_results.borrow().expr_ty(expr);
let return_ty = fn_sig.output();
if !matches!(expr.kind, hir::ExprKind::Ret(..))
&& self.may_coerce(expr_ty, return_ty)
{
found_semi = true;
}
}
}
hir::Node::Block(_block) => {
if found_semi {
block_num += 1;
}
}
hir::Node::Item(item) => {
if let hir::ItemKind::Fn { .. } = item.kind {
break;
}
}
_ => {}
}
}
if block_num > 1 && found_semi {
err.span_suggestion_verbose(
// use the span of the *whole* expr
self.tcx.hir().span(binding_hir_id).shrink_to_lo(),
"you might have meant to return this to infer its type parameters",
"return ",
Applicability::MaybeIncorrect,
);
}
}
});
}
}

/// Given a vector of fulfillment errors, try to adjust the spans of the
/// errors to more accurately point at the cause of the failure.
///
Expand Down
Loading
Loading