Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ checksum = "fe6d2e5af09e8c8ad56c969f2157a3d4238cebc7c55f0a517728c38f7b200f81"
dependencies = [
"serde",
"termcolor",
"unicode-width 0.2.1",
"unicode-width 0.1.14",
]

[[package]]
Expand Down Expand Up @@ -1458,9 +1458,9 @@ dependencies = [

[[package]]
name = "getopts"
version = "0.2.23"
version = "0.2.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cba6ae63eb948698e300f645f87c70f76630d505f23b8907cf1e193ee85048c1"
checksum = "cfe4fbac503b8d1f88e6676011885f34b7174f46e59956bba534ba83abded4df"
dependencies = [
"unicode-width 0.2.1",
]
Expand Down
73 changes: 46 additions & 27 deletions compiler/rustc_hir_analysis/src/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ use rustc_infer::traits::ObligationCause;
use rustc_middle::query::Providers;
use rustc_middle::ty::error::{ExpectedFound, TypeError};
use rustc_middle::ty::print::with_types_for_signature;
use rustc_middle::ty::{self, GenericArgs, GenericArgsRef, Ty, TyCtxt, TypingMode};
use rustc_middle::ty::{
self, GenericArgs, GenericArgsRef, GenericParamDefKind, Ty, TyCtxt, TypingMode,
};
use rustc_middle::{bug, span_bug};
use rustc_session::parse::feature_err;
use rustc_span::def_id::CRATE_DEF_ID;
Expand Down Expand Up @@ -233,8 +235,7 @@ fn missing_items_err(
};

// Obtain the level of indentation ending in `sugg_sp`.
let padding =
tcx.sess.source_map().indentation_before(sugg_sp).unwrap_or_else(|| String::new());
let padding = tcx.sess.source_map().indentation_before(sugg_sp).unwrap_or_else(String::new);
let (mut missing_trait_item, mut missing_trait_item_none, mut missing_trait_item_label) =
(Vec::new(), Vec::new(), Vec::new());

Expand Down Expand Up @@ -331,6 +332,7 @@ fn default_body_is_unstable(
fn bounds_from_generic_predicates<'tcx>(
tcx: TyCtxt<'tcx>,
predicates: impl IntoIterator<Item = (ty::Clause<'tcx>, Span)>,
assoc: ty::AssocItem,
) -> (String, String) {
let mut types: FxIndexMap<Ty<'tcx>, Vec<DefId>> = FxIndexMap::default();
let mut projections = vec![];
Expand All @@ -354,34 +356,50 @@ fn bounds_from_generic_predicates<'tcx>(
}

let mut where_clauses = vec![];
let mut types_str = vec![];
for (ty, bounds) in types {
if let ty::Param(_) = ty.kind() {
let mut bounds_str = vec![];
for bound in bounds {
let mut projections_str = vec![];
for projection in &projections {
let p = projection.skip_binder();
if bound == tcx.parent(p.projection_term.def_id)
&& p.projection_term.self_ty() == ty
{
let name = tcx.item_name(p.projection_term.def_id);
projections_str.push(format!("{} = {}", name, p.term));
let generics = tcx.generics_of(assoc.def_id);
let types_str = generics
.own_params
.iter()
.filter(|p| matches!(p.kind, GenericParamDefKind::Type { synthetic: false, .. }))
.map(|p| {
// we just checked that it's a type, so the unwrap can't fail
let ty = tcx.mk_param_from_def(p).as_type().unwrap();
if let Some(bounds) = types.get(&ty) {
let mut bounds_str = vec![];
for bound in bounds.iter().copied() {
let mut projections_str = vec![];
for projection in &projections {
let p = projection.skip_binder();
if bound == tcx.parent(p.projection_term.def_id)
&& p.projection_term.self_ty() == ty
{
let name = tcx.item_name(p.projection_term.def_id);
projections_str.push(format!("{} = {}", name, p.term));
}
}
let bound_def_path = tcx.def_path_str(bound);
if projections_str.is_empty() {
where_clauses.push(format!("{}: {}", ty, bound_def_path));
} else {
bounds_str.push(format!(
"{}<{}>",
bound_def_path,
projections_str.join(", ")
));
}
}
let bound_def_path = tcx.def_path_str(bound);
if projections_str.is_empty() {
where_clauses.push(format!("{}: {}", ty, bound_def_path));
if bounds_str.is_empty() {
ty.to_string()
} else {
bounds_str.push(format!("{}<{}>", bound_def_path, projections_str.join(", ")));
format!("{}: {}", ty, bounds_str.join(" + "))
}
}
if bounds_str.is_empty() {
types_str.push(ty.to_string());
} else {
types_str.push(format!("{}: {}", ty, bounds_str.join(" + ")));
ty.to_string()
}
} else {
})
.collect::<Vec<_>>();
for (ty, bounds) in types.into_iter() {
if !matches!(ty.kind(), ty::Param(_)) {
// Avoid suggesting the following:
// fn foo<T, <T as Trait>::Bar>(_: T) where T: Trait, <T as Trait>::Bar: Other {}
where_clauses.extend(
Expand Down Expand Up @@ -473,10 +491,10 @@ fn fn_sig_suggestion<'tcx>(
let output = if !output.is_unit() { format!(" -> {output}") } else { String::new() };

let safety = sig.safety.prefix_str();
let (generics, where_clauses) = bounds_from_generic_predicates(tcx, predicates);
let (generics, where_clauses) = bounds_from_generic_predicates(tcx, predicates, assoc);

// FIXME: this is not entirely correct, as the lifetimes from borrowed params will
// not be present in the `fn` definition, not will we account for renamed
// not be present in the `fn` definition, nor will we account for renamed
// lifetimes between the `impl` and the `trait`, but this should be good enough to
// fill in a significant portion of the missing code, and other subsequent
// suggestions can help the user fix the code.
Expand Down Expand Up @@ -512,6 +530,7 @@ fn suggestion_signature<'tcx>(
let (generics, where_clauses) = bounds_from_generic_predicates(
tcx,
tcx.predicates_of(assoc.def_id).instantiate_own(tcx, args),
assoc,
);
format!("type {}{generics} = /* Type */{where_clauses};", assoc.name())
}
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_parse/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,6 @@ parse_invalid_identifier_with_leading_number = identifiers cannot start with a n

parse_invalid_literal_suffix_on_tuple_index = suffixes on a tuple index are invalid
.label = invalid suffix `{$suffix}`
.tuple_exception_line_1 = `{$suffix}` is *temporarily* accepted on tuple index fields as it was incorrectly accepted on stable for a few releases
.tuple_exception_line_2 = on proc macros, you'll want to use `syn::Index::from` or `proc_macro::Literal::*_unsuffixed` for code that will desugar to tuple field access
.tuple_exception_line_3 = see issue #60210 <https://github.com/rust-lang/rust/issues/60210> for more information

parse_invalid_logical_operator = `{$incorrect}` is not a logical operator
.note = unlike in e.g., Python and PHP, `&&` and `||` are used for logical operators
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_parse/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1017,10 +1017,6 @@ pub(crate) struct InvalidLiteralSuffixOnTupleIndex {
#[label]
pub span: Span,
pub suffix: Symbol,
#[help(parse_tuple_exception_line_1)]
#[help(parse_tuple_exception_line_2)]
#[help(parse_tuple_exception_line_3)]
pub exception: bool,
}

#[derive(Diagnostic)]
Expand Down
26 changes: 6 additions & 20 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,10 @@ impl<'a> Parser<'a> {
suffix,
}) => {
if let Some(suffix) = suffix {
self.expect_no_tuple_index_suffix(current.span, suffix);
self.dcx().emit_err(errors::InvalidLiteralSuffixOnTupleIndex {
span: current.span,
suffix,
});
}
match self.break_up_float(symbol, current.span) {
// 1e2
Expand Down Expand Up @@ -1239,7 +1242,8 @@ impl<'a> Parser<'a> {
suffix: Option<Symbol>,
) -> Box<Expr> {
if let Some(suffix) = suffix {
self.expect_no_tuple_index_suffix(ident_span, suffix);
self.dcx()
.emit_err(errors::InvalidLiteralSuffixOnTupleIndex { span: ident_span, suffix });
}
self.mk_expr(lo.to(ident_span), ExprKind::Field(base, Ident::new(field, ident_span)))
}
Expand Down Expand Up @@ -2225,24 +2229,6 @@ impl<'a> Parser<'a> {
})
}

pub(super) fn expect_no_tuple_index_suffix(&self, span: Span, suffix: Symbol) {
if [sym::i32, sym::u32, sym::isize, sym::usize].contains(&suffix) {
// #59553: warn instead of reject out of hand to allow the fix to percolate
// through the ecosystem when people fix their macros
self.dcx().emit_warn(errors::InvalidLiteralSuffixOnTupleIndex {
span,
suffix,
exception: true,
});
} else {
self.dcx().emit_err(errors::InvalidLiteralSuffixOnTupleIndex {
span,
suffix,
exception: false,
});
}
}

/// Matches `'-' lit | lit` (cf. `ast_validation::AstValidator::check_expr_within_pat`).
/// Keep this in sync with `Token::can_begin_literal_maybe_minus`.
pub fn parse_literal_maybe_minus(&mut self) -> PResult<'a, Box<Expr>> {
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_parse/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1335,7 +1335,10 @@ impl<'a> Parser<'a> {
if let token::Literal(token::Lit { kind: token::Integer, symbol, suffix }) = self.token.kind
{
if let Some(suffix) = suffix {
self.expect_no_tuple_index_suffix(self.token.span, suffix);
self.dcx().emit_err(errors::InvalidLiteralSuffixOnTupleIndex {
span: self.token.span,
suffix,
});
}
self.bump();
Ok(Ident::new(symbol, self.prev_token.span))
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_type_ir/src/search_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,7 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
encountered_overflow |= stack_entry.encountered_overflow;
debug_assert_eq!(stack_entry.input, input);

// If the current goal is not the root of a cycle, we are done.
// If the current goal is not a cycle head, we are done.
//
// There are no provisional cache entries which depend on this goal.
let Some(usages) = stack_entry.usages else {
Expand All @@ -1278,7 +1278,7 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
//
// Check whether we reached a fixpoint, either because the final result
// is equal to the provisional result of the previous iteration, or because
// this was only the root of either coinductive or inductive cycles, and the
// this was only the head of either coinductive or inductive cycles, and the
// final result is equal to the initial response for that case.
if self.reached_fixpoint(cx, &stack_entry, usages, result) {
self.rebase_provisional_cache_entries(&stack_entry, |_, result| result);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_type_ir/src/search_graph/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ rustc_index::newtype_index! {
pub(super) struct StackDepth {}
}

/// Stack entries of the evaluation stack. Its fields tend to be lazily
/// Stack entries of the evaluation stack. Its fields tend to be lazily updated
/// when popping a child goal or completely immutable.
#[derive_where(Debug; X: Cx)]
pub(super) struct StackEntry<X: Cx> {
Expand Down Expand Up @@ -42,7 +42,7 @@ pub(super) struct StackEntry<X: Cx> {
/// Whether evaluating this goal encountered overflow. Lazily updated.
pub encountered_overflow: bool,

/// Whether and how this goal has been used as the root of a cycle. Lazily updated.
/// Whether and how this goal has been used as a cycle head. Lazily updated.
pub usages: Option<HeadUsages>,

/// We want to be able to ignore head usages if they happen inside of candidates
Expand Down
15 changes: 2 additions & 13 deletions library/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,12 @@ dependencies = [

[[package]]
name = "getopts"
version = "0.2.23"
version = "0.2.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cba6ae63eb948698e300f645f87c70f76630d505f23b8907cf1e193ee85048c1"
checksum = "cfe4fbac503b8d1f88e6676011885f34b7174f46e59956bba534ba83abded4df"
dependencies = [
"rustc-std-workspace-core",
"rustc-std-workspace-std",
"unicode-width",
]

[[package]]
Expand Down Expand Up @@ -361,16 +360,6 @@ dependencies = [
"std",
]

[[package]]
name = "unicode-width"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a1a07cc7db3810833284e8d372ccdc6da29741639ecc70c9ec107df0fa6154c"
dependencies = [
"rustc-std-workspace-core",
"rustc-std-workspace-std",
]

[[package]]
name = "unwind"
version = "0.0.0"
Expand Down
10 changes: 5 additions & 5 deletions library/std/tests/floats/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,13 @@ fn test_atanh() {
#[test]
fn test_gamma() {
// precision can differ between platforms
assert_approx_eq!(1.0f32.gamma(), 1.0f32);
assert_approx_eq!(2.0f32.gamma(), 1.0f32);
assert_approx_eq!(3.0f32.gamma(), 2.0f32);
assert_approx_eq!(1.0f32.gamma(), 1.0f32, APPROX_DELTA);
assert_approx_eq!(2.0f32.gamma(), 1.0f32, APPROX_DELTA);
assert_approx_eq!(3.0f32.gamma(), 2.0f32, APPROX_DELTA);
assert_approx_eq!(4.0f32.gamma(), 6.0f32, APPROX_DELTA);
assert_approx_eq!(5.0f32.gamma(), 24.0f32, APPROX_DELTA);
assert_approx_eq!(0.5f32.gamma(), consts::PI.sqrt());
assert_approx_eq!((-0.5f32).gamma(), -2.0 * consts::PI.sqrt());
assert_approx_eq!(0.5f32.gamma(), consts::PI.sqrt(), APPROX_DELTA);
assert_approx_eq!((-0.5f32).gamma(), -2.0 * consts::PI.sqrt(), APPROX_DELTA);
assert_eq!(0.0f32.gamma(), f32::INFINITY);
assert_eq!((-0.0f32).gamma(), f32::NEG_INFINITY);
assert!((-1.0f32).gamma().is_nan());
Expand Down
2 changes: 1 addition & 1 deletion library/test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ version = "0.0.0"
edition = "2024"

[dependencies]
getopts = { version = "0.2.21", features = ['rustc-dep-of-std'] }
getopts = { version = "0.2.24", default-features = false, features = ['rustc-dep-of-std'] }
std = { path = "../std", public = true }
core = { path = "../core", public = true }

Expand Down
1 change: 0 additions & 1 deletion src/tools/tidy/src/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,6 @@ const PERMITTED_STDLIB_DEPENDENCIES: &[&str] = &[
"rustc-demangle",
"rustc-literal-escaper",
"shlex",
"unicode-width",
"unwinding",
"wasi",
"windows-sys",
Expand Down
1 change: 0 additions & 1 deletion src/tools/tidy/src/issues.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2021,7 +2021,6 @@ ui/parser/issues/issue-5806.rs
ui/parser/issues/issue-58094-missing-right-square-bracket.rs
ui/parser/issues/issue-58856-1.rs
ui/parser/issues/issue-58856-2.rs
ui/parser/issues/issue-59418.rs
ui/parser/issues/issue-60075.rs
ui/parser/issues/issue-61858.rs
ui/parser/issues/issue-62524.rs
Expand Down
33 changes: 33 additions & 0 deletions tests/ui/parser/auxiliary/tuple-index-suffix-proc-macro-aux.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#![feature(proc_macro_quote, proc_macro_span)]

extern crate proc_macro;

use proc_macro::{Ident, Literal, Span, TokenStream, TokenTree, quote};

#[proc_macro]
pub fn bad_tup_indexing(input: TokenStream) -> TokenStream {
let tt = input.into_iter().next().unwrap();
let TokenTree::Literal(indexing_expr) = tt else {
unreachable!();
};
quote! { (42,).$indexing_expr }
}

// Expects {IDENT, COMMA, LITERAL}
#[proc_macro]
pub fn bad_tup_struct_indexing(input: TokenStream) -> TokenStream {
let mut input = input.into_iter();

let ident = input.next().unwrap();
let _comma = input.next().unwrap();
let lit = input.next().unwrap();

let TokenTree::Ident(ident) = ident else {
unreachable!("id");
};
let TokenTree::Literal(indexing_expr) = lit else {
unreachable!("lit");
};

quote! { $ident.$indexing_expr }
}
18 changes: 0 additions & 18 deletions tests/ui/parser/issues/issue-59418.rs

This file was deleted.

Loading
Loading