Skip to content

Commit 004e155

Browse files
committed
Auto merge of rust-lang#128169 - matthiaskrgr:rollup-ylsoq30, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#127054 (Reorder trait bound modifiers *after* `for<...>` binder in trait bounds) - rust-lang#127528 (Replace ASCII control chars with Unicode Control Pictures) - rust-lang#127872 (Migrate `pointer-auth-link-with-c`, `c-dynamic-rlib` and `c-dynamic-dylib` `run-make` tests to rmake) - rust-lang#128111 (Do not use question as label) - rust-lang#128160 (Don't ICE when auto trait has assoc ty in old solver) r? `@ghost` `@rustbot` modify labels: rollup
2 parents e7d66ea + 1fda084 commit 004e155

File tree

147 files changed

+792
-607
lines changed

Some content is hidden

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

147 files changed

+792
-607
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_ast_passes/messages.ftl

-2
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,6 @@ ast_passes_impl_trait_path = `impl Trait` is not allowed in path parameters
155155
ast_passes_incompatible_features = `{$f1}` and `{$f2}` are incompatible, using them at the same time is not allowed
156156
.help = remove one of these features
157157
158-
ast_passes_incompatible_trait_bound_modifiers = `{$left}` and `{$right}` are mutually exclusive
159-
160158
ast_passes_inherent_cannot_be = inherent impls cannot be {$annotation}
161159
.because = {$annotation} because of this
162160
.type = inherent impl for this type

compiler/rustc_ast_passes/src/ast_validation.rs

-11
Original file line numberDiff line numberDiff line change
@@ -1366,17 +1366,6 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
13661366
{
13671367
self.dcx().emit_err(errors::TildeConstDisallowed { span, reason });
13681368
}
1369-
(
1370-
_,
1371-
BoundConstness::Always(_) | BoundConstness::Maybe(_),
1372-
BoundPolarity::Negative(_) | BoundPolarity::Maybe(_),
1373-
) => {
1374-
self.dcx().emit_err(errors::IncompatibleTraitBoundModifiers {
1375-
span: bound.span(),
1376-
left: modifiers.constness.as_str(),
1377-
right: modifiers.polarity.as_str(),
1378-
});
1379-
}
13801369
_ => {}
13811370
}
13821371

compiler/rustc_ast_passes/src/errors.rs

-9
Original file line numberDiff line numberDiff line change
@@ -656,15 +656,6 @@ pub enum TildeConstReason {
656656
Item,
657657
}
658658

659-
#[derive(Diagnostic)]
660-
#[diag(ast_passes_incompatible_trait_bound_modifiers)]
661-
pub struct IncompatibleTraitBoundModifiers {
662-
#[primary_span]
663-
pub span: Span,
664-
pub left: &'static str,
665-
pub right: &'static str,
666-
}
667-
668659
#[derive(Diagnostic)]
669660
#[diag(ast_passes_const_and_async)]
670661
pub struct ConstAndAsync {

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_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_parse/messages.ftl

+9
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ parse_bare_cr = {$double_quotes ->
5353
5454
parse_bare_cr_in_raw_string = bare CR not allowed in raw string
5555
56+
parse_binder_and_polarity = `for<...>` binder not allowed with `{$polarity}` trait polarity modifier
57+
.label = there is not a well-defined meaning for a higher-ranked `{$polarity}` trait
58+
59+
parse_binder_before_modifiers = `for<...>` binder should be placed before trait bound modifiers
60+
.label = place the `for<...>` binder before any modifiers
61+
5662
parse_bounds_not_allowed_on_trait_aliases = bounds are not allowed on trait aliases
5763
5864
parse_box_not_pat = expected pattern, found {$descr}
@@ -577,6 +583,9 @@ parse_missing_trait_in_trait_impl = missing trait in a trait impl
577583
parse_modifier_lifetime = `{$modifier}` may only modify trait bounds, not lifetime bounds
578584
.suggestion = remove the `{$modifier}`
579585
586+
parse_modifiers_and_polarity = `{$modifiers_concatenated}` trait not allowed with `{$polarity}` trait polarity modifier
587+
.label = there is not a well-defined meaning for a `{$modifiers_concatenated} {$polarity}` trait
588+
580589
parse_more_than_one_char = character literal may only contain one codepoint
581590
.followed_by = this `{$chr}` is followed by the combining {$len ->
582591
[one] mark

compiler/rustc_parse/src/errors.rs

+30
Original file line numberDiff line numberDiff line change
@@ -3212,3 +3212,33 @@ pub struct UnsafeAttrOutsideUnsafeSuggestion {
32123212
#[suggestion_part(code = ")")]
32133213
pub right: Span,
32143214
}
3215+
3216+
#[derive(Diagnostic)]
3217+
#[diag(parse_binder_before_modifiers)]
3218+
pub struct BinderBeforeModifiers {
3219+
#[primary_span]
3220+
pub binder_span: Span,
3221+
#[label]
3222+
pub modifiers_span: Span,
3223+
}
3224+
3225+
#[derive(Diagnostic)]
3226+
#[diag(parse_binder_and_polarity)]
3227+
pub struct BinderAndPolarity {
3228+
#[primary_span]
3229+
pub polarity_span: Span,
3230+
#[label]
3231+
pub binder_span: Span,
3232+
pub polarity: &'static str,
3233+
}
3234+
3235+
#[derive(Diagnostic)]
3236+
#[diag(parse_modifiers_and_polarity)]
3237+
pub struct PolarityAndModifiers {
3238+
#[primary_span]
3239+
pub polarity_span: Span,
3240+
#[label]
3241+
pub modifiers_span: Span,
3242+
pub polarity: &'static str,
3243+
pub modifiers_concatenated: String,
3244+
}

compiler/rustc_parse/src/parser/ty.rs

+57-3
Original file line numberDiff line numberDiff line change
@@ -935,9 +935,14 @@ impl<'a> Parser<'a> {
935935
/// If no modifiers are present, this does not consume any tokens.
936936
///
937937
/// ```ebnf
938-
/// TRAIT_BOUND_MODIFIERS = [["~"] "const"] ["async"] ["?" | "!"]
938+
/// CONSTNESS = [["~"] "const"]
939+
/// ASYNCNESS = ["async"]
940+
/// POLARITY = ["?" | "!"]
939941
/// ```
942+
///
943+
/// See `parse_generic_ty_bound` for the complete grammar of trait bound modifiers.
940944
fn parse_trait_bound_modifiers(&mut self) -> PResult<'a, TraitBoundModifiers> {
945+
let modifier_lo = self.token.span;
941946
let constness = if self.eat(&token::Tilde) {
942947
let tilde = self.prev_token.span;
943948
self.expect_keyword(kw::Const)?;
@@ -970,6 +975,7 @@ impl<'a> Parser<'a> {
970975
} else {
971976
BoundAsyncness::Normal
972977
};
978+
let modifier_hi = self.prev_token.span;
973979

974980
let polarity = if self.eat(&token::Question) {
975981
BoundPolarity::Maybe(self.prev_token.span)
@@ -980,13 +986,40 @@ impl<'a> Parser<'a> {
980986
BoundPolarity::Positive
981987
};
982988

989+
// Enforce the mutual-exclusivity of `const`/`async` and `?`/`!`.
990+
match polarity {
991+
BoundPolarity::Positive => {
992+
// All trait bound modifiers allowed to combine with positive polarity
993+
}
994+
BoundPolarity::Maybe(polarity_span) | BoundPolarity::Negative(polarity_span) => {
995+
match (asyncness, constness) {
996+
(BoundAsyncness::Normal, BoundConstness::Never) => {
997+
// Ok, no modifiers.
998+
}
999+
(_, _) => {
1000+
let constness = constness.as_str();
1001+
let asyncness = asyncness.as_str();
1002+
let glue =
1003+
if !constness.is_empty() && !asyncness.is_empty() { " " } else { "" };
1004+
let modifiers_concatenated = format!("{constness}{glue}{asyncness}");
1005+
self.dcx().emit_err(errors::PolarityAndModifiers {
1006+
polarity_span,
1007+
polarity: polarity.as_str(),
1008+
modifiers_span: modifier_lo.to(modifier_hi),
1009+
modifiers_concatenated,
1010+
});
1011+
}
1012+
}
1013+
}
1014+
}
1015+
9831016
Ok(TraitBoundModifiers { constness, asyncness, polarity })
9841017
}
9851018

9861019
/// Parses a type bound according to:
9871020
/// ```ebnf
9881021
/// TY_BOUND = TY_BOUND_NOPAREN | (TY_BOUND_NOPAREN)
989-
/// TY_BOUND_NOPAREN = [TRAIT_BOUND_MODIFIERS] [for<LT_PARAM_DEFS>] SIMPLE_PATH
1022+
/// TY_BOUND_NOPAREN = [for<GENERIC_PARAMS> CONSTNESS ASYNCNESS | POLARITY] SIMPLE_PATH
9901023
/// ```
9911024
///
9921025
/// For example, this grammar accepts `for<'a: 'b> ~const ?m::Trait<'a>`.
@@ -996,16 +1029,37 @@ impl<'a> Parser<'a> {
9961029
has_parens: bool,
9971030
leading_token: &Token,
9981031
) -> PResult<'a, GenericBound> {
999-
let modifiers = self.parse_trait_bound_modifiers()?;
10001032
let (mut lifetime_defs, binder_span) = self.parse_late_bound_lifetime_defs()?;
10011033

1034+
let modifiers_lo = self.token.span;
1035+
let modifiers = self.parse_trait_bound_modifiers()?;
1036+
let modifiers_span = modifiers_lo.to(self.prev_token.span);
1037+
1038+
if let Some(binder_span) = binder_span {
1039+
match modifiers.polarity {
1040+
BoundPolarity::Negative(polarity_span) | BoundPolarity::Maybe(polarity_span) => {
1041+
self.dcx().emit_err(errors::BinderAndPolarity {
1042+
binder_span,
1043+
polarity_span,
1044+
polarity: modifiers.polarity.as_str(),
1045+
});
1046+
}
1047+
BoundPolarity::Positive => {}
1048+
}
1049+
}
1050+
10021051
// Recover erroneous lifetime bound with modifiers or binder.
10031052
// e.g. `T: for<'a> 'a` or `T: ~const 'a`.
10041053
if self.token.is_lifetime() {
10051054
let _: ErrorGuaranteed = self.error_lt_bound_with_modifiers(modifiers, binder_span);
10061055
return self.parse_generic_lt_bound(lo, has_parens);
10071056
}
10081057

1058+
if let (more_lifetime_defs, Some(binder_span)) = self.parse_late_bound_lifetime_defs()? {
1059+
lifetime_defs.extend(more_lifetime_defs);
1060+
self.dcx().emit_err(errors::BinderBeforeModifiers { binder_span, modifiers_span });
1061+
}
1062+
10091063
let mut path = if self.token.is_keyword(kw::Fn)
10101064
&& self.look_ahead(1, |tok| tok.kind == TokenKind::OpenDelim(Delimiter::Parenthesis))
10111065
&& let Some(path) = self.recover_path_from_fn()

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);

compiler/rustc_resolve/src/diagnostics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2012,7 +2012,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
20122012
)
20132013
} else if ident.name == sym::core {
20142014
(
2015-
format!("maybe a missing crate `{ident}`?"),
2015+
format!("you might be missing crate `{ident}`"),
20162016
Some((
20172017
vec![(ident.span, "std".to_string())],
20182018
"try using `std` instead of `core`".to_string(),
@@ -2021,7 +2021,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
20212021
)
20222022
} else if self.tcx.sess.is_rust_2015() {
20232023
(
2024-
format!("maybe a missing crate `{ident}`?"),
2024+
format!("you might be missing crate `{ident}`"),
20252025
Some((
20262026
vec![],
20272027
format!(

0 commit comments

Comments
 (0)