Auto merge of #95351 - Dylan-DPC:rollup-o1il7tx, r=Dylan-DPC

Rollup of 5 pull requests

Successful merges:

 - #91981 (Recover suggestions and useful information lost in previous PR)
 - #93469 (Skip pointing out ambiguous impls in alloc/std crates too in inference errors)
 - #95335 (Move resolve_path to rustc_builtin_macros and make it private)
 - #95340 (interpret: with enforce_number_validity, ensure integers are truly Scalar::Int (i.e., no pointers))
 - #95341 (ARMv6K Horizon OS has_thread_local support)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2022-03-27 04:20:07 +00:00
commit 185a3f0a11
51 changed files with 281 additions and 149 deletions

View File

@ -3,15 +3,17 @@ use rustc_ast::ptr::P;
use rustc_ast::token;
use rustc_ast::tokenstream::TokenStream;
use rustc_ast_pretty::pprust;
use rustc_errors::PResult;
use rustc_expand::base::{self, *};
use rustc_expand::module::DirOwnership;
use rustc_parse::parser::{ForceCollect, Parser};
use rustc_parse::{self, new_parser_from_file};
use rustc_session::lint::builtin::INCOMPLETE_INCLUDE;
use rustc_span::symbol::Symbol;
use rustc_span::{self, Pos, Span};
use rustc_span::{self, FileName, Pos, Span};
use smallvec::SmallVec;
use std::path::PathBuf;
use std::rc::Rc;
// These macros all relate to the file system; they either return
@ -102,7 +104,7 @@ pub fn expand_include<'cx>(
return DummyResult::any(sp);
};
// The file will be added to the code map by the parser
let file = match cx.resolve_path(file, sp) {
let file = match resolve_path(cx, file, sp) {
Ok(f) => f,
Err(mut err) => {
err.emit();
@ -171,7 +173,7 @@ pub fn expand_include_str(
let Some(file) = get_single_str_from_tts(cx, sp, tts, "include_str!") else {
return DummyResult::any(sp);
};
let file = match cx.resolve_path(file, sp) {
let file = match resolve_path(cx, file, sp) {
Ok(f) => f,
Err(mut err) => {
err.emit();
@ -205,7 +207,7 @@ pub fn expand_include_bytes(
let Some(file) = get_single_str_from_tts(cx, sp, tts, "include_bytes!") else {
return DummyResult::any(sp);
};
let file = match cx.resolve_path(file, sp) {
let file = match resolve_path(cx, file, sp) {
Ok(f) => f,
Err(mut err) => {
err.emit();
@ -220,3 +222,40 @@ pub fn expand_include_bytes(
}
}
}
/// Resolves a `path` mentioned inside Rust code, returning an absolute path.
///
/// This unifies the logic used for resolving `include_X!`.
fn resolve_path<'a>(
cx: &mut ExtCtxt<'a>,
path: impl Into<PathBuf>,
span: Span,
) -> PResult<'a, PathBuf> {
let path = path.into();
// Relative paths are resolved relative to the file in which they are found
// after macro expansion (that is, they are unhygienic).
if !path.is_absolute() {
let callsite = span.source_callsite();
let mut result = match cx.source_map().span_to_filename(callsite) {
FileName::Real(name) => name
.into_local_path()
.expect("attempting to resolve a file path in an external file"),
FileName::DocTest(path, _) => path,
other => {
return Err(cx.struct_span_err(
span,
&format!(
"cannot resolve relative path in non-file source `{}`",
cx.source_map().filename_for_diagnostics(&other)
),
));
}
};
result.pop();
result.push(path);
Ok(result)
} else {
Ok(path)
}
}

View File

@ -444,6 +444,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
match scalar.try_to_int() {
Ok(int) => int.is_null(),
Err(_) => {
// Can only happen during CTFE.
let ptr = self.scalar_to_ptr(scalar);
match self.memory.ptr_try_get_alloc(ptr) {
Ok((alloc_id, offset, _)) => {
@ -455,7 +456,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
// Note that one-past-the-end (offset == size) is still inbounds, and never null.
offset > size
}
Err(offset) => offset == 0,
Err(_offset) => bug!("a non-int scalar is always a pointer"),
}
}
}

View File

@ -21,7 +21,7 @@ use std::hash::Hash;
use super::{
alloc_range, CheckInAllocMsg, GlobalAlloc, InterpCx, InterpResult, MPlaceTy, Machine,
MemPlaceMeta, OpTy, ScalarMaybeUninit, ValueVisitor,
MemPlaceMeta, OpTy, Scalar, ScalarMaybeUninit, ValueVisitor,
};
macro_rules! throw_validation_failure {
@ -521,8 +521,11 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
// NOTE: Keep this in sync with the array optimization for int/float
// types below!
if M::enforce_number_validity(self.ecx) {
// Integers/floats in CTFE: Must be scalar bits, pointers are dangerous
let is_bits = value.check_init().map_or(false, |v| v.try_to_int().is_ok());
// Integers/floats with number validity: Must be scalar bits, pointers are dangerous.
// As a special exception we *do* match on a `Scalar` here, since we truly want
// to know its underlying representation (and *not* cast it to an integer).
let is_bits =
value.check_init().map_or(false, |v| matches!(v, Scalar::Int(..)));
if !is_bits {
throw_validation_failure!(self.path,
{ "{:x}", value } expected { "initialized plain (non-pointer) bytes" }

View File

@ -10,7 +10,7 @@ use rustc_ast::{self as ast, AstLike, Attribute, Item, NodeId, PatKind};
use rustc_attr::{self as attr, Deprecation, Stability};
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::sync::{self, Lrc};
use rustc_errors::{Applicability, DiagnosticBuilder, ErrorGuaranteed, PResult};
use rustc_errors::{Applicability, DiagnosticBuilder, ErrorGuaranteed};
use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT;
use rustc_lint_defs::BuiltinLintDiagnostics;
use rustc_parse::{self, nt_to_tokenstream, parser, MACRO_ARGUMENTS};
@ -20,7 +20,7 @@ use rustc_span::edition::Edition;
use rustc_span::hygiene::{AstPass, ExpnData, ExpnKind, LocalExpnId};
use rustc_span::source_map::SourceMap;
use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::{FileName, MultiSpan, Span, DUMMY_SP};
use rustc_span::{MultiSpan, Span, DUMMY_SP};
use smallvec::{smallvec, SmallVec};
use std::default::Default;
@ -1128,41 +1128,6 @@ impl<'a> ExtCtxt<'a> {
pub fn check_unused_macros(&mut self) {
self.resolver.check_unused_macros();
}
/// Resolves a `path` mentioned inside Rust code, returning an absolute path.
///
/// This unifies the logic used for resolving `include_X!`.
///
/// FIXME: move this to `rustc_builtin_macros` and make it private.
pub fn resolve_path(&self, path: impl Into<PathBuf>, span: Span) -> PResult<'a, PathBuf> {
let path = path.into();
// Relative paths are resolved relative to the file in which they are found
// after macro expansion (that is, they are unhygienic).
if !path.is_absolute() {
let callsite = span.source_callsite();
let mut result = match self.source_map().span_to_filename(callsite) {
FileName::Real(name) => name
.into_local_path()
.expect("attempting to resolve a file path in an external file"),
FileName::DocTest(path, _) => path,
other => {
return Err(self.struct_span_err(
span,
&format!(
"cannot resolve relative path in non-file source `{}`",
self.source_map().filename_for_diagnostics(&other)
),
));
}
};
result.pop();
result.push(path);
Ok(result)
} else {
Ok(path)
}
}
}
/// Extracts a string literal from the macro expanded version of `expr`,

View File

@ -333,6 +333,9 @@ pub fn same_type_modulo_infer<'tcx>(a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
)
| (&ty::Infer(ty::InferTy::TyVar(_)), _)
| (_, &ty::Infer(ty::InferTy::TyVar(_))) => true,
(&ty::Ref(reg_a, ty_a, mut_a), &ty::Ref(reg_b, ty_b, mut_b)) => {
reg_a == reg_b && mut_a == mut_b && same_type_modulo_infer(*ty_a, *ty_b)
}
_ => a == b,
}
}
@ -602,7 +605,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
match *cause.code() {
ObligationCauseCode::Pattern { origin_expr: true, span: Some(span), root_ty } => {
let ty = self.resolve_vars_if_possible(root_ty);
if ty.is_suggestable() {
if !matches!(ty.kind(), ty::Infer(ty::InferTy::TyVar(_) | ty::InferTy::FreshTy(_)))
{
// don't show type `_`
err.span_label(span, format!("this expression has type `{}`", ty));
}

View File

@ -1434,6 +1434,17 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
value.fold_with(&mut r)
}
pub fn resolve_numeric_literals_with_default<T>(&self, value: T) -> T
where
T: TypeFoldable<'tcx>,
{
if !value.needs_infer() {
return value; // Avoid duplicated subst-folding.
}
let mut r = InferenceLiteralEraser { tcx: self.tcx };
value.fold_with(&mut r)
}
/// Returns the first unresolved variable contained in `T`. In the
/// process of visiting `T`, this will resolve (where possible)
/// type variables in `T`, but it never constructs the final,
@ -1785,6 +1796,26 @@ impl<'tcx> TyOrConstInferVar<'tcx> {
}
}
/// Replace `{integer}` with `i32` and `{float}` with `f64`.
/// Used only for diagnostics.
struct InferenceLiteralEraser<'tcx> {
tcx: TyCtxt<'tcx>,
}
impl<'tcx> TypeFolder<'tcx> for InferenceLiteralEraser<'tcx> {
fn tcx(&self) -> TyCtxt<'tcx> {
self.tcx
}
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
match ty.kind() {
ty::Infer(ty::IntVar(_) | ty::FreshIntTy(_)) => self.tcx.types.i32,
ty::Infer(ty::FloatVar(_) | ty::FreshFloatTy(_)) => self.tcx.types.f64,
_ => ty.super_fold_with(self),
}
}
}
struct ShallowResolver<'a, 'tcx> {
infcx: &'a InferCtxt<'a, 'tcx>,
}

View File

@ -37,6 +37,7 @@ pub fn target() -> Target {
pre_link_args,
exe_suffix: ".elf".to_string(),
no_default_libraries: false,
has_thread_local: true,
..Default::default()
},
}

View File

@ -1954,7 +1954,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
if self.is_tainted_by_errors()
&& crate_names.len() == 1
&& crate_names[0] == "`core`"
&& ["`core`", "`alloc`", "`std`"].contains(&crate_names[0].as_str())
&& spans.len() == 0
{
// Avoid complaining about other inference issues for expressions like

View File

@ -11,6 +11,7 @@ use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::DefId;
use rustc_hir::GenericArg;
use rustc_infer::infer::TyCtxtInferExt;
use rustc_middle::ty::{
self, subst, subst::SubstsRef, GenericParamDef, GenericParamDefKind, Ty, TyCtxt,
};
@ -83,7 +84,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
if let Some(param_local_id) = param.def_id.as_local() {
let param_hir_id = tcx.hir().local_def_id_to_hir_id(param_local_id);
let param_name = tcx.hir().ty_param_name(param_hir_id);
let param_type = tcx.type_of(param.def_id);
let param_type = tcx.infer_ctxt().enter(|infcx| {
infcx.resolve_numeric_literals_with_default(tcx.type_of(param.def_id))
});
if param_type.is_suggestable() {
err.span_suggestion(
tcx.def_span(src_def_id),

View File

@ -521,6 +521,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
can_suggest: bool,
fn_id: hir::HirId,
) -> bool {
let found =
self.resolve_numeric_literals_with_default(self.resolve_vars_if_possible(found));
// Only suggest changing the return type for methods that
// haven't set a return type at all (and aren't `fn main()` or an impl).
match (&fn_decl.output, found.is_suggestable(), can_suggest, expected.is_unit()) {
@ -528,13 +530,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
err.span_suggestion(
span,
"try adding a return type",
format!("-> {} ", self.resolve_vars_with_obligations(found)),
format!("-> {} ", found),
Applicability::MachineApplicable,
);
true
}
(&hir::FnRetTy::DefaultReturn(span), false, true, true) => {
err.span_label(span, "possibly return type missing here?");
// FIXME: if `found` could be `impl Iterator` or `impl Fn*`, we should suggest
// that.
err.span_suggestion(
span,
"a return type might be missing here",
"-> _ ".to_string(),
Applicability::HasPlaceholders,
);
true
}
(&hir::FnRetTy::DefaultReturn(span), _, false, true) => {

View File

@ -87,6 +87,7 @@ async fn baz() -> Result<(), ()> {
async fn match_() {
match tuple() { //~ HELP consider `await`ing on the `Future`
//~^ NOTE this expression has type `impl Future<Output = Tuple>`
Tuple(_) => {} //~ ERROR mismatched types
//~^ NOTE expected opaque type, found struct `Tuple`
//~| NOTE expected opaque type `impl Future<Output = Tuple>`

View File

@ -56,8 +56,11 @@ LL | struct_().await.method();
| ++++++
error[E0308]: mismatched types
--> $DIR/issue-61076.rs:90:9
--> $DIR/issue-61076.rs:91:9
|
LL | match tuple() {
| ------- this expression has type `impl Future<Output = Tuple>`
LL |
LL | Tuple(_) => {}
| ^^^^^^^^ expected opaque type, found struct `Tuple`
|

View File

@ -91,6 +91,8 @@ LL ~ 1 => dummy().await,
error[E0308]: mismatched types
--> $DIR/suggest-missing-await.rs:53:9
|
LL | let _x = match dummy() {
| ------- this expression has type `impl Future<Output = ()>`
LL | () => {}
| ^^ expected opaque type, found `()`
|
@ -109,6 +111,9 @@ LL | let _x = match dummy().await {
error[E0308]: mismatched types
--> $DIR/suggest-missing-await.rs:67:9
|
LL | match dummy_result() {
| -------------- this expression has type `impl Future<Output = Result<(), ()>>`
...
LL | Ok(_) => {}
| ^^^^^ expected opaque type, found enum `Result`
|
@ -127,6 +132,9 @@ LL | match dummy_result().await {
error[E0308]: mismatched types
--> $DIR/suggest-missing-await.rs:69:9
|
LL | match dummy_result() {
| -------------- this expression has type `impl Future<Output = Result<(), ()>>`
...
LL | Err(_) => {}
| ^^^^^^ expected opaque type, found enum `Result`
|

View File

@ -5,7 +5,7 @@ LL | mod foo { pub struct bar; }
| --------------- unit struct defined here
...
LL | let bar = 5;
| ^^^
| ^^^ - this expression has type `{integer}`
| |
| expected integer, found struct `bar`
| `bar` is interpreted as a unit struct, not a new binding

View File

@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/issue-20862.rs:2:5
|
LL | fn foo(x: i32) {
| - possibly return type missing here?
| - help: a return type might be missing here: `-> _`
LL | |y| x + y
| ^^^^^^^^^ expected `()`, found closure
|

View File

@ -2,7 +2,9 @@ error[E0308]: mismatched types
--> $DIR/default-match-bindings-forbidden.rs:4:5
|
LL | (x, y) = &(1, 2);
| ^^^^^^ expected reference, found tuple
| ^^^^^^ ------- this expression has type `&({integer}, {integer})`
| |
| expected reference, found tuple
|
= note: expected type `&({integer}, {integer})`
found tuple `(_, _)`

View File

@ -10,7 +10,9 @@ error[E0308]: mismatched types
--> $DIR/tuple_destructure_fail.rs:6:5
|
LL | (a, a, b) = (1, 2);
| ^^^^^^^^^ expected a tuple with 2 elements, found one with 3 elements
| ^^^^^^^^^ ------ this expression has type `({integer}, {integer})`
| |
| expected a tuple with 2 elements, found one with 3 elements
|
= note: expected type `({integer}, {integer})`
found tuple `(_, _, _)`
@ -27,7 +29,9 @@ error[E0308]: mismatched types
--> $DIR/tuple_destructure_fail.rs:8:5
|
LL | (_,) = (1, 2);
| ^^^^ expected a tuple with 2 elements, found one with 1 element
| ^^^^ ------ this expression has type `({integer}, {integer})`
| |
| expected a tuple with 2 elements, found one with 1 element
|
= note: expected type `({integer}, {integer})`
found tuple `(_,)`

View File

@ -1,6 +1,8 @@
error[E0308]: mismatched types
--> $DIR/exclusive_range_pattern_syntax_collision.rs:6:13
|
LL | match [5..4, 99..105, 43..44] {
| ----------------------- this expression has type `[std::ops::Range<{integer}>; 3]`
LL | [_, 99.., _] => {},
| ^^ expected struct `std::ops::Range`, found integer
|

View File

@ -7,6 +7,8 @@ LL | [_, 99..] => {},
error[E0308]: mismatched types
--> $DIR/exclusive_range_pattern_syntax_collision2.rs:6:13
|
LL | match [5..4, 99..105, 43..44] {
| ----------------------- this expression has type `[std::ops::Range<{integer}>; 3]`
LL | [_, 99..] => {},
| ^^ expected struct `std::ops::Range`, found integer
|

View File

@ -1,6 +1,8 @@
error[E0308]: mismatched types
--> $DIR/exclusive_range_pattern_syntax_collision3.rs:6:12
|
LL | match [5..4, 99..105, 43..44] {
| ----------------------- this expression has type `[std::ops::Range<{integer}>; 3]`
LL | [..9, 99..100, _] => {},
| ^ expected struct `std::ops::Range`, found integer
|
@ -10,6 +12,8 @@ LL | [..9, 99..100, _] => {},
error[E0308]: mismatched types
--> $DIR/exclusive_range_pattern_syntax_collision3.rs:6:15
|
LL | match [5..4, 99..105, 43..44] {
| ----------------------- this expression has type `[std::ops::Range<{integer}>; 3]`
LL | [..9, 99..100, _] => {},
| ^^ --- this is of type `{integer}`
| |
@ -21,6 +25,8 @@ LL | [..9, 99..100, _] => {},
error[E0308]: mismatched types
--> $DIR/exclusive_range_pattern_syntax_collision3.rs:6:19
|
LL | match [5..4, 99..105, 43..44] {
| ----------------------- this expression has type `[std::ops::Range<{integer}>; 3]`
LL | [..9, 99..100, _] => {},
| -- ^^^ expected struct `std::ops::Range`, found integer
| |

View File

@ -1,6 +1,8 @@
error[E0308]: mismatched types
--> $DIR/pat-tuple-5.rs:8:10
|
LL | match (0, 1) {
| ------ this expression has type `({integer}, {integer})`
LL | (PAT ..) => {}
| ^^^ expected tuple, found `u8`
|

View File

@ -17,7 +17,7 @@ fn two(x: bool) -> impl Foo {
//~| expected `i32`, found `u32`
}
fn sum_to(n: u32) -> impl Foo { //~ ERROR type annotations needed
fn sum_to(n: u32) -> impl Foo {
if n == 0 {
0
} else {

View File

@ -34,22 +34,7 @@ LL | n + sum_to(n - 1)
|
= help: the trait `Add<impl Foo>` is not implemented for `u32`
error[E0283]: type annotations needed
--> $DIR/equality.rs:20:22
|
LL | fn sum_to(n: u32) -> impl Foo {
| ^^^^^^^^ cannot infer type for type `{integer}`
|
= note: multiple `impl`s satisfying `{integer}: ToString` found in the `alloc` crate:
- impl ToString for i8;
- impl ToString for u8;
note: required because of the requirements on the impl of `Foo` for `{integer}`
--> $DIR/equality.rs:5:26
|
LL | impl<T: Copy + ToString> Foo for T {}
| ^^^ ^
error: aborting due to 2 previous errors; 1 warning emitted
error: aborting due to 3 previous errors; 1 warning emitted
Some errors have detailed explanations: E0277, E0283, E0308.
Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.

View File

@ -1,6 +1,8 @@
error[E0308]: mismatched types
--> $DIR/issue-11844.rs:6:9
|
LL | match a {
| - this expression has type `Option<Box<{integer}>>`
LL | Ok(a) =>
| ^^^^^ expected enum `Option`, found enum `Result`
|

View File

@ -1,6 +1,8 @@
error[E0308]: mismatched types
--> $DIR/issue-12552.rs:6:5
|
LL | match t {
| - this expression has type `Result<_, {integer}>`
LL | Some(k) => match k {
| ^^^^^^^ expected enum `Result`, found enum `Option`
|
@ -10,6 +12,9 @@ LL | Some(k) => match k {
error[E0308]: mismatched types
--> $DIR/issue-12552.rs:9:5
|
LL | match t {
| - this expression has type `Result<_, {integer}>`
...
LL | None => ()
| ^^^^ expected enum `Result`, found enum `Option`
|

View File

@ -1,6 +1,8 @@
error[E0308]: mismatched types
--> $DIR/issue-13466.rs:8:9
|
LL | let _x: usize = match Some(1) {
| ------- this expression has type `Option<{integer}>`
LL | Ok(u) => u,
| ^^^^^ expected enum `Option`, found enum `Result`
|
@ -10,6 +12,9 @@ LL | Ok(u) => u,
error[E0308]: mismatched types
--> $DIR/issue-13466.rs:14:9
|
LL | let _x: usize = match Some(1) {
| ------- this expression has type `Option<{integer}>`
...
LL | Err(e) => panic!(e)
| ^^^^^^ expected enum `Option`, found enum `Result`
|

View File

@ -5,7 +5,7 @@ LL | struct Test;
| ------------ unit struct defined here
...
LL | let Test = 1;
| ^^^^
| ^^^^ - this expression has type `{integer}`
| |
| expected integer, found struct `Test`
| `Test` is interpreted as a unit struct, not a new binding

View File

@ -1,6 +1,8 @@
error[E0308]: mismatched types
--> $DIR/issue-3680.rs:3:9
|
LL | match None {
| ---- this expression has type `Option<_>`
LL | Err(_) => ()
| ^^^^^^ expected enum `Option`, found enum `Result`
|

View File

@ -5,11 +5,12 @@ LL | const A: (isize,isize) = (4,2);
| ------------------------------- constant defined here
LL | fn main() {
LL | match 42 { A => () }
| ^
| |
| expected integer, found tuple
| `A` is interpreted as a constant, not a new binding
| help: introduce a new binding instead: `other_a`
| -- ^
| | |
| | expected integer, found tuple
| | `A` is interpreted as a constant, not a new binding
| | help: introduce a new binding instead: `other_a`
| this expression has type `{integer}`
|
= note: expected type `{integer}`
found tuple `(isize, isize)`

View File

@ -36,7 +36,7 @@ error[E0308]: mismatched types
--> $DIR/issue-66706.rs:2:5
|
LL | fn a() {
| - possibly return type missing here?
| - help: try adding a return type: `-> [i32; _]`
LL | [0; [|_: _ &_| ()].len()]
| ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found array `[{integer}; _]`
@ -44,7 +44,7 @@ error[E0308]: mismatched types
--> $DIR/issue-66706.rs:14:5
|
LL | fn c() {
| - possibly return type missing here?
| - help: try adding a return type: `-> [i32; _]`
LL | [0; [|&_: _ &_| {}; 0 ].len()]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found array `[{integer}; _]`
@ -52,7 +52,7 @@ error[E0308]: mismatched types
--> $DIR/issue-66706.rs:20:5
|
LL | fn d() {
| - possibly return type missing here?
| - help: try adding a return type: `-> [i32; _]`
LL | [0; match [|f @ &ref _| () ] {} ]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found array `[{integer}; _]`

View File

@ -21,6 +21,8 @@ LL | (_a, _x @ ..) => {}
error[E0308]: mismatched types
--> $DIR/issue-72574-1.rs:4:9
|
LL | match x {
| - this expression has type `({integer}, {integer}, {integer})`
LL | (_a, _x @ ..) => {}
| ^^^^^^^^^^^^^ expected a tuple with 3 elements, found one with 2 elements
|

View File

@ -10,7 +10,6 @@ fn err() {
fn arg_pat_closure_err() {
|x| String::from("x".as_ref()); //~ ERROR type annotations needed
//~^ ERROR type annotations needed
//~| ERROR type annotations needed
}

View File

@ -29,16 +29,6 @@ error[E0282]: type annotations needed
LL | |x| String::from("x".as_ref());
| ^ consider giving this closure parameter a type
error[E0283]: type annotations needed
--> $DIR/issue-72690.rs:12:9
|
LL | |x| String::from("x".as_ref());
| ^^^^^^^^^^^^ cannot infer type for reference `&_`
|
= note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate:
- impl<> From<&String> for String;
- impl<> From<&str> for String;
error[E0283]: type annotations needed
--> $DIR/issue-72690.rs:12:26
|
@ -55,7 +45,7 @@ LL | |x| String::from("x".as_ref());
- impl AsRef<str> for str;
error[E0283]: type annotations needed for `&T`
--> $DIR/issue-72690.rs:18:17
--> $DIR/issue-72690.rs:17:17
|
LL | let _ = "x".as_ref();
| - ^^^^^^ cannot infer type for type parameter `T` declared on the trait `AsRef`
@ -69,7 +59,7 @@ LL | let _ = "x".as_ref();
- impl AsRef<str> for str;
error[E0283]: type annotations needed
--> $DIR/issue-72690.rs:22:5
--> $DIR/issue-72690.rs:21:5
|
LL | String::from("x".as_ref());
| ^^^^^^^^^^^^ cannot infer type for reference `&_`
@ -79,7 +69,7 @@ LL | String::from("x".as_ref());
- impl<> From<&str> for String;
error[E0283]: type annotations needed
--> $DIR/issue-72690.rs:22:22
--> $DIR/issue-72690.rs:21:22
|
LL | String::from("x".as_ref());
| ----^^^^^^--
@ -94,7 +84,7 @@ LL | String::from("x".as_ref());
- impl AsRef<str> for str;
error[E0283]: type annotations needed
--> $DIR/issue-72690.rs:29:5
--> $DIR/issue-72690.rs:28:5
|
LL | String::from("x".as_ref());
| ^^^^^^^^^^^^ cannot infer type for reference `&_`
@ -104,7 +94,7 @@ LL | String::from("x".as_ref());
- impl<> From<&str> for String;
error[E0283]: type annotations needed
--> $DIR/issue-72690.rs:29:22
--> $DIR/issue-72690.rs:28:22
|
LL | String::from("x".as_ref());
| ----^^^^^^--
@ -119,7 +109,7 @@ LL | String::from("x".as_ref());
- impl AsRef<str> for str;
error[E0283]: type annotations needed
--> $DIR/issue-72690.rs:38:5
--> $DIR/issue-72690.rs:37:5
|
LL | String::from("x".as_ref());
| ^^^^^^^^^^^^ cannot infer type for reference `&_`
@ -129,7 +119,7 @@ LL | String::from("x".as_ref());
- impl<> From<&str> for String;
error[E0283]: type annotations needed
--> $DIR/issue-72690.rs:38:22
--> $DIR/issue-72690.rs:37:22
|
LL | String::from("x".as_ref());
| ----^^^^^^--
@ -144,7 +134,7 @@ LL | String::from("x".as_ref());
- impl AsRef<str> for str;
error[E0283]: type annotations needed
--> $DIR/issue-72690.rs:47:5
--> $DIR/issue-72690.rs:46:5
|
LL | String::from("x".as_ref());
| ^^^^^^^^^^^^ cannot infer type for reference `&_`
@ -154,7 +144,7 @@ LL | String::from("x".as_ref());
- impl<> From<&str> for String;
error[E0283]: type annotations needed
--> $DIR/issue-72690.rs:47:22
--> $DIR/issue-72690.rs:46:22
|
LL | String::from("x".as_ref());
| ----^^^^^^--
@ -169,7 +159,7 @@ LL | String::from("x".as_ref());
- impl AsRef<str> for str;
error[E0283]: type annotations needed
--> $DIR/issue-72690.rs:54:5
--> $DIR/issue-72690.rs:53:5
|
LL | String::from("x".as_ref());
| ^^^^^^^^^^^^ cannot infer type for reference `&_`
@ -179,7 +169,7 @@ LL | String::from("x".as_ref());
- impl<> From<&str> for String;
error[E0283]: type annotations needed
--> $DIR/issue-72690.rs:54:22
--> $DIR/issue-72690.rs:53:22
|
LL | String::from("x".as_ref());
| ----^^^^^^--
@ -194,7 +184,7 @@ LL | String::from("x".as_ref());
- impl AsRef<str> for str;
error[E0283]: type annotations needed
--> $DIR/issue-72690.rs:63:5
--> $DIR/issue-72690.rs:62:5
|
LL | String::from("x".as_ref());
| ^^^^^^^^^^^^ cannot infer type for reference `&_`
@ -204,7 +194,7 @@ LL | String::from("x".as_ref());
- impl<> From<&str> for String;
error[E0283]: type annotations needed
--> $DIR/issue-72690.rs:63:22
--> $DIR/issue-72690.rs:62:22
|
LL | String::from("x".as_ref());
| ----^^^^^^--
@ -218,7 +208,7 @@ LL | String::from("x".as_ref());
- impl AsRef<[u8]> for str;
- impl AsRef<str> for str;
error: aborting due to 18 previous errors
error: aborting due to 17 previous errors
Some errors have detailed explanations: E0282, E0283.
For more information about an error, try `rustc --explain E0282`.

View File

@ -2,7 +2,9 @@ error[E0308]: mismatched types
--> $DIR/keyword-false-as-identifier.rs:2:9
|
LL | let false = 22;
| ^^^^^ expected integer, found `bool`
| ^^^^^ -- this expression has type `{integer}`
| |
| expected integer, found `bool`
error: aborting due to previous error

View File

@ -2,7 +2,9 @@ error[E0308]: mismatched types
--> $DIR/keyword-true-as-identifier.rs:2:9
|
LL | let true = 22;
| ^^^^ expected integer, found `bool`
| ^^^^ -- this expression has type `{integer}`
| |
| expected integer, found `bool`
error: aborting due to previous error

View File

@ -27,6 +27,8 @@ LL | true ..= "what" => {}
error[E0308]: mismatched types
--> $DIR/match-range-fail.rs:18:9
|
LL | match 5 {
| - this expression has type `{integer}`
LL | 'c' ..= 100 => { }
| ^^^ --- this is of type `{integer}`
| |

View File

@ -9,6 +9,8 @@ LL | (0, ref y) | (y, 0) => {}
error[E0308]: mismatched types
--> $DIR/E0409.rs:5:23
|
LL | match x {
| - this expression has type `({integer}, {integer})`
LL | (0, ref y) | (y, 0) => {}
| ----- ^ expected `&{integer}`, found integer
| |

View File

@ -3,6 +3,9 @@ error[E0308]: mismatched types
|
LL | let &_
| ^^ types differ in mutability
...
LL | = foo;
| --- this expression has type `&mut {integer}`
|
= note: expected mutable reference `&mut {integer}`
found reference `&_`
@ -12,6 +15,9 @@ error[E0308]: mismatched types
|
LL | let &mut _
| ^^^^^^ types differ in mutability
...
LL | = bar;
| --- this expression has type `&{integer}`
|
= note: expected reference `&{integer}`
found mutable reference `&mut _`

View File

@ -1,13 +1,15 @@
error[E0308]: mismatched types
--> $DIR/diverging-tuple-parts-39485.rs:8:5
|
LL | fn g() {
| - possibly return type missing here?
LL | &panic!()
| ^^^^^^^^^ expected `()`, found reference
|
= note: expected unit type `()`
found reference `&_`
help: a return type might be missing here
|
LL | fn g() -> _ {
| ++++
help: consider removing the borrow
|
LL - &panic!()

View File

@ -86,8 +86,9 @@ error[E0308]: mismatched types
--> $DIR/already-bound-name.rs:30:32
|
LL | let (B(A(a, _) | B(a)) | A(a, A(a, _) | B(a))) = B(B(1));
| - ^ expected integer, found enum `E`
| |
| - ^ ------- this expression has type `E<E<{integer}>>`
| | |
| | expected integer, found enum `E`
| first introduced with type `{integer}` here
|
= note: expected type `{integer}`

View File

@ -65,8 +65,9 @@ error[E0308]: mismatched types
--> $DIR/inconsistent-modes.rs:13:32
|
LL | let (Ok((ref a, b)) | Err((ref mut a, ref b))) = Ok((0, &0));
| ----- ^^^^^^^^^ types differ in mutability
| |
| ----- ^^^^^^^^^ ----------- this expression has type `Result<({integer}, &{integer}), (_, _)>`
| | |
| | types differ in mutability
| first introduced with type `&{integer}` here
|
= note: expected type `&{integer}`

View File

@ -303,8 +303,9 @@ error[E0308]: mismatched types
--> $DIR/recover-range-pats.rs:22:12
|
LL | if let .0..Y = 0 {}
| ^^ - this is of type `u8`
| |
| ^^ - - this expression has type `{integer}`
| | |
| | this is of type `u8`
| expected integer, found floating-point number
error[E0308]: mismatched types
@ -336,8 +337,9 @@ error[E0308]: mismatched types
--> $DIR/recover-range-pats.rs:35:12
|
LL | if let .0..=Y = 0 {}
| ^^ - this is of type `u8`
| |
| ^^ - - this expression has type `{integer}`
| | |
| | this is of type `u8`
| expected integer, found floating-point number
error[E0308]: mismatched types
@ -369,8 +371,9 @@ error[E0308]: mismatched types
--> $DIR/recover-range-pats.rs:60:12
|
LL | if let .0...Y = 0 {}
| ^^ - this is of type `u8`
| |
| ^^ - - this expression has type `{integer}`
| | |
| | this is of type `u8`
| expected integer, found floating-point number
error[E0308]: mismatched types
@ -392,7 +395,9 @@ error[E0308]: mismatched types
--> $DIR/recover-range-pats.rs:75:12
|
LL | if let .0.. = 0 {}
| ^^ expected integer, found floating-point number
| ^^ - this expression has type `{integer}`
| |
| expected integer, found floating-point number
error[E0029]: only `char` and numeric types are allowed in range patterns
--> $DIR/recover-range-pats.rs:83:12
@ -404,7 +409,9 @@ error[E0308]: mismatched types
--> $DIR/recover-range-pats.rs:85:12
|
LL | if let .0..= = 0 {}
| ^^ expected integer, found floating-point number
| ^^ - this expression has type `{integer}`
| |
| expected integer, found floating-point number
error[E0029]: only `char` and numeric types are allowed in range patterns
--> $DIR/recover-range-pats.rs:93:12
@ -416,7 +423,9 @@ error[E0308]: mismatched types
--> $DIR/recover-range-pats.rs:95:12
|
LL | if let .0... = 0 {}
| ^^ expected integer, found floating-point number
| ^^ - this expression has type `{integer}`
| |
| expected integer, found floating-point number
error[E0029]: only `char` and numeric types are allowed in range patterns
--> $DIR/recover-range-pats.rs:103:14
@ -428,7 +437,9 @@ error[E0308]: mismatched types
--> $DIR/recover-range-pats.rs:105:15
|
LL | if let .. .0 = 0 {}
| ^^ expected integer, found floating-point number
| ^^ - this expression has type `{integer}`
| |
| expected integer, found floating-point number
error[E0029]: only `char` and numeric types are allowed in range patterns
--> $DIR/recover-range-pats.rs:113:15
@ -440,7 +451,9 @@ error[E0308]: mismatched types
--> $DIR/recover-range-pats.rs:115:15
|
LL | if let ..=.0 = 0 {}
| ^^ expected integer, found floating-point number
| ^^ - this expression has type `{integer}`
| |
| expected integer, found floating-point number
error[E0029]: only `char` and numeric types are allowed in range patterns
--> $DIR/recover-range-pats.rs:125:15
@ -452,7 +465,9 @@ error[E0308]: mismatched types
--> $DIR/recover-range-pats.rs:128:15
|
LL | if let ....3 = 0 {}
| ^^ expected integer, found floating-point number
| ^^ - this expression has type `{integer}`
| |
| expected integer, found floating-point number
error: aborting due to 60 previous errors

View File

@ -22,7 +22,9 @@ error[E0308]: mismatched types
--> $DIR/issue-74702.rs:2:9
|
LL | let (foo @ ..,) = (0, 0);
| ^^^^^^^^^^^ expected a tuple with 2 elements, found one with 1 element
| ^^^^^^^^^^^ ------ this expression has type `({integer}, {integer})`
| |
| expected a tuple with 2 elements, found one with 1 element
|
= note: expected tuple `({integer}, {integer})`
found tuple `(_,)`

View File

@ -150,6 +150,8 @@ LL | E1::Z0 => {}
error[E0308]: mismatched types
--> $DIR/pat-tuple-overfield.rs:19:9
|
LL | match (1, 2, 3) {
| --------- this expression has type `({integer}, {integer}, {integer})`
LL | (1, 2, 3, 4) => {}
| ^^^^^^^^^^^^ expected a tuple with 3 elements, found one with 4 elements
|
@ -159,6 +161,9 @@ LL | (1, 2, 3, 4) => {}
error[E0308]: mismatched types
--> $DIR/pat-tuple-overfield.rs:20:9
|
LL | match (1, 2, 3) {
| --------- this expression has type `({integer}, {integer}, {integer})`
LL | (1, 2, 3, 4) => {}
LL | (1, 2, .., 3, 4) => {}
| ^^^^^^^^^^^^^^^^ expected a tuple with 3 elements, found one with 4 elements
|

View File

@ -38,7 +38,7 @@ error[E0308]: mismatched types
--> $DIR/span-preservation.rs:39:5
|
LL | extern "C" fn bar() {
| - possibly return type missing here?
| - help: try adding a return type: `-> i32`
LL | 0
| ^ expected `()`, found integer
@ -46,7 +46,7 @@ error[E0308]: mismatched types
--> $DIR/span-preservation.rs:44:5
|
LL | extern "C" fn baz() {
| - possibly return type missing here?
| - help: try adding a return type: `-> i32`
LL | 0
| ^ expected `()`, found integer
@ -54,7 +54,7 @@ error[E0308]: mismatched types
--> $DIR/span-preservation.rs:49:5
|
LL | extern "Rust" fn rust_abi() {
| - possibly return type missing here?
| - help: try adding a return type: `-> i32`
LL | 0
| ^ expected `()`, found integer
@ -62,7 +62,7 @@ error[E0308]: mismatched types
--> $DIR/span-preservation.rs:54:5
|
LL | extern "\x43" fn c_abi_escaped() {
| - possibly return type missing here?
| - help: try adding a return type: `-> i32`
LL | 0
| ^ expected `()`, found integer

View File

@ -1,15 +1,19 @@
error[E0308]: mismatched types
--> $DIR/return-type.rs:10:5
|
LL | fn bar() {
| - possibly return type missing here?
LL | foo(4 as usize)
| ^^^^^^^^^^^^^^^- help: consider using a semicolon here: `;`
| |
| expected `()`, found struct `S`
| ^^^^^^^^^^^^^^^ expected `()`, found struct `S`
|
= note: expected unit type `()`
found struct `S<usize>`
help: consider using a semicolon here
|
LL | foo(4 as usize);
| +
help: try adding a return type
|
LL | fn bar() -> S<usize> {
| +++++++++++
error: aborting due to previous error

View File

@ -1,6 +1,8 @@
error[E0308]: mismatched types
--> $DIR/slightly-nice-generic-literal-messages.rs:7:9
|
LL | match Foo(1.1, marker::PhantomData) {
| ----------------------------- this expression has type `Foo<{float}, _>`
LL | 1 => {}
| ^ expected struct `Foo`, found integer
|

View File

@ -101,6 +101,8 @@ LL | type PointF = Point<f32>;
error[E0308]: mismatched types
--> $DIR/structure-constructor-type-mismatch.rs:54:9
|
LL | match (Point { x: 1, y: 2 }) {
| ---------------------- this expression has type `Point<{integer}>`
LL | PointF::<u32> { .. } => {}
| ^^^^^^^^^^^^^^^^^^^^ expected integer, found `f32`
|
@ -110,6 +112,8 @@ LL | PointF::<u32> { .. } => {}
error[E0308]: mismatched types
--> $DIR/structure-constructor-type-mismatch.rs:59:9
|
LL | match (Point { x: 1, y: 2 }) {
| ---------------------- this expression has type `Point<{integer}>`
LL | PointF { .. } => {}
| ^^^^^^^^^^^^^ expected integer, found `f32`
|
@ -119,6 +123,8 @@ LL | PointF { .. } => {}
error[E0308]: mismatched types
--> $DIR/structure-constructor-type-mismatch.rs:67:9
|
LL | match (Pair { x: 1, y: 2 }) {
| --------------------- this expression has type `Pair<{integer}, {integer}>`
LL | PairF::<u32> { .. } => {}
| ^^^^^^^^^^^^^^^^^^^ expected integer, found `f32`
|

View File

@ -40,7 +40,7 @@ error[E0308]: mismatched types
LL | fn f(){||yield(((){),
| -^^^^^^^^^^^^^^^ expected `()`, found generator
| |
| possibly return type missing here?
| help: a return type might be missing here: `-> _`
|
= note: expected unit type `()`
found generator `[generator@$DIR/issue-91334.rs:10:8: 10:23]`

View File

@ -1,10 +1,10 @@
#[allow(unused)]
fn foo() {
//~^ NOTE possibly return type missing here?
fn foo() { //~ HELP a return type might be missing here
vec!['a'].iter().map(|c| c)
//~^ ERROR mismatched types [E0308]
//~| NOTE expected `()`, found struct `Map`
//~| NOTE expected unit type `()`
//~| HELP consider using a semicolon here
}
fn main() {}

View File

@ -1,16 +1,19 @@
error[E0308]: mismatched types
--> $DIR/return_type_containing_closure.rs:4:5
--> $DIR/return_type_containing_closure.rs:3:5
|
LL | fn foo() {
| - possibly return type missing here?
LL |
LL | vec!['a'].iter().map(|c| c)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^- help: consider using a semicolon here: `;`
| |
| expected `()`, found struct `Map`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found struct `Map`
|
= note: expected unit type `()`
found struct `Map<std::slice::Iter<'_, char>, [closure@$DIR/return_type_containing_closure.rs:4:26: 4:31]>`
found struct `Map<std::slice::Iter<'_, char>, [closure@$DIR/return_type_containing_closure.rs:3:26: 3:31]>`
help: consider using a semicolon here
|
LL | vec!['a'].iter().map(|c| c);
| +
help: a return type might be missing here
|
LL | fn foo() -> _ {
| ++++
error: aborting due to previous error