Skip to content

Commit 65d053a

Browse files
committed
Auto merge of #79927 - tmandry:rollup-pwn4b1v, r=tmandry
Rollup of 11 pull requests Successful merges: - #77027 (Improve documentation for `std::{f32,f64}::mul_add`) - #79375 (Make the kernel_copy tests more robust/concurrent.) - #79639 (Add long explanation for E0212) - #79698 (Add tracking issue template for library features.) - #79809 (Dogfood `str_split_once()`) - #79851 (Clarify the 'default is only allowed on...' error) - #79858 (Update const-fn doc in unstable-book) - #79860 (Clarify that String::split_at takes a byte index.) - #79871 (Fix small typo in `wrapping_shl` documentation) - #79896 (Make search results tab and help button focusable with keyboard) - #79917 (Use Symbol for inline asm register class names) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0c9ef56 + 0327b5d commit 65d053a

Some content is hidden

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

51 files changed

+421
-307
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
name: Library Tracking Issue
3+
about: A tracking issue for an unstable library feature.
4+
title: Tracking Issue for XXX
5+
labels: C-tracking-issue T-libs
6+
---
7+
<!--
8+
Thank you for creating a tracking issue!
9+
10+
Tracking issues are for tracking a feature from implementation to stabilization.
11+
12+
Make sure to include the relevant RFC for the feature if it has one.
13+
14+
If the new feature is small, it may be fine to skip the RFC process. In that
15+
case, you can use use `issue = "none"` in your initial implementation PR. The
16+
reviewer will ask you to open a tracking issue if they agree your feature can be
17+
added without an RFC.
18+
-->
19+
20+
Feature gate: `#![feature(...)]`
21+
22+
This is a tracking issue for ...
23+
24+
<!--
25+
Include a short description of the feature.
26+
-->
27+
28+
### Public API
29+
30+
<!--
31+
For most library features, it'd be useful to include a summarized version of the public API.
32+
(E.g. just the public function signatures without their doc comments or implementation.)
33+
-->
34+
35+
```rust
36+
...
37+
```
38+
39+
### Steps / History
40+
41+
<!--
42+
In the simplest case, this is a PR implementing the feature followed by a PR
43+
that stabilises the feature. However it's not uncommon for the feature to be
44+
changed before stabilization. For larger features, the implementation could be
45+
split up in multiple steps.
46+
-->
47+
48+
- [ ] Implementation: ...
49+
- [ ] Stabilization PR
50+
51+
### Unresolved Questions
52+
53+
<!--
54+
Include any open questions that need to be answered before the feature can be
55+
stabilised. If multiple (unrelated) big questions come up, it can be a good idea
56+
to open a separate issue for each, to make it easier to keep track of the
57+
discussions.
58+
59+
It's useful to link any relevant discussions and conclusions (whether on GitHub,
60+
Zulip, or the internals forum) here.
61+
-->
62+
63+
- None yet.

compiler/rustc_ast_passes/src/ast_validation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ impl<'a> AstValidator<'a> {
400400
if let Defaultness::Default(def_span) = defaultness {
401401
let span = self.session.source_map().guess_head_span(span);
402402
self.err_handler()
403-
.struct_span_err(span, "`default` is only allowed on items in `impl` definitions")
403+
.struct_span_err(span, "`default` is only allowed on items in trait impls")
404404
.span_label(def_span, "`default` because of this")
405405
.emit();
406406
}

compiler/rustc_error_codes/src/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ E0206: include_str!("./error_codes/E0206.md"),
111111
E0207: include_str!("./error_codes/E0207.md"),
112112
E0210: include_str!("./error_codes/E0210.md"),
113113
E0211: include_str!("./error_codes/E0211.md"),
114+
E0212: include_str!("./error_codes/E0212.md"),
114115
E0214: include_str!("./error_codes/E0214.md"),
115116
E0220: include_str!("./error_codes/E0220.md"),
116117
E0221: include_str!("./error_codes/E0221.md"),
@@ -503,7 +504,6 @@ E0779: include_str!("./error_codes/E0779.md"),
503504
// E0196, // cannot determine a type for this closure
504505
E0208,
505506
// E0209, // builtin traits can only be implemented on structs or enums
506-
E0212, // cannot extract an associated type from a higher-ranked trait bound
507507
// E0213, // associated types are not accepted in this context
508508
// E0215, // angle-bracket notation is not stable with `Fn`
509509
// E0216, // parenthetical notation is only stable with `Fn`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Cannot use the associated type of
2+
a trait with uninferred generic parameters.
3+
4+
Erroneous code example:
5+
6+
```compile_fail,E0212
7+
pub trait Foo<T> {
8+
type A;
9+
10+
fn get(&self, t: T) -> Self::A;
11+
}
12+
13+
fn foo2<I : for<'x> Foo<&'x isize>>(
14+
field: I::A) {} // error!
15+
```
16+
17+
In this example, we have to instantiate `'x`, and
18+
we don't know what lifetime to instantiate it with.
19+
To fix this, spell out the precise lifetimes involved.
20+
Example:
21+
22+
```
23+
pub trait Foo<T> {
24+
type A;
25+
26+
fn get(&self, t: T) -> Self::A;
27+
}
28+
29+
fn foo3<I : for<'x> Foo<&'x isize>>(
30+
x: <I as Foo<&isize>>::A) {} // ok!
31+
32+
33+
fn foo4<'a, I : for<'x> Foo<&'x isize>>(
34+
x: <I as Foo<&'a isize>>::A) {} // ok!
35+
```

compiler/rustc_mir/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Rust MIR: a lowered representation of Rust.
2828
#![feature(or_patterns)]
2929
#![feature(once_cell)]
3030
#![feature(control_flow_enum)]
31+
#![feature(str_split_once)]
3132
#![recursion_limit = "256"]
3233

3334
#[macro_use]

compiler/rustc_mir/src/transform/coverage/debug.rs

+34-28
Original file line numberDiff line numberDiff line change
@@ -148,40 +148,46 @@ impl DebugOptions {
148148

149149
if let Ok(env_debug_options) = std::env::var(RUSTC_COVERAGE_DEBUG_OPTIONS) {
150150
for setting_str in env_debug_options.replace(" ", "").replace("-", "_").split(',') {
151-
let mut setting = setting_str.splitn(2, '=');
152-
match setting.next() {
153-
Some(option) if option == "allow_unused_expressions" => {
154-
allow_unused_expressions = bool_option_val(option, setting.next());
151+
let (option, value) = match setting_str.split_once('=') {
152+
None => (setting_str, None),
153+
Some((k, v)) => (k, Some(v)),
154+
};
155+
match option {
156+
"allow_unused_expressions" => {
157+
allow_unused_expressions = bool_option_val(option, value);
155158
debug!(
156159
"{} env option `allow_unused_expressions` is set to {}",
157160
RUSTC_COVERAGE_DEBUG_OPTIONS, allow_unused_expressions
158161
);
159162
}
160-
Some(option) if option == "counter_format" => {
161-
if let Some(strval) = setting.next() {
162-
counter_format = counter_format_option_val(strval);
163-
debug!(
164-
"{} env option `counter_format` is set to {:?}",
165-
RUSTC_COVERAGE_DEBUG_OPTIONS, counter_format
166-
);
167-
} else {
168-
bug!(
169-
"`{}` option in environment variable {} requires one or more \
170-
plus-separated choices (a non-empty subset of \
171-
`id+block+operation`)",
172-
option,
173-
RUSTC_COVERAGE_DEBUG_OPTIONS
174-
);
175-
}
163+
"counter_format" => {
164+
match value {
165+
None => {
166+
bug!(
167+
"`{}` option in environment variable {} requires one or more \
168+
plus-separated choices (a non-empty subset of \
169+
`id+block+operation`)",
170+
option,
171+
RUSTC_COVERAGE_DEBUG_OPTIONS
172+
);
173+
}
174+
Some(val) => {
175+
counter_format = counter_format_option_val(val);
176+
debug!(
177+
"{} env option `counter_format` is set to {:?}",
178+
RUSTC_COVERAGE_DEBUG_OPTIONS, counter_format
179+
);
180+
}
181+
};
176182
}
177-
Some("") => {}
178-
Some(invalid) => bug!(
179-
"Unsupported setting `{}` in environment variable {}",
180-
invalid,
181-
RUSTC_COVERAGE_DEBUG_OPTIONS
182-
),
183-
None => {}
184-
}
183+
_ => {
184+
bug!(
185+
"Unsupported setting `{}` in environment variable {}",
186+
option,
187+
RUSTC_COVERAGE_DEBUG_OPTIONS
188+
)
189+
}
190+
};
185191
}
186192
}
187193

compiler/rustc_session/src/config.rs

+50-59
Original file line numberDiff line numberDiff line change
@@ -1296,8 +1296,10 @@ fn parse_output_types(
12961296
if !debugging_opts.parse_only {
12971297
for list in matches.opt_strs("emit") {
12981298
for output_type in list.split(',') {
1299-
let mut parts = output_type.splitn(2, '=');
1300-
let shorthand = parts.next().unwrap();
1299+
let (shorthand, path) = match output_type.split_once('=') {
1300+
None => (output_type, None),
1301+
Some((shorthand, path)) => (shorthand, Some(PathBuf::from(path))),
1302+
};
13011303
let output_type = OutputType::from_shorthand(shorthand).unwrap_or_else(|| {
13021304
early_error(
13031305
error_format,
@@ -1308,7 +1310,6 @@ fn parse_output_types(
13081310
),
13091311
)
13101312
});
1311-
let path = parts.next().map(PathBuf::from);
13121313
output_types.insert(output_type, path);
13131314
}
13141315
}
@@ -1452,11 +1453,10 @@ fn parse_opt_level(
14521453
let max_c = matches
14531454
.opt_strs_pos("C")
14541455
.into_iter()
1455-
.flat_map(
1456-
|(i, s)| {
1457-
if let Some("opt-level") = s.splitn(2, '=').next() { Some(i) } else { None }
1458-
},
1459-
)
1456+
.flat_map(|(i, s)| {
1457+
// NB: This can match a string without `=`.
1458+
if let Some("opt-level") = s.splitn(2, '=').next() { Some(i) } else { None }
1459+
})
14601460
.max();
14611461
if max_o > max_c {
14621462
OptLevel::Default
@@ -1491,11 +1491,10 @@ fn select_debuginfo(
14911491
let max_c = matches
14921492
.opt_strs_pos("C")
14931493
.into_iter()
1494-
.flat_map(
1495-
|(i, s)| {
1496-
if let Some("debuginfo") = s.splitn(2, '=').next() { Some(i) } else { None }
1497-
},
1498-
)
1494+
.flat_map(|(i, s)| {
1495+
// NB: This can match a string without `=`.
1496+
if let Some("debuginfo") = s.splitn(2, '=').next() { Some(i) } else { None }
1497+
})
14991498
.max();
15001499
if max_g > max_c {
15011500
DebugInfo::Full
@@ -1528,23 +1527,26 @@ fn parse_libs(
15281527
.map(|s| {
15291528
// Parse string of the form "[KIND=]lib[:new_name]",
15301529
// where KIND is one of "dylib", "framework", "static".
1531-
let mut parts = s.splitn(2, '=');
1532-
let kind = parts.next().unwrap();
1533-
let (name, kind) = match (parts.next(), kind) {
1534-
(None, name) => (name, NativeLibKind::Unspecified),
1535-
(Some(name), "dylib") => (name, NativeLibKind::Dylib),
1536-
(Some(name), "framework") => (name, NativeLibKind::Framework),
1537-
(Some(name), "static") => (name, NativeLibKind::StaticBundle),
1538-
(Some(name), "static-nobundle") => (name, NativeLibKind::StaticNoBundle),
1539-
(_, s) => {
1540-
early_error(
1541-
error_format,
1542-
&format!(
1543-
"unknown library kind `{}`, expected \
1544-
one of dylib, framework, or static",
1545-
s
1546-
),
1547-
);
1530+
let (name, kind) = match s.split_once('=') {
1531+
None => (s, NativeLibKind::Unspecified),
1532+
Some((kind, name)) => {
1533+
let kind = match kind {
1534+
"dylib" => NativeLibKind::Dylib,
1535+
"framework" => NativeLibKind::Framework,
1536+
"static" => NativeLibKind::StaticBundle,
1537+
"static-nobundle" => NativeLibKind::StaticNoBundle,
1538+
s => {
1539+
early_error(
1540+
error_format,
1541+
&format!(
1542+
"unknown library kind `{}`, expected \
1543+
one of dylib, framework, or static",
1544+
s
1545+
),
1546+
);
1547+
}
1548+
};
1549+
(name.to_string(), kind)
15481550
}
15491551
};
15501552
if kind == NativeLibKind::StaticNoBundle
@@ -1556,10 +1558,11 @@ fn parse_libs(
15561558
accepted on the nightly compiler",
15571559
);
15581560
}
1559-
let mut name_parts = name.splitn(2, ':');
1560-
let name = name_parts.next().unwrap();
1561-
let new_name = name_parts.next();
1562-
(name.to_owned(), new_name.map(|n| n.to_owned()), kind)
1561+
let (name, new_name) = match name.split_once(':') {
1562+
None => (name, None),
1563+
Some((name, new_name)) => (name.to_string(), Some(new_name.to_owned())),
1564+
};
1565+
(name, new_name, kind)
15631566
})
15641567
.collect()
15651568
}
@@ -1580,20 +1583,13 @@ pub fn parse_externs(
15801583
let is_unstable_enabled = debugging_opts.unstable_options;
15811584
let mut externs: BTreeMap<String, ExternEntry> = BTreeMap::new();
15821585
for arg in matches.opt_strs("extern") {
1583-
let mut parts = arg.splitn(2, '=');
1584-
let name = parts
1585-
.next()
1586-
.unwrap_or_else(|| early_error(error_format, "--extern value must not be empty"));
1587-
let path = parts.next().map(|s| s.to_string());
1588-
1589-
let mut name_parts = name.splitn(2, ':');
1590-
let first_part = name_parts.next();
1591-
let second_part = name_parts.next();
1592-
let (options, name) = match (first_part, second_part) {
1593-
(Some(opts), Some(name)) => (Some(opts), name),
1594-
(Some(name), None) => (None, name),
1595-
(None, None) => early_error(error_format, "--extern name must not be empty"),
1596-
_ => unreachable!(),
1586+
let (name, path) = match arg.split_once('=') {
1587+
None => (arg, None),
1588+
Some((name, path)) => (name.to_string(), Some(path.to_string())),
1589+
};
1590+
let (options, name) = match name.split_once(':') {
1591+
None => (None, name),
1592+
Some((opts, name)) => (Some(opts), name.to_string()),
15971593
};
15981594

15991595
let entry = externs.entry(name.to_owned());
@@ -1682,17 +1678,12 @@ fn parse_remap_path_prefix(
16821678
matches
16831679
.opt_strs("remap-path-prefix")
16841680
.into_iter()
1685-
.map(|remap| {
1686-
let mut parts = remap.rsplitn(2, '='); // reverse iterator
1687-
let to = parts.next();
1688-
let from = parts.next();
1689-
match (from, to) {
1690-
(Some(from), Some(to)) => (PathBuf::from(from), PathBuf::from(to)),
1691-
_ => early_error(
1692-
error_format,
1693-
"--remap-path-prefix must contain '=' between FROM and TO",
1694-
),
1695-
}
1681+
.map(|remap| match remap.rsplit_once('=') {
1682+
None => early_error(
1683+
error_format,
1684+
"--remap-path-prefix must contain '=' between FROM and TO",
1685+
),
1686+
Some((from, to)) => (PathBuf::from(from), PathBuf::from(to)),
16961687
})
16971688
.collect()
16981689
}

compiler/rustc_session/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![feature(crate_visibility_modifier)]
22
#![feature(once_cell)]
33
#![feature(or_patterns)]
4+
#![feature(str_split_once)]
45

56
#[macro_use]
67
extern crate bitflags;

compiler/rustc_session/src/options.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,10 @@ macro_rules! options {
179179
{
180180
let mut op = $defaultfn();
181181
for option in matches.opt_strs($prefix) {
182-
let mut iter = option.splitn(2, '=');
183-
let key = iter.next().unwrap();
184-
let value = iter.next();
182+
let (key, value) = match option.split_once('=') {
183+
None => (option, None),
184+
Some((k, v)) => (k.to_string(), Some(v)),
185+
};
185186
let option_to_lookup = key.replace("-", "_");
186187
let mut found = false;
187188
for &(candidate, setter, type_desc, _) in $stat {

0 commit comments

Comments
 (0)