Skip to content

Commit d3f816b

Browse files
committed
Auto merge of rust-lang#128148 - matthiaskrgr:rollup-82zv908, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#126548 (Improved clarity of documentation for std::fs::create_dir_all) - rust-lang#127528 (Replace ASCII control chars with Unicode Control Pictures) - rust-lang#127717 (Fix malformed suggestion for repeated maybe unsized bounds) - rust-lang#128046 (Fix some `#[cfg_attr(not(doc), repr(..))]`) - rust-lang#128122 (Mark `missing_fragment_specifier` as `FutureReleaseErrorReportInDeps`) - rust-lang#128135 (std: use duplicate thread local state in tests) - rust-lang#128140 (Remove Unnecessary `.as_str()` Conversions) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 6106b05 + c9fdddf commit d3f816b

File tree

87 files changed

+651
-379
lines changed

Some content is hidden

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

87 files changed

+651
-379
lines changed

Cargo.lock

-1
Original file line numberDiff line numberDiff line change
@@ -3882,7 +3882,6 @@ dependencies = [
38823882
"termcolor",
38833883
"termize",
38843884
"tracing",
3885-
"unicode-width",
38863885
"windows",
38873886
]
38883887

compiler/rustc_errors/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ serde_json = "1.0.59"
2626
termcolor = "1.2.0"
2727
termize = "0.1.1"
2828
tracing = "0.1"
29-
unicode-width = "0.1.4"
3029
# tidy-alphabetical-end
3130

3231
[target.'cfg(windows)'.dependencies.windows]

compiler/rustc_errors/src/emitter.rs

+51-26
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//! The output types are defined in `rustc_session::config::ErrorOutputType`.
99
1010
use rustc_span::source_map::SourceMap;
11-
use rustc_span::{FileLines, FileName, SourceFile, Span};
11+
use rustc_span::{char_width, FileLines, FileName, SourceFile, Span};
1212

1313
use crate::snippet::{
1414
Annotation, AnnotationColumn, AnnotationType, Line, MultilineAnnotation, Style, StyledString,
@@ -677,10 +677,7 @@ impl HumanEmitter {
677677
.skip(left)
678678
.take_while(|ch| {
679679
// Make sure that the trimming on the right will fall within the terminal width.
680-
// FIXME: `unicode_width` sometimes disagrees with terminals on how wide a `char`
681-
// is. For now, just accept that sometimes the code line will be longer than
682-
// desired.
683-
let next = unicode_width::UnicodeWidthChar::width(*ch).unwrap_or(1);
680+
let next = char_width(*ch);
684681
if taken + next > right - left {
685682
return false;
686683
}
@@ -742,11 +739,7 @@ impl HumanEmitter {
742739
let left = margin.left(source_string.len());
743740

744741
// Account for unicode characters of width !=0 that were removed.
745-
let left = source_string
746-
.chars()
747-
.take(left)
748-
.map(|ch| unicode_width::UnicodeWidthChar::width(ch).unwrap_or(1))
749-
.sum();
742+
let left = source_string.chars().take(left).map(|ch| char_width(ch)).sum();
750743

751744
self.draw_line(
752745
buffer,
@@ -2039,7 +2032,7 @@ impl HumanEmitter {
20392032
let sub_len: usize =
20402033
if is_whitespace_addition { &part.snippet } else { part.snippet.trim() }
20412034
.chars()
2042-
.map(|ch| unicode_width::UnicodeWidthChar::width(ch).unwrap_or(1))
2035+
.map(|ch| char_width(ch))
20432036
.sum();
20442037

20452038
let offset: isize = offsets
@@ -2076,11 +2069,8 @@ impl HumanEmitter {
20762069
}
20772070

20782071
// length of the code after substitution
2079-
let full_sub_len = part
2080-
.snippet
2081-
.chars()
2082-
.map(|ch| unicode_width::UnicodeWidthChar::width(ch).unwrap_or(1))
2083-
.sum::<usize>() as isize;
2072+
let full_sub_len =
2073+
part.snippet.chars().map(|ch| char_width(ch)).sum::<usize>() as isize;
20842074

20852075
// length of the code to be substituted
20862076
let snippet_len = span_end_pos as isize - span_start_pos as isize;
@@ -2568,18 +2558,53 @@ fn num_decimal_digits(num: usize) -> usize {
25682558
}
25692559

25702560
// We replace some characters so the CLI output is always consistent and underlines aligned.
2561+
// Keep the following list in sync with `rustc_span::char_width`.
25712562
const OUTPUT_REPLACEMENTS: &[(char, &str)] = &[
2572-
('\t', " "), // We do our own tab replacement
2563+
('\t', " "), // We do our own tab replacement
25732564
('\u{200D}', ""), // Replace ZWJ with nothing for consistent terminal output of grapheme clusters.
2574-
('\u{202A}', ""), // The following unicode text flow control characters are inconsistently
2575-
('\u{202B}', ""), // supported across CLIs and can cause confusion due to the bytes on disk
2576-
('\u{202D}', ""), // not corresponding to the visible source code, so we replace them always.
2577-
('\u{202E}', ""),
2578-
('\u{2066}', ""),
2579-
('\u{2067}', ""),
2580-
('\u{2068}', ""),
2581-
('\u{202C}', ""),
2582-
('\u{2069}', ""),
2565+
('\u{202A}', "�"), // The following unicode text flow control characters are inconsistently
2566+
('\u{202B}', "�"), // supported across CLIs and can cause confusion due to the bytes on disk
2567+
('\u{202D}', "�"), // not corresponding to the visible source code, so we replace them always.
2568+
('\u{202E}', "�"),
2569+
('\u{2066}', "�"),
2570+
('\u{2067}', "�"),
2571+
('\u{2068}', "�"),
2572+
('\u{202C}', "�"),
2573+
('\u{2069}', "�"),
2574+
// In terminals without Unicode support the following will be garbled, but in *all* terminals
2575+
// the underlying codepoint will be as well. We could gate this replacement behind a "unicode
2576+
// support" gate.
2577+
('\u{0000}', "␀"),
2578+
('\u{0001}', "␁"),
2579+
('\u{0002}', "␂"),
2580+
('\u{0003}', "␃"),
2581+
('\u{0004}', "␄"),
2582+
('\u{0005}', "␅"),
2583+
('\u{0006}', "␆"),
2584+
('\u{0007}', "␇"),
2585+
('\u{0008}', "␈"),
2586+
('\u{000B}', "␋"),
2587+
('\u{000C}', "␌"),
2588+
('\u{000D}', "␍"),
2589+
('\u{000E}', "␎"),
2590+
('\u{000F}', "␏"),
2591+
('\u{0010}', "␐"),
2592+
('\u{0011}', "␑"),
2593+
('\u{0012}', "␒"),
2594+
('\u{0013}', "␓"),
2595+
('\u{0014}', "␔"),
2596+
('\u{0015}', "␕"),
2597+
('\u{0016}', "␖"),
2598+
('\u{0017}', "␗"),
2599+
('\u{0018}', "␘"),
2600+
('\u{0019}', "␙"),
2601+
('\u{001A}', "␚"),
2602+
('\u{001B}', "␛"),
2603+
('\u{001C}', "␜"),
2604+
('\u{001D}', "␝"),
2605+
('\u{001E}', "␞"),
2606+
('\u{001F}', "␟"),
2607+
('\u{007F}', "␡"),
25832608
];
25842609

25852610
fn normalize_whitespace(str: &str) -> String {

compiler/rustc_hir/src/hir.rs

+15-9
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ impl<'hir> Generics<'hir> {
763763
)
764764
}
765765

766-
fn span_for_predicate_removal(&self, pos: usize) -> Span {
766+
pub fn span_for_predicate_removal(&self, pos: usize) -> Span {
767767
let predicate = &self.predicates[pos];
768768
let span = predicate.span();
769769

@@ -806,15 +806,21 @@ impl<'hir> Generics<'hir> {
806806
return self.span_for_predicate_removal(predicate_pos);
807807
}
808808

809-
let span = bounds[bound_pos].span();
810-
if bound_pos == 0 {
811-
// where T: ?Sized + Bar, Foo: Bar,
812-
// ^^^^^^^^^
813-
span.to(bounds[1].span().shrink_to_lo())
809+
let bound_span = bounds[bound_pos].span();
810+
if bound_pos < bounds.len() - 1 {
811+
// If there's another bound after the current bound
812+
// include the following '+' e.g.:
813+
//
814+
// `T: Foo + CurrentBound + Bar`
815+
// ^^^^^^^^^^^^^^^
816+
bound_span.to(bounds[bound_pos + 1].span().shrink_to_lo())
814817
} else {
815-
// where T: Bar + ?Sized, Foo: Bar,
816-
// ^^^^^^^^^
817-
bounds[bound_pos - 1].span().shrink_to_hi().to(span)
818+
// If the current bound is the last bound
819+
// include the preceding '+' E.g.:
820+
//
821+
// `T: Foo + Bar + CurrentBound`
822+
// ^^^^^^^^^^^^^^^
823+
bound_span.with_lo(bounds[bound_pos - 1].span().hi())
818824
}
819825
}
820826
}

compiler/rustc_hir_typeck/src/method/probe.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1846,7 +1846,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
18461846
/// Determine if the associated item with the given DefId matches
18471847
/// the desired name via a doc alias.
18481848
fn matches_by_doc_alias(&self, def_id: DefId) -> bool {
1849-
let Some(name) = self.method_name else {
1849+
let Some(method) = self.method_name else {
18501850
return false;
18511851
};
18521852
let Some(local_def_id) = def_id.as_local() else {
@@ -1863,7 +1863,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
18631863
// #[rustc_confusables("foo", "bar"))]
18641864
for n in confusables {
18651865
if let Some(lit) = n.lit()
1866-
&& name.as_str() == lit.symbol.as_str()
1866+
&& method.name == lit.symbol
18671867
{
18681868
return true;
18691869
}
@@ -1883,14 +1883,14 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
18831883
// #[doc(alias("foo", "bar"))]
18841884
for n in nested {
18851885
if let Some(lit) = n.lit()
1886-
&& name.as_str() == lit.symbol.as_str()
1886+
&& method.name == lit.symbol
18871887
{
18881888
return true;
18891889
}
18901890
}
18911891
} else if let Some(meta) = v.meta_item()
18921892
&& let Some(lit) = meta.name_value_literal()
1893-
&& name.as_str() == lit.symbol.as_str()
1893+
&& method.name == lit.symbol
18941894
{
18951895
// #[doc(alias = "foo")]
18961896
return true;

compiler/rustc_lint_defs/src/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1424,7 +1424,7 @@ declare_lint! {
14241424
Deny,
14251425
"detects missing fragment specifiers in unused `macro_rules!` patterns",
14261426
@future_incompatible = FutureIncompatibleInfo {
1427-
reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps,
1427+
reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
14281428
reference: "issue #40107 <https://github.com/rust-lang/rust/issues/40107>",
14291429
};
14301430
}

compiler/rustc_metadata/src/rmeta/decoder.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1728,7 +1728,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
17281728
source_len,
17291729
lines,
17301730
multibyte_chars,
1731-
non_narrow_chars,
17321731
normalized_pos,
17331732
stable_id,
17341733
..
@@ -1780,7 +1779,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
17801779
self.cnum,
17811780
lines,
17821781
multibyte_chars,
1783-
non_narrow_chars,
17841782
normalized_pos,
17851783
source_file_index,
17861784
);

compiler/rustc_middle/src/ty/diagnostics.rs

+49-20
Original file line numberDiff line numberDiff line change
@@ -188,31 +188,60 @@ fn suggest_changing_unsized_bound(
188188
continue;
189189
};
190190

191-
for (pos, bound) in predicate.bounds.iter().enumerate() {
192-
let hir::GenericBound::Trait(poly, hir::TraitBoundModifier::Maybe) = bound else {
193-
continue;
194-
};
195-
if poly.trait_ref.trait_def_id() != def_id {
196-
continue;
197-
}
198-
if predicate.origin == PredicateOrigin::ImplTrait && predicate.bounds.len() == 1 {
199-
// For `impl ?Sized` with no other bounds, suggest `impl Sized` instead.
200-
let bound_span = bound.span();
201-
if bound_span.can_be_used_for_suggestions() {
202-
let question_span = bound_span.with_hi(bound_span.lo() + BytePos(1));
203-
suggestions.push((
191+
let unsized_bounds = predicate
192+
.bounds
193+
.iter()
194+
.enumerate()
195+
.filter(|(_, bound)| {
196+
if let hir::GenericBound::Trait(poly, hir::TraitBoundModifier::Maybe) = bound
197+
&& poly.trait_ref.trait_def_id() == def_id
198+
{
199+
true
200+
} else {
201+
false
202+
}
203+
})
204+
.collect::<Vec<_>>();
205+
206+
if unsized_bounds.is_empty() {
207+
continue;
208+
}
209+
210+
let mut push_suggestion = |sp, msg| suggestions.push((sp, String::new(), msg));
211+
212+
if predicate.bounds.len() == unsized_bounds.len() {
213+
// All the bounds are unsized bounds, e.g.
214+
// `T: ?Sized + ?Sized` or `_: impl ?Sized + ?Sized`,
215+
// so in this case:
216+
// - if it's an impl trait predicate suggest changing the
217+
// the first bound to sized and removing the rest
218+
// - Otherwise simply suggest removing the entire predicate
219+
if predicate.origin == PredicateOrigin::ImplTrait {
220+
let first_bound = unsized_bounds[0].1;
221+
let first_bound_span = first_bound.span();
222+
if first_bound_span.can_be_used_for_suggestions() {
223+
let question_span =
224+
first_bound_span.with_hi(first_bound_span.lo() + BytePos(1));
225+
push_suggestion(
204226
question_span,
205-
String::new(),
206227
SuggestChangingConstraintsMessage::ReplaceMaybeUnsizedWithSized,
207-
));
228+
);
229+
230+
for (pos, _) in unsized_bounds.iter().skip(1) {
231+
let sp = generics.span_for_bound_removal(where_pos, *pos);
232+
push_suggestion(sp, SuggestChangingConstraintsMessage::RemoveMaybeUnsized);
233+
}
208234
}
209235
} else {
236+
let sp = generics.span_for_predicate_removal(where_pos);
237+
push_suggestion(sp, SuggestChangingConstraintsMessage::RemoveMaybeUnsized);
238+
}
239+
} else {
240+
// Some of the bounds are other than unsized.
241+
// So push separate removal suggestion for each unsized bound
242+
for (pos, _) in unsized_bounds {
210243
let sp = generics.span_for_bound_removal(where_pos, pos);
211-
suggestions.push((
212-
sp,
213-
String::new(),
214-
SuggestChangingConstraintsMessage::RemoveMaybeUnsized,
215-
));
244+
push_suggestion(sp, SuggestChangingConstraintsMessage::RemoveMaybeUnsized);
216245
}
217246
}
218247
}

compiler/rustc_query_system/src/ich/impls_syntax.rs

-6
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for SourceFile {
7373
source_len: _,
7474
lines: _,
7575
ref multibyte_chars,
76-
ref non_narrow_chars,
7776
ref normalized_pos,
7877
} = *self;
7978

@@ -98,11 +97,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for SourceFile {
9897
char_pos.hash_stable(hcx, hasher);
9998
}
10099

101-
non_narrow_chars.len().hash_stable(hcx, hasher);
102-
for &char_pos in non_narrow_chars.iter() {
103-
char_pos.hash_stable(hcx, hasher);
104-
}
105-
106100
normalized_pos.len().hash_stable(hcx, hasher);
107101
for &char_pos in normalized_pos.iter() {
108102
char_pos.hash_stable(hcx, hasher);

0 commit comments

Comments
 (0)