Skip to content
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

Rollup of 4 pull requests #119797

Merged
merged 13 commits into from
Jan 10, 2024
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
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ ast_lowering_bad_return_type_notation_output =

ast_lowering_base_expression_double_dot =
base expression required after `..`
.label = add a base expression here
.suggestion = add a base expression here

ast_lowering_clobber_abi_not_supported =
`clobber_abi` is not supported on this target
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ pub struct UnderscoreExprLhsAssign {
}

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

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_error_codes/src/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ E0793: include_str!("./error_codes/E0793.md"),
E0794: include_str!("./error_codes/E0794.md"),
E0795: include_str!("./error_codes/E0795.md"),
E0796: include_str!("./error_codes/E0796.md"),
E0797: include_str!("./error_codes/E0797.md"),
}

// Undocumented removed error codes. Note that many removed error codes are kept in the list above
Expand Down
26 changes: 26 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0797.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Struct update syntax was used without a base expression.

Erroneous code example:

```compile_fail,E0797
struct Foo {
fizz: u8,
buzz: u8
}

let f1 = Foo { fizz: 10, buzz: 1};
let f2 = Foo { fizz: 10, .. }; // error
```

Using struct update syntax requires a 'base expression'.
This will be used to fill remaining fields.

```
struct Foo {
fizz: u8,
buzz: u8
}

let f1 = Foo { fizz: 10, buzz: 1};
let f2 = Foo { fizz: 10, ..f1 };
```
1 change: 1 addition & 0 deletions compiler/rustc_transmute/src/layout/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ pub(crate) mod rustc {
match err {
LayoutError::Unknown(..) | LayoutError::ReferencesError(..) => Self::UnknownLayout,
LayoutError::SizeOverflow(..) => Self::SizeOverflow,
LayoutError::Cycle(err) => Self::TypeError(*err),
err => unimplemented!("{:?}", err),
}
}
Expand Down
4 changes: 4 additions & 0 deletions library/core/src/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1787,6 +1787,8 @@ extern "rust-intrinsic" {
/// so this rounds half-way cases to the number with an even least significant digit.
///
/// May raise an inexact floating-point exception if the argument is not an integer.
/// However, Rust assumes floating-point exceptions cannot be observed, so this is not something that
/// can actually be used from Rust code.
///
/// The stabilized version of this intrinsic is
/// [`f32::round_ties_even`](../../std/primitive.f32.html#method.round_ties_even)
Expand All @@ -1796,6 +1798,8 @@ extern "rust-intrinsic" {
/// so this rounds half-way cases to the number with an even least significant digit.
///
/// May raise an inexact floating-point exception if the argument is not an integer.
/// However, Rust assumes floating-point exceptions cannot be observed, so this is not something that
/// can actually be used from Rust code.
///
/// The stabilized version of this intrinsic is
/// [`f64::round_ties_even`](../../std/primitive.f64.html#method.round_ties_even)
Expand Down
52 changes: 26 additions & 26 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,13 @@ pub(crate) fn clean_trait_ref_with_bindings<'tcx>(
span_bug!(cx.tcx.def_span(trait_ref.def_id()), "`TraitRef` had unexpected kind {kind:?}");
}
inline::record_extern_fqn(cx, trait_ref.def_id(), kind);
let path =
external_path(cx, trait_ref.def_id(), true, bindings, trait_ref.map_bound(|tr| tr.args));
let path = clean_middle_path(
cx,
trait_ref.def_id(),
true,
bindings,
trait_ref.map_bound(|tr| tr.args),
);

debug!(?trait_ref);

Expand Down Expand Up @@ -467,7 +472,7 @@ fn projection_to_path_segment<'tcx>(
PathSegment {
name: item.name,
args: GenericArgs::AngleBracketed {
args: ty_args_to_args(
args: clean_middle_generic_args(
cx,
ty.map_bound(|ty| &ty.args[generics.parent_count..]),
false,
Expand Down Expand Up @@ -1903,7 +1908,7 @@ fn normalize<'tcx>(

fn clean_trait_object_lifetime_bound<'tcx>(
region: ty::Region<'tcx>,
container: Option<ContainerTy<'tcx>>,
container: Option<ContainerTy<'_, 'tcx>>,
preds: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
tcx: TyCtxt<'tcx>,
) -> Option<Lifetime> {
Expand Down Expand Up @@ -1932,7 +1937,7 @@ fn clean_trait_object_lifetime_bound<'tcx>(

fn can_elide_trait_object_lifetime_bound<'tcx>(
region: ty::Region<'tcx>,
container: Option<ContainerTy<'tcx>>,
container: Option<ContainerTy<'_, 'tcx>>,
preds: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
tcx: TyCtxt<'tcx>,
) -> bool {
Expand Down Expand Up @@ -1979,21 +1984,22 @@ fn can_elide_trait_object_lifetime_bound<'tcx>(
}

#[derive(Debug)]
pub(crate) enum ContainerTy<'tcx> {
pub(crate) enum ContainerTy<'a, 'tcx> {
Ref(ty::Region<'tcx>),
Regular {
ty: DefId,
args: ty::Binder<'tcx, &'tcx [ty::GenericArg<'tcx>]>,
has_self: bool,
/// The arguments *have* to contain an arg for the self type if the corresponding generics
/// contain a self type.
args: ty::Binder<'tcx, &'a [ty::GenericArg<'tcx>]>,
arg: usize,
},
}

impl<'tcx> ContainerTy<'tcx> {
impl<'tcx> ContainerTy<'_, 'tcx> {
fn object_lifetime_default(self, tcx: TyCtxt<'tcx>) -> ObjectLifetimeDefault<'tcx> {
match self {
Self::Ref(region) => ObjectLifetimeDefault::Arg(region),
Self::Regular { ty: container, args, has_self, arg: index } => {
Self::Regular { ty: container, args, arg: index } => {
let (DefKind::Struct
| DefKind::Union
| DefKind::Enum
Expand All @@ -2006,14 +2012,7 @@ impl<'tcx> ContainerTy<'tcx> {
let generics = tcx.generics_of(container);
debug_assert_eq!(generics.parent_count, 0);

// If the container is a trait object type, the arguments won't contain the self type but the
// generics of the corresponding trait will. In such a case, offset the index by one.
// For comparison, if the container is a trait inside a bound, the arguments do contain the
// self type.
let offset =
if !has_self && generics.parent.is_none() && generics.has_self { 1 } else { 0 };
let param = generics.params[index + offset].def_id;

let param = generics.params[index].def_id;
let default = tcx.object_lifetime_default(param);
match default {
rbv::ObjectLifetimeDefault::Param(lifetime) => {
Expand Down Expand Up @@ -2045,7 +2044,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
bound_ty: ty::Binder<'tcx, Ty<'tcx>>,
cx: &mut DocContext<'tcx>,
parent_def_id: Option<DefId>,
container: Option<ContainerTy<'tcx>>,
container: Option<ContainerTy<'_, 'tcx>>,
) -> Type {
let bound_ty = normalize(cx, bound_ty).unwrap_or(bound_ty);
match *bound_ty.skip_binder().kind() {
Expand Down Expand Up @@ -2096,12 +2095,12 @@ pub(crate) fn clean_middle_ty<'tcx>(
AdtKind::Enum => ItemType::Enum,
};
inline::record_extern_fqn(cx, did, kind);
let path = external_path(cx, did, false, ThinVec::new(), bound_ty.rebind(args));
let path = clean_middle_path(cx, did, false, ThinVec::new(), bound_ty.rebind(args));
Type::Path { path }
}
ty::Foreign(did) => {
inline::record_extern_fqn(cx, did, ItemType::ForeignType);
let path = external_path(
let path = clean_middle_path(
cx,
did,
false,
Expand Down Expand Up @@ -2132,7 +2131,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
let mut bounds = dids
.map(|did| {
let empty = ty::Binder::dummy(ty::GenericArgs::empty());
let path = external_path(cx, did, false, ThinVec::new(), empty);
let path = clean_middle_path(cx, did, false, ThinVec::new(), empty);
inline::record_extern_fqn(cx, did, ItemType::Trait);
PolyTrait { trait_: path, generic_params: Vec::new() }
})
Expand Down Expand Up @@ -2171,7 +2170,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
.collect();
let late_bound_regions = late_bound_regions.into_iter().collect();

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

DynTrait(bounds, lifetime)
Expand All @@ -2193,7 +2192,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
assoc: PathSegment {
name: cx.tcx.associated_item(def_id).name,
args: GenericArgs::AngleBracketed {
args: ty_args_to_args(
args: clean_middle_generic_args(
cx,
alias_ty.map_bound(|ty| ty.args.as_slice()),
true,
Expand All @@ -2213,7 +2212,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
if cx.tcx.features().lazy_type_alias {
// Weak type alias `data` represents the `type X` in `type X = Y`. If we need `Y`,
// we need to use `type_of`.
let path = external_path(
let path = clean_middle_path(
cx,
data.def_id,
false,
Expand Down Expand Up @@ -2243,7 +2242,8 @@ pub(crate) fn clean_middle_ty<'tcx>(
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => {
// If it's already in the same alias, don't get an infinite loop.
if cx.current_type_aliases.contains_key(&def_id) {
let path = external_path(cx, def_id, false, ThinVec::new(), bound_ty.rebind(args));
let path =
clean_middle_path(cx, def_id, false, ThinVec::new(), bound_ty.rebind(args));
Type::Path { path }
} else {
*cx.current_type_aliases.entry(def_id).or_insert(0) += 1;
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use rustc_target::abi::VariantIdx;
use rustc_target::spec::abi::Abi;

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