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 8 pull requests #130722

Closed
wants to merge 17 commits into from
Closed
Changes from 2 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
3dcb5a3
Add str.as_str() for easy dereferencing of Box<str>
kornelski Aug 25, 2024
f48c5ec
Mark and implement 'char::encode_utf16' as const; Rewrite 'encode_utf…
bjoernager Sep 21, 2024
95469dc
No longer mark RTN as incomplete
compiler-errors Sep 21, 2024
86fc657
Try to write the panic message with a single `write_all` call
Zoxc Mar 15, 2024
3b8089a
Introduce structurally_normalize_const, use it in hir_typeck
compiler-errors Sep 22, 2024
2daf076
Mark 'make_ascii_uppercase' and 'make_ascii_lowercase' in 'u8' as con…
bjoernager Sep 22, 2024
8f57949
Don't call const normalize in error reporting
compiler-errors Sep 22, 2024
01d19d7
Don't call try_eval_target_usize in error reporting
compiler-errors Sep 22, 2024
2273aee
Replace calls to Const::eval in mir build
compiler-errors Sep 22, 2024
a9cc537
Rollup merge of #122565 - Zoxc:atomic-panic-msg, r=the8472
matthiaskrgr Sep 22, 2024
77dc029
Rollup merge of #129550 - kornelski:boxasstr, r=joshtriplett,dtolnay
matthiaskrgr Sep 22, 2024
7460e4d
Rollup merge of #130659 - bjoernager:const-char-encode-utf16, r=dtolnay
matthiaskrgr Sep 22, 2024
bfcf31a
Rollup merge of #130705 - compiler-errors:rtn-complete, r=jackh726
matthiaskrgr Sep 22, 2024
1d4beed
Rollup merge of #130712 - compiler-errors:const-eval-error-reporting,…
matthiaskrgr Sep 22, 2024
40f4934
Rollup merge of #130713 - bjoernager:const-char-make-ascii, r=Noratrieb
matthiaskrgr Sep 22, 2024
4e69d0b
Rollup merge of #130714 - compiler-errors:try-structurally-resolve-co…
matthiaskrgr Sep 22, 2024
4217792
Rollup merge of #130715 - compiler-errors:mir-build-const-eval, r=Box…
matthiaskrgr Sep 22, 2024
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
15 changes: 1 addition & 14 deletions compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
@@ -1721,20 +1721,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}

if item_name.name == sym::as_str && rcvr_ty.peel_refs().is_str() {
let msg = "remove this method call";
let mut fallback_span = true;
if let SelfSource::MethodCall(expr) = source {
let call_expr = self.tcx.hir().expect_expr(self.tcx.parent_hir_id(expr.hir_id));
if let Some(span) = call_expr.span.trim_start(expr.span) {
err.span_suggestion(span, msg, "", Applicability::MachineApplicable);
fallback_span = false;
}
}
if fallback_span {
err.span_label(span, msg);
}
} else if let Some(similar_candidate) = similar_candidate {
if let Some(similar_candidate) = similar_candidate {
// Don't emit a suggestion if we found an actual method
// that had unsatisfied trait bounds
if unsatisfied_predicates.is_empty()
1 change: 1 addition & 0 deletions library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -93,6 +93,7 @@
// tidy-alphabetical-start
#![cfg_attr(not(no_global_oom_handling), feature(const_alloc_error))]
#![cfg_attr(not(no_global_oom_handling), feature(const_btree_len))]
#![cfg_attr(test, feature(str_as_str))]
#![feature(alloc_layout_extra)]
#![feature(allocator_api)]
#![feature(array_chunks)]
4 changes: 4 additions & 0 deletions library/alloc/src/rc/tests.rs
Original file line number Diff line number Diff line change
@@ -448,7 +448,11 @@ fn test_from_box_str() {
use std::string::String;

let s = String::from("foo").into_boxed_str();
assert_eq!((&&&s).as_str(), "foo");

let r: Rc<str> = Rc::from(s);
assert_eq!((&r).as_str(), "foo");
assert_eq!(r.as_str(), "foo");

assert_eq!(&r[..], "foo");
}
11 changes: 11 additions & 0 deletions library/core/src/str/mod.rs
Original file line number Diff line number Diff line change
@@ -2740,6 +2740,17 @@ impl str {
pub fn substr_range(&self, substr: &str) -> Option<Range<usize>> {
self.as_bytes().subslice_range(substr.as_bytes())
}

/// Returns the same string as a string slice `&str`.
///
/// This method is redundant when used directly on `&str`, but
/// it helps dereferencing other string-like types to string slices,
/// for example references to `Box<str>` or `Arc<str>`.
#[inline]
#[unstable(feature = "str_as_str", issue = "130366")]
pub fn as_str(&self) -> &str {
self
}
}

#[stable(feature = "rust1", since = "1.0.0")]
21 changes: 0 additions & 21 deletions tests/ui/suggestions/remove-as_str.rs

This file was deleted.

27 changes: 0 additions & 27 deletions tests/ui/suggestions/remove-as_str.stderr

This file was deleted.