Skip to content

Commit d9b3ff7

Browse files
committed
Auto merge of #96117 - Dylan-DPC:rollup-5traczf, r=Dylan-DPC
Rollup of 7 pull requests Successful merges: - #95887 (resolve: Create dummy bindings for all unresolved imports) - #96023 (couple of clippy::perf fixes) - #96035 (Update GitHub Actions actions/checkout Version v2 -> v3) - #96038 (docs: add link from zip to unzip) - #96047 (:arrow_up: rust-analyzer) - #96059 (clarify doc(cfg) wording) - #96081 (Make some `usize`-typed masks definitions agnostic to the size of `usize`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents febce1f + 4ed7627 commit d9b3ff7

File tree

28 files changed

+137
-126
lines changed

28 files changed

+137
-126
lines changed

Diff for: .github/workflows/ci.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
- name: disable git crlf conversion
5757
run: git config --global core.autocrlf false
5858
- name: checkout the source code
59-
uses: actions/checkout@v2
59+
uses: actions/checkout@v3
6060
with:
6161
fetch-depth: 2
6262
- name: configure the PR in which the error message will be posted
@@ -454,7 +454,7 @@ jobs:
454454
- name: disable git crlf conversion
455455
run: git config --global core.autocrlf false
456456
- name: checkout the source code
457-
uses: actions/checkout@v2
457+
uses: actions/checkout@v3
458458
with:
459459
fetch-depth: 2
460460
- name: configure the PR in which the error message will be posted
@@ -567,7 +567,7 @@ jobs:
567567
- name: disable git crlf conversion
568568
run: git config --global core.autocrlf false
569569
- name: checkout the source code
570-
uses: actions/checkout@v2
570+
uses: actions/checkout@v3
571571
with:
572572
fetch-depth: 2
573573
- name: configure the PR in which the error message will be posted
@@ -670,7 +670,7 @@ jobs:
670670
if: "github.event_name == 'push' && github.ref == 'refs/heads/master' && github.repository == 'rust-lang-ci/rust'"
671671
steps:
672672
- name: checkout the source code
673-
uses: actions/checkout@v2
673+
uses: actions/checkout@v3
674674
with:
675675
fetch-depth: 2
676676
- name: publish toolstate

Diff for: compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs

-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,6 @@ fn build_union_fields_for_direct_tag_generator<'ll, 'tcx>(
372372

373373
// Build the type node for each field.
374374
let variant_field_infos: SmallVec<VariantFieldInfo<'ll>> = variant_range
375-
.clone()
376375
.map(|variant_index| {
377376
let variant_struct_type_di_node = super::build_generator_variant_struct_type_di_node(
378377
cx,

Diff for: compiler/rustc_errors/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@ impl HandlerInner {
12081208
(0, 0) => return,
12091209
(0, _) => self.emitter.emit_diagnostic(&Diagnostic::new(
12101210
Level::Warning,
1211-
DiagnosticMessage::Str(warnings.to_owned()),
1211+
DiagnosticMessage::Str(warnings),
12121212
)),
12131213
(_, 0) => {
12141214
let _ = self.fatal(&errors);

Diff for: compiler/rustc_expand/src/mbe/macro_parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ impl TtParser {
590590
(_, 0) => {
591591
// Dump all possible `next_mps` into `cur_mps` for the next iteration. Then
592592
// process the next token.
593-
self.cur_mps.extend(self.next_mps.drain(..));
593+
self.cur_mps.append(&mut self.next_mps);
594594
parser.to_mut().bump();
595595
}
596596

Diff for: compiler/rustc_mir_build/src/thir/pattern/check_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ fn non_exhaustive_match<'p, 'tcx>(
844844
format!(
845845
"{}{}{} => todo!()",
846846
comma,
847-
snippet.strip_prefix(",").unwrap_or(&snippet),
847+
snippet.strip_prefix(',').unwrap_or(&snippet),
848848
pattern
849849
),
850850
));

Diff for: compiler/rustc_resolve/src/imports.rs

+28-30
Original file line numberDiff line numberDiff line change
@@ -310,18 +310,23 @@ impl<'a> Resolver<'a> {
310310
t
311311
}
312312

313-
// Define a "dummy" resolution containing a Res::Err as a placeholder for a
314-
// failed resolution
313+
// Define a dummy resolution containing a `Res::Err` as a placeholder for a failed resolution,
314+
// also mark such failed imports as used to avoid duplicate diagnostics.
315315
fn import_dummy_binding(&mut self, import: &'a Import<'a>) {
316-
if let ImportKind::Single { target, .. } = import.kind {
316+
if let ImportKind::Single { target, ref target_bindings, .. } = import.kind {
317+
if target_bindings.iter().any(|binding| binding.get().is_some()) {
318+
return; // Has resolution, do not create the dummy binding
319+
}
317320
let dummy_binding = self.dummy_binding;
318321
let dummy_binding = self.import(dummy_binding, import);
319322
self.per_ns(|this, ns| {
320323
let key = this.new_key(target, ns);
321324
let _ = this.try_define(import.parent_scope.module, key, dummy_binding);
322325
});
323-
// Consider erroneous imports used to avoid duplicate diagnostics.
324326
self.record_use(target, dummy_binding, false);
327+
} else if import.imported_module.get().is_none() {
328+
import.used.set(true);
329+
self.used_imports.insert(import.id);
325330
}
326331
}
327332
}
@@ -386,7 +391,13 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
386391
.map(|i| (false, i))
387392
.chain(indeterminate_imports.into_iter().map(|i| (true, i)))
388393
{
389-
if let Some(err) = self.finalize_import(import) {
394+
let unresolved_import_error = self.finalize_import(import);
395+
396+
// If this import is unresolved then create a dummy import
397+
// resolution for it so that later resolve stages won't complain.
398+
self.r.import_dummy_binding(import);
399+
400+
if let Some(err) = unresolved_import_error {
390401
if let ImportKind::Single { source, ref source_bindings, .. } = import.kind {
391402
if source.name == kw::SelfLower {
392403
// Silence `unresolved import` error if E0429 is already emitted
@@ -396,9 +407,6 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
396407
}
397408
}
398409

399-
// If the error is a single failed import then create a "fake" import
400-
// resolution for it so that later resolve stages won't complain.
401-
self.r.import_dummy_binding(import);
402410
if prev_root_id.as_u32() != 0
403411
&& prev_root_id.as_u32() != import.root_id.as_u32()
404412
&& !errors.is_empty()
@@ -418,8 +426,6 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
418426
prev_root_id = import.root_id;
419427
}
420428
} else if is_indeterminate {
421-
// Consider erroneous imports used to avoid duplicate diagnostics.
422-
self.r.used_imports.insert(import.id);
423429
let path = import_path_to_string(
424430
&import.module_path.iter().map(|seg| seg.ident).collect::<Vec<_>>(),
425431
&import.kind,
@@ -553,26 +559,23 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
553559
Err(Undetermined) => indeterminate = true,
554560
// Don't update the resolution, because it was never added.
555561
Err(Determined) if target.name == kw::Underscore => {}
556-
Err(Determined) => {
562+
Ok(binding) if binding.is_importable() => {
563+
let imported_binding = this.import(binding, import);
564+
target_bindings[ns].set(Some(imported_binding));
565+
this.define(parent, target, ns, imported_binding);
566+
}
567+
source_binding @ (Ok(..) | Err(Determined)) => {
568+
if source_binding.is_ok() {
569+
let msg = format!("`{}` is not directly importable", target);
570+
struct_span_err!(this.session, import.span, E0253, "{}", &msg)
571+
.span_label(import.span, "cannot be imported directly")
572+
.emit();
573+
}
557574
let key = this.new_key(target, ns);
558575
this.update_resolution(parent, key, |_, resolution| {
559576
resolution.single_imports.remove(&Interned::new_unchecked(import));
560577
});
561578
}
562-
Ok(binding) if !binding.is_importable() => {
563-
let msg = format!("`{}` is not directly importable", target);
564-
struct_span_err!(this.session, import.span, E0253, "{}", &msg)
565-
.span_label(import.span, "cannot be imported directly")
566-
.emit();
567-
// Do not import this illegal binding. Import a dummy binding and pretend
568-
// everything is fine
569-
this.import_dummy_binding(import);
570-
}
571-
Ok(binding) => {
572-
let imported_binding = this.import(binding, import);
573-
target_bindings[ns].set(Some(imported_binding));
574-
this.define(parent, target, ns, imported_binding);
575-
}
576579
}
577580
}
578581
});
@@ -605,10 +608,6 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
605608
);
606609
let no_ambiguity = self.r.ambiguity_errors.len() == prev_ambiguity_errors_len;
607610
import.vis.set(orig_vis);
608-
if let PathResult::Failed { .. } | PathResult::NonModule(..) = path_res {
609-
// Consider erroneous imports used to avoid duplicate diagnostics.
610-
self.r.used_imports.insert(import.id);
611-
}
612611
let module = match path_res {
613612
PathResult::Module(module) => {
614613
// Consistency checks, analogous to `finalize_macro_resolutions`.
@@ -872,7 +871,6 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
872871
})
873872
} else {
874873
// `resolve_ident_in_module` reported a privacy error.
875-
self.r.import_dummy_binding(import);
876874
None
877875
};
878876
}

Diff for: compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2724,9 +2724,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
27242724
&format!(
27252725
"consider annotating `{}` with `#[derive({})]`",
27262726
trait_pred.skip_binder().self_ty(),
2727-
diagnostic_name.to_string(),
2727+
diagnostic_name,
27282728
),
2729-
format!("#[derive({})]\n", diagnostic_name.to_string()),
2729+
format!("#[derive({})]\n", diagnostic_name),
27302730
Applicability::MaybeIncorrect,
27312731
);
27322732
}

Diff for: library/core/benches/ascii/is_ascii.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,6 @@ fn is_ascii_align_to_unrolled(bytes: &[u8]) -> bool {
7777

7878
#[inline]
7979
fn contains_nonascii(v: usize) -> bool {
80-
const NONASCII_MASK: usize = 0x80808080_80808080u64 as usize;
80+
const NONASCII_MASK: usize = usize::from_ne_bytes([0x80; core::mem::size_of::<usize>()]);
8181
(NONASCII_MASK & v) != 0
8282
}

Diff for: library/core/src/iter/traits/iterator.rs

+4
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,10 @@ pub trait Iterator {
470470
/// it will first try to advance the first iterator at most one time and if it still yielded an item
471471
/// try to advance the second iterator at most one time.
472472
///
473+
/// To 'undo' the result of zipping up two iterators, see [`unzip`].
474+
///
475+
/// [`unzip`]: Iterator::unzip
476+
///
473477
/// # Examples
474478
///
475479
/// Basic usage:

Diff for: library/core/src/num/mod.rs

+21
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,27 @@ impl usize {
890890
widening_impl! { usize, u128, 64, unsigned }
891891
}
892892

893+
impl usize {
894+
/// Returns an `usize` where every byte is equal to `x`.
895+
#[inline]
896+
pub(crate) const fn repeat_u8(x: u8) -> usize {
897+
usize::from_ne_bytes([x; mem::size_of::<usize>()])
898+
}
899+
900+
/// Returns an `usize` where every byte pair is equal to `x`.
901+
#[inline]
902+
pub(crate) const fn repeat_u16(x: u16) -> usize {
903+
let mut r = 0usize;
904+
let mut i = 0;
905+
while i < mem::size_of::<usize>() {
906+
// Use `wrapping_shl` to make it work on targets with 16-bit `usize`
907+
r = r.wrapping_shl(16) | (x as usize);
908+
i += 2;
909+
}
910+
r
911+
}
912+
}
913+
893914
/// A classification of floating point numbers.
894915
///
895916
/// This `enum` is used as the return type for [`f32::classify`] and [`f64::classify`]. See

Diff for: library/core/src/slice/ascii.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ impl<'a> fmt::Debug for EscapeAscii<'a> {
235235
/// from `../str/mod.rs`, which does something similar for utf8 validation.
236236
#[inline]
237237
fn contains_nonascii(v: usize) -> bool {
238-
const NONASCII_MASK: usize = 0x80808080_80808080u64 as usize;
238+
const NONASCII_MASK: usize = usize::repeat_u8(0x80);
239239
(NONASCII_MASK & v) != 0
240240
}
241241

Diff for: library/core/src/slice/memchr.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,8 @@
44
use crate::cmp;
55
use crate::mem;
66

7-
const LO_U64: u64 = 0x0101010101010101;
8-
const HI_U64: u64 = 0x8080808080808080;
9-
10-
// Use truncation.
11-
const LO_USIZE: usize = LO_U64 as usize;
12-
const HI_USIZE: usize = HI_U64 as usize;
7+
const LO_USIZE: usize = usize::repeat_u8(0x01);
8+
const HI_USIZE: usize = usize::repeat_u8(0x80);
139
const USIZE_BYTES: usize = mem::size_of::<usize>();
1410

1511
/// Returns `true` if `x` contains any zero byte.

Diff for: library/core/src/str/count.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,16 @@ fn do_count_chars(s: &str) -> usize {
112112
// true)
113113
#[inline]
114114
fn contains_non_continuation_byte(w: usize) -> usize {
115-
const LSB: usize = 0x0101_0101_0101_0101u64 as usize;
115+
const LSB: usize = usize::repeat_u8(0x01);
116116
((!w >> 7) | (w >> 6)) & LSB
117117
}
118118

119119
// Morally equivalent to `values.to_ne_bytes().into_iter().sum::<usize>()`, but
120120
// more efficient.
121121
#[inline]
122122
fn sum_bytes_in_usize(values: usize) -> usize {
123-
const LSB_SHORTS: usize = 0x0001_0001_0001_0001_u64 as usize;
124-
const SKIP_BYTES: usize = 0x00ff_00ff_00ff_00ff_u64 as usize;
123+
const LSB_SHORTS: usize = usize::repeat_u16(0x0001);
124+
const SKIP_BYTES: usize = usize::repeat_u16(0x00ff);
125125

126126
let pair_sum: usize = (values & SKIP_BYTES) + ((values >> 8) & SKIP_BYTES);
127127
pair_sum.wrapping_mul(LSB_SHORTS) >> ((USIZE_SIZE - 2) * 8)

Diff for: library/core/src/str/validations.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ where
112112
Some(ch)
113113
}
114114

115-
// use truncation to fit u64 into usize
116-
const NONASCII_MASK: usize = 0x80808080_80808080u64 as usize;
115+
const NONASCII_MASK: usize = usize::repeat_u8(0x80);
117116

118117
/// Returns `true` if any byte in the word `x` is nonascii (>= 128).
119118
#[inline]

Diff for: src/ci/github-actions/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ x--expand-yaml-anchors--remove:
9999
run: git config --global core.autocrlf false
100100

101101
- name: checkout the source code
102-
uses: actions/checkout@v2
102+
uses: actions/checkout@v3
103103
with:
104104
fetch-depth: 2
105105

@@ -703,7 +703,7 @@ jobs:
703703
if: github.event_name == 'push' && github.ref == 'refs/heads/master' && github.repository == 'rust-lang-ci/rust'
704704
steps:
705705
- name: checkout the source code
706-
uses: actions/checkout@v2
706+
uses: actions/checkout@v3
707707
with:
708708
fetch-depth: 2
709709

Diff for: src/doc/unstable-book/src/language-features/doc-cfg.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ The tracking issue for this feature is: [#43781]
77
The `doc_cfg` feature allows an API be documented as only available in some specific platforms.
88
This attribute has two effects:
99

10-
1. In the annotated item's documentation, there will be a message saying "This is supported on
10+
1. In the annotated item's documentation, there will be a message saying "Available on
1111
(platform) only".
1212

1313
2. The item's doc-tests will only run on the specific platform.

Diff for: src/librustdoc/clean/cfg.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,8 @@ impl Cfg {
171171
pub(crate) fn render_long_html(&self) -> String {
172172
let on = if self.should_use_with_in_description() { "with" } else { "on" };
173173

174-
let mut msg = format!(
175-
"This is supported {} <strong>{}</strong>",
176-
on,
177-
Display(self, Format::LongHtml)
178-
);
174+
let mut msg =
175+
format!("Available {on} <strong>{}</strong>", Display(self, Format::LongHtml));
179176
if self.should_append_only_to_description() {
180177
msg.push_str(" only");
181178
}
@@ -187,7 +184,7 @@ impl Cfg {
187184
pub(crate) fn render_long_plain(&self) -> String {
188185
let on = if self.should_use_with_in_description() { "with" } else { "on" };
189186

190-
let mut msg = format!("This is supported {} {}", on, Display(self, Format::LongPlain));
187+
let mut msg = format!("Available {on} {}", Display(self, Format::LongPlain));
191188
if self.should_append_only_to_description() {
192189
msg.push_str(" only");
193190
}

0 commit comments

Comments
 (0)