Skip to content

Commit 276b75a

Browse files
committed
Auto merge of rust-lang#108732 - Dylan-DPC:rollup-dy1l8sx, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - rust-lang#108298 (Fix ICE: check if snippet is `)`) - rust-lang#108405 (Lazily compute crate name for consider_optimizing) - rust-lang#108656 (Rustdoc search: Emit an error for unclosed generic) - rust-lang#108660 (Remove ne implementations from strings) - rust-lang#108669 (Allow checking whether a type allows being uninitialized) - rust-lang#108727 (rustc_expand: make proc-macro derive error translatable) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 01b7a6a + 0965c7e commit 276b75a

File tree

15 files changed

+73
-19
lines changed

15 files changed

+73
-19
lines changed

compiler/rustc_const_eval/src/interpret/intrinsics.rs

+1
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
444444
"aborted execution: attempted to leave type `{}` uninitialized, which is invalid",
445445
ty
446446
),
447+
ValidityRequirement::Uninit => bug!("assert_uninit_valid doesn't exist"),
447448
};
448449

449450
M::abort(self, msg)?;

compiler/rustc_const_eval/src/util/check_validity_requirement.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub fn check_validity_requirement<'tcx>(
3030
return Ok(!layout.abi.is_uninhabited());
3131
}
3232

33-
if tcx.sess.opts.unstable_opts.strict_init_checks {
33+
if kind == ValidityRequirement::Uninit || tcx.sess.opts.unstable_opts.strict_init_checks {
3434
might_permit_raw_init_strict(layout, tcx, kind)
3535
} else {
3636
let layout_cx = LayoutCx { tcx, param_env: param_env_and_ty.param_env };
@@ -99,6 +99,9 @@ fn might_permit_raw_init_lax<'tcx>(
9999
}
100100
s.valid_range(cx).contains(val)
101101
}
102+
ValidityRequirement::Uninit => {
103+
bug!("ValidityRequirement::Uninit should have been handled above")
104+
}
102105
}
103106
};
104107

compiler/rustc_expand/locales/en-US.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,6 @@ expand_trace_macro = trace_macro
133133
expand_proc_macro_panicked =
134134
proc macro panicked
135135
.help = message: {$message}
136+
137+
expand_proc_macro_derive_tokens =
138+
proc-macro derive produced unparseable tokens

compiler/rustc_expand/src/errors.rs

+7
Original file line numberDiff line numberDiff line change
@@ -390,3 +390,10 @@ pub(crate) struct ProcMacroPanicked {
390390
pub(crate) struct ProcMacroPanickedHelp {
391391
pub message: String,
392392
}
393+
394+
#[derive(Diagnostic)]
395+
#[diag(expand_proc_macro_derive_tokens)]
396+
pub struct ProcMacroDeriveTokens {
397+
#[primary_span]
398+
pub span: Span,
399+
}

compiler/rustc_expand/src/proc_macro.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl MultiItemModifier for DeriveProcMacro {
176176

177177
// fail if there have been errors emitted
178178
if ecx.sess.parse_sess.span_diagnostic.err_count() > error_count_before {
179-
ecx.struct_span_err(span, "proc-macro derive produced unparseable tokens").emit();
179+
ecx.sess.emit_err(errors::ProcMacroDeriveTokens { span });
180180
}
181181

182182
ExpandResult::Ready(items)

compiler/rustc_middle/src/ty/context.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -794,8 +794,7 @@ impl<'tcx> TyCtxt<'tcx> {
794794
}
795795

796796
pub fn consider_optimizing<T: Fn() -> String>(self, msg: T) -> bool {
797-
let cname = self.crate_name(LOCAL_CRATE);
798-
self.sess.consider_optimizing(cname.as_str(), msg)
797+
self.sess.consider_optimizing(|| self.crate_name(LOCAL_CRATE), msg)
799798
}
800799

801800
/// Obtain all lang items of this crate and all dependencies (recursively)

compiler/rustc_middle/src/ty/layout.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,17 @@ pub const FAT_PTR_EXTRA: usize = 1;
170170
/// * Cranelift stores the base-2 log of the lane count in a 4 bit integer.
171171
pub const MAX_SIMD_LANES: u64 = 1 << 0xF;
172172

173-
/// Used in `might_permit_raw_init` to indicate the kind of initialisation
173+
/// Used in `check_validity_requirement` to indicate the kind of initialization
174174
/// that is checked to be valid
175175
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable)]
176176
pub enum ValidityRequirement {
177177
Inhabited,
178178
Zero,
179+
/// The return value of mem::uninitialized, 0x01
180+
/// (unless -Zstrict-init-checks is on, in which case it's the same as Uninit).
179181
UninitMitigated0x01Fill,
182+
/// True uninitialized memory.
183+
Uninit,
180184
}
181185

182186
impl ValidityRequirement {
@@ -196,6 +200,7 @@ impl fmt::Display for ValidityRequirement {
196200
Self::Inhabited => f.write_str("is inhabited"),
197201
Self::Zero => f.write_str("allows being left zeroed"),
198202
Self::UninitMitigated0x01Fill => f.write_str("allows being filled with 0x01"),
203+
Self::Uninit => f.write_str("allows being left uninitialized"),
199204
}
200205
}
201206
}

compiler/rustc_parse/src/parser/expr.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1210,8 +1210,13 @@ impl<'a> Parser<'a> {
12101210
// `Enum::Foo { a: 3, b: 4 }` or `Enum::Foo(3, 4)`.
12111211
self.restore_snapshot(snapshot);
12121212
let close_paren = self.prev_token.span;
1213-
let span = lo.to(self.prev_token.span);
1214-
if !fields.is_empty() {
1213+
let span = lo.to(close_paren);
1214+
if !fields.is_empty() &&
1215+
// `token.kind` should not be compared here.
1216+
// This is because the `snapshot.token.kind` is treated as the same as
1217+
// that of the open delim in `TokenTreesReader::parse_token_tree`, even if they are different.
1218+
self.span_to_snippet(close_paren).map_or(false, |snippet| snippet == ")")
1219+
{
12151220
let mut replacement_err = errors::ParenthesesWithStructFields {
12161221
span,
12171222
r#type: path,

compiler/rustc_session/src/session.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -882,10 +882,14 @@ impl Session {
882882

883883
/// We want to know if we're allowed to do an optimization for crate foo from -z fuel=foo=n.
884884
/// This expends fuel if applicable, and records fuel if applicable.
885-
pub fn consider_optimizing<T: Fn() -> String>(&self, crate_name: &str, msg: T) -> bool {
885+
pub fn consider_optimizing(
886+
&self,
887+
get_crate_name: impl Fn() -> Symbol,
888+
msg: impl Fn() -> String,
889+
) -> bool {
886890
let mut ret = true;
887891
if let Some((ref c, _)) = self.opts.unstable_opts.fuel {
888-
if c == crate_name {
892+
if c == get_crate_name().as_str() {
889893
assert_eq!(self.threads(), 1);
890894
let mut fuel = self.optimization_fuel.lock();
891895
ret = fuel.remaining != 0;
@@ -903,7 +907,7 @@ impl Session {
903907
}
904908
}
905909
if let Some(ref c) = self.opts.unstable_opts.print_fuel {
906-
if c == crate_name {
910+
if c == get_crate_name().as_str() {
907911
assert_eq!(self.threads(), 1);
908912
self.print_fuel.fetch_add(1, SeqCst);
909913
}

library/alloc/src/string.rs

-4
Original file line numberDiff line numberDiff line change
@@ -2213,10 +2213,6 @@ impl PartialEq for String {
22132213
fn eq(&self, other: &String) -> bool {
22142214
PartialEq::eq(&self[..], &other[..])
22152215
}
2216-
#[inline]
2217-
fn ne(&self, other: &String) -> bool {
2218-
PartialEq::ne(&self[..], &other[..])
2219-
}
22202216
}
22212217

22222218
macro_rules! impl_eq {

library/core/src/str/traits.rs

-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ impl PartialEq for str {
2828
fn eq(&self, other: &str) -> bool {
2929
self.as_bytes() == other.as_bytes()
3030
}
31-
#[inline]
32-
fn ne(&self, other: &str) -> bool {
33-
!(*self).eq(other)
34-
}
3531
}
3632

3733
#[stable(feature = "rust1", since = "1.0.0")]

src/librustdoc/html/static/js/search.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,15 @@ function initSearch(rawSearchIndex) {
469469
}
470470
const posBefore = parserState.pos;
471471
getNextElem(query, parserState, elems, endChar === ">");
472+
if (endChar !== "") {
473+
if (parserState.pos >= parserState.length) {
474+
throw ["Unclosed ", "<"];
475+
}
476+
const c2 = parserState.userQuery[parserState.pos];
477+
if (!isSeparatorCharacter(c2) && c2 !== endChar) {
478+
throw ["Expected ", endChar, ", found ", c2];
479+
}
480+
}
472481
// This case can be encountered if `getNextElem` encountered a "stop character" right
473482
// from the start. For example if you have `,,` or `<>`. In this case, we simply move up
474483
// the current position to continue the parsing.
@@ -477,7 +486,10 @@ function initSearch(rawSearchIndex) {
477486
}
478487
foundStopChar = false;
479488
}
480-
// We are either at the end of the string or on the `endChar`` character, let's move forward
489+
if (parserState.pos >= parserState.length && endChar !== "") {
490+
throw ["Unclosed ", "<"];
491+
}
492+
// We are either at the end of the string or on the `endChar` character, let's move forward
481493
// in any case.
482494
parserState.pos += 1;
483495
}

tests/rustdoc-js-std/parser-errors.js

+10
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const QUERY = [
3939
"a!!",
4040
"mod:a!",
4141
"a!::a",
42+
"a<",
4243
];
4344

4445
const PARSED = [
@@ -402,4 +403,13 @@ const PARSED = [
402403
userQuery: "a!::a",
403404
error: 'Cannot have associated items in macros',
404405
},
406+
{
407+
elems: [],
408+
foundElems: 0,
409+
original: "a<",
410+
returned: [],
411+
typeFilter: -1,
412+
userQuery: "a<",
413+
error: "Unclosed `<`",
414+
},
405415
];

tests/ui/parser/issue-107705.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// compile-flags: -C debug-assertions
2+
3+
fn f() {a(b:&, //~ ERROR this file contains an unclosed delimiter

tests/ui/parser/issue-107705.stderr

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: this file contains an unclosed delimiter
2+
--> $DIR/issue-107705.rs:3:67
3+
|
4+
LL | fn f() {a(b:&,
5+
| - - unclosed delimiter ^
6+
| |
7+
| unclosed delimiter
8+
9+
error: aborting due to previous error
10+

0 commit comments

Comments
 (0)