Skip to content

Commit e927184

Browse files
committed
Auto merge of #119797 - matthiaskrgr:rollup-nn2lt39, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - #106893 (Explain base expression for struct update syntax) - #119769 (rustdoc: offset generic args of cross-crate trait object types when cleaning) - #119772 (Fix an ICE that occurs after an error has already been reported) - #119782 (rint intrinsics: caution against actually trying to check for floating-point exceptions) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9273d63 + 3fcddf1 commit e927184

File tree

15 files changed

+219
-111
lines changed

15 files changed

+219
-111
lines changed

compiler/rustc_ast_lowering/messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ ast_lowering_bad_return_type_notation_output =
3535
3636
ast_lowering_base_expression_double_dot =
3737
base expression required after `..`
38-
.label = add a base expression here
38+
.suggestion = add a base expression here
3939
4040
ast_lowering_clobber_abi_not_supported =
4141
`clobber_abi` is not supported on this target

compiler/rustc_ast_lowering/src/errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ pub struct UnderscoreExprLhsAssign {
114114
}
115115

116116
#[derive(Diagnostic, Clone, Copy)]
117-
#[diag(ast_lowering_base_expression_double_dot)]
117+
#[diag(ast_lowering_base_expression_double_dot, code = "E0797")]
118118
pub struct BaseExpressionDoubleDot {
119119
#[primary_span]
120-
#[label]
120+
#[suggestion(code = "/* expr */", applicability = "has-placeholders", style = "verbose")]
121121
pub span: Span,
122122
}
123123

compiler/rustc_error_codes/src/error_codes.rs

+1
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ E0793: include_str!("./error_codes/E0793.md"),
516516
E0794: include_str!("./error_codes/E0794.md"),
517517
E0795: include_str!("./error_codes/E0795.md"),
518518
E0796: include_str!("./error_codes/E0796.md"),
519+
E0797: include_str!("./error_codes/E0797.md"),
519520
}
520521

521522
// Undocumented removed error codes. Note that many removed error codes are kept in the list above
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Struct update syntax was used without a base expression.
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0797
6+
struct Foo {
7+
fizz: u8,
8+
buzz: u8
9+
}
10+
11+
let f1 = Foo { fizz: 10, buzz: 1};
12+
let f2 = Foo { fizz: 10, .. }; // error
13+
```
14+
15+
Using struct update syntax requires a 'base expression'.
16+
This will be used to fill remaining fields.
17+
18+
```
19+
struct Foo {
20+
fizz: u8,
21+
buzz: u8
22+
}
23+
24+
let f1 = Foo { fizz: 10, buzz: 1};
25+
let f2 = Foo { fizz: 10, ..f1 };
26+
```

compiler/rustc_transmute/src/layout/tree.rs

+1
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ pub(crate) mod rustc {
199199
match err {
200200
LayoutError::Unknown(..) | LayoutError::ReferencesError(..) => Self::UnknownLayout,
201201
LayoutError::SizeOverflow(..) => Self::SizeOverflow,
202+
LayoutError::Cycle(err) => Self::TypeError(*err),
202203
err => unimplemented!("{:?}", err),
203204
}
204205
}

library/core/src/intrinsics.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1787,6 +1787,8 @@ extern "rust-intrinsic" {
17871787
/// so this rounds half-way cases to the number with an even least significant digit.
17881788
///
17891789
/// May raise an inexact floating-point exception if the argument is not an integer.
1790+
/// However, Rust assumes floating-point exceptions cannot be observed, so this is not something that
1791+
/// can actually be used from Rust code.
17901792
///
17911793
/// The stabilized version of this intrinsic is
17921794
/// [`f32::round_ties_even`](../../std/primitive.f32.html#method.round_ties_even)
@@ -1796,6 +1798,8 @@ extern "rust-intrinsic" {
17961798
/// so this rounds half-way cases to the number with an even least significant digit.
17971799
///
17981800
/// May raise an inexact floating-point exception if the argument is not an integer.
1801+
/// However, Rust assumes floating-point exceptions cannot be observed, so this is not something that
1802+
/// can actually be used from Rust code.
17991803
///
18001804
/// The stabilized version of this intrinsic is
18011805
/// [`f64::round_ties_even`](../../std/primitive.f64.html#method.round_ties_even)

src/librustdoc/clean/mod.rs

+26-26
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,13 @@ pub(crate) fn clean_trait_ref_with_bindings<'tcx>(
207207
span_bug!(cx.tcx.def_span(trait_ref.def_id()), "`TraitRef` had unexpected kind {kind:?}");
208208
}
209209
inline::record_extern_fqn(cx, trait_ref.def_id(), kind);
210-
let path =
211-
external_path(cx, trait_ref.def_id(), true, bindings, trait_ref.map_bound(|tr| tr.args));
210+
let path = clean_middle_path(
211+
cx,
212+
trait_ref.def_id(),
213+
true,
214+
bindings,
215+
trait_ref.map_bound(|tr| tr.args),
216+
);
212217

213218
debug!(?trait_ref);
214219

@@ -467,7 +472,7 @@ fn projection_to_path_segment<'tcx>(
467472
PathSegment {
468473
name: item.name,
469474
args: GenericArgs::AngleBracketed {
470-
args: ty_args_to_args(
475+
args: clean_middle_generic_args(
471476
cx,
472477
ty.map_bound(|ty| &ty.args[generics.parent_count..]),
473478
false,
@@ -1903,7 +1908,7 @@ fn normalize<'tcx>(
19031908

19041909
fn clean_trait_object_lifetime_bound<'tcx>(
19051910
region: ty::Region<'tcx>,
1906-
container: Option<ContainerTy<'tcx>>,
1911+
container: Option<ContainerTy<'_, 'tcx>>,
19071912
preds: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
19081913
tcx: TyCtxt<'tcx>,
19091914
) -> Option<Lifetime> {
@@ -1932,7 +1937,7 @@ fn clean_trait_object_lifetime_bound<'tcx>(
19321937

19331938
fn can_elide_trait_object_lifetime_bound<'tcx>(
19341939
region: ty::Region<'tcx>,
1935-
container: Option<ContainerTy<'tcx>>,
1940+
container: Option<ContainerTy<'_, 'tcx>>,
19361941
preds: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
19371942
tcx: TyCtxt<'tcx>,
19381943
) -> bool {
@@ -1979,21 +1984,22 @@ fn can_elide_trait_object_lifetime_bound<'tcx>(
19791984
}
19801985

19811986
#[derive(Debug)]
1982-
pub(crate) enum ContainerTy<'tcx> {
1987+
pub(crate) enum ContainerTy<'a, 'tcx> {
19831988
Ref(ty::Region<'tcx>),
19841989
Regular {
19851990
ty: DefId,
1986-
args: ty::Binder<'tcx, &'tcx [ty::GenericArg<'tcx>]>,
1987-
has_self: bool,
1991+
/// The arguments *have* to contain an arg for the self type if the corresponding generics
1992+
/// contain a self type.
1993+
args: ty::Binder<'tcx, &'a [ty::GenericArg<'tcx>]>,
19881994
arg: usize,
19891995
},
19901996
}
19911997

1992-
impl<'tcx> ContainerTy<'tcx> {
1998+
impl<'tcx> ContainerTy<'_, 'tcx> {
19931999
fn object_lifetime_default(self, tcx: TyCtxt<'tcx>) -> ObjectLifetimeDefault<'tcx> {
19942000
match self {
19952001
Self::Ref(region) => ObjectLifetimeDefault::Arg(region),
1996-
Self::Regular { ty: container, args, has_self, arg: index } => {
2002+
Self::Regular { ty: container, args, arg: index } => {
19972003
let (DefKind::Struct
19982004
| DefKind::Union
19992005
| DefKind::Enum
@@ -2006,14 +2012,7 @@ impl<'tcx> ContainerTy<'tcx> {
20062012
let generics = tcx.generics_of(container);
20072013
debug_assert_eq!(generics.parent_count, 0);
20082014

2009-
// If the container is a trait object type, the arguments won't contain the self type but the
2010-
// generics of the corresponding trait will. In such a case, offset the index by one.
2011-
// For comparison, if the container is a trait inside a bound, the arguments do contain the
2012-
// self type.
2013-
let offset =
2014-
if !has_self && generics.parent.is_none() && generics.has_self { 1 } else { 0 };
2015-
let param = generics.params[index + offset].def_id;
2016-
2015+
let param = generics.params[index].def_id;
20172016
let default = tcx.object_lifetime_default(param);
20182017
match default {
20192018
rbv::ObjectLifetimeDefault::Param(lifetime) => {
@@ -2045,7 +2044,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
20452044
bound_ty: ty::Binder<'tcx, Ty<'tcx>>,
20462045
cx: &mut DocContext<'tcx>,
20472046
parent_def_id: Option<DefId>,
2048-
container: Option<ContainerTy<'tcx>>,
2047+
container: Option<ContainerTy<'_, 'tcx>>,
20492048
) -> Type {
20502049
let bound_ty = normalize(cx, bound_ty).unwrap_or(bound_ty);
20512050
match *bound_ty.skip_binder().kind() {
@@ -2096,12 +2095,12 @@ pub(crate) fn clean_middle_ty<'tcx>(
20962095
AdtKind::Enum => ItemType::Enum,
20972096
};
20982097
inline::record_extern_fqn(cx, did, kind);
2099-
let path = external_path(cx, did, false, ThinVec::new(), bound_ty.rebind(args));
2098+
let path = clean_middle_path(cx, did, false, ThinVec::new(), bound_ty.rebind(args));
21002099
Type::Path { path }
21012100
}
21022101
ty::Foreign(did) => {
21032102
inline::record_extern_fqn(cx, did, ItemType::ForeignType);
2104-
let path = external_path(
2103+
let path = clean_middle_path(
21052104
cx,
21062105
did,
21072106
false,
@@ -2132,7 +2131,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
21322131
let mut bounds = dids
21332132
.map(|did| {
21342133
let empty = ty::Binder::dummy(ty::GenericArgs::empty());
2135-
let path = external_path(cx, did, false, ThinVec::new(), empty);
2134+
let path = clean_middle_path(cx, did, false, ThinVec::new(), empty);
21362135
inline::record_extern_fqn(cx, did, ItemType::Trait);
21372136
PolyTrait { trait_: path, generic_params: Vec::new() }
21382137
})
@@ -2171,7 +2170,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
21712170
.collect();
21722171
let late_bound_regions = late_bound_regions.into_iter().collect();
21732172

2174-
let path = external_path(cx, did, false, bindings, args);
2173+
let path = clean_middle_path(cx, did, false, bindings, args);
21752174
bounds.insert(0, PolyTrait { trait_: path, generic_params: late_bound_regions });
21762175

21772176
DynTrait(bounds, lifetime)
@@ -2193,7 +2192,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
21932192
assoc: PathSegment {
21942193
name: cx.tcx.associated_item(def_id).name,
21952194
args: GenericArgs::AngleBracketed {
2196-
args: ty_args_to_args(
2195+
args: clean_middle_generic_args(
21972196
cx,
21982197
alias_ty.map_bound(|ty| ty.args.as_slice()),
21992198
true,
@@ -2213,7 +2212,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
22132212
if cx.tcx.features().lazy_type_alias {
22142213
// Weak type alias `data` represents the `type X` in `type X = Y`. If we need `Y`,
22152214
// we need to use `type_of`.
2216-
let path = external_path(
2215+
let path = clean_middle_path(
22172216
cx,
22182217
data.def_id,
22192218
false,
@@ -2243,7 +2242,8 @@ pub(crate) fn clean_middle_ty<'tcx>(
22432242
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => {
22442243
// If it's already in the same alias, don't get an infinite loop.
22452244
if cx.current_type_aliases.contains_key(&def_id) {
2246-
let path = external_path(cx, def_id, false, ThinVec::new(), bound_ty.rebind(args));
2245+
let path =
2246+
clean_middle_path(cx, def_id, false, ThinVec::new(), bound_ty.rebind(args));
22472247
Type::Path { path }
22482248
} else {
22492249
*cx.current_type_aliases.entry(def_id).or_insert(0) += 1;

src/librustdoc/clean/types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use rustc_target::abi::VariantIdx;
3636
use rustc_target::spec::abi::Abi;
3737

3838
use crate::clean::cfg::Cfg;
39-
use crate::clean::external_path;
39+
use crate::clean::clean_middle_path;
4040
use crate::clean::inline::{self, print_inlined_const};
4141
use crate::clean::utils::{is_literal_expr, print_evaluated_const};
4242
use crate::core::DocContext;
@@ -1258,7 +1258,7 @@ impl GenericBound {
12581258
fn sized_with(cx: &mut DocContext<'_>, modifier: hir::TraitBoundModifier) -> GenericBound {
12591259
let did = cx.tcx.require_lang_item(LangItem::Sized, None);
12601260
let empty = ty::Binder::dummy(ty::GenericArgs::empty());
1261-
let path = external_path(cx, did, false, ThinVec::new(), empty);
1261+
let path = clean_middle_path(cx, did, false, ThinVec::new(), empty);
12621262
inline::record_extern_fqn(cx, did, ItemType::Trait);
12631263
GenericBound::TraitBound(PolyTrait { trait_: path, generic_params: Vec::new() }, modifier)
12641264
}

0 commit comments

Comments
 (0)