Skip to content

Rollup of 5 pull requests #99533

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

Closed
wants to merge 13 commits into from
Closed
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_error_messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ impl DiagnosticMessage {
/// - If `self` is non-translatable then return `self`'s message.
pub fn with_subdiagnostic_message(&self, sub: SubdiagnosticMessage) -> Self {
let attr = match sub {
SubdiagnosticMessage::Str(s) => return DiagnosticMessage::Str(s.clone()),
SubdiagnosticMessage::Str(s) => return DiagnosticMessage::Str(s),
SubdiagnosticMessage::FluentIdentifier(id) => {
return DiagnosticMessage::FluentIdentifier(id, None);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl DiagnosticDeriveBuilder {
}
NestedMeta::Meta(meta @ Meta::NameValue(_))
if !is_help_note_or_warn
&& meta.path().segments.last().unwrap().ident.to_string() == "code" =>
&& meta.path().segments.last().unwrap().ident == "code" =>
{
// don't error for valid follow-up attributes
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_macros/src/diagnostics/fluent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok
let snake_name = Ident::new(
// FIXME: should probably trim prefix, not replace all occurrences
&name
.replace(&format!("{}-", res.ident).replace("_", "-"), "")
.replace("-", "_"),
.replace(&format!("{}-", res.ident).replace('_', "-"), "")
.replace('-', "_"),
span,
);
constants.extend(quote! {
Expand All @@ -207,7 +207,7 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok
});

for Attribute { id: Identifier { name: attr_name }, .. } in attributes {
let snake_name = Ident::new(&attr_name.replace("-", "_"), span);
let snake_name = Ident::new(&attr_name.replace('-', "_"), span);
if !previous_attrs.insert(snake_name.clone()) {
continue;
}
Expand Down
10 changes: 4 additions & 6 deletions compiler/rustc_middle/src/ty/consts/valtree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,17 @@ impl<'tcx> ValTree<'tcx> {
let leafs = self
.unwrap_branch()
.into_iter()
.map(|v| v.unwrap_leaf().try_to_u8().unwrap())
.collect::<Vec<_>>();
.map(|v| v.unwrap_leaf().try_to_u8().unwrap());

return Some(tcx.arena.alloc_from_iter(leafs.into_iter()));
return Some(tcx.arena.alloc_from_iter(leafs));
}
ty::Slice(slice_ty) if *slice_ty == tcx.types.u8 => {
let leafs = self
.unwrap_branch()
.into_iter()
.map(|v| v.unwrap_leaf().try_to_u8().unwrap())
.collect::<Vec<_>>();
.map(|v| v.unwrap_leaf().try_to_u8().unwrap());

return Some(tcx.arena.alloc_from_iter(leafs.into_iter()));
return Some(tcx.arena.alloc_from_iter(leafs));
}
_ => {}
},
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1727,7 +1727,7 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
}

fn print_const(self, ct: ty::Const<'tcx>) -> Result<Self::Const, Self::Error> {
self.pretty_print_const(ct, true)
self.pretty_print_const(ct, false)
}

fn path_crate(mut self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_privacy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1754,7 +1754,6 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
|| self.in_assoc_ty
|| self.tcx.resolutions(()).has_pub_restricted
{
let descr = descr.to_string();
let vis_span =
self.tcx.sess.source_map().guess_head_span(self.tcx.def_span(def_id));
if kind == "trait" {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2608,7 +2608,7 @@ fn show_candidates(
"item"
};
let plural_descr =
if descr.ends_with("s") { format!("{}es", descr) } else { format!("{}s", descr) };
if descr.ends_with('s') { format!("{}es", descr) } else { format!("{}s", descr) };

let mut msg = format!("{}these {} exist but are inaccessible", prefix, plural_descr);
let mut has_colon = false;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ mod parse {
) -> bool {
match v {
Some(s) => {
for s in s.split(",") {
for s in s.split(',') {
let Some(pass_name) = s.strip_prefix(&['+', '-'][..]) else { return false };
slot.push((pass_name.to_string(), &s[..1] == "+"));
}
Expand Down
15 changes: 12 additions & 3 deletions compiler/rustc_trait_selection/src/traits/const_evaluatable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,20 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
}
let concrete = infcx.const_eval_resolve(param_env, uv.expand(), Some(span));
match concrete {
Err(ErrorHandled::TooGeneric) => Err(if !uv.has_infer_types_or_consts() {
Err(ErrorHandled::TooGeneric) => Err(if uv.has_infer_types_or_consts() {
NotConstEvaluatable::MentionsInfer
} else if uv.has_param_types_or_consts() {
infcx
.tcx
.sess
.delay_span_bug(span, &format!("unexpected `TooGeneric` for {:?}", uv));
NotConstEvaluatable::MentionsParam
} else {
NotConstEvaluatable::MentionsInfer
let guar = infcx.tcx.sess.delay_span_bug(
span,
format!("Missing value for constant, but no error reported?"),
);
NotConstEvaluatable::Error(guar)
}),
Err(ErrorHandled::Linted) => {
let reported = infcx
Expand Down Expand Up @@ -240,8 +246,11 @@ pub fn is_const_evaluatable<'cx, 'tcx>(

Err(ErrorHandled::TooGeneric) => Err(if uv.has_infer_types_or_consts() {
NotConstEvaluatable::MentionsInfer
} else {
} else if uv.has_param_types_or_consts() {
NotConstEvaluatable::MentionsParam
} else {
let guar = infcx.tcx.sess.delay_span_bug(span, format!("Missing value for constant, but no error reported?"));
NotConstEvaluatable::Error(guar)
}),
Err(ErrorHandled::Linted) => {
let reported =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,10 +607,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
"{}, {}={}>",
&constraint[..constraint.len() - 1],
item.name,
term.to_string()
term
);
} else {
constraint.push_str(&format!("<{}={}>", item.name, term.to_string()));
constraint.push_str(&format!("<{}={}>", item.name, term));
}
}

Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_ty_utils/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ fn resolve_associated_item<'tcx>(
return Ok(None);
}

// If the item does not have a value, then we cannot return an instance.
if !leaf_def.item.defaultness.has_value() {
return Ok(None);
}

let substs = tcx.erase_regions(substs);

// Check if we just resolved an associated `const` declaration from
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_typeck/src/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1803,7 +1803,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.source_map()
.span_to_snippet(range_end.expr.span)
.map(|s| format!(" from `{s}`"))
.unwrap_or(String::new());
.unwrap_or_default();
err.span_suggestion(
range_start.span.shrink_to_hi(),
&format!("to set the remaining fields{instead}, separate the last named field with a comma"),
Expand Down Expand Up @@ -2362,7 +2362,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
false
};
let expr_snippet =
self.tcx.sess.source_map().span_to_snippet(expr.span).unwrap_or(String::new());
self.tcx.sess.source_map().span_to_snippet(expr.span).unwrap_or_default();
let is_wrapped = expr_snippet.starts_with('(') && expr_snippet.ends_with(')');
let after_open = expr.span.lo() + rustc_span::BytePos(1);
let before_close = expr.span.hi() - rustc_span::BytePos(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ impl<'tcx> ExprUseDelegate<'tcx> {
}

fn mark_consumed(&mut self, consumer: HirId, target: TrackedValue) {
if !self.places.consumed.contains_key(&consumer) {
self.places.consumed.insert(consumer, <_>::default());
}
self.places.consumed.entry(consumer).or_insert_with(|| <_>::default());

debug!(?consumer, ?target, "mark_consumed");
self.places.consumed.get_mut(&consumer).map(|places| places.insert(target));
}
Expand Down
35 changes: 35 additions & 0 deletions library/core/src/ops/control_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,41 @@ impl<B, C> ControlFlow<B, C> {
ControlFlow::Break(x) => ControlFlow::Break(f(x)),
}
}

/// Converts the `ControlFlow` into an `Option` which is `Some` if the
/// `ControlFlow` was `Continue` and `None` otherwise.
///
/// # Examples
///
/// ```
/// #![feature(control_flow_enum)]
/// use std::ops::ControlFlow;
///
/// assert_eq!(ControlFlow::<i32, String>::Break(3).continue_value(), None);
/// assert_eq!(ControlFlow::<String, i32>::Continue(3).continue_value(), Some(3));
/// ```
#[inline]
#[unstable(feature = "control_flow_enum", reason = "new API", issue = "75744")]
pub fn continue_value(self) -> Option<C> {
match self {
ControlFlow::Continue(x) => Some(x),
ControlFlow::Break(..) => None,
}
}

/// Maps `ControlFlow<B, C>` to `ControlFlow<B, T>` by applying a function
/// to the continue value in case it exists.
#[inline]
#[unstable(feature = "control_flow_enum", reason = "new API", issue = "75744")]
pub fn map_continue<T, F>(self, f: F) -> ControlFlow<B, T>
where
F: FnOnce(C) -> T,
{
match self {
ControlFlow::Continue(x) => ControlFlow::Continue(f(x)),
ControlFlow::Break(x) => ControlFlow::Break(x),
}
}
}

/// These are used only as part of implementing the iterator adapters.
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/os/fd/owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ impl From<OwnedFd> for crate::net::UdpSocket {
}
}

#[stable(feature = "io_safety", since = "1.63.0")]
#[stable(feature = "asfd_ptrs", since = "1.64.0")]
/// This impl allows implementing traits that require `AsFd` on Arc.
/// ```
/// # #[cfg(any(unix, target_os = "wasi"))] mod group_cfg {
Expand All @@ -379,7 +379,7 @@ impl<T: AsFd> AsFd for crate::sync::Arc<T> {
}
}

#[stable(feature = "io_safety", since = "1.63.0")]
#[stable(feature = "asfd_ptrs", since = "1.64.0")]
impl<T: AsFd> AsFd for Box<T> {
#[inline]
fn as_fd(&self) -> BorrowedFd<'_> {
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc/const-generics/add-impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct Simd<T, const WIDTH: usize> {
inner: T,
}

// @has foo/struct.Simd.html '//div[@id="trait-implementations-list"]//h3[@class="code-header in-band"]' 'impl Add<Simd<u8, 16_usize>> for Simd<u8, 16>'
// @has foo/struct.Simd.html '//div[@id="trait-implementations-list"]//h3[@class="code-header in-band"]' 'impl Add<Simd<u8, 16>> for Simd<u8, 16>'
impl Add for Simd<u8, 16> {
type Output = Self;

Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc/const-generics/const-generic-defaults.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![crate_name = "foo"]

// @has foo/struct.Foo.html '//pre[@class="rust struct"]' \
// 'pub struct Foo<const M: usize = 10_usize, const N: usize = M, T = i32>(_);'
// 'pub struct Foo<const M: usize = 10, const N: usize = M, T = i32>(_);'
pub struct Foo<const M: usize = 10, const N: usize = M, T = i32>(T);
4 changes: 2 additions & 2 deletions src/test/rustdoc/const-generics/const-generics-docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ pub use extern_crate::WTrait;

// @has foo/trait.Trait.html '//pre[@class="rust trait"]' \
// 'pub trait Trait<const N: usize>'
// @has - '//*[@id="impl-Trait%3C1_usize%3E-for-u8"]//h3[@class="code-header in-band"]' 'impl Trait<1_usize> for u8'
// @has - '//*[@id="impl-Trait%3C2_usize%3E-for-u8"]//h3[@class="code-header in-band"]' 'impl Trait<2_usize> for u8'
// @has - '//*[@id="impl-Trait%3C1%3E-for-u8"]//h3[@class="code-header in-band"]' 'impl Trait<1> for u8'
// @has - '//*[@id="impl-Trait%3C2%3E-for-u8"]//h3[@class="code-header in-band"]' 'impl Trait<2> for u8'
// @has - '//*[@id="impl-Trait%3C{1%20+%202}%3E-for-u8"]//h3[@class="code-header in-band"]' 'impl Trait<{1 + 2}> for u8'
// @has - '//*[@id="impl-Trait%3CN%3E-for-%5Bu8%3B%20N%5D"]//h3[@class="code-header in-band"]' \
// 'impl<const N: usize> Trait<N> for [u8; N]'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ struct WithParameters<T, const N: usize, M = u32> {
}

impl<T> WithParameters<T, 1> {
fn with_ref(&self) {} //~ ERROR passing `WithParameters<T, 1_usize>` by reference
fn with_ref(&self) {} //~ ERROR passing `WithParameters<T, 1>` by reference
}

impl<T> WithParameters<T, 1, u8> {
fn with_ref(&self) {} //~ ERROR passing `WithParameters<T, 1_usize, u8>` by reference
fn with_ref(&self) {} //~ ERROR passing `WithParameters<T, 1, u8>` by reference
}

fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ error: passing `Foo` by reference
LL | fn with_ref(&self) {}
| ^^^^^ help: try passing by value: `Foo`

error: passing `WithParameters<T, 1_usize>` by reference
error: passing `WithParameters<T, 1>` by reference
--> $DIR/rustc_pass_by_value_self.rs:47:17
|
LL | fn with_ref(&self) {}
| ^^^^^ help: try passing by value: `WithParameters<T, 1_usize>`
| ^^^^^ help: try passing by value: `WithParameters<T, 1>`

error: passing `WithParameters<T, 1_usize, u8>` by reference
error: passing `WithParameters<T, 1, u8>` by reference
--> $DIR/rustc_pass_by_value_self.rs:51:17
|
LL | fn with_ref(&self) {}
| ^^^^^ help: try passing by value: `WithParameters<T, 1_usize, u8>`
| ^^^^^ help: try passing by value: `WithParameters<T, 1, u8>`

error: aborting due to 5 previous errors

2 changes: 1 addition & 1 deletion src/test/ui/array-slice-vec/match_arr_unknown_len.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/match_arr_unknown_len.rs:3:9
|
LL | [1, 2] => true,
| ^^^^^^ expected `2_usize`, found `N`
| ^^^^^^ expected `2`, found `N`
|
= note: expected array `[u32; 2]`
found array `[u32; N]`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0277]: the trait bound `u16: Bar<N>` is not satisfied
LL | type Assoc = u16;
| ^^^ the trait `Bar<N>` is not implemented for `u16`
|
= help: the trait `Bar<3_usize>` is implemented for `u16`
= help: the trait `Bar<3>` is implemented for `u16`
note: required by a bound in `Foo::Assoc`
--> $DIR/associated-type-bound-fail.rs:4:17
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ error[E0308]: mismatched types
--> $DIR/generic-expr-default-concrete.rs:10:5
|
LL | Foo::<10, 12>
| ^^^^^^^^^^^^^ expected `11_usize`, found `12_usize`
| ^^^^^^^^^^^^^ expected `11`, found `12`
|
= note: expected type `11_usize`
found type `12_usize`
= note: expected type `11`
found type `12`

error: aborting due to previous error

Expand Down
22 changes: 11 additions & 11 deletions src/test/ui/const-generics/defaults/mismatch.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
pub struct Example<const N: usize=13>;
pub struct Example2<T=u32, const N: usize=13>(T);
pub struct Example3<const N: usize=13, T=u32>(T);
pub struct Example4<const N: usize=13, const M: usize=4>;
pub struct Example<const N: usize = 13>;
pub struct Example2<T = u32, const N: usize = 13>(T);
pub struct Example3<const N: usize = 13, T = u32>(T);
pub struct Example4<const N: usize = 13, const M: usize = 4>;

fn main() {
let e: Example::<13> = ();
let e: Example<13> = ();
//~^ Error: mismatched types
//~| expected struct `Example`
let e: Example2::<u32, 13> = ();
let e: Example2<u32, 13> = ();
//~^ Error: mismatched types
//~| expected struct `Example2`
let e: Example3::<13, u32> = ();
let e: Example3<13, u32> = ();
//~^ Error: mismatched types
//~| expected struct `Example3`
let e: Example3::<7> = ();
let e: Example3<7> = ();
//~^ Error: mismatched types
//~| expected struct `Example3<7_usize>`
let e: Example4::<7> = ();
//~| expected struct `Example3<7>`
let e: Example4<7> = ();
//~^ Error: mismatched types
//~| expected struct `Example4<7_usize>`
//~| expected struct `Example4<7>`
}
Loading