Skip to content

Commit 7ad23f4

Browse files
committed
Auto merge of #146375 - matthiaskrgr:rollup-utik9zj, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #145463 (Reject invalid literal suffixes in tuple indexing, tuple struct indexing, and struct field name position) - #145929 (fix APITIT being treated as a normal generic parameter in suggestions) - #146001 (Update getopts to remove unicode-width dependency) - #146365 (triagebot: warn about #[rustc_intrinsic_const_stable_indirect]) - #146366 (add approx_delta to all gamma tests) - #146373 (fix comments about trait solver cycle heads) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 364da5d + a40ec4c commit 7ad23f4

File tree

24 files changed

+416
-129
lines changed

24 files changed

+416
-129
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ checksum = "fe6d2e5af09e8c8ad56c969f2157a3d4238cebc7c55f0a517728c38f7b200f81"
674674
dependencies = [
675675
"serde",
676676
"termcolor",
677-
"unicode-width 0.2.1",
677+
"unicode-width 0.1.14",
678678
]
679679

680680
[[package]]
@@ -1458,9 +1458,9 @@ dependencies = [
14581458

14591459
[[package]]
14601460
name = "getopts"
1461-
version = "0.2.23"
1461+
version = "0.2.24"
14621462
source = "registry+https://github.com/rust-lang/crates.io-index"
1463-
checksum = "cba6ae63eb948698e300f645f87c70f76630d505f23b8907cf1e193ee85048c1"
1463+
checksum = "cfe4fbac503b8d1f88e6676011885f34b7174f46e59956bba534ba83abded4df"
14641464
dependencies = [
14651465
"unicode-width 0.2.1",
14661466
]

compiler/rustc_hir_analysis/src/check/mod.rs

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ use rustc_infer::traits::ObligationCause;
8585
use rustc_middle::query::Providers;
8686
use rustc_middle::ty::error::{ExpectedFound, TypeError};
8787
use rustc_middle::ty::print::with_types_for_signature;
88-
use rustc_middle::ty::{self, GenericArgs, GenericArgsRef, Ty, TyCtxt, TypingMode};
88+
use rustc_middle::ty::{
89+
self, GenericArgs, GenericArgsRef, GenericParamDefKind, Ty, TyCtxt, TypingMode,
90+
};
8991
use rustc_middle::{bug, span_bug};
9092
use rustc_session::parse::feature_err;
9193
use rustc_span::def_id::CRATE_DEF_ID;
@@ -233,8 +235,7 @@ fn missing_items_err(
233235
};
234236

235237
// Obtain the level of indentation ending in `sugg_sp`.
236-
let padding =
237-
tcx.sess.source_map().indentation_before(sugg_sp).unwrap_or_else(|| String::new());
238+
let padding = tcx.sess.source_map().indentation_before(sugg_sp).unwrap_or_else(String::new);
238239
let (mut missing_trait_item, mut missing_trait_item_none, mut missing_trait_item_label) =
239240
(Vec::new(), Vec::new(), Vec::new());
240241

@@ -331,6 +332,7 @@ fn default_body_is_unstable(
331332
fn bounds_from_generic_predicates<'tcx>(
332333
tcx: TyCtxt<'tcx>,
333334
predicates: impl IntoIterator<Item = (ty::Clause<'tcx>, Span)>,
335+
assoc: ty::AssocItem,
334336
) -> (String, String) {
335337
let mut types: FxIndexMap<Ty<'tcx>, Vec<DefId>> = FxIndexMap::default();
336338
let mut projections = vec![];
@@ -354,34 +356,50 @@ fn bounds_from_generic_predicates<'tcx>(
354356
}
355357

356358
let mut where_clauses = vec![];
357-
let mut types_str = vec![];
358-
for (ty, bounds) in types {
359-
if let ty::Param(_) = ty.kind() {
360-
let mut bounds_str = vec![];
361-
for bound in bounds {
362-
let mut projections_str = vec![];
363-
for projection in &projections {
364-
let p = projection.skip_binder();
365-
if bound == tcx.parent(p.projection_term.def_id)
366-
&& p.projection_term.self_ty() == ty
367-
{
368-
let name = tcx.item_name(p.projection_term.def_id);
369-
projections_str.push(format!("{} = {}", name, p.term));
359+
let generics = tcx.generics_of(assoc.def_id);
360+
let types_str = generics
361+
.own_params
362+
.iter()
363+
.filter(|p| matches!(p.kind, GenericParamDefKind::Type { synthetic: false, .. }))
364+
.map(|p| {
365+
// we just checked that it's a type, so the unwrap can't fail
366+
let ty = tcx.mk_param_from_def(p).as_type().unwrap();
367+
if let Some(bounds) = types.get(&ty) {
368+
let mut bounds_str = vec![];
369+
for bound in bounds.iter().copied() {
370+
let mut projections_str = vec![];
371+
for projection in &projections {
372+
let p = projection.skip_binder();
373+
if bound == tcx.parent(p.projection_term.def_id)
374+
&& p.projection_term.self_ty() == ty
375+
{
376+
let name = tcx.item_name(p.projection_term.def_id);
377+
projections_str.push(format!("{} = {}", name, p.term));
378+
}
379+
}
380+
let bound_def_path = tcx.def_path_str(bound);
381+
if projections_str.is_empty() {
382+
where_clauses.push(format!("{}: {}", ty, bound_def_path));
383+
} else {
384+
bounds_str.push(format!(
385+
"{}<{}>",
386+
bound_def_path,
387+
projections_str.join(", ")
388+
));
370389
}
371390
}
372-
let bound_def_path = tcx.def_path_str(bound);
373-
if projections_str.is_empty() {
374-
where_clauses.push(format!("{}: {}", ty, bound_def_path));
391+
if bounds_str.is_empty() {
392+
ty.to_string()
375393
} else {
376-
bounds_str.push(format!("{}<{}>", bound_def_path, projections_str.join(", ")));
394+
format!("{}: {}", ty, bounds_str.join(" + "))
377395
}
378-
}
379-
if bounds_str.is_empty() {
380-
types_str.push(ty.to_string());
381396
} else {
382-
types_str.push(format!("{}: {}", ty, bounds_str.join(" + ")));
397+
ty.to_string()
383398
}
384-
} else {
399+
})
400+
.collect::<Vec<_>>();
401+
for (ty, bounds) in types.into_iter() {
402+
if !matches!(ty.kind(), ty::Param(_)) {
385403
// Avoid suggesting the following:
386404
// fn foo<T, <T as Trait>::Bar>(_: T) where T: Trait, <T as Trait>::Bar: Other {}
387405
where_clauses.extend(
@@ -473,10 +491,10 @@ fn fn_sig_suggestion<'tcx>(
473491
let output = if !output.is_unit() { format!(" -> {output}") } else { String::new() };
474492

475493
let safety = sig.safety.prefix_str();
476-
let (generics, where_clauses) = bounds_from_generic_predicates(tcx, predicates);
494+
let (generics, where_clauses) = bounds_from_generic_predicates(tcx, predicates, assoc);
477495

478496
// FIXME: this is not entirely correct, as the lifetimes from borrowed params will
479-
// not be present in the `fn` definition, not will we account for renamed
497+
// not be present in the `fn` definition, nor will we account for renamed
480498
// lifetimes between the `impl` and the `trait`, but this should be good enough to
481499
// fill in a significant portion of the missing code, and other subsequent
482500
// suggestions can help the user fix the code.
@@ -512,6 +530,7 @@ fn suggestion_signature<'tcx>(
512530
let (generics, where_clauses) = bounds_from_generic_predicates(
513531
tcx,
514532
tcx.predicates_of(assoc.def_id).instantiate_own(tcx, args),
533+
assoc,
515534
);
516535
format!("type {}{generics} = /* Type */{where_clauses};", assoc.name())
517536
}

compiler/rustc_parse/messages.ftl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,9 +479,6 @@ parse_invalid_identifier_with_leading_number = identifiers cannot start with a n
479479
480480
parse_invalid_literal_suffix_on_tuple_index = suffixes on a tuple index are invalid
481481
.label = invalid suffix `{$suffix}`
482-
.tuple_exception_line_1 = `{$suffix}` is *temporarily* accepted on tuple index fields as it was incorrectly accepted on stable for a few releases
483-
.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
484-
.tuple_exception_line_3 = see issue #60210 <https://github.com/rust-lang/rust/issues/60210> for more information
485482
486483
parse_invalid_logical_operator = `{$incorrect}` is not a logical operator
487484
.note = unlike in e.g., Python and PHP, `&&` and `||` are used for logical operators

compiler/rustc_parse/src/errors.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,10 +1017,6 @@ pub(crate) struct InvalidLiteralSuffixOnTupleIndex {
10171017
#[label]
10181018
pub span: Span,
10191019
pub suffix: Symbol,
1020-
#[help(parse_tuple_exception_line_1)]
1021-
#[help(parse_tuple_exception_line_2)]
1022-
#[help(parse_tuple_exception_line_3)]
1023-
pub exception: bool,
10241020
}
10251021

10261022
#[derive(Diagnostic)]

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,10 @@ impl<'a> Parser<'a> {
11631163
suffix,
11641164
}) => {
11651165
if let Some(suffix) = suffix {
1166-
self.expect_no_tuple_index_suffix(current.span, suffix);
1166+
self.dcx().emit_err(errors::InvalidLiteralSuffixOnTupleIndex {
1167+
span: current.span,
1168+
suffix,
1169+
});
11671170
}
11681171
match self.break_up_float(symbol, current.span) {
11691172
// 1e2
@@ -1239,7 +1242,8 @@ impl<'a> Parser<'a> {
12391242
suffix: Option<Symbol>,
12401243
) -> Box<Expr> {
12411244
if let Some(suffix) = suffix {
1242-
self.expect_no_tuple_index_suffix(ident_span, suffix);
1245+
self.dcx()
1246+
.emit_err(errors::InvalidLiteralSuffixOnTupleIndex { span: ident_span, suffix });
12431247
}
12441248
self.mk_expr(lo.to(ident_span), ExprKind::Field(base, Ident::new(field, ident_span)))
12451249
}
@@ -2225,24 +2229,6 @@ impl<'a> Parser<'a> {
22252229
})
22262230
}
22272231

2228-
pub(super) fn expect_no_tuple_index_suffix(&self, span: Span, suffix: Symbol) {
2229-
if [sym::i32, sym::u32, sym::isize, sym::usize].contains(&suffix) {
2230-
// #59553: warn instead of reject out of hand to allow the fix to percolate
2231-
// through the ecosystem when people fix their macros
2232-
self.dcx().emit_warn(errors::InvalidLiteralSuffixOnTupleIndex {
2233-
span,
2234-
suffix,
2235-
exception: true,
2236-
});
2237-
} else {
2238-
self.dcx().emit_err(errors::InvalidLiteralSuffixOnTupleIndex {
2239-
span,
2240-
suffix,
2241-
exception: false,
2242-
});
2243-
}
2244-
}
2245-
22462232
/// Matches `'-' lit | lit` (cf. `ast_validation::AstValidator::check_expr_within_pat`).
22472233
/// Keep this in sync with `Token::can_begin_literal_maybe_minus`.
22482234
pub fn parse_literal_maybe_minus(&mut self) -> PResult<'a, Box<Expr>> {

compiler/rustc_parse/src/parser/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1335,7 +1335,10 @@ impl<'a> Parser<'a> {
13351335
if let token::Literal(token::Lit { kind: token::Integer, symbol, suffix }) = self.token.kind
13361336
{
13371337
if let Some(suffix) = suffix {
1338-
self.expect_no_tuple_index_suffix(self.token.span, suffix);
1338+
self.dcx().emit_err(errors::InvalidLiteralSuffixOnTupleIndex {
1339+
span: self.token.span,
1340+
suffix,
1341+
});
13391342
}
13401343
self.bump();
13411344
Ok(Ident::new(symbol, self.prev_token.span))

compiler/rustc_type_ir/src/search_graph/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,7 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
12621262
encountered_overflow |= stack_entry.encountered_overflow;
12631263
debug_assert_eq!(stack_entry.input, input);
12641264

1265-
// If the current goal is not the root of a cycle, we are done.
1265+
// If the current goal is not a cycle head, we are done.
12661266
//
12671267
// There are no provisional cache entries which depend on this goal.
12681268
let Some(usages) = stack_entry.usages else {
@@ -1278,7 +1278,7 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
12781278
//
12791279
// Check whether we reached a fixpoint, either because the final result
12801280
// is equal to the provisional result of the previous iteration, or because
1281-
// this was only the root of either coinductive or inductive cycles, and the
1281+
// this was only the head of either coinductive or inductive cycles, and the
12821282
// final result is equal to the initial response for that case.
12831283
if self.reached_fixpoint(cx, &stack_entry, usages, result) {
12841284
self.rebase_provisional_cache_entries(&stack_entry, |_, result| result);

compiler/rustc_type_ir/src/search_graph/stack.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ rustc_index::newtype_index! {
1313
pub(super) struct StackDepth {}
1414
}
1515

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

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

4848
/// We want to be able to ignore head usages if they happen inside of candidates

library/Cargo.lock

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,12 @@ dependencies = [
9999

100100
[[package]]
101101
name = "getopts"
102-
version = "0.2.23"
102+
version = "0.2.24"
103103
source = "registry+https://github.com/rust-lang/crates.io-index"
104-
checksum = "cba6ae63eb948698e300f645f87c70f76630d505f23b8907cf1e193ee85048c1"
104+
checksum = "cfe4fbac503b8d1f88e6676011885f34b7174f46e59956bba534ba83abded4df"
105105
dependencies = [
106106
"rustc-std-workspace-core",
107107
"rustc-std-workspace-std",
108-
"unicode-width",
109108
]
110109

111110
[[package]]
@@ -361,16 +360,6 @@ dependencies = [
361360
"std",
362361
]
363362

364-
[[package]]
365-
name = "unicode-width"
366-
version = "0.2.1"
367-
source = "registry+https://github.com/rust-lang/crates.io-index"
368-
checksum = "4a1a07cc7db3810833284e8d372ccdc6da29741639ecc70c9ec107df0fa6154c"
369-
dependencies = [
370-
"rustc-std-workspace-core",
371-
"rustc-std-workspace-std",
372-
]
373-
374363
[[package]]
375364
name = "unwind"
376365
version = "0.0.0"

library/std/tests/floats/f32.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,13 @@ fn test_atanh() {
193193
#[test]
194194
fn test_gamma() {
195195
// precision can differ between platforms
196-
assert_approx_eq!(1.0f32.gamma(), 1.0f32);
197-
assert_approx_eq!(2.0f32.gamma(), 1.0f32);
198-
assert_approx_eq!(3.0f32.gamma(), 2.0f32);
196+
assert_approx_eq!(1.0f32.gamma(), 1.0f32, APPROX_DELTA);
197+
assert_approx_eq!(2.0f32.gamma(), 1.0f32, APPROX_DELTA);
198+
assert_approx_eq!(3.0f32.gamma(), 2.0f32, APPROX_DELTA);
199199
assert_approx_eq!(4.0f32.gamma(), 6.0f32, APPROX_DELTA);
200200
assert_approx_eq!(5.0f32.gamma(), 24.0f32, APPROX_DELTA);
201-
assert_approx_eq!(0.5f32.gamma(), consts::PI.sqrt());
202-
assert_approx_eq!((-0.5f32).gamma(), -2.0 * consts::PI.sqrt());
201+
assert_approx_eq!(0.5f32.gamma(), consts::PI.sqrt(), APPROX_DELTA);
202+
assert_approx_eq!((-0.5f32).gamma(), -2.0 * consts::PI.sqrt(), APPROX_DELTA);
203203
assert_eq!(0.0f32.gamma(), f32::INFINITY);
204204
assert_eq!((-0.0f32).gamma(), f32::NEG_INFINITY);
205205
assert!((-1.0f32).gamma().is_nan());

0 commit comments

Comments
 (0)