Skip to content

Commit 91775db

Browse files
committed
Auto merge of #154013 - JonathanBrouwer:rollup-J4887ML, r=JonathanBrouwer
Rollup of 6 pull requests Successful merges: - #152998 (std: make `OsString::truncate` a no-op when `len > current_len`) - #153682 (Tweak E0599 note) - #153795 (Point turbofish inference errors at the uninferred generic arg) - #153994 (move `tests/ui/invalid` tests to new folders) - #154006 (attrs: Ignore ExprKind::Err when converting path attr expr to lit) - #154012 (unstable impl of `From<{i64, u64}> for f128`)
2 parents 91021cc + eb61706 commit 91775db

59 files changed

Lines changed: 229 additions & 271 deletions

File tree

Some content is hidden

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

compiler/rustc_attr_parsing/src/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ fn expr_to_lit<'sess>(
390390
}
391391
}
392392
} else {
393-
if matches!(should_emit, ShouldEmit::Nothing) {
393+
if matches!(should_emit, ShouldEmit::Nothing) || matches!(expr.kind, ExprKind::Err(_)) {
394394
return Ok(None);
395395
}
396396

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_data_structures::sorted_map::SortedMap;
1414
use rustc_data_structures::unord::UnordSet;
1515
use rustc_errors::codes::*;
1616
use rustc_errors::{
17-
Applicability, Diag, MultiSpan, StashKey, listify, pluralize, struct_span_code_err,
17+
Applicability, Diag, MultiSpan, StashKey, StringPart, listify, pluralize, struct_span_code_err,
1818
};
1919
use rustc_hir::attrs::diagnostic::OnUnimplementedNote;
2020
use rustc_hir::def::{CtorKind, DefKind, Res};
@@ -1413,33 +1413,45 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14131413
}
14141414
})
14151415
.collect::<Vec<_>>();
1416-
if !inherent_impls_candidate.is_empty() {
1417-
inherent_impls_candidate.sort_by_key(|&id| self.tcx.def_path_str(id));
1418-
inherent_impls_candidate.dedup();
1419-
1420-
// number of types to show at most
1421-
let limit = if inherent_impls_candidate.len() == 5 { 5 } else { 4 };
1422-
let type_candidates = inherent_impls_candidate
1423-
.iter()
1424-
.take(limit)
1425-
.map(|impl_item| {
1426-
format!(
1427-
"- `{}`",
1428-
self.tcx.at(span).type_of(*impl_item).instantiate_identity()
1429-
)
1430-
})
1431-
.collect::<Vec<_>>()
1432-
.join("\n");
1433-
let additional_types = if inherent_impls_candidate.len() > limit {
1434-
format!("\nand {} more types", inherent_impls_candidate.len() - limit)
1435-
} else {
1436-
"".to_string()
1437-
};
1438-
err.note(format!(
1439-
"the {item_kind} was found for\n{type_candidates}{additional_types}"
1440-
));
1441-
*find_candidate_for_method = mode == Mode::MethodCall;
1442-
}
1416+
inherent_impls_candidate.sort_by_key(|&id| self.tcx.def_path_str(id));
1417+
inherent_impls_candidate.dedup();
1418+
let msg = match &inherent_impls_candidate[..] {
1419+
[] => return,
1420+
[only] => {
1421+
vec![
1422+
StringPart::normal(format!("the {item_kind} was found for `")),
1423+
StringPart::highlighted(
1424+
self.tcx.at(span).type_of(*only).instantiate_identity().to_string(),
1425+
),
1426+
StringPart::normal(format!("`")),
1427+
]
1428+
}
1429+
candidates => {
1430+
// number of types to show at most
1431+
let limit = if candidates.len() == 5 { 5 } else { 4 };
1432+
let type_candidates = candidates
1433+
.iter()
1434+
.take(limit)
1435+
.map(|impl_item| {
1436+
format!(
1437+
"- `{}`",
1438+
self.tcx.at(span).type_of(*impl_item).instantiate_identity()
1439+
)
1440+
})
1441+
.collect::<Vec<_>>()
1442+
.join("\n");
1443+
let additional_types = if candidates.len() > limit {
1444+
format!("\nand {} more types", candidates.len() - limit)
1445+
} else {
1446+
"".to_string()
1447+
};
1448+
vec![StringPart::normal(format!(
1449+
"the {item_kind} was found for\n{type_candidates}{additional_types}"
1450+
))]
1451+
}
1452+
};
1453+
err.highlighted_note(msg);
1454+
*find_candidate_for_method = mode == Mode::MethodCall;
14431455
}
14441456
} else {
14451457
let ty_str = if ty_str.len() > 50 { String::new() } else { format!("on `{ty_str}` ") };

compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,21 +1313,32 @@ impl<'a, 'tcx> Visitor<'tcx> for FindInferSourceVisitor<'a, 'tcx> {
13131313
have_turbofish,
13141314
} = args;
13151315
let generics = tcx.generics_of(generics_def_id);
1316-
if let Some(mut argument_index) = generics
1316+
if let Some(argument_index) = generics
13171317
.own_args(args)
13181318
.iter()
13191319
.position(|&arg| self.generic_arg_contains_target(arg))
13201320
{
1321-
if generics.has_own_self() {
1322-
argument_index += 1;
1323-
}
13241321
let args = self.tecx.resolve_vars_if_possible(args);
13251322
let generic_args =
13261323
&generics.own_args_no_defaults(tcx, args)[generics.own_counts().lifetimes..];
13271324
let span = match expr.kind {
1328-
ExprKind::MethodCall(path, ..) => path.ident.span,
1325+
ExprKind::MethodCall(segment, ..)
1326+
if have_turbofish
1327+
&& let Some(hir_args) = segment.args
1328+
&& let Some(idx) =
1329+
argument_index.checked_sub(generics.own_counts().lifetimes)
1330+
&& let Some(arg) =
1331+
hir_args.args.get(hir_args.num_lifetime_params() + idx) =>
1332+
{
1333+
arg.span()
1334+
}
1335+
ExprKind::MethodCall(segment, ..) => segment.ident.span,
13291336
_ => expr.span,
13301337
};
1338+
let mut argument_index = argument_index;
1339+
if generics.has_own_self() {
1340+
argument_index += 1;
1341+
}
13311342

13321343
self.update_infer_source(InferSource {
13331344
span,

library/alloc/src/wtf8/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,14 +342,18 @@ impl Wtf8Buf {
342342

343343
/// Shortens a string to the specified length.
344344
///
345+
/// If `new_len` is greater than the string's current length, this has no
346+
/// effect.
347+
///
345348
/// # Panics
346349
///
347-
/// Panics if `new_len` > current length,
348-
/// or if `new_len` is not a code point boundary.
350+
/// Panics if `new_len` does not lie on a code point boundary.
349351
#[inline]
350352
pub fn truncate(&mut self, new_len: usize) {
351-
assert!(self.is_code_point_boundary(new_len));
352-
self.bytes.truncate(new_len)
353+
if new_len <= self.len() {
354+
assert!(self.is_code_point_boundary(new_len));
355+
self.bytes.truncate(new_len)
356+
}
353357
}
354358

355359
/// Consumes the WTF-8 string and tries to convert it to a vec of bytes.

library/alloc/src/wtf8/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,10 @@ fn wtf8buf_truncate_fail_code_point_boundary() {
308308
}
309309

310310
#[test]
311-
#[should_panic]
312-
fn wtf8buf_truncate_fail_longer() {
311+
fn wtf8buf_truncate_invalid_len() {
313312
let mut string = Wtf8Buf::from_str("aé");
314313
string.truncate(4);
314+
assert_eq!(string, Wtf8Buf::from_str("aé"));
315315
}
316316

317317
#[test]

library/core/src/convert/num.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ impl_from_bool!(i8 i16 i32 i64 i128 isize);
7070

7171
/// Implement `From<$small>` for `$large`
7272
macro_rules! impl_from {
73-
($small:ty => $large:ty, #[$attr:meta]) => {
74-
#[$attr]
73+
($small:ty => $large:ty, $(#[$attrs:meta]),+) => {
74+
$(#[$attrs])+
7575
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
7676
impl const From<$small> for $large {
7777
#[doc = concat!("Converts from [`", stringify!($small), "`] to [`", stringify!($large), "`] losslessly.")]
@@ -157,8 +157,7 @@ impl_from!(i16 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0"
157157
impl_from!(i16 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
158158
impl_from!(i32 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
159159
impl_from!(i32 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
160-
// FIXME(f128): This impl would allow using `f128` on stable before it is stabilised.
161-
// impl_from!(i64 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
160+
impl_from!(i64 => f128, #[unstable(feature = "f128", issue = "116909")], #[unstable_feature_bound(f128)]);
162161

163162
// unsigned integer -> float
164163
impl_from!(u8 => f16, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
@@ -170,8 +169,7 @@ impl_from!(u16 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0"
170169
impl_from!(u16 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
171170
impl_from!(u32 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
172171
impl_from!(u32 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
173-
// FIXME(f128): This impl would allow using `f128` on stable before it is stabilised.
174-
// impl_from!(u64 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
172+
impl_from!(u64 => f128, #[unstable(feature = "f128", issue = "116909")], #[unstable_feature_bound(f128)]);
175173

176174
// float -> float
177175
// FIXME(f16,f128): adding additional `From<{float}>` impls to `f32` breaks inference. See

library/std/src/ffi/os_str.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -576,15 +576,21 @@ impl OsString {
576576

577577
/// Truncate the `OsString` to the specified length.
578578
///
579+
/// If `new_len` is greater than the string's current length, this has no
580+
/// effect.
581+
///
579582
/// # Panics
583+
///
580584
/// Panics if `len` does not lie on a valid `OsStr` boundary
581585
/// (as described in [`OsStr::slice_encoded_bytes`]).
582586
#[inline]
583587
#[unstable(feature = "os_string_truncate", issue = "133262")]
584588
pub fn truncate(&mut self, len: usize) {
585-
self.as_os_str().inner.check_public_boundary(len);
586-
// SAFETY: The length was just checked to be at a valid boundary.
587-
unsafe { self.inner.truncate_unchecked(len) };
589+
if len <= self.len() {
590+
self.as_os_str().inner.check_public_boundary(len);
591+
// SAFETY: The length was just checked to be at a valid boundary.
592+
unsafe { self.inner.truncate_unchecked(len) };
593+
}
588594
}
589595

590596
/// Provides plumbing to `Vec::extend_from_slice` without giving full

src/tools/tidy/src/issues.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1358,7 +1358,6 @@ ui/infinite/issue-41731-infinite-macro-print.rs
13581358
ui/infinite/issue-41731-infinite-macro-println.rs
13591359
ui/intrinsics/issue-28575.rs
13601360
ui/intrinsics/issue-84297-reifying-copy.rs
1361-
ui/invalid/issue-114435-layout-type-err.rs
13621361
ui/iterators/issue-28098.rs
13631362
ui/iterators/issue-58952-filter-type-length.rs
13641363
ui/lang-items/issue-83471.rs

tests/ui/README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -756,12 +756,6 @@ Tests for rustc-internal lints.
756756

757757
Tests for the `{std,core}::intrinsics`, internal implementation detail.
758758

759-
## `tests/ui/invalid/`
760-
761-
Various tests related to rejecting invalid inputs.
762-
763-
**FIXME**: This is rather uninformative, possibly rehome into more meaningful directories.
764-
765759
## `tests/ui/io-checks/`: Input Output
766760

767761
Tests for I/O related behaviour, covering stdout/stderr handling and error propagation.

tests/ui/associated-consts/wrong-projection-self-ty-invalid-bivariant-arg.stderr

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ LL | struct Fail<T>;
1616
LL | Fail::<()>::C
1717
| ^ associated item not found in `Fail<()>`
1818
|
19-
= note: the associated item was found for
20-
- `Fail<i32>`
19+
= note: the associated item was found for `Fail<i32>`
2120

2221
error: aborting due to 2 previous errors
2322

0 commit comments

Comments
 (0)