Skip to content

Commit 5746c75

Browse files
committed
Auto merge of rust-lang#100626 - Dylan-DPC:rollup-mwbm7kj, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - rust-lang#99942 (Fix nonsense non-tupled `Fn` trait error) - rust-lang#100609 (Extend invalid floating point literal suffix suggestion) - rust-lang#100610 (Ast and parser tweaks) - rust-lang#100613 (compiletest: fix typo in runtest.rs) - rust-lang#100616 (:arrow_up: rust-analyzer) - rust-lang#100622 (Support 128-bit atomics on all aarch64 targets) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents a39bdb1 + 35bd1d6 commit 5746c75

File tree

139 files changed

+5964
-5168
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+5964
-5168
lines changed

compiler/rustc_ast/src/ast.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,6 @@ pub struct WhereRegionPredicate {
497497
/// E.g., `T = int`.
498498
#[derive(Clone, Encodable, Decodable, Debug)]
499499
pub struct WhereEqPredicate {
500-
pub id: NodeId,
501500
pub span: Span,
502501
pub lhs_ty: P<Ty>,
503502
pub rhs_ty: P<Ty>,
@@ -3042,6 +3041,7 @@ mod size_asserts {
30423041
static_assert_size!(Attribute, 32);
30433042
static_assert_size!(Block, 48);
30443043
static_assert_size!(Expr, 104);
3044+
static_assert_size!(ExprKind, 72);
30453045
static_assert_size!(Fn, 192);
30463046
static_assert_size!(ForeignItem, 160);
30473047
static_assert_size!(ForeignItemKind, 72);
@@ -3051,9 +3051,13 @@ mod size_asserts {
30513051
static_assert_size!(Item, 200);
30523052
static_assert_size!(ItemKind, 112);
30533053
static_assert_size!(Lit, 48);
3054+
static_assert_size!(LitKind, 24);
30543055
static_assert_size!(Pat, 120);
3056+
static_assert_size!(PatKind, 96);
30553057
static_assert_size!(Path, 40);
30563058
static_assert_size!(PathSegment, 24);
30573059
static_assert_size!(Stmt, 32);
3060+
static_assert_size!(StmtKind, 16);
30583061
static_assert_size!(Ty, 96);
3062+
static_assert_size!(TyKind, 72);
30593063
}

compiler/rustc_ast/src/mut_visit.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -935,8 +935,7 @@ pub fn noop_visit_where_predicate<T: MutVisitor>(pred: &mut WherePredicate, vis:
935935
visit_vec(bounds, |bound| noop_visit_param_bound(bound, vis));
936936
}
937937
WherePredicate::EqPredicate(ep) => {
938-
let WhereEqPredicate { id, span, lhs_ty, rhs_ty } = ep;
939-
vis.visit_id(id);
938+
let WhereEqPredicate { span, lhs_ty, rhs_ty } = ep;
940939
vis.visit_span(span);
941940
vis.visit_ty(lhs_ty);
942941
vis.visit_ty(rhs_ty);

compiler/rustc_ast_lowering/src/item.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1498,9 +1498,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
14981498
),
14991499
in_where_clause: true,
15001500
}),
1501-
WherePredicate::EqPredicate(WhereEqPredicate { id, ref lhs_ty, ref rhs_ty, span }) => {
1501+
WherePredicate::EqPredicate(WhereEqPredicate { ref lhs_ty, ref rhs_ty, span }) => {
15021502
hir::WherePredicate::EqPredicate(hir::WhereEqPredicate {
1503-
hir_id: self.lower_node_id(id),
15041503
lhs_ty: self
15051504
.lower_ty(lhs_ty, ImplTraitContext::Disallowed(ImplTraitPosition::Type)),
15061505
rhs_ty: self

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -640,11 +640,7 @@ impl<'a> TraitDef<'a> {
640640
}
641641
ast::WherePredicate::EqPredicate(we) => {
642642
let span = we.span.with_ctxt(ctxt);
643-
ast::WherePredicate::EqPredicate(ast::WhereEqPredicate {
644-
id: ast::DUMMY_NODE_ID,
645-
span,
646-
..we.clone()
647-
})
643+
ast::WherePredicate::EqPredicate(ast::WhereEqPredicate { span, ..we.clone() })
648644
}
649645
}
650646
}));

compiler/rustc_hir/src/hir.rs

-1
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,6 @@ impl<'hir> WhereRegionPredicate<'hir> {
778778
/// An equality predicate (e.g., `T = int`); currently unsupported.
779779
#[derive(Debug, HashStable_Generic)]
780780
pub struct WhereEqPredicate<'hir> {
781-
pub hir_id: HirId,
782781
pub span: Span,
783782
pub lhs_ty: &'hir Ty<'hir>,
784783
pub rhs_ty: &'hir Ty<'hir>,

compiler/rustc_hir/src/intravisit.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -876,10 +876,7 @@ pub fn walk_where_predicate<'v, V: Visitor<'v>>(
876876
visitor.visit_lifetime(lifetime);
877877
walk_list!(visitor, visit_param_bound, bounds);
878878
}
879-
WherePredicate::EqPredicate(WhereEqPredicate {
880-
hir_id, ref lhs_ty, ref rhs_ty, ..
881-
}) => {
882-
visitor.visit_id(hir_id);
879+
WherePredicate::EqPredicate(WhereEqPredicate { ref lhs_ty, ref rhs_ty, .. }) => {
883880
visitor.visit_ty(lhs_ty);
884881
visitor.visit_ty(rhs_ty);
885882
}

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1750,6 +1750,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
17501750
if let Some(ValuePairs::PolyTraitRefs(exp_found)) = values
17511751
&& let ty::Closure(def_id, _) = exp_found.expected.skip_binder().self_ty().kind()
17521752
&& let Some(def_id) = def_id.as_local()
1753+
&& terr.involves_regions()
17531754
{
17541755
let span = self.tcx.def_span(def_id);
17551756
diag.span_note(span, "this closure does not fulfill the lifetime requirements");

compiler/rustc_infer/src/infer/mod.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1935,6 +1935,18 @@ impl<'tcx> TypeTrace<'tcx> {
19351935
}
19361936
}
19371937

1938+
pub fn poly_trait_refs(
1939+
cause: &ObligationCause<'tcx>,
1940+
a_is_expected: bool,
1941+
a: ty::PolyTraitRef<'tcx>,
1942+
b: ty::PolyTraitRef<'tcx>,
1943+
) -> TypeTrace<'tcx> {
1944+
TypeTrace {
1945+
cause: cause.clone(),
1946+
values: PolyTraitRefs(ExpectedFound::new(a_is_expected, a.into(), b.into())),
1947+
}
1948+
}
1949+
19381950
pub fn consts(
19391951
cause: &ObligationCause<'tcx>,
19401952
a_is_expected: bool,

compiler/rustc_middle/src/ty/error.rs

+12
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ pub enum TypeError<'tcx> {
7474
TargetFeatureCast(DefId),
7575
}
7676

77+
impl TypeError<'_> {
78+
pub fn involves_regions(self) -> bool {
79+
match self {
80+
TypeError::RegionsDoesNotOutlive(_, _)
81+
| TypeError::RegionsInsufficientlyPolymorphic(_, _)
82+
| TypeError::RegionsOverlyPolymorphic(_, _)
83+
| TypeError::RegionsPlaceholderMismatch => true,
84+
_ => false,
85+
}
86+
}
87+
}
88+
7789
/// Explains the source of a type err in a short, human readable way. This is meant to be placed
7890
/// in parentheses after some larger message. You should also invoke `note_and_explain_type_err()`
7991
/// afterwards to present additional details, particularly when it comes to lifetime-related

compiler/rustc_parse/src/parser/generics.rs

-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,6 @@ impl<'a> Parser<'a> {
314314
span: lo.to(self.prev_token.span),
315315
lhs_ty: ty,
316316
rhs_ty,
317-
id: ast::DUMMY_NODE_ID,
318317
}))
319318
} else {
320319
self.maybe_recover_bounds_doubled_colon(&ty)?;

compiler/rustc_parse/src/parser/path.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ impl<'a> Parser<'a> {
527527
Ok(ident_gen_args) => ident_gen_args,
528528
Err(()) => return Ok(Some(AngleBracketedArg::Arg(arg))),
529529
};
530-
if binder.is_some() {
530+
if binder {
531531
// FIXME(compiler-errors): this could be improved by suggesting lifting
532532
// this up to the trait, at least before this becomes real syntax.
533533
// e.g. `Trait<for<'a> Assoc = Ty>` -> `for<'a> Trait<Assoc = Ty>`
@@ -720,28 +720,24 @@ impl<'a> Parser<'a> {
720720

721721
/// Given a arg inside of generics, we try to destructure it as if it were the LHS in
722722
/// `LHS = ...`, i.e. an associated type binding.
723-
/// This returns (optionally, if they are present) any `for<'a, 'b>` binder args, the
723+
/// This returns a bool indicating if there are any `for<'a, 'b>` binder args, the
724724
/// identifier, and any GAT arguments.
725725
fn get_ident_from_generic_arg(
726726
&self,
727727
gen_arg: &GenericArg,
728-
) -> Result<(Option<Vec<ast::GenericParam>>, Ident, Option<GenericArgs>), ()> {
728+
) -> Result<(bool, Ident, Option<GenericArgs>), ()> {
729729
if let GenericArg::Type(ty) = gen_arg {
730730
if let ast::TyKind::Path(qself, path) = &ty.kind
731731
&& qself.is_none()
732732
&& let [seg] = path.segments.as_slice()
733733
{
734-
return Ok((None, seg.ident, seg.args.as_deref().cloned()));
734+
return Ok((false, seg.ident, seg.args.as_deref().cloned()));
735735
} else if let ast::TyKind::TraitObject(bounds, ast::TraitObjectSyntax::None) = &ty.kind
736736
&& let [ast::GenericBound::Trait(trait_ref, ast::TraitBoundModifier::None)] =
737737
bounds.as_slice()
738738
&& let [seg] = trait_ref.trait_ref.path.segments.as_slice()
739739
{
740-
return Ok((
741-
Some(trait_ref.bound_generic_params.clone()),
742-
seg.ident,
743-
seg.args.as_deref().cloned(),
744-
));
740+
return Ok((true, seg.ident, seg.args.as_deref().cloned()));
745741
}
746742
}
747743
Err(())

compiler/rustc_target/src/spec/aarch64_pc_windows_gnullvm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::spec::Target;
22

33
pub fn target() -> Target {
44
let mut base = super::windows_gnullvm_base::opts();
5-
base.max_atomic_width = Some(64);
5+
base.max_atomic_width = Some(128);
66
base.features = "+neon,+fp-armv8".into();
77
base.linker = Some("aarch64-w64-mingw32-clang".into());
88

compiler/rustc_target/src/spec/aarch64_pc_windows_msvc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::spec::Target;
22

33
pub fn target() -> Target {
44
let mut base = super::windows_msvc_base::opts();
5-
base.max_atomic_width = Some(64);
5+
base.max_atomic_width = Some(128);
66
base.features = "+neon,+fp-armv8".into();
77

88
Target {

compiler/rustc_target/src/spec/aarch64_unknown_uefi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::spec::{LinkerFlavor, Target};
77
pub fn target() -> Target {
88
let mut base = uefi_msvc_base::opts();
99

10-
base.max_atomic_width = Some(64);
10+
base.max_atomic_width = Some(128);
1111
base.add_pre_link_args(LinkerFlavor::Msvc, &["/machine:arm64"]);
1212

1313
Target {

compiler/rustc_target/src/spec/aarch64_uwp_windows_msvc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::spec::Target;
22

33
pub fn target() -> Target {
44
let mut base = super::windows_uwp_msvc_base::opts();
5-
base.max_atomic_width = Some(64);
5+
base.max_atomic_width = Some(128);
66

77
Target {
88
llvm_target: "aarch64-pc-windows-msvc".into(),

compiler/rustc_target/src/spec/arm64_32_apple_watchos.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub fn target() -> Target {
1010
arch: "aarch64".into(),
1111
options: TargetOptions {
1212
features: "+neon,+fp-armv8,+apple-a7".into(),
13-
max_atomic_width: Some(64),
13+
max_atomic_width: Some(128),
1414
forces_embed_bitcode: true,
1515
// These arguments are not actually invoked - they just have
1616
// to look right to pass App Store validation.

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+27-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use rustc_hir::intravisit::Visitor;
2222
use rustc_hir::GenericParam;
2323
use rustc_hir::Item;
2424
use rustc_hir::Node;
25+
use rustc_infer::infer::TypeTrace;
2526
use rustc_infer::traits::TraitEngine;
2627
use rustc_middle::traits::select::OverflowError;
2728
use rustc_middle::ty::abstract_const::NotConstEvaluatable;
@@ -941,20 +942,43 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
941942

942943
self.reported_closure_mismatch.borrow_mut().insert((span, found_span));
943944

945+
let mut not_tupled = false;
946+
944947
let found = match found_trait_ref.skip_binder().substs.type_at(1).kind() {
945948
ty::Tuple(ref tys) => vec![ArgKind::empty(); tys.len()],
946-
_ => vec![ArgKind::empty()],
949+
_ => {
950+
not_tupled = true;
951+
vec![ArgKind::empty()]
952+
}
947953
};
948954

949955
let expected_ty = expected_trait_ref.skip_binder().substs.type_at(1);
950956
let expected = match expected_ty.kind() {
951957
ty::Tuple(ref tys) => {
952958
tys.iter().map(|t| ArgKind::from_expected_ty(t, Some(span))).collect()
953959
}
954-
_ => vec![ArgKind::Arg("_".to_owned(), expected_ty.to_string())],
960+
_ => {
961+
not_tupled = true;
962+
vec![ArgKind::Arg("_".to_owned(), expected_ty.to_string())]
963+
}
955964
};
956965

957-
if found.len() == expected.len() {
966+
// If this is a `Fn` family trait and either the expected or found
967+
// is not tupled, then fall back to just a regular mismatch error.
968+
// This shouldn't be common unless manually implementing one of the
969+
// traits manually, but don't make it more confusing when it does
970+
// happen.
971+
if Some(expected_trait_ref.def_id()) != tcx.lang_items().gen_trait() && not_tupled {
972+
self.report_and_explain_type_error(
973+
TypeTrace::poly_trait_refs(
974+
&obligation.cause,
975+
true,
976+
expected_trait_ref,
977+
found_trait_ref,
978+
),
979+
ty::error::TypeError::Mismatch,
980+
)
981+
} else if found.len() == expected.len() {
958982
self.report_closure_arg_mismatch(
959983
span,
960984
found_span,

compiler/rustc_typeck/src/check/expr.rs

+27-8
Original file line numberDiff line numberDiff line change
@@ -2193,7 +2193,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21932193
E0610,
21942194
"`{expr_t}` is a primitive type and therefore doesn't have fields",
21952195
);
2196-
let is_valid_suffix = |field: String| {
2196+
let is_valid_suffix = |field: &str| {
21972197
if field == "f32" || field == "f64" {
21982198
return true;
21992199
}
@@ -2218,20 +2218,39 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
22182218
let suffix = chars.collect::<String>();
22192219
suffix.is_empty() || suffix == "f32" || suffix == "f64"
22202220
};
2221+
let maybe_partial_suffix = |field: &str| -> Option<&str> {
2222+
let first_chars = ['f', 'l'];
2223+
if field.len() >= 1
2224+
&& field.to_lowercase().starts_with(first_chars)
2225+
&& field[1..].chars().all(|c| c.is_ascii_digit())
2226+
{
2227+
if field.to_lowercase().starts_with(['f']) { Some("f32") } else { Some("f64") }
2228+
} else {
2229+
None
2230+
}
2231+
};
22212232
if let ty::Infer(ty::IntVar(_)) = expr_t.kind()
22222233
&& let ExprKind::Lit(Spanned {
22232234
node: ast::LitKind::Int(_, ast::LitIntType::Unsuffixed),
22242235
..
22252236
}) = base.kind
22262237
&& !base.span.from_expansion()
2227-
&& is_valid_suffix(field_name)
22282238
{
2229-
err.span_suggestion_verbose(
2230-
field.span.shrink_to_lo(),
2231-
"If the number is meant to be a floating point number, consider adding a `0` after the period",
2232-
'0',
2233-
Applicability::MaybeIncorrect,
2234-
);
2239+
if is_valid_suffix(&field_name) {
2240+
err.span_suggestion_verbose(
2241+
field.span.shrink_to_lo(),
2242+
"if intended to be a floating point literal, consider adding a `0` after the period",
2243+
'0',
2244+
Applicability::MaybeIncorrect,
2245+
);
2246+
} else if let Some(correct_suffix) = maybe_partial_suffix(&field_name) {
2247+
err.span_suggestion_verbose(
2248+
field.span,
2249+
format!("if intended to be a floating point literal, consider adding a `0` after the period and a `{correct_suffix}` suffix"),
2250+
format!("0{correct_suffix}"),
2251+
Applicability::MaybeIncorrect,
2252+
);
2253+
}
22352254
}
22362255
err.emit();
22372256
}

src/test/ui/attempted-access-non-fatal.rs

+4
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@ fn main() {
33
let x = 0;
44
let _ = x.foo; //~ `{integer}` is a primitive type and therefore doesn't have fields [E0610]
55
let _ = x.bar; //~ `{integer}` is a primitive type and therefore doesn't have fields [E0610]
6+
let _ = 0.f; //~ `{integer}` is a primitive type and therefore doesn't have fields [E0610]
7+
let _ = 2.l; //~ `{integer}` is a primitive type and therefore doesn't have fields [E0610]
8+
let _ = 12.F; //~ `{integer}` is a primitive type and therefore doesn't have fields [E0610]
9+
let _ = 34.L; //~ `{integer}` is a primitive type and therefore doesn't have fields [E0610]
610
}

src/test/ui/attempted-access-non-fatal.stderr

+45-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,50 @@ error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields
1010
LL | let _ = x.bar;
1111
| ^^^
1212

13-
error: aborting due to 2 previous errors
13+
error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields
14+
--> $DIR/attempted-access-non-fatal.rs:6:15
15+
|
16+
LL | let _ = 0.f;
17+
| ^
18+
|
19+
help: if intended to be a floating point literal, consider adding a `0` after the period and a `f32` suffix
20+
|
21+
LL | let _ = 0.0f32;
22+
| ~~~~
23+
24+
error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields
25+
--> $DIR/attempted-access-non-fatal.rs:7:15
26+
|
27+
LL | let _ = 2.l;
28+
| ^
29+
|
30+
help: if intended to be a floating point literal, consider adding a `0` after the period and a `f64` suffix
31+
|
32+
LL | let _ = 2.0f64;
33+
| ~~~~
34+
35+
error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields
36+
--> $DIR/attempted-access-non-fatal.rs:8:16
37+
|
38+
LL | let _ = 12.F;
39+
| ^
40+
|
41+
help: if intended to be a floating point literal, consider adding a `0` after the period and a `f32` suffix
42+
|
43+
LL | let _ = 12.0f32;
44+
| ~~~~
45+
46+
error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields
47+
--> $DIR/attempted-access-non-fatal.rs:9:16
48+
|
49+
LL | let _ = 34.L;
50+
| ^
51+
|
52+
help: if intended to be a floating point literal, consider adding a `0` after the period and a `f64` suffix
53+
|
54+
LL | let _ = 34.0f64;
55+
| ~~~~
56+
57+
error: aborting due to 6 previous errors
1458

1559
For more information about this error, try `rustc --explain E0610`.

0 commit comments

Comments
 (0)