Skip to content

Commit efe4bfa

Browse files
committed
update unimpl diagnostics, clippy lints
This adds a diagnostic name `string_in_global` so that clippy can easily check for the alloc::string::String type alias.
1 parent d5bd2cd commit efe4bfa

24 files changed

+74
-74
lines changed

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,6 +2192,7 @@ symbols! {
21922192
string_as_str,
21932193
string_deref_patterns,
21942194
string_from_utf8,
2195+
string_in_global,
21952196
string_insert_str,
21962197
string_new,
21972198
string_push_str,

library/core/src/convert/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ pub const trait Into<T>: Sized {
579579
#[rustc_diagnostic_item = "From"]
580580
#[stable(feature = "rust1", since = "1.0.0")]
581581
#[rustc_on_unimplemented(on(
582-
all(Self = "&str", T = "alloc::string::String"),
582+
all(Self = "&str", T = "alloc::string::generic::String<A>"),
583583
note = "to coerce a `{T}` into a `{Self}`, use `&*` as a prefix",
584584
))]
585585
#[doc(search_unbox)]

library/core/src/iter/traits/collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ pub trait FromIterator<A>: Sized {
261261
),
262262
on(Self = "&str", label = "`{Self}` is not an iterator; try calling `.chars()` or `.bytes()`"),
263263
on(
264-
Self = "alloc::string::String",
264+
Self = "alloc::string::generic::String<A>",
265265
label = "`{Self}` is not an iterator; try calling `.chars()` or `.bytes()`"
266266
),
267267
on(

library/core/src/ops/index.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#ind
155155
see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>"
156156
),
157157
on(
158-
Self = "alloc::string::String",
158+
Self = "alloc::string::generic::String<A>",
159159
note = "you can use `.chars().nth()` or `.bytes().nth()`
160160
see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>"
161161
),

library/core/src/slice/index.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ mod private_slice_index {
151151
#[rustc_on_unimplemented(
152152
on(T = "str", label = "string indices are ranges of `usize`",),
153153
on(
154-
all(any(T = "str", T = "&str", T = "alloc::string::String"), Self = "{integer}"),
154+
all(
155+
any(T = "str", T = "&str", T = "alloc::string::generic::String<A>"),
156+
Self = "{integer}"
157+
),
155158
note = "you can use `.chars().nth()` or `.bytes().nth()`\n\
156159
for more information, see chapter 8 in The Book: \
157160
<https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>"

src/doc/rustc-dev-guide/src/diagnostics.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ You can match on the following names and values, using `name = "value"`:
955955
- `from_desugaring`: Match against a particular variant of the `DesugaringKind`
956956
enum. The desugaring is identified by its variant name, for example
957957
`"QuestionMark"` for `?` desugaring or `"TryBlock"` for `try` blocks.
958-
- `Self` and any generic arguments of the trait, like `Self = "alloc::string::String"`
958+
- `Self` and any generic arguments of the trait, like `Self = "alloc::string::generic::String<A>"`
959959
or `Rhs="i32"`.
960960

961961
The compiler can provide several values to match on, for example:
@@ -1007,7 +1007,7 @@ The `on` filter accepts `all`, `any` and `not` predicates similar to the `cfg` a
10071007

10081008
```rust,ignore
10091009
#[rustc_on_unimplemented(on(
1010-
all(Self = "&str", T = "alloc::string::String"),
1010+
all(Self = "&str", T = "alloc::string::generic::String<A>"),
10111011
note = "you can coerce a `{T}` into a `{Self}` by writing `&*variable`"
10121012
))]
10131013
pub trait From<T>: Sized {

src/tools/clippy/clippy_lints/src/operators/arithmetic_side_effects.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl ArithmeticSideEffects {
3333
allowed_binary.extend([
3434
("f32", FxHashSet::from_iter(["f32"])),
3535
("f64", FxHashSet::from_iter(["f64"])),
36-
("std::string::String", FxHashSet::from_iter(["str"])),
36+
("std::string::generic::String", FxHashSet::from_iter(["str"])),
3737
]);
3838
for (lhs, rhs) in &conf.arithmetic_side_effects_allowed_binary {
3939
allowed_binary.entry(lhs).or_default().insert(rhs);

src/tools/clippy/clippy_lints/src/redundant_type_annotations.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ declare_clippy_lint! {
2525
///
2626
/// ### Example
2727
/// ```no_run
28-
/// let foo: String = String::new();
28+
/// let foo: u64 = u64::MAX;
2929
/// ```
3030
/// Use instead:
3131
/// ```no_run
32-
/// let foo = String::new();
32+
/// let foo = u64::MAX;
3333
/// ```
3434
#[clippy::version = "1.72.0"]
3535
pub REDUNDANT_TYPE_ANNOTATIONS,

src/tools/clippy/clippy_lints/src/types/box_collection.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_
1313
&& let Some(item_type) = get_std_collection(cx, qpath)
1414
{
1515
let generic = match item_type {
16-
sym::String => "",
16+
sym::string_in_global => "",
1717
_ => "<..>",
1818
};
19+
let item_type = match item_type {
20+
sym::string_in_global => sym::String,
21+
_ => item_type,
22+
};
1923

2024
let box_content = format!("{item_type}{generic}");
2125
span_lint_and_help(
@@ -48,6 +52,7 @@ fn get_std_collection(cx: &LateContext<'_>, qpath: &QPath<'_>) -> Option<Symbol>
4852
| sym::BTreeMap
4953
| sym::BTreeSet
5054
| sym::BinaryHeap
55+
| sym::string_in_global,
5156
)
5257
})
5358
.or_else(|| {

src/tools/clippy/clippy_lints/src/types/owned_cow.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ pub(super) fn check(cx: &LateContext<'_>, qpath: &hir::QPath<'_>, def_id: DefId)
3131
}
3232

3333
fn replacement(cx: &LateContext<'_>, cty: &hir::Ty<'_>) -> Option<(Span, String)> {
34-
if cty.basic_res().is_lang_item(cx, hir::LangItem::String) {
34+
if cty.basic_res().is_lang_item(cx, hir::LangItem::String)
35+
|| cty.basic_res().is_diag_item(cx, sym::string_in_global)
36+
{
3537
return Some((cty.span, "str".into()));
3638
}
3739
if cty.basic_res().is_diag_item(cx, sym::Vec) {

0 commit comments

Comments
 (0)