Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d32d4b3

Browse files
committedOct 27, 2023
Auto merge of #117294 - matthiaskrgr:rollup-xylsec7, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #116834 (Remove `rustc_symbol_mangling/messages.ftl`.) - #117212 (Properly restore snapshot when failing to recover parsing ternary) - #117246 (Fix ICE: Restrict param constraint suggestion) - #117247 (NVPTX: Allow PassMode::Direct for ptx kernels for now) - #117270 (Hide internal methods from documentation) - #117281 (std::thread : add SAFETY comment) - #117287 (fix miri target information for Test step) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 10143e7 + b9015da commit d32d4b3

File tree

19 files changed

+299
-214
lines changed

19 files changed

+299
-214
lines changed
 

‎Cargo.lock

-2
Original file line numberDiff line numberDiff line change
@@ -4557,9 +4557,7 @@ dependencies = [
45574557
"rustc-demangle",
45584558
"rustc_data_structures",
45594559
"rustc_errors",
4560-
"rustc_fluent_macro",
45614560
"rustc_hir",
4562-
"rustc_macros",
45634561
"rustc_middle",
45644562
"rustc_session",
45654563
"rustc_span",

‎compiler/rustc_codegen_llvm/src/abi.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,14 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
362362
// currently use this mode so we have to allow it -- but we absolutely
363363
// shouldn't let any more targets do that.
364364
// (Also see <https://github.com/rust-lang/rust/issues/115666>.)
365+
//
366+
// The unstable abi `PtxKernel` also uses Direct for now.
367+
// It needs to switch to something else before stabilization can happen.
368+
// (See issue: https://github.com/rust-lang/rust/issues/117271)
365369
assert!(
366-
matches!(&*cx.tcx.sess.target.arch, "wasm32" | "wasm64"),
367-
"`PassMode::Direct` for aggregates only allowed on wasm targets\nProblematic type: {:#?}",
370+
matches!(&*cx.tcx.sess.target.arch, "wasm32" | "wasm64")
371+
|| self.conv == Conv::PtxKernel,
372+
"`PassMode::Direct` for aggregates only allowed on wasm and `extern \"ptx-kernel\"` fns\nProblematic type: {:#?}",
368373
arg.layout,
369374
);
370375
}

‎compiler/rustc_driver_impl/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ pub static DEFAULT_LOCALE_RESOURCES: &[&str] = &[
136136
rustc_query_system::DEFAULT_LOCALE_RESOURCE,
137137
rustc_resolve::DEFAULT_LOCALE_RESOURCE,
138138
rustc_session::DEFAULT_LOCALE_RESOURCE,
139-
rustc_symbol_mangling::DEFAULT_LOCALE_RESOURCE,
140139
rustc_trait_selection::DEFAULT_LOCALE_RESOURCE,
141140
rustc_ty_utils::DEFAULT_LOCALE_RESOURCE,
142141
// tidy-alphabetical-end

‎compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs

+67-46
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,17 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
5454
}
5555
(ty::Param(expected), ty::Param(found)) => {
5656
let generics = tcx.generics_of(body_owner_def_id);
57-
let e_span = tcx.def_span(generics.type_param(expected, tcx).def_id);
58-
if !sp.contains(e_span) {
59-
diag.span_label(e_span, "expected type parameter");
57+
if let Some(param) = generics.opt_type_param(expected, tcx) {
58+
let e_span = tcx.def_span(param.def_id);
59+
if !sp.contains(e_span) {
60+
diag.span_label(e_span, "expected type parameter");
61+
}
6062
}
61-
let f_span = tcx.def_span(generics.type_param(found, tcx).def_id);
62-
if !sp.contains(f_span) {
63-
diag.span_label(f_span, "found type parameter");
63+
if let Some(param) = generics.opt_type_param(found, tcx) {
64+
let f_span = tcx.def_span(param.def_id);
65+
if !sp.contains(f_span) {
66+
diag.span_label(f_span, "found type parameter");
67+
}
6468
}
6569
diag.note(
6670
"a type parameter was expected, but a different one was found; \
@@ -83,23 +87,29 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
8387
| (ty::Alias(ty::Projection, proj), ty::Param(p))
8488
if !tcx.is_impl_trait_in_trait(proj.def_id) =>
8589
{
86-
let p_def_id = tcx.generics_of(body_owner_def_id).type_param(p, tcx).def_id;
87-
let p_span = tcx.def_span(p_def_id);
88-
let expected = match (values.expected.kind(), values.found.kind()) {
89-
(ty::Param(_), _) => "expected ",
90-
(_, ty::Param(_)) => "found ",
91-
_ => "",
92-
};
93-
if !sp.contains(p_span) {
94-
diag.span_label(p_span, format!("{expected}this type parameter"));
95-
}
96-
let hir = tcx.hir();
90+
let parent = tcx.generics_of(body_owner_def_id)
91+
.opt_type_param(p, tcx)
92+
.and_then(|param| {
93+
let p_def_id = param.def_id;
94+
let p_span = tcx.def_span(p_def_id);
95+
let expected = match (values.expected.kind(), values.found.kind()) {
96+
(ty::Param(_), _) => "expected ",
97+
(_, ty::Param(_)) => "found ",
98+
_ => "",
99+
};
100+
if !sp.contains(p_span) {
101+
diag.span_label(
102+
p_span,
103+
format!("{expected}this type parameter"),
104+
);
105+
}
106+
p_def_id.as_local().and_then(|id| {
107+
let local_id = tcx.hir().local_def_id_to_hir_id(id);
108+
let generics = tcx.hir().find_parent(local_id)?.generics()?;
109+
Some((id, generics))
110+
})
111+
});
97112
let mut note = true;
98-
let parent = p_def_id.as_local().and_then(|id| {
99-
let local_id = hir.local_def_id_to_hir_id(id);
100-
let generics = tcx.hir().find_parent(local_id)?.generics()?;
101-
Some((id, generics))
102-
});
103113
if let Some((local_id, generics)) = parent {
104114
// Synthesize the associated type restriction `Add<Output = Expected>`.
105115
// FIXME: extract this logic for use in other diagnostics.
@@ -172,14 +182,16 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
172182
(ty::Param(p), ty::Dynamic(..) | ty::Alias(ty::Opaque, ..))
173183
| (ty::Dynamic(..) | ty::Alias(ty::Opaque, ..), ty::Param(p)) => {
174184
let generics = tcx.generics_of(body_owner_def_id);
175-
let p_span = tcx.def_span(generics.type_param(p, tcx).def_id);
176-
let expected = match (values.expected.kind(), values.found.kind()) {
177-
(ty::Param(_), _) => "expected ",
178-
(_, ty::Param(_)) => "found ",
179-
_ => "",
180-
};
181-
if !sp.contains(p_span) {
182-
diag.span_label(p_span, format!("{expected}this type parameter"));
185+
if let Some(param) = generics.opt_type_param(p, tcx) {
186+
let p_span = tcx.def_span(param.def_id);
187+
let expected = match (values.expected.kind(), values.found.kind()) {
188+
(ty::Param(_), _) => "expected ",
189+
(_, ty::Param(_)) => "found ",
190+
_ => "",
191+
};
192+
if !sp.contains(p_span) {
193+
diag.span_label(p_span, format!("{expected}this type parameter"));
194+
}
183195
}
184196
diag.help("type parameters must be constrained to match other types");
185197
if tcx.sess.teach(&diag.get_code().unwrap()) {
@@ -217,9 +229,11 @@ impl<T> Trait<T> for X {
217229
}
218230
(ty::Param(p), ty::Closure(..) | ty::Coroutine(..)) => {
219231
let generics = tcx.generics_of(body_owner_def_id);
220-
let p_span = tcx.def_span(generics.type_param(p, tcx).def_id);
221-
if !sp.contains(p_span) {
222-
diag.span_label(p_span, "expected this type parameter");
232+
if let Some(param) = generics.opt_type_param(p, tcx) {
233+
let p_span = tcx.def_span(param.def_id);
234+
if !sp.contains(p_span) {
235+
diag.span_label(p_span, "expected this type parameter");
236+
}
223237
}
224238
diag.help(format!(
225239
"every closure has a distinct type and so could not always match the \
@@ -228,14 +242,16 @@ impl<T> Trait<T> for X {
228242
}
229243
(ty::Param(p), _) | (_, ty::Param(p)) => {
230244
let generics = tcx.generics_of(body_owner_def_id);
231-
let p_span = tcx.def_span(generics.type_param(p, tcx).def_id);
232-
let expected = match (values.expected.kind(), values.found.kind()) {
233-
(ty::Param(_), _) => "expected ",
234-
(_, ty::Param(_)) => "found ",
235-
_ => "",
236-
};
237-
if !sp.contains(p_span) {
238-
diag.span_label(p_span, format!("{expected}this type parameter"));
245+
if let Some(param) = generics.opt_type_param(p, tcx) {
246+
let p_span = tcx.def_span(param.def_id);
247+
let expected = match (values.expected.kind(), values.found.kind()) {
248+
(ty::Param(_), _) => "expected ",
249+
(_, ty::Param(_)) => "found ",
250+
_ => "",
251+
};
252+
if !sp.contains(p_span) {
253+
diag.span_label(p_span, format!("{expected}this type parameter"));
254+
}
239255
}
240256
}
241257
(ty::Alias(ty::Projection | ty::Inherent, proj_ty), _)
@@ -364,13 +380,14 @@ impl<T> Trait<T> for X {
364380
};
365381
// Get the `DefId` for the type parameter corresponding to `A` in `<A as T>::Foo`.
366382
// This will also work for `impl Trait`.
367-
let def_id = if let ty::Param(param_ty) = proj_ty.self_ty().kind() {
368-
let generics = tcx.generics_of(body_owner_def_id);
369-
generics.type_param(param_ty, tcx).def_id
370-
} else {
383+
let ty::Param(param_ty) = proj_ty.self_ty().kind() else {
371384
return false;
372385
};
373-
let Some(def_id) = def_id.as_local() else {
386+
let generics = tcx.generics_of(body_owner_def_id);
387+
let Some(param) = generics.opt_type_param(param_ty, tcx) else {
388+
return false;
389+
};
390+
let Some(def_id) = param.def_id.as_local() else {
374391
return false;
375392
};
376393

@@ -390,6 +407,10 @@ impl<T> Trait<T> for X {
390407
return true;
391408
}
392409
}
410+
if (param_ty.index as usize) >= generics.parent_count {
411+
// The param comes from the current item, do not look at the parent. (#117209)
412+
return false;
413+
}
393414
// If associated item, look to constrain the params of the trait/impl.
394415
let hir_id = match item {
395416
hir::Node::ImplItem(item) => item.hir_id(),

‎compiler/rustc_middle/src/ty/generics.rs

+28
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,20 @@ impl<'tcx> Generics {
237237
}
238238
}
239239

240+
/// Returns the `GenericParamDef` with the given index if available.
241+
pub fn opt_param_at(
242+
&'tcx self,
243+
param_index: usize,
244+
tcx: TyCtxt<'tcx>,
245+
) -> Option<&'tcx GenericParamDef> {
246+
if let Some(index) = param_index.checked_sub(self.parent_count) {
247+
self.params.get(index)
248+
} else {
249+
tcx.generics_of(self.parent.expect("parent_count > 0 but no parent?"))
250+
.opt_param_at(param_index, tcx)
251+
}
252+
}
253+
240254
pub fn params_to(&'tcx self, param_index: usize, tcx: TyCtxt<'tcx>) -> &'tcx [GenericParamDef] {
241255
if let Some(index) = param_index.checked_sub(self.parent_count) {
242256
&self.params[..index]
@@ -268,6 +282,20 @@ impl<'tcx> Generics {
268282
}
269283
}
270284

285+
/// Returns the `GenericParamDef` associated with this `ParamTy` if it belongs to this
286+
/// `Generics`.
287+
pub fn opt_type_param(
288+
&'tcx self,
289+
param: &ParamTy,
290+
tcx: TyCtxt<'tcx>,
291+
) -> Option<&'tcx GenericParamDef> {
292+
let param = self.opt_param_at(param.index as usize, tcx)?;
293+
match param.kind {
294+
GenericParamDefKind::Type { .. } => Some(param),
295+
_ => None,
296+
}
297+
}
298+
271299
/// Returns the `GenericParamDef` associated with this `ParamConst`.
272300
pub fn const_param(&'tcx self, param: &ParamConst, tcx: TyCtxt<'tcx>) -> &GenericParamDef {
273301
let param = self.param_at(param.index as usize, tcx);

‎compiler/rustc_parse/src/parser/diagnostics.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,10 @@ impl<'a> Parser<'a> {
504504

505505
// Special-case "expected `;`" errors
506506
if expected.contains(&TokenType::Token(token::Semi)) {
507-
if self.prev_token == token::Question && self.maybe_recover_from_ternary_operator() {
508-
return Ok(true);
507+
// If the user is trying to write a ternary expression, recover it and
508+
// return an Err to prevent a cascade of irrelevant diagnostics
509+
if self.prev_token == token::Question && let Err(e) = self.maybe_recover_from_ternary_operator() {
510+
return Err(e);
509511
}
510512

511513
if self.token.span == DUMMY_SP || self.prev_token.span == DUMMY_SP {
@@ -1428,10 +1430,10 @@ impl<'a> Parser<'a> {
14281430

14291431
/// Rust has no ternary operator (`cond ? then : else`). Parse it and try
14301432
/// to recover from it if `then` and `else` are valid expressions. Returns
1431-
/// whether it was a ternary operator.
1432-
pub(super) fn maybe_recover_from_ternary_operator(&mut self) -> bool {
1433+
/// an err if this appears to be a ternary expression.
1434+
pub(super) fn maybe_recover_from_ternary_operator(&mut self) -> PResult<'a, ()> {
14331435
if self.prev_token != token::Question {
1434-
return false;
1436+
return PResult::Ok(());
14351437
}
14361438

14371439
let lo = self.prev_token.span.lo();
@@ -1449,20 +1451,18 @@ impl<'a> Parser<'a> {
14491451
if self.eat_noexpect(&token::Colon) {
14501452
match self.parse_expr() {
14511453
Ok(_) => {
1452-
self.sess.emit_err(TernaryOperator { span: self.token.span.with_lo(lo) });
1453-
return true;
1454+
return Err(self
1455+
.sess
1456+
.create_err(TernaryOperator { span: self.token.span.with_lo(lo) }));
14541457
}
14551458
Err(err) => {
14561459
err.cancel();
1457-
self.restore_snapshot(snapshot);
14581460
}
14591461
};
14601462
}
1461-
} else {
1462-
self.restore_snapshot(snapshot);
1463-
};
1464-
1465-
false
1463+
}
1464+
self.restore_snapshot(snapshot);
1465+
Ok(())
14661466
}
14671467

14681468
pub(super) fn maybe_recover_from_bad_type_plus(&mut self, ty: &Ty) -> PResult<'a, ()> {

‎compiler/rustc_symbol_mangling/Cargo.toml

-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ twox-hash = "1.6.3"
1515
rustc_span = { path = "../rustc_span" }
1616
rustc_middle = { path = "../rustc_middle" }
1717
rustc_hir = { path = "../rustc_hir" }
18-
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
1918
rustc_target = { path = "../rustc_target" }
2019
rustc_data_structures = { path = "../rustc_data_structures" }
2120
rustc_session = { path = "../rustc_session" }
22-
rustc_macros = { path = "../rustc_macros" }
2321
rustc_errors = { path = "../rustc_errors" }

‎compiler/rustc_symbol_mangling/messages.ftl

-1
This file was deleted.
+26-14
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,46 @@
11
//! Errors emitted by symbol_mangling.
22
3-
use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg};
4-
use rustc_macros::Diagnostic;
3+
use rustc_errors::{ErrorGuaranteed, IntoDiagnostic};
54
use rustc_span::Span;
5+
use std::fmt;
66

7-
#[derive(Diagnostic)]
8-
#[diag(symbol_mangling_test_output)]
97
pub struct TestOutput {
10-
#[primary_span]
118
pub span: Span,
129
pub kind: Kind,
1310
pub content: String,
1411
}
1512

13+
// This diagnostic doesn't need translation because (a) it doesn't contain any
14+
// natural language, and (b) it's only used in tests. So we construct it
15+
// manually and avoid the fluent machinery.
16+
impl IntoDiagnostic<'_> for TestOutput {
17+
fn into_diagnostic(
18+
self,
19+
handler: &'_ rustc_errors::Handler,
20+
) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
21+
let TestOutput { span, kind, content } = self;
22+
23+
#[allow(rustc::untranslatable_diagnostic)]
24+
let mut diag = handler.struct_err(format!("{kind}({content})"));
25+
diag.set_span(span);
26+
diag
27+
}
28+
}
29+
1630
pub enum Kind {
1731
SymbolName,
1832
Demangling,
1933
DemanglingAlt,
2034
DefPath,
2135
}
2236

23-
impl IntoDiagnosticArg for Kind {
24-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
25-
let kind = match self {
26-
Kind::SymbolName => "symbol-name",
27-
Kind::Demangling => "demangling",
28-
Kind::DemanglingAlt => "demangling-alt",
29-
Kind::DefPath => "def-path",
37+
impl fmt::Display for Kind {
38+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39+
match self {
40+
Kind::SymbolName => write!(f, "symbol-name"),
41+
Kind::Demangling => write!(f, "demangling"),
42+
Kind::DemanglingAlt => write!(f, "demangling-alt"),
43+
Kind::DefPath => write!(f, "def-path"),
3044
}
31-
.into();
32-
DiagnosticArgValue::Str(kind)
3345
}
3446
}

‎compiler/rustc_symbol_mangling/src/lib.rs

-4
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ extern crate rustc_middle;
103103
#[macro_use]
104104
extern crate tracing;
105105

106-
use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage};
107-
use rustc_fluent_macro::fluent_messages;
108106
use rustc_hir::def::DefKind;
109107
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
110108
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
@@ -121,8 +119,6 @@ pub mod errors;
121119
pub mod test;
122120
pub mod typeid;
123121

124-
fluent_messages! { "../messages.ftl" }
125-
126122
/// This function computes the symbol name for the given `instance` and the
127123
/// given instantiating crate. That is, if you know that instance X is
128124
/// instantiated in crate Y, this is the symbol name this instance would have.

‎library/std/src/io/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ pub use self::stdio::set_output_capture;
317317
#[stable(feature = "is_terminal", since = "1.70.0")]
318318
pub use self::stdio::IsTerminal;
319319
#[unstable(feature = "print_internals", issue = "none")]
320+
#[doc(hidden)]
320321
pub use self::stdio::{_eprint, _print};
321322
#[stable(feature = "rust1", since = "1.0.0")]
322323
pub use self::{

‎library/std/src/thread/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,8 @@ impl Builder {
546546
}
547547

548548
let main = Box::new(main);
549+
// SAFETY: dynamic size and alignment of the Box remain the same. See below for why the
550+
// lifetime change is justified.
549551
#[cfg(bootstrap)]
550552
let main =
551553
unsafe { mem::transmute::<Box<dyn FnOnce() + 'a>, Box<dyn FnOnce() + 'static>>(main) };

‎src/bootstrap/src/core/build_steps/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ impl Step for Miri {
630630
SourceType::InTree,
631631
&[],
632632
);
633-
let _guard = builder.msg_sysroot_tool(Kind::Test, compiler.stage, "miri", host, host);
633+
let _guard = builder.msg_sysroot_tool(Kind::Test, compiler.stage, "miri", host, target);
634634

635635
cargo.add_rustc_lib_path(builder, compiler);
636636

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use std::collections::HashMap;
2+
use std::hash::Hash;
3+
4+
trait LowT: Identify {}
5+
6+
trait Identify {
7+
type Id: Clone + Hash + PartialEq + Eq;
8+
fn identify(&self) -> Self::Id;
9+
}
10+
11+
struct MapStore<L, I>
12+
where
13+
L: LowT + Identify<Id = I>,
14+
{
15+
lows: HashMap<I, L>,
16+
}
17+
18+
impl<L, I> MapStore<L, I>
19+
where
20+
L: LowT + Identify<Id = I>,
21+
I: Clone + Hash + PartialEq + Eq,
22+
{
23+
fn remove_low(&mut self, low: &impl LowT) {
24+
let _low = self.lows.remove(low.identify()).unwrap(); //~ ERROR mismatched types
25+
}
26+
}
27+
28+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/do-not-look-at-parent-item-in-suggestion-for-type-param-of-current-assoc-item.rs:24:37
3+
|
4+
LL | let _low = self.lows.remove(low.identify()).unwrap();
5+
| ------ ^^^^^^^^^^^^^^ expected `&I`, found associated type
6+
| |
7+
| arguments to this method are incorrect
8+
|
9+
= note: expected reference `&I`
10+
found associated type `<impl LowT as Identify>::Id`
11+
= help: consider constraining the associated type `<impl LowT as Identify>::Id` to `&I`
12+
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
13+
note: method defined here
14+
--> $SRC_DIR/std/src/collections/hash/map.rs:LL:COL
15+
16+
error: aborting due to previous error
17+
18+
For more information about this error, try `rustc --explain E0308`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
struct A<B>(B);
2+
impl<B>A<B>{fn d(){fn d(){Self(1)}}}
3+
//~^ ERROR the size for values of type `B` cannot be known at compilation time
4+
//~| ERROR the size for values of type `B` cannot be known at compilation time
5+
//~| ERROR mismatched types
6+
//~| ERROR mismatched types
7+
//~| ERROR `main` function not found in crate
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
error[E0601]: `main` function not found in crate `do_not_ice_on_note_and_explain`
2+
--> $DIR/do-not-ice-on-note_and_explain.rs:2:37
3+
|
4+
LL | impl<B>A<B>{fn d(){fn d(){Self(1)}}}
5+
| ^ consider adding a `main` function to `$DIR/do-not-ice-on-note_and_explain.rs`
6+
7+
error[E0277]: the size for values of type `B` cannot be known at compilation time
8+
--> $DIR/do-not-ice-on-note_and_explain.rs:2:32
9+
|
10+
LL | impl<B>A<B>{fn d(){fn d(){Self(1)}}}
11+
| - ---- ^ doesn't have a size known at compile-time
12+
| | |
13+
| | required by a bound introduced by this call
14+
| this type parameter needs to be `Sized`
15+
|
16+
note: required by a bound in `A`
17+
--> $DIR/do-not-ice-on-note_and_explain.rs:1:10
18+
|
19+
LL | struct A<B>(B);
20+
| ^ required by this bound in `A`
21+
22+
error[E0308]: mismatched types
23+
--> $DIR/do-not-ice-on-note_and_explain.rs:2:32
24+
|
25+
LL | impl<B>A<B>{fn d(){fn d(){Self(1)}}}
26+
| ---- ^ expected type parameter `B`, found integer
27+
| |
28+
| arguments to this function are incorrect
29+
|
30+
= note: expected type parameter `B`
31+
found type `{integer}`
32+
note: tuple struct defined here
33+
--> $DIR/do-not-ice-on-note_and_explain.rs:1:8
34+
|
35+
LL | struct A<B>(B);
36+
| ^
37+
38+
error[E0308]: mismatched types
39+
--> $DIR/do-not-ice-on-note_and_explain.rs:2:27
40+
|
41+
LL | impl<B>A<B>{fn d(){fn d(){Self(1)}}}
42+
| ^^^^^^^ expected `()`, found `A<B>`
43+
|
44+
= note: expected unit type `()`
45+
found struct `A<B>`
46+
help: consider using a semicolon here
47+
|
48+
LL | impl<B>A<B>{fn d(){fn d(){Self(1);}}}
49+
| +
50+
help: try adding a return type
51+
|
52+
LL | impl<B>A<B>{fn d(){fn d() -> A<B>{Self(1)}}}
53+
| +++++++
54+
55+
error[E0277]: the size for values of type `B` cannot be known at compilation time
56+
--> $DIR/do-not-ice-on-note_and_explain.rs:2:27
57+
|
58+
LL | impl<B>A<B>{fn d(){fn d(){Self(1)}}}
59+
| - ^^^^^^^ doesn't have a size known at compile-time
60+
| |
61+
| this type parameter needs to be `Sized`
62+
|
63+
note: required by a bound in `A`
64+
--> $DIR/do-not-ice-on-note_and_explain.rs:1:10
65+
|
66+
LL | struct A<B>(B);
67+
| ^ required by this bound in `A`
68+
help: you could relax the implicit `Sized` bound on `B` if it were used through indirection like `&B` or `Box<B>`
69+
--> $DIR/do-not-ice-on-note_and_explain.rs:1:10
70+
|
71+
LL | struct A<B>(B);
72+
| ^ - ...if indirection were used here: `Box<B>`
73+
| |
74+
| this could be changed to `B: ?Sized`...
75+
76+
error: aborting due to 5 previous errors
77+
78+
Some errors have detailed explanations: E0277, E0308, E0601.
79+
For more information about an error, try `rustc --explain E0277`.

‎tests/ui/parser/ternary_operator.rs

+10-49
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,30 @@
1-
// A good chunk of these errors aren't shown to the user, but are still
2-
// required in the test for it to pass.
3-
4-
fn a() { //~ NOTE this function should return `Result` or `Option` to accept `?`
1+
fn a() {
52
let x = 5 > 2 ? true : false;
63
//~^ ERROR Rust has no ternary operator
74
//~| HELP use an `if-else` expression instead
8-
//~| ERROR the `?` operator can only be applied to values that implement `Try` [E0277]
9-
//~| HELP the trait `Try` is not implemented for `{integer}`
10-
//~| ERROR the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`) [E0277]
11-
//~| HELP the trait `FromResidual<_>` is not implemented for `()`
12-
//~| NOTE in this expansion of desugaring of operator `?`
13-
//~| NOTE the `?` operator cannot be applied to type `{integer}`
14-
//~| NOTE in this expansion of desugaring of operator `?`
15-
//~| NOTE in this expansion of desugaring of operator `?`
16-
//~| NOTE cannot use the `?` operator in a function that returns `()`
17-
//~| NOTE in this expansion of desugaring of operator `?`
185
}
196

20-
fn b() { //~ NOTE this function should return `Result` or `Option` to accept `?`
7+
fn b() {
218
let x = 5 > 2 ? { true } : { false };
229
//~^ ERROR Rust has no ternary operator
2310
//~| HELP use an `if-else` expression instead
24-
//~| ERROR the `?` operator can only be applied to values that implement `Try` [E0277]
25-
//~| HELP the trait `Try` is not implemented for `{integer}`
26-
//~| ERROR the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`) [E0277]
27-
//~| HELP the trait `FromResidual<_>` is not implemented for `()`
28-
//~| NOTE in this expansion of desugaring of operator `?`
29-
//~| NOTE the `?` operator cannot be applied to type `{integer}`
30-
//~| NOTE in this expansion of desugaring of operator `?`
31-
//~| NOTE in this expansion of desugaring of operator `?`
32-
//~| NOTE cannot use the `?` operator in a function that returns `()`
33-
//~| NOTE in this expansion of desugaring of operator `?`
3411
}
3512

36-
fn c() { //~ NOTE this function should return `Result` or `Option` to accept `?`
13+
fn c() {
3714
let x = 5 > 2 ? f32::MAX : f32::MIN;
3815
//~^ ERROR Rust has no ternary operator
3916
//~| HELP use an `if-else` expression instead
40-
//~| ERROR the `?` operator can only be applied to values that implement `Try` [E0277]
41-
//~| HELP the trait `Try` is not implemented for `{integer}`
42-
//~| ERROR the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`) [E0277]
43-
//~| HELP the trait `FromResidual<_>` is not implemented for `()`
44-
//~| NOTE in this expansion of desugaring of operator `?`
45-
//~| NOTE the `?` operator cannot be applied to type `{integer}`
46-
//~| NOTE in this expansion of desugaring of operator `?`
47-
//~| NOTE in this expansion of desugaring of operator `?`
48-
//~| NOTE cannot use the `?` operator in a function that returns `()`
49-
//~| NOTE in this expansion of desugaring of operator `?`
5017
}
5118

52-
fn main() { //~ NOTE this function should return `Result` or `Option` to accept `?`
19+
fn bad() {
20+
// regression test for #117208
21+
v ? return;
22+
//~^ ERROR expected one of
23+
}
24+
25+
fn main() {
5326
let x = 5 > 2 ? { let x = vec![]: Vec<u16>; x } : { false };
5427
//~^ ERROR Rust has no ternary operator
5528
//~| HELP use an `if-else` expression instead
5629
//~| ERROR expected one of `.`, `;`, `?`, `else`, or an operator, found `:`
57-
//~| NOTE expected one of `.`, `;`, `?`, `else`, or an operator
58-
//~| ERROR the `?` operator can only be applied to values that implement `Try` [E0277]
59-
//~| HELP the trait `Try` is not implemented for `{integer}`
60-
//~| ERROR the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`) [E0277]
61-
//~| HELP the trait `FromResidual<_>` is not implemented for `()`
62-
//~| NOTE type ascription syntax has been removed, see issue #101728 <https://github.com/rust-lang/rust/issues/101728>
63-
//~| NOTE in this expansion of desugaring of operator `?`
64-
//~| NOTE the `?` operator cannot be applied to type `{integer}`
65-
//~| NOTE in this expansion of desugaring of operator `?`
66-
//~| NOTE in this expansion of desugaring of operator `?`
67-
//~| NOTE cannot use the `?` operator in a function that returns `()`
68-
//~| NOTE in this expansion of desugaring of operator `?`
6930
}
+12-79
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,48 @@
11
error: Rust has no ternary operator
2-
--> $DIR/ternary_operator.rs:5:19
2+
--> $DIR/ternary_operator.rs:2:19
33
|
44
LL | let x = 5 > 2 ? true : false;
55
| ^^^^^^^^^^^^^^^
66
|
77
= help: use an `if-else` expression instead
88

99
error: Rust has no ternary operator
10-
--> $DIR/ternary_operator.rs:21:19
10+
--> $DIR/ternary_operator.rs:8:19
1111
|
1212
LL | let x = 5 > 2 ? { true } : { false };
1313
| ^^^^^^^^^^^^^^^^^^^^^^^
1414
|
1515
= help: use an `if-else` expression instead
1616

1717
error: Rust has no ternary operator
18-
--> $DIR/ternary_operator.rs:37:19
18+
--> $DIR/ternary_operator.rs:14:19
1919
|
2020
LL | let x = 5 > 2 ? f32::MAX : f32::MIN;
2121
| ^^^^^^^^^^^^^^^^^^^^^^
2222
|
2323
= help: use an `if-else` expression instead
2424

25+
error: expected one of `.`, `;`, `?`, `}`, or an operator, found keyword `return`
26+
--> $DIR/ternary_operator.rs:21:9
27+
|
28+
LL | v ? return;
29+
| ^^^^^^ expected one of `.`, `;`, `?`, `}`, or an operator
30+
2531
error: expected one of `.`, `;`, `?`, `else`, or an operator, found `:`
26-
--> $DIR/ternary_operator.rs:53:37
32+
--> $DIR/ternary_operator.rs:26:37
2733
|
2834
LL | let x = 5 > 2 ? { let x = vec![]: Vec<u16>; x } : { false };
2935
| ^ expected one of `.`, `;`, `?`, `else`, or an operator
3036
|
3137
= note: type ascription syntax has been removed, see issue #101728 <https://github.com/rust-lang/rust/issues/101728>
3238

3339
error: Rust has no ternary operator
34-
--> $DIR/ternary_operator.rs:53:19
40+
--> $DIR/ternary_operator.rs:26:19
3541
|
3642
LL | let x = 5 > 2 ? { let x = vec![]: Vec<u16>; x } : { false };
3743
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3844
|
3945
= help: use an `if-else` expression instead
4046

41-
error[E0277]: the `?` operator can only be applied to values that implement `Try`
42-
--> $DIR/ternary_operator.rs:5:17
43-
|
44-
LL | let x = 5 > 2 ? true : false;
45-
| ^^^ the `?` operator cannot be applied to type `{integer}`
46-
|
47-
= help: the trait `Try` is not implemented for `{integer}`
48-
49-
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)
50-
--> $DIR/ternary_operator.rs:5:19
51-
|
52-
LL | fn a() {
53-
| ------ this function should return `Result` or `Option` to accept `?`
54-
LL | let x = 5 > 2 ? true : false;
55-
| ^ cannot use the `?` operator in a function that returns `()`
56-
|
57-
= help: the trait `FromResidual<_>` is not implemented for `()`
58-
59-
error[E0277]: the `?` operator can only be applied to values that implement `Try`
60-
--> $DIR/ternary_operator.rs:21:17
61-
|
62-
LL | let x = 5 > 2 ? { true } : { false };
63-
| ^^^ the `?` operator cannot be applied to type `{integer}`
64-
|
65-
= help: the trait `Try` is not implemented for `{integer}`
66-
67-
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)
68-
--> $DIR/ternary_operator.rs:21:19
69-
|
70-
LL | fn b() {
71-
| ------ this function should return `Result` or `Option` to accept `?`
72-
LL | let x = 5 > 2 ? { true } : { false };
73-
| ^ cannot use the `?` operator in a function that returns `()`
74-
|
75-
= help: the trait `FromResidual<_>` is not implemented for `()`
76-
77-
error[E0277]: the `?` operator can only be applied to values that implement `Try`
78-
--> $DIR/ternary_operator.rs:37:17
79-
|
80-
LL | let x = 5 > 2 ? f32::MAX : f32::MIN;
81-
| ^^^ the `?` operator cannot be applied to type `{integer}`
82-
|
83-
= help: the trait `Try` is not implemented for `{integer}`
84-
85-
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)
86-
--> $DIR/ternary_operator.rs:37:19
87-
|
88-
LL | fn c() {
89-
| ------ this function should return `Result` or `Option` to accept `?`
90-
LL | let x = 5 > 2 ? f32::MAX : f32::MIN;
91-
| ^ cannot use the `?` operator in a function that returns `()`
92-
|
93-
= help: the trait `FromResidual<_>` is not implemented for `()`
94-
95-
error[E0277]: the `?` operator can only be applied to values that implement `Try`
96-
--> $DIR/ternary_operator.rs:53:17
97-
|
98-
LL | let x = 5 > 2 ? { let x = vec![]: Vec<u16>; x } : { false };
99-
| ^^^ the `?` operator cannot be applied to type `{integer}`
100-
|
101-
= help: the trait `Try` is not implemented for `{integer}`
102-
103-
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)
104-
--> $DIR/ternary_operator.rs:53:19
105-
|
106-
LL | fn main() {
107-
| --------- this function should return `Result` or `Option` to accept `?`
108-
LL | let x = 5 > 2 ? { let x = vec![]: Vec<u16>; x } : { false };
109-
| ^ cannot use the `?` operator in a function that returns `()`
110-
|
111-
= help: the trait `FromResidual<_>` is not implemented for `()`
112-
113-
error: aborting due to 13 previous errors
47+
error: aborting due to 6 previous errors
11448

115-
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)
Please sign in to comment.