Auto merge of #127326 - matthiaskrgr:rollup-kz7vd3w, r=matthiaskrgr

Rollup of 9 pull requests

Successful merges:

 - #123043 (Disable dead variant removal for `#[repr(C)]` enums.)
 - #126405 (Migrate some rustc_builtin_macros to SessionDiagnostic)
 - #127037 (Remove some duplicated tests)
 - #127283 (Reject SmartPointer constructions not serving the purpose)
 - #127301 (Tweak some structured suggestions to be more verbose and accurate)
 - #127307 (Allow to have different types for arguments of `Rustc::remap_path_prefix`)
 - #127309 (jsondocck: add `$FILE` built-in variable)
 - #127314 (Trivial update on tidy bless note)
 - #127319 (Remove a use of `StructuredDiag`, which is incompatible with automatic error tainting and error translations)

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2024-07-04 16:37:39 +00:00
commit 8a9cccb100
117 changed files with 2642 additions and 640 deletions

View File

@ -186,7 +186,7 @@ pub trait LayoutCalculator {
let (present_first, present_second) = {
let mut present_variants = variants
.iter_enumerated()
.filter_map(|(i, v)| if absent(v) { None } else { Some(i) });
.filter_map(|(i, v)| if !repr.c() && absent(v) { None } else { Some(i) });
(present_variants.next(), present_variants.next())
};
let present_first = match present_first {
@ -621,7 +621,7 @@ where
let discr_type = repr.discr_type();
let bits = Integer::from_attr(dl, discr_type).size().bits();
for (i, mut val) in discriminants {
if variants[i].iter().any(|f| f.abi.is_uninhabited()) {
if !repr.c() && variants[i].iter().any(|f| f.abi.is_uninhabited()) {
continue;
}
if discr_type.is_signed() {

View File

@ -1429,7 +1429,7 @@ pub enum Variants<FieldIdx: Idx, VariantIdx: Idx> {
/// Single enum variants, structs/tuples, unions, and all non-ADTs.
Single { index: VariantIdx },
/// Enum-likes with more than one inhabited variant: each variant comes with
/// Enum-likes with more than one variant: each variant comes with
/// a *discriminant* (usually the same as the variant index but the user can
/// assign explicit discriminant values). That discriminant is encoded
/// as a *tag* on the machine. The layout of each variant is

View File

@ -3757,13 +3757,11 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
assigned_span: Span,
err_place: Place<'tcx>,
) {
let (from_arg, local_decl, local_name) = match err_place.as_local() {
Some(local) => (
self.body.local_kind(local) == LocalKind::Arg,
Some(&self.body.local_decls[local]),
self.local_names[local],
),
None => (false, None, None),
let (from_arg, local_decl) = match err_place.as_local() {
Some(local) => {
(self.body.local_kind(local) == LocalKind::Arg, Some(&self.body.local_decls[local]))
}
None => (false, None),
};
// If root local is initialized immediately (everything apart from let
@ -3795,13 +3793,12 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
err.span_label(assigned_span, format!("first assignment to {place_description}"));
}
if let Some(decl) = local_decl
&& let Some(name) = local_name
&& decl.can_be_made_mutable()
{
err.span_suggestion(
decl.source_info.span,
err.span_suggestion_verbose(
decl.source_info.span.shrink_to_lo(),
"consider making this binding mutable",
format!("mut {name}"),
"mut ".to_string(),
Applicability::MachineApplicable,
);
if !from_arg
@ -3813,10 +3810,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
}))
)
{
err.span_suggestion(
decl.source_info.span,
err.span_suggestion_verbose(
decl.source_info.span.shrink_to_lo(),
"to modify the original value, take a borrow instead",
format!("ref mut {name}"),
"ref mut ".to_string(),
Applicability::MaybeIncorrect,
);
}

View File

@ -408,10 +408,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
fn_decl.implicit_self,
hir::ImplicitSelfKind::RefImm | hir::ImplicitSelfKind::RefMut
) {
err.span_suggestion(
upvar_ident.span,
err.span_suggestion_verbose(
upvar_ident.span.shrink_to_lo(),
"consider changing this to be mutable",
format!("mut {}", upvar_ident.name),
"mut ",
Applicability::MachineApplicable,
);
break;
@ -419,10 +419,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
}
}
} else {
err.span_suggestion(
upvar_ident.span,
err.span_suggestion_verbose(
upvar_ident.span.shrink_to_lo(),
"consider changing this to be mutable",
format!("mut {}", upvar_ident.name),
"mut ",
Applicability::MachineApplicable,
);
}
@ -449,8 +449,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
.is_ok_and(|snippet| snippet.starts_with("&mut ")) =>
{
err.span_label(span, format!("cannot {act}"));
err.span_suggestion(
span,
err.span_suggestion_verbose(
span.with_hi(span.lo() + BytePos(5)),
"try removing `&mut` here",
"",
Applicability::MaybeIncorrect,
@ -755,13 +755,16 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
pat: hir::Pat { kind: hir::PatKind::Ref(_, _), .. },
..
}) = node
&& let Ok(name) =
self.infcx.tcx.sess.source_map().span_to_snippet(local_decl.source_info.span)
{
err.span_suggestion(
pat_span,
err.multipart_suggestion(
"consider changing this to be mutable",
format!("&(mut {name})"),
vec![
(pat_span.until(local_decl.source_info.span), "&(mut ".to_string()),
(
local_decl.source_info.span.shrink_to_hi().with_hi(pat_span.hi()),
")".to_string(),
),
],
Applicability::MachineApplicable,
);
return;

View File

@ -17,6 +17,9 @@ builtin_macros_asm_expected_other = expected operand, {$is_global_asm ->
*[false] clobber_abi, options
}, or additional template string
builtin_macros_asm_expected_string_literal = expected string literal
.label = not a string literal
builtin_macros_asm_explicit_register_name = explicit register arguments cannot have names
builtin_macros_asm_mayunwind = asm labels are not allowed with the `may_unwind` option
@ -25,6 +28,8 @@ builtin_macros_asm_modifier_invalid = asm template modifier must be a single cha
builtin_macros_asm_mutually_exclusive = the `{$opt1}` and `{$opt2}` options are mutually exclusive
builtin_macros_asm_no_matched_argument_name = there is no argument named `{$name}`
builtin_macros_asm_noreturn = asm outputs are not allowed with the `noreturn` option
builtin_macros_asm_opt_already_provided = the `{$symbol}` option was already provided
@ -228,10 +233,16 @@ builtin_macros_only_one_argument = {$name} takes 1 argument
builtin_macros_proc_macro = `proc-macro` crate types currently cannot export any items other than functions tagged with `#[proc_macro]`, `#[proc_macro_derive]`, or `#[proc_macro_attribute]`
builtin_macros_proc_macro_attribute_only_be_used_on_bare_functions = the `#[{$path}]` attribute may only be used on bare functions
builtin_macros_proc_macro_attribute_only_usable_with_crate_type = the `#[{$path}]` attribute is only usable with crates of the `proc-macro` crate type
builtin_macros_requires_cfg_pattern =
macro requires a cfg-pattern as an argument
.label = cfg-pattern required
builtin_macros_source_uitls_expected_item = expected item, found `{$token}`
builtin_macros_takes_no_arguments = {$name} takes no arguments
builtin_macros_test_bad_fn = {$kind} functions cannot be used for tests

View File

@ -390,9 +390,7 @@ fn parse_clobber_abi<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> PResult<'a,
}
Err(opt_lit) => {
let span = opt_lit.map_or(p.token.span, |lit| lit.span);
let mut err = p.dcx().struct_span_err(span, "expected string literal");
err.span_label(span, "not a string literal");
return Err(err);
return Err(p.dcx().create_err(errors::AsmExpectedStringLiteral { span }));
}
};
@ -639,14 +637,13 @@ fn expand_preparsed_asm(
match args.named_args.get(&Symbol::intern(name)) {
Some(&idx) => Some(idx),
None => {
let msg = format!("there is no argument named `{name}`");
let span = arg.position_span;
ecx.dcx()
.struct_span_err(
template_span
.create_err(errors::AsmNoMatchedArgumentName {
name: name.to_owned(),
span: template_span
.from_inner(InnerSpan::new(span.start, span.end)),
msg,
)
})
.emit();
None
}

View File

@ -3,8 +3,9 @@ use std::mem::swap;
use ast::HasAttrs;
use rustc_ast::{
self as ast, GenericArg, GenericBound, GenericParamKind, ItemKind, MetaItem,
TraitBoundModifiers,
TraitBoundModifiers, VariantData,
};
use rustc_attr as attr;
use rustc_expand::base::{Annotatable, ExtCtxt};
use rustc_span::symbol::{sym, Ident};
use rustc_span::Span;
@ -24,11 +25,43 @@ pub fn expand_deriving_smart_ptr(
_is_const: bool,
) {
let (name_ident, generics) = if let Annotatable::Item(aitem) = item
&& let ItemKind::Struct(_, g) = &aitem.kind
&& let ItemKind::Struct(struct_data, g) = &aitem.kind
{
let is_transparent = aitem.attrs.iter().any(|attr| {
attr::find_repr_attrs(cx.sess, attr)
.into_iter()
.any(|r| matches!(r, attr::ReprTransparent))
});
if !is_transparent {
cx.dcx()
.struct_span_err(
span,
"`SmartPointer` can only be derived on `struct`s with `#[repr(transparent)]`",
)
.emit();
return;
}
if !matches!(
struct_data,
VariantData::Struct { fields, recovered: _ } | VariantData::Tuple(fields, _)
if !fields.is_empty())
{
cx.dcx()
.struct_span_err(
span,
"`SmartPointer` can only be derived on `struct`s with at least one field",
)
.emit();
return;
}
(aitem.ident, g)
} else {
cx.dcx().struct_span_err(span, "`SmartPointer` can only be derived on `struct`s").emit();
cx.dcx()
.struct_span_err(
span,
"`SmartPointer` can only be derived on `struct`s with `#[repr(transparent)]`",
)
.emit();
return;
};

View File

@ -728,6 +728,14 @@ pub(crate) struct AsmExpectedComma {
pub(crate) span: Span,
}
#[derive(Diagnostic)]
#[diag(builtin_macros_asm_expected_string_literal)]
pub(crate) struct AsmExpectedStringLiteral {
#[primary_span]
#[label]
pub(crate) span: Span,
}
#[derive(Diagnostic)]
#[diag(builtin_macros_asm_underscore_input)]
pub(crate) struct AsmUnderscoreInput {
@ -781,6 +789,14 @@ pub(crate) struct AsmNoReturn {
pub(crate) outputs_sp: Vec<Span>,
}
#[derive(Diagnostic)]
#[diag(builtin_macros_asm_no_matched_argument_name)]
pub(crate) struct AsmNoMatchedArgumentName {
pub(crate) name: String,
#[primary_span]
pub(crate) span: Span,
}
#[derive(Diagnostic)]
#[diag(builtin_macros_asm_mayunwind)]
pub(crate) struct AsmMayUnwind {
@ -872,3 +888,27 @@ pub(crate) struct TakesNoArguments<'a> {
pub span: Span,
pub name: &'a str,
}
#[derive(Diagnostic)]
#[diag(builtin_macros_proc_macro_attribute_only_be_used_on_bare_functions)]
pub(crate) struct AttributeOnlyBeUsedOnBareFunctions<'a> {
#[primary_span]
pub span: Span,
pub path: &'a str,
}
#[derive(Diagnostic)]
#[diag(builtin_macros_proc_macro_attribute_only_usable_with_crate_type)]
pub(crate) struct AttributeOnlyUsableWithCrateType<'a> {
#[primary_span]
pub span: Span,
pub path: &'a str,
}
#[derive(Diagnostic)]
#[diag(builtin_macros_source_uitls_expected_item)]
pub(crate) struct ExpectedItem<'a> {
#[primary_span]
pub span: Span,
pub token: &'a str,
}

View File

@ -214,12 +214,12 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
};
if !is_fn {
let msg = format!(
"the `#[{}]` attribute may only be used on bare functions",
pprust::path_to_string(&attr.get_normal_item().path),
);
self.dcx.span_err(attr.span, msg);
self.dcx
.create_err(errors::AttributeOnlyBeUsedOnBareFunctions {
span: attr.span,
path: &pprust::path_to_string(&attr.get_normal_item().path),
})
.emit();
return;
}
@ -228,12 +228,12 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
}
if !self.is_proc_macro_crate {
let msg = format!(
"the `#[{}]` attribute is only usable with crates of the `proc-macro` crate type",
pprust::path_to_string(&attr.get_normal_item().path),
);
self.dcx.span_err(attr.span, msg);
self.dcx
.create_err(errors::AttributeOnlyUsableWithCrateType {
span: attr.span,
path: &pprust::path_to_string(&attr.get_normal_item().path),
})
.emit();
return;
}

View File

@ -1,3 +1,4 @@
use crate::errors;
use crate::util::{
check_zero_tts, get_single_str_from_tts, get_single_str_spanned_from_tts, parse_expr,
};
@ -165,9 +166,13 @@ pub(crate) fn expand_include<'cx>(
Ok(Some(item)) => ret.push(item),
Ok(None) => {
if self.p.token != token::Eof {
let token = pprust::token_to_string(&self.p.token);
let msg = format!("expected item, found `{token}`");
self.p.dcx().span_err(self.p.token.span, msg);
self.p
.dcx()
.create_err(errors::ExpectedItem {
span: self.p.token.span,
token: &pprust::token_to_string(&self.p.token),
})
.emit();
}
break;

View File

@ -2273,9 +2273,26 @@ impl HumanEmitter {
&normalize_whitespace(last_line),
Style::NoStyle,
);
buffer.puts(*row_num, 0, &self.maybe_anonymized(line_num), Style::LineNumber);
buffer.puts(*row_num, max_line_num_len + 1, "+ ", Style::Addition);
buffer.append(*row_num, &normalize_whitespace(line_to_add), Style::NoStyle);
if !line_to_add.trim().is_empty() {
// Check if after the removal, the line is left with only whitespace. If so, we
// will not show an "addition" line, as removing the whole line is what the user
// would really want.
// For example, for the following:
// |
// 2 - .await
// 2 + (note the left over whitepsace)
// |
// We really want
// |
// 2 - .await
// |
// *row_num -= 1;
buffer.puts(*row_num, 0, &self.maybe_anonymized(line_num), Style::LineNumber);
buffer.puts(*row_num, max_line_num_len + 1, "+ ", Style::Addition);
buffer.append(*row_num, &normalize_whitespace(line_to_add), Style::NoStyle);
} else {
*row_num -= 1;
}
} else {
*row_num -= 2;
}

View File

@ -55,8 +55,6 @@ hir_analysis_cannot_capture_late_bound_ty =
cannot capture late-bound type parameter in {$what}
.label = parameter defined here
hir_analysis_cast_thin_pointer_to_fat_pointer = cannot cast thin pointer `{$expr_ty}` to fat pointer `{$cast_ty}`
hir_analysis_closure_implicit_hrtb = implicit types in closure signatures are forbidden when `for<...>` is present
.label = `for<...>` is here

View File

@ -453,12 +453,11 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for MissingTypeParams {
} else {
// The user wrote `Iterator`, so we don't have a type we can suggest, but at
// least we can clue them to the correct syntax `Iterator<Type>`.
err.span_suggestion(
self.span,
err.span_suggestion_verbose(
self.span.shrink_to_hi(),
fluent::hir_analysis_suggestion,
format!(
"{}<{}>",
snippet,
"<{}>",
self.missing_type_params
.iter()
.map(|n| n.to_string())
@ -707,15 +706,6 @@ pub(crate) struct PassToVariadicFunction<'tcx, 'a> {
pub help: Option<()>,
}
#[derive(Diagnostic)]
#[diag(hir_analysis_cast_thin_pointer_to_fat_pointer, code = E0607)]
pub(crate) struct CastThinPointerToFatPointer<'tcx> {
#[primary_span]
pub span: Span,
pub expr_ty: Ty<'tcx>,
pub cast_ty: String,
}
#[derive(Diagnostic)]
#[diag(hir_analysis_invalid_union_field, code = E0740)]
pub(crate) struct InvalidUnionField {

View File

@ -1,10 +1,7 @@
mod missing_cast_for_variadic_arg;
mod sized_unsized_cast;
mod wrong_number_of_generic_args;
pub use self::{
missing_cast_for_variadic_arg::*, sized_unsized_cast::*, wrong_number_of_generic_args::*,
};
pub use self::{missing_cast_for_variadic_arg::*, wrong_number_of_generic_args::*};
use rustc_errors::{Diag, ErrCode};
use rustc_session::Session;

View File

@ -1,56 +0,0 @@
use crate::{errors, structured_errors::StructuredDiag};
use rustc_errors::{codes::*, Diag};
use rustc_middle::ty::{Ty, TypeVisitableExt};
use rustc_session::Session;
use rustc_span::Span;
pub struct SizedUnsizedCast<'tcx> {
pub sess: &'tcx Session,
pub span: Span,
pub expr_ty: Ty<'tcx>,
pub cast_ty: String,
}
impl<'tcx> StructuredDiag<'tcx> for SizedUnsizedCast<'tcx> {
fn session(&self) -> &Session {
self.sess
}
fn code(&self) -> ErrCode {
E0607
}
fn diagnostic_common(&self) -> Diag<'tcx> {
let mut err = self.sess.dcx().create_err(errors::CastThinPointerToFatPointer {
span: self.span,
expr_ty: self.expr_ty,
cast_ty: self.cast_ty.to_owned(),
});
if self.expr_ty.references_error() {
err.downgrade_to_delayed_bug();
}
err
}
fn diagnostic_extended(&self, mut err: Diag<'tcx>) -> Diag<'tcx> {
err.help(
"Thin pointers are \"simple\" pointers: they are purely a reference to a
memory address.
Fat pointers are pointers referencing \"Dynamically Sized Types\" (also
called DST). DST don't have a statically known size, therefore they can
only exist behind some kind of pointers that contain additional
information. Slices and trait objects are DSTs. In the case of slices,
the additional information the fat pointer holds is their size.
To fix this error, don't try to cast directly between thin and fat
pointers.
For more information about casts, take a look at The Book:
https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions",
);
err
}
}

View File

@ -23,6 +23,21 @@ hir_typeck_cannot_cast_to_bool = cannot cast `{$expr_ty}` as `bool`
hir_typeck_cast_enum_drop = cannot cast enum `{$expr_ty}` into integer `{$cast_ty}` because it implements `Drop`
hir_typeck_cast_thin_pointer_to_fat_pointer = cannot cast thin pointer `{$expr_ty}` to fat pointer `{$cast_ty}`
.teach_help = Thin pointers are "simple" pointers: they are purely a reference to a
memory address.
Fat pointers are pointers referencing "Dynamically Sized Types" (also
called DST). DST don't have a statically known size, therefore they can
only exist behind some kind of pointers that contain additional
information. Slices and trait objects are DSTs. In the case of slices,
the additional information the fat pointer holds is their size.
To fix this error, don't try to cast directly between thin and fat
pointers.
For more information about casts, take a look at The Book:
https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions",
hir_typeck_cast_unknown_pointer = cannot cast {$to ->
[true] to
*[false] from

View File

@ -500,16 +500,12 @@ impl<'a, 'tcx> CastCheck<'tcx> {
err.emit();
}
CastError::SizedUnsizedCast => {
use rustc_hir_analysis::structured_errors::{SizedUnsizedCast, StructuredDiag};
SizedUnsizedCast {
sess: fcx.tcx.sess,
fcx.dcx().emit_err(errors::CastThinPointerToFatPointer {
span: self.span,
expr_ty: self.expr_ty,
cast_ty: fcx.ty_to_string(self.cast_ty),
}
.diagnostic()
.emit();
teach: fcx.tcx.sess.teach(E0607).then_some(()),
});
}
CastError::IntToFatCast(known_metadata) => {
let expr_if_nightly = fcx.tcx.sess.is_nightly_build().then_some(self.expr_span);

View File

@ -689,3 +689,14 @@ pub struct ReplaceWithName {
pub span: Span,
pub name: String,
}
#[derive(Diagnostic)]
#[diag(hir_typeck_cast_thin_pointer_to_fat_pointer, code = E0607)]
pub(crate) struct CastThinPointerToFatPointer<'tcx> {
#[primary_span]
pub span: Span,
pub expr_ty: Ty<'tcx>,
pub cast_ty: String,
#[note(hir_typeck_teach_help)]
pub(crate) teach: Option<()>,
}

View File

@ -2551,10 +2551,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
match *base_ty.peel_refs().kind() {
ty::Array(_, len) => {
self.maybe_suggest_array_indexing(&mut err, expr, base, ident, len);
self.maybe_suggest_array_indexing(&mut err, base, ident, len);
}
ty::RawPtr(..) => {
self.suggest_first_deref_field(&mut err, expr, base, ident);
self.suggest_first_deref_field(&mut err, base, ident);
}
ty::Param(param_ty) => {
err.span_label(ident.span, "unknown field");
@ -2721,7 +2721,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn maybe_suggest_array_indexing(
&self,
err: &mut Diag<'_>,
expr: &hir::Expr<'_>,
base: &hir::Expr<'_>,
field: Ident,
len: ty::Const<'tcx>,
@ -2729,32 +2728,41 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
err.span_label(field.span, "unknown field");
if let (Some(len), Ok(user_index)) =
(len.try_eval_target_usize(self.tcx, self.param_env), field.as_str().parse::<u64>())
&& let Ok(base) = self.tcx.sess.source_map().span_to_snippet(base.span)
{
let help = "instead of using tuple indexing, use array indexing";
let suggestion = format!("{base}[{field}]");
let applicability = if len < user_index {
Applicability::MachineApplicable
} else {
Applicability::MaybeIncorrect
};
err.span_suggestion(expr.span, help, suggestion, applicability);
err.multipart_suggestion(
help,
vec![
(base.span.between(field.span), "[".to_string()),
(field.span.shrink_to_hi(), "]".to_string()),
],
applicability,
);
}
}
fn suggest_first_deref_field(
&self,
err: &mut Diag<'_>,
expr: &hir::Expr<'_>,
base: &hir::Expr<'_>,
field: Ident,
) {
fn suggest_first_deref_field(&self, err: &mut Diag<'_>, base: &hir::Expr<'_>, field: Ident) {
err.span_label(field.span, "unknown field");
if let Ok(base) = self.tcx.sess.source_map().span_to_snippet(base.span) {
let msg = format!("`{base}` is a raw pointer; try dereferencing it");
let suggestion = format!("(*{base}).{field}");
err.span_suggestion(expr.span, msg, suggestion, Applicability::MaybeIncorrect);
}
let val = if let Ok(base) = self.tcx.sess.source_map().span_to_snippet(base.span)
&& base.len() < 20
{
format!("`{base}`")
} else {
"the value".to_string()
};
err.multipart_suggestion(
format!("{val} is a raw pointer; try dereferencing it"),
vec![
(base.span.shrink_to_lo(), "(*".to_string()),
(base.span.shrink_to_hi(), ")".to_string()),
],
Applicability::MaybeIncorrect,
);
}
fn no_such_field_err(&self, field: Ident, expr_t: Ty<'tcx>, id: HirId) -> Diag<'_> {

View File

@ -2499,7 +2499,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.any(|(ty, _)| matches!(ty.kind(), ty::Slice(..) | ty::Array(..)))
&& let Some(span) = ti.span
&& let Some(_) = ti.origin_expr
&& let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span)
{
let resolved_ty = self.resolve_vars_if_possible(ti.expected);
let (is_slice_or_array_or_vector, resolved_ty) =
@ -2510,10 +2509,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|| self.tcx.is_diagnostic_item(sym::Result, adt_def.did()) =>
{
// Slicing won't work here, but `.as_deref()` might (issue #91328).
err.span_suggestion(
span,
err.span_suggestion_verbose(
span.shrink_to_hi(),
"consider using `as_deref` here",
format!("{snippet}.as_deref()"),
".as_deref()",
Applicability::MaybeIncorrect,
);
}
@ -2522,10 +2521,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let is_top_level = current_depth <= 1;
if is_slice_or_array_or_vector && is_top_level {
err.span_suggestion(
span,
err.span_suggestion_verbose(
span.shrink_to_hi(),
"consider slicing here",
format!("{snippet}[..]"),
"[..]",
Applicability::MachineApplicable,
);
}

View File

@ -52,10 +52,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
) = tcx.sess.source_map().span_to_snippet(sp) =>
{
if snippet.chars().all(|c| c.is_digit(10) || c == '-' || c == '_') {
diag.span_suggestion(
sp,
diag.span_suggestion_verbose(
sp.shrink_to_hi(),
"use a float literal",
format!("{snippet}.0"),
".0",
MachineApplicable,
);
}

View File

@ -19,22 +19,22 @@ pub(super) fn visit_item(cx: &DocContext<'_>, item: &Item) {
};
let dox = item.doc_value();
if !dox.is_empty() {
let report_diag =
|cx: &DocContext<'_>, msg: &'static str, url: &str, range: Range<usize>| {
let sp =
source_span_for_markdown_range(cx.tcx, &dox, &range, &item.attrs.doc_strings)
.unwrap_or_else(|| item.attr_span(cx.tcx));
cx.tcx.node_span_lint(crate::lint::BARE_URLS, hir_id, sp, |lint| {
lint.primary_message(msg)
.note("bare URLs are not automatically turned into clickable links")
.span_suggestion(
sp,
"use an automatic link instead",
format!("<{url}>"),
Applicability::MachineApplicable,
);
});
};
let report_diag = |cx: &DocContext<'_>, msg: &'static str, range: Range<usize>| {
let sp = source_span_for_markdown_range(cx.tcx, &dox, &range, &item.attrs.doc_strings)
.unwrap_or_else(|| item.attr_span(cx.tcx));
cx.tcx.node_span_lint(crate::lint::BARE_URLS, hir_id, sp, |lint| {
lint.primary_message(msg)
.note("bare URLs are not automatically turned into clickable links")
.multipart_suggestion(
"use an automatic link instead",
vec![
(sp.shrink_to_lo(), "<".to_string()),
(sp.shrink_to_hi(), ">".to_string()),
],
Applicability::MachineApplicable,
);
});
};
let mut p = Parser::new_ext(&dox, main_body_opts()).into_offset_iter();
@ -74,17 +74,15 @@ fn find_raw_urls(
cx: &DocContext<'_>,
text: &str,
range: Range<usize>,
f: &impl Fn(&DocContext<'_>, &'static str, &str, Range<usize>),
f: &impl Fn(&DocContext<'_>, &'static str, Range<usize>),
) {
trace!("looking for raw urls in {text}");
// For now, we only check "full" URLs (meaning, starting with "http://" or "https://").
for match_ in URL_REGEX.find_iter(text) {
let url = match_.as_str();
let url_range = match_.range();
f(
cx,
"this URL is not a hyperlink",
url,
Range { start: range.start + url_range.start, end: range.start + url_range.end },
);
}

View File

@ -86,7 +86,6 @@ LL | dbg!();
help: remove the invocation before committing it to a version control system
|
LL - dbg!();
LL +
|
error: the `dbg!` macro is intended as a debugging tool
@ -146,7 +145,6 @@ LL | expand_to_dbg!();
help: remove the invocation before committing it to a version control system
|
LL - dbg!();
LL +
|
error: the `dbg!` macro is intended as a debugging tool

View File

@ -9,7 +9,6 @@ LL | dbg!();
help: remove the invocation before committing it to a version control system
|
LL - dbg!();
LL +
|
error: the `dbg!` macro is intended as a debugging tool

View File

@ -96,12 +96,10 @@ LL | let (l, r) = "a.b.c".split_once('.').unwrap();
help: remove the `iter` usages
|
LL - let l = iter.next().unwrap();
LL +
|
help: remove the `iter` usages
|
LL - let r = iter.next().unwrap();
LL +
|
error: manual implementation of `split_once`
@ -121,12 +119,10 @@ LL | let (l, r) = "a.b.c".split_once('.')?;
help: remove the `iter` usages
|
LL - let l = iter.next()?;
LL +
|
help: remove the `iter` usages
|
LL - let r = iter.next()?;
LL +
|
error: manual implementation of `rsplit_once`
@ -146,12 +142,10 @@ LL | let (l, r) = "a.b.c".rsplit_once('.').unwrap();
help: remove the `iter` usages
|
LL - let r = iter.next().unwrap();
LL +
|
help: remove the `iter` usages
|
LL - let l = iter.next().unwrap();
LL +
|
error: manual implementation of `rsplit_once`
@ -171,12 +165,10 @@ LL | let (l, r) = "a.b.c".rsplit_once('.')?;
help: remove the `iter` usages
|
LL - let r = iter.next()?;
LL +
|
help: remove the `iter` usages
|
LL - let l = iter.next()?;
LL +
|
error: manual implementation of `split_once`
@ -202,12 +194,10 @@ LL | let (a, b) = "a.b.c".split_once('.').unwrap();
help: remove the `iter` usages
|
LL - let a = iter.next().unwrap();
LL +
|
help: remove the `iter` usages
|
LL - let b = iter.next().unwrap();
LL +
|
error: aborting due to 19 previous errors

View File

@ -64,7 +64,6 @@ LL + let rslt0 = mutex.lock().unwrap().abs();
help: remove separated single usage
|
LL - let rslt0 = lock.abs();
LL +
|
error: temporary with significant `Drop` can be early dropped
@ -88,7 +87,6 @@ LL + mutex.lock().unwrap().clear();
help: remove separated single usage
|
LL - lock.clear();
LL +
|
error: aborting due to 4 previous errors

View File

@ -23,7 +23,7 @@ impl Cache {
Cache {
value: serde_json::from_str::<Value>(&content).expect("failed to convert from JSON"),
variables: HashMap::new(),
variables: HashMap::from([("FILE".to_owned(), config.template.clone().into())]),
}
}

View File

@ -108,7 +108,11 @@ impl Rustc {
}
/// Remap source path prefixes in all output.
pub fn remap_path_prefix<P: AsRef<Path>>(&mut self, from: P, to: P) -> &mut Self {
pub fn remap_path_prefix<P: AsRef<Path>, P2: AsRef<Path>>(
&mut self,
from: P,
to: P2,
) -> &mut Self {
let from = from.as_ref().to_string_lossy();
let to = to.as_ref().to_string_lossy();

View File

@ -95,7 +95,7 @@ pub fn check(tests_path: &Path, src_path: &Path, bless: bool, bad: &mut bool) {
tidy_error!(
bad,
"Makefile `{}` no longer exists and should be removed from the exclusions in \
`src/tools/tidy/src/allowed_run_make_makefiles.txt`, you can run --bless to update \
`src/tools/tidy/src/allowed_run_make_makefiles.txt`, you can run `x test tidy --bless` to update \
the allow list",
p.display()
);

View File

@ -2,7 +2,7 @@ error: this URL is not a hyperlink
--> $DIR/diagnostic-width.rs:4:41
|
LL | ... a http://link.com
| ^^^^^^^^^^^^^^^ help: use an automatic link instead: `<http://link.com>`
| ^^^^^^^^^^^^^^^
|
= note: bare URLs are not automatically turned into clickable links
note: the lint level is defined here
@ -10,6 +10,10 @@ note: the lint level is defined here
|
LL | ...ny(rustdoc::bare_url...
| ^^^^^^^^^^^^^^^^^^
help: use an automatic link instead
|
LL | /// This is a long line that contains a <http://link.com>
| + +
error: aborting due to 1 previous error

View File

@ -2,7 +2,7 @@ error: this URL is not a hyperlink
--> $DIR/auxiliary/include-str-bare-urls.md:1:11
|
LL | HEADS UP! https://example.com MUST SHOW UP IN THE STDERR FILE!
| ^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://example.com>`
| ^^^^^^^^^^^^^^^^^^^
|
= note: bare URLs are not automatically turned into clickable links
note: the lint level is defined here
@ -10,6 +10,10 @@ note: the lint level is defined here
|
LL | #![deny(rustdoc::bare_urls)]
| ^^^^^^^^^^^^^^^^^^
help: use an automatic link instead
|
LL | HEADS UP! <https://example.com> MUST SHOW UP IN THE STDERR FILE!
| + +
error: aborting due to 1 previous error

View File

@ -2,7 +2,7 @@ error: this URL is not a hyperlink
--> $DIR/bare-urls.rs:5:5
|
LL | /// https://somewhere.com
| ^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com>`
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: bare URLs are not automatically turned into clickable links
note: the lint level is defined here
@ -10,134 +10,202 @@ note: the lint level is defined here
|
LL | #![deny(rustdoc::bare_urls)]
| ^^^^^^^^^^^^^^^^^^
help: use an automatic link instead
|
LL | /// <https://somewhere.com>
| + +
error: this URL is not a hyperlink
--> $DIR/bare-urls.rs:7:5
|
LL | /// https://somewhere.com/a
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com/a>`
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: bare URLs are not automatically turned into clickable links
help: use an automatic link instead
|
LL | /// <https://somewhere.com/a>
| + +
error: this URL is not a hyperlink
--> $DIR/bare-urls.rs:9:5
|
LL | /// https://www.somewhere.com
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://www.somewhere.com>`
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: bare URLs are not automatically turned into clickable links
help: use an automatic link instead
|
LL | /// <https://www.somewhere.com>
| + +
error: this URL is not a hyperlink
--> $DIR/bare-urls.rs:11:5
|
LL | /// https://www.somewhere.com/a
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://www.somewhere.com/a>`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: bare URLs are not automatically turned into clickable links
help: use an automatic link instead
|
LL | /// <https://www.somewhere.com/a>
| + +
error: this URL is not a hyperlink
--> $DIR/bare-urls.rs:13:5
|
LL | /// https://subdomain.example.com
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://subdomain.example.com>`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: bare URLs are not automatically turned into clickable links
help: use an automatic link instead
|
LL | /// <https://subdomain.example.com>
| + +
error: this URL is not a hyperlink
--> $DIR/bare-urls.rs:15:5
|
LL | /// https://somewhere.com?
| ^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com?>`
| ^^^^^^^^^^^^^^^^^^^^^^
|
= note: bare URLs are not automatically turned into clickable links
help: use an automatic link instead
|
LL | /// <https://somewhere.com?>
| + +
error: this URL is not a hyperlink
--> $DIR/bare-urls.rs:17:5
|
LL | /// https://somewhere.com/a?
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com/a?>`
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: bare URLs are not automatically turned into clickable links
help: use an automatic link instead
|
LL | /// <https://somewhere.com/a?>
| + +
error: this URL is not a hyperlink
--> $DIR/bare-urls.rs:19:5
|
LL | /// https://somewhere.com?hello=12
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com?hello=12>`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: bare URLs are not automatically turned into clickable links
help: use an automatic link instead
|
LL | /// <https://somewhere.com?hello=12>
| + +
error: this URL is not a hyperlink
--> $DIR/bare-urls.rs:21:5
|
LL | /// https://somewhere.com/a?hello=12
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com/a?hello=12>`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: bare URLs are not automatically turned into clickable links
help: use an automatic link instead
|
LL | /// <https://somewhere.com/a?hello=12>
| + +
error: this URL is not a hyperlink
--> $DIR/bare-urls.rs:23:5
|
LL | /// https://example.com?hello=12#xyz
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://example.com?hello=12#xyz>`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: bare URLs are not automatically turned into clickable links
help: use an automatic link instead
|
LL | /// <https://example.com?hello=12#xyz>
| + +
error: this URL is not a hyperlink
--> $DIR/bare-urls.rs:25:5
|
LL | /// https://example.com/a?hello=12#xyz
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://example.com/a?hello=12#xyz>`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: bare URLs are not automatically turned into clickable links
help: use an automatic link instead
|
LL | /// <https://example.com/a?hello=12#xyz>
| + +
error: this URL is not a hyperlink
--> $DIR/bare-urls.rs:27:5
|
LL | /// https://example.com#xyz
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://example.com#xyz>`
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: bare URLs are not automatically turned into clickable links
help: use an automatic link instead
|
LL | /// <https://example.com#xyz>
| + +
error: this URL is not a hyperlink
--> $DIR/bare-urls.rs:29:5
|
LL | /// https://example.com/a#xyz
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://example.com/a#xyz>`
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: bare URLs are not automatically turned into clickable links
help: use an automatic link instead
|
LL | /// <https://example.com/a#xyz>
| + +
error: this URL is not a hyperlink
--> $DIR/bare-urls.rs:31:5
|
LL | /// https://somewhere.com?hello=12&bye=11
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com?hello=12&bye=11>`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: bare URLs are not automatically turned into clickable links
help: use an automatic link instead
|
LL | /// <https://somewhere.com?hello=12&bye=11>
| + +
error: this URL is not a hyperlink
--> $DIR/bare-urls.rs:33:5
|
LL | /// https://somewhere.com/a?hello=12&bye=11
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com/a?hello=12&bye=11>`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: bare URLs are not automatically turned into clickable links
help: use an automatic link instead
|
LL | /// <https://somewhere.com/a?hello=12&bye=11>
| + +
error: this URL is not a hyperlink
--> $DIR/bare-urls.rs:35:5
|
LL | /// https://somewhere.com?hello=12&bye=11#xyz
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com?hello=12&bye=11#xyz>`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: bare URLs are not automatically turned into clickable links
help: use an automatic link instead
|
LL | /// <https://somewhere.com?hello=12&bye=11#xyz>
| + +
error: this URL is not a hyperlink
--> $DIR/bare-urls.rs:37:10
|
LL | /// hey! https://somewhere.com/a?hello=12&bye=11#xyz
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com/a?hello=12&bye=11#xyz>`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: bare URLs are not automatically turned into clickable links
help: use an automatic link instead
|
LL | /// hey! <https://somewhere.com/a?hello=12&bye=11#xyz>
| + +
error: aborting due to 17 previous errors

View File

@ -29,7 +29,7 @@ error: this URL is not a hyperlink
--> $DIR/renamed-lint-still-applies.rs:9:5
|
LL | //! http://example.com
| ^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<http://example.com>`
| ^^^^^^^^^^^^^^^^^^
|
= note: bare URLs are not automatically turned into clickable links
note: the lint level is defined here
@ -37,6 +37,10 @@ note: the lint level is defined here
|
LL | #![deny(rustdoc::non_autolinks)]
| ^^^^^^^^^^^^^^^^^^^^^^
help: use an automatic link instead
|
LL | //! <http://example.com>
| + +
error: aborting due to 2 previous errors; 2 warnings emitted

View File

@ -271,6 +271,11 @@ test_abi_compatible!(zst_unit, Zst, ());
test_abi_compatible!(zst_array, Zst, [u8; 0]);
test_abi_compatible!(nonzero_int, NonZero<i32>, i32);
// `#[repr(C)]` enums should not change ABI based on individual variant inhabitedness.
// (However, this is *not* a guarantee. We only guarantee same layout, not same ABI.)
enum Void {}
test_abi_compatible!(repr_c_enum_void, ReprCEnum<Void>, ReprCEnum<ReprCUnion<Void>>);
// `DispatchFromDyn` relies on ABI compatibility.
// This is interesting since these types are not `repr(transparent)`. So this is not part of our
// public ABI guarantees, but is relied on by the compiler.

View File

@ -1,7 +1,7 @@
fn test() {
let v: isize;
//~^ HELP consider making this binding mutable
//~| SUGGESTION mut v
//~| SUGGESTION mut
v = 1; //~ NOTE first assignment
println!("v={}", v);
v = 2; //~ ERROR cannot assign twice to immutable variable

View File

@ -1,14 +1,16 @@
error[E0384]: cannot assign twice to immutable variable `v`
--> $DIR/assign-imm-local-twice.rs:7:5
|
LL | let v: isize;
| - help: consider making this binding mutable: `mut v`
...
LL | v = 1;
| ----- first assignment to `v`
LL | println!("v={}", v);
LL | v = 2;
| ^^^^^ cannot assign twice to immutable variable
|
help: consider making this binding mutable
|
LL | let mut v: isize;
| +++
error: aborting due to 1 previous error

View File

@ -35,9 +35,13 @@ LL | trait Add<Rhs=Self> {
| ------------------- type parameter `Rhs` must be specified for this
...
LL | type Test = dyn Add + Sub;
| ^^^ help: set the type parameter to the desired type: `Add<Rhs>`
| ^^^
|
= note: because of the default `Self` reference, type parameters must be specified on object types
help: set the type parameter to the desired type
|
LL | type Test = dyn Add<Rhs> + Sub;
| +++++
error[E0393]: the type parameter `Rhs` must be explicitly specified
--> $DIR/issue-22560.rs:9:23
@ -46,9 +50,13 @@ LL | trait Sub<Rhs=Self> {
| ------------------- type parameter `Rhs` must be specified for this
...
LL | type Test = dyn Add + Sub;
| ^^^ help: set the type parameter to the desired type: `Sub<Rhs>`
| ^^^
|
= note: because of the default `Self` reference, type parameters must be specified on object types
help: set the type parameter to the desired type
|
LL | type Test = dyn Add + Sub<Rhs>;
| +++++
error: aborting due to 4 previous errors

View File

@ -13,12 +13,14 @@ error[E0384]: cannot assign twice to immutable variable `x`
--> $DIR/issue-61452.rs:9:5
|
LL | pub async fn g(x: usize) {
| -
| |
| first assignment to `x`
| help: consider making this binding mutable: `mut x`
| - first assignment to `x`
LL | x += 1;
| ^^^^^^ cannot assign twice to immutable variable
|
help: consider making this binding mutable
|
LL | pub async fn g(mut x: usize) {
| +++
error: aborting due to 2 previous errors

View File

@ -12,11 +12,13 @@ LL | let mut x = 0;
error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
--> $DIR/borrow-raw-address-of-mutability.rs:11:17
|
LL | let x = 0;
| - help: consider changing this to be mutable: `mut x`
LL | let mut f = || {
LL | let y = &raw mut x;
| ^^^^^^^^^^ cannot borrow as mutable
|
help: consider changing this to be mutable
|
LL | let mut x = 0;
| +++
error[E0596]: cannot borrow `f` as mutable, as it is not declared as mutable
--> $DIR/borrow-raw-address-of-mutability.rs:21:5

View File

@ -43,10 +43,13 @@ LL | c1;
error[E0594]: cannot assign to `x`, as it is not declared as mutable
--> $DIR/borrowck-closures-unique.rs:43:38
|
LL | fn e(x: &'static mut isize) {
| - help: consider changing this to be mutable: `mut x`
LL | let c1 = |y: &'static mut isize| x = y;
| ^^^^^ cannot assign
|
help: consider changing this to be mutable
|
LL | fn e(mut x: &'static mut isize) {
| +++
error: aborting due to 4 previous errors

View File

@ -9,11 +9,11 @@ LL | x += 1;
help: consider making this binding mutable
|
LL | mut x => {
| ~~~~~
| +++
help: to modify the original value, take a borrow instead
|
LL | ref mut x => {
| ~~~~~~~~~
| +++++++
error[E0384]: cannot assign twice to immutable variable `x`
--> $DIR/borrowck-match-binding-is-assignment.rs:20:13
@ -26,11 +26,11 @@ LL | x += 1;
help: consider making this binding mutable
|
LL | E::Foo(mut x) => {
| ~~~~~
| +++
help: to modify the original value, take a borrow instead
|
LL | E::Foo(ref mut x) => {
| ~~~~~~~~~
| +++++++
error[E0384]: cannot assign twice to immutable variable `x`
--> $DIR/borrowck-match-binding-is-assignment.rs:26:13
@ -43,11 +43,11 @@ LL | x += 1;
help: consider making this binding mutable
|
LL | S { bar: mut x } => {
| ~~~~~
| +++
help: to modify the original value, take a borrow instead
|
LL | S { bar: ref mut x } => {
| ~~~~~~~~~
| +++++++
error[E0384]: cannot assign twice to immutable variable `x`
--> $DIR/borrowck-match-binding-is-assignment.rs:32:13
@ -60,11 +60,11 @@ LL | x += 1;
help: consider making this binding mutable
|
LL | (mut x,) => {
| ~~~~~
| +++
help: to modify the original value, take a borrow instead
|
LL | (ref mut x,) => {
| ~~~~~~~~~
| +++++++
error[E0384]: cannot assign twice to immutable variable `x`
--> $DIR/borrowck-match-binding-is-assignment.rs:38:13
@ -77,11 +77,11 @@ LL | x += 1;
help: consider making this binding mutable
|
LL | [mut x,_,_] => {
| ~~~~~
| +++
help: to modify the original value, take a borrow instead
|
LL | [ref mut x,_,_] => {
| ~~~~~~~~~
| +++++++
error: aborting due to 5 previous errors

View File

@ -1,10 +1,13 @@
error[E0384]: cannot assign to immutable argument `_x`
--> $DIR/immutable-arg.rs:2:5
|
LL | fn foo(_x: u32) {
| -- help: consider making this binding mutable: `mut _x`
LL | _x = 4;
| ^^^^^^ cannot assign to immutable argument
|
help: consider making this binding mutable
|
LL | fn foo(mut _x: u32) {
| +++
error: aborting due to 1 previous error

View File

@ -19,10 +19,13 @@ LL | || bar(&mut self);
error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable
--> $DIR/issue-111554.rs:21:16
|
LL | pub fn quux(self) {
| ---- help: consider changing this to be mutable: `mut self`
LL | || bar(&mut self);
| ^^^^^^^^^ cannot borrow as mutable
|
help: consider changing this to be mutable
|
LL | pub fn quux(mut self) {
| +++
error: aborting due to 4 previous errors

View File

@ -2,10 +2,13 @@ error[E0596]: cannot borrow `v` as mutable, as it is not declared as mutable
--> $DIR/issue-33819.rs:4:34
|
LL | Some(ref v) => { let a = &mut v; },
| ^^^^^^
| |
| cannot borrow as mutable
| help: try removing `&mut` here
| ^^^^^^ cannot borrow as mutable
|
help: try removing `&mut` here
|
LL - Some(ref v) => { let a = &mut v; },
LL + Some(ref v) => { let a = v; },
|
error: aborting due to 1 previous error

View File

@ -1,7 +1,7 @@
fn test_drop_replace() {
let b: Box<isize>;
//~^ HELP consider making this binding mutable
//~| SUGGESTION mut b
//~| SUGGESTION mut
b = Box::new(1); //~ NOTE first assignment
b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b`
//~| NOTE cannot assign twice to immutable
@ -10,13 +10,13 @@ fn test_drop_replace() {
fn test_call() {
let b = Box::new(1); //~ NOTE first assignment
//~| HELP consider making this binding mutable
//~| SUGGESTION mut b
//~| SUGGESTION mut
b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b`
//~| NOTE cannot assign twice to immutable
}
fn test_args(b: Box<i32>) { //~ HELP consider making this binding mutable
//~| SUGGESTION mut b
//~| SUGGESTION mut
b = Box::new(2); //~ ERROR cannot assign to immutable argument `b`
//~| NOTE cannot assign to immutable argument
}

View File

@ -1,34 +1,40 @@
error[E0384]: cannot assign twice to immutable variable `b`
--> $DIR/issue-45199.rs:6:5
|
LL | let b: Box<isize>;
| - help: consider making this binding mutable: `mut b`
...
LL | b = Box::new(1);
| - first assignment to `b`
LL | b = Box::new(2);
| ^ cannot assign twice to immutable variable
|
help: consider making this binding mutable
|
LL | let mut b: Box<isize>;
| +++
error[E0384]: cannot assign twice to immutable variable `b`
--> $DIR/issue-45199.rs:14:5
|
LL | let b = Box::new(1);
| -
| |
| first assignment to `b`
| help: consider making this binding mutable: `mut b`
| - first assignment to `b`
...
LL | b = Box::new(2);
| ^ cannot assign twice to immutable variable
|
help: consider making this binding mutable
|
LL | let mut b = Box::new(1);
| +++
error[E0384]: cannot assign to immutable argument `b`
--> $DIR/issue-45199.rs:20:5
|
LL | fn test_args(b: Box<i32>) {
| - help: consider making this binding mutable: `mut b`
LL |
LL | b = Box::new(2);
| ^ cannot assign to immutable argument
|
help: consider making this binding mutable
|
LL | fn test_args(mut b: Box<i32>) {
| +++
error: aborting due to 3 previous errors

View File

@ -44,56 +44,68 @@ LL | borrowck_closures_unique::e(addr_of_mut!(X));
error[E0594]: cannot assign to `x`, as it is not declared as mutable
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:9:46
|
LL | pub fn e(x: &'static mut isize) {
| - help: consider changing this to be mutable: `mut x`
LL | static mut Y: isize = 3;
LL | let mut c1 = |y: &'static mut isize| x = y;
| ^^^^^ cannot assign
|
help: consider changing this to be mutable
|
LL | pub fn e(mut x: &'static mut isize) {
| +++
error[E0594]: cannot assign to `x`, as it is not declared as mutable
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:22:50
|
LL | pub fn ee(x: &'static mut isize) {
| - help: consider changing this to be mutable: `mut x`
...
LL | let mut c2 = |y: &'static mut isize| x = y;
| ^^^^^ cannot assign
|
help: consider changing this to be mutable
|
LL | pub fn ee(mut x: &'static mut isize) {
| +++
error[E0594]: cannot assign to `x`, as it is not declared as mutable
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:37:13
|
LL | pub fn capture_assign_whole(x: (i32,)) {
| - help: consider changing this to be mutable: `mut x`
LL | || {
LL | x = (1,);
| ^^^^^^^^ cannot assign
|
help: consider changing this to be mutable
|
LL | pub fn capture_assign_whole(mut x: (i32,)) {
| +++
error[E0594]: cannot assign to `x.0`, as `x` is not declared as mutable
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:43:13
|
LL | pub fn capture_assign_part(x: (i32,)) {
| - help: consider changing this to be mutable: `mut x`
LL | || {
LL | x.0 = 1;
| ^^^^^^^ cannot assign
|
help: consider changing this to be mutable
|
LL | pub fn capture_assign_part(mut x: (i32,)) {
| +++
error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:49:13
|
LL | pub fn capture_reborrow_whole(x: (i32,)) {
| - help: consider changing this to be mutable: `mut x`
LL | || {
LL | &mut x;
| ^^^^^^ cannot borrow as mutable
|
help: consider changing this to be mutable
|
LL | pub fn capture_reborrow_whole(mut x: (i32,)) {
| +++
error[E0596]: cannot borrow `x.0` as mutable, as `x` is not declared as mutable
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:55:13
|
LL | pub fn capture_reborrow_part(x: (i32,)) {
| - help: consider changing this to be mutable: `mut x`
LL | || {
LL | &mut x.0;
| ^^^^^^^^ cannot borrow as mutable
|
help: consider changing this to be mutable
|
LL | pub fn capture_reborrow_part(mut x: (i32,)) {
| +++
error: aborting due to 6 previous errors; 3 warnings emitted

View File

@ -262,74 +262,90 @@ LL | fn imm_local(mut x: (i32,)) {
error[E0594]: cannot assign to `x`, as it is not declared as mutable
--> $DIR/mutability-errors.rs:60:9
|
LL | fn imm_capture(x: (i32,)) {
| - help: consider changing this to be mutable: `mut x`
LL | || {
LL | x = (1,);
| ^^^^^^^^ cannot assign
|
help: consider changing this to be mutable
|
LL | fn imm_capture(mut x: (i32,)) {
| +++
error[E0594]: cannot assign to `x.0`, as `x` is not declared as mutable
--> $DIR/mutability-errors.rs:61:9
|
LL | fn imm_capture(x: (i32,)) {
| - help: consider changing this to be mutable: `mut x`
...
LL | x.0 = 1;
| ^^^^^^^ cannot assign
|
help: consider changing this to be mutable
|
LL | fn imm_capture(mut x: (i32,)) {
| +++
error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
--> $DIR/mutability-errors.rs:62:9
|
LL | fn imm_capture(x: (i32,)) {
| - help: consider changing this to be mutable: `mut x`
...
LL | &mut x;
| ^^^^^^ cannot borrow as mutable
|
help: consider changing this to be mutable
|
LL | fn imm_capture(mut x: (i32,)) {
| +++
error[E0596]: cannot borrow `x.0` as mutable, as `x` is not declared as mutable
--> $DIR/mutability-errors.rs:63:9
|
LL | fn imm_capture(x: (i32,)) {
| - help: consider changing this to be mutable: `mut x`
...
LL | &mut x.0;
| ^^^^^^^^ cannot borrow as mutable
|
help: consider changing this to be mutable
|
LL | fn imm_capture(mut x: (i32,)) {
| +++
error[E0594]: cannot assign to `x`, as it is not declared as mutable
--> $DIR/mutability-errors.rs:66:9
|
LL | fn imm_capture(x: (i32,)) {
| - help: consider changing this to be mutable: `mut x`
...
LL | x = (1,);
| ^^^^^^^^ cannot assign
|
help: consider changing this to be mutable
|
LL | fn imm_capture(mut x: (i32,)) {
| +++
error[E0594]: cannot assign to `x.0`, as `x` is not declared as mutable
--> $DIR/mutability-errors.rs:67:9
|
LL | fn imm_capture(x: (i32,)) {
| - help: consider changing this to be mutable: `mut x`
...
LL | x.0 = 1;
| ^^^^^^^ cannot assign
|
help: consider changing this to be mutable
|
LL | fn imm_capture(mut x: (i32,)) {
| +++
error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
--> $DIR/mutability-errors.rs:68:9
|
LL | fn imm_capture(x: (i32,)) {
| - help: consider changing this to be mutable: `mut x`
...
LL | &mut x;
| ^^^^^^ cannot borrow as mutable
|
help: consider changing this to be mutable
|
LL | fn imm_capture(mut x: (i32,)) {
| +++
error[E0596]: cannot borrow `x.0` as mutable, as `x` is not declared as mutable
--> $DIR/mutability-errors.rs:69:9
|
LL | fn imm_capture(x: (i32,)) {
| - help: consider changing this to be mutable: `mut x`
...
LL | &mut x.0;
| ^^^^^^^^ cannot borrow as mutable
|
help: consider changing this to be mutable
|
LL | fn imm_capture(mut x: (i32,)) {
| +++
error[E0594]: cannot assign to immutable static item `X`
--> $DIR/mutability-errors.rs:76:5

View File

@ -9,11 +9,11 @@ LL | x = 2;
help: consider making this binding mutable
|
LL | if let Some(mut x) = y {
| ~~~~~
| +++
help: to modify the original value, take a borrow instead
|
LL | if let Some(ref mut x) = y {
| ~~~~~~~~~
| +++++++
error[E0384]: cannot assign twice to immutable variable `x`
--> $DIR/suggest-ref-mut-issue-118596.rs:9:5
@ -26,11 +26,11 @@ LL | x = 0;
help: consider making this binding mutable
|
LL | let [mut x, ref xs_hold @ ..] = arr;
| ~~~~~
| +++
help: to modify the original value, take a borrow instead
|
LL | let [ref mut x, ref xs_hold @ ..] = arr;
| ~~~~~~~~~
| +++++++
error: aborting due to 2 previous errors

View File

@ -2,12 +2,14 @@ error[E0384]: cannot assign twice to immutable variable `a`
--> $DIR/tainted-promoteds.rs:7:5
|
LL | let a = 0;
| -
| |
| first assignment to `a`
| help: consider making this binding mutable: `mut a`
| - first assignment to `a`
LL | a = &0 * &1 * &2 * &3;
| ^^^^^^^^^^^^^^^^^^^^^ cannot assign twice to immutable variable
|
help: consider making this binding mutable
|
LL | let mut a = 0;
| +++
error: aborting due to 1 previous error

View File

@ -1,18 +1,24 @@
error[E0594]: cannot assign to `x`, as it is not declared as mutable
--> $DIR/cannot-mutate-captured-non-mut-var.rs:9:25
|
LL | let x = 1;
| - help: consider changing this to be mutable: `mut x`
LL | to_fn_once(move|| { x = 2; });
| ^^^^^ cannot assign
|
help: consider changing this to be mutable
|
LL | let mut x = 1;
| +++
error[E0596]: cannot borrow `s` as mutable, as it is not declared as mutable
--> $DIR/cannot-mutate-captured-non-mut-var.rs:13:25
|
LL | let s = std::io::stdin();
| - help: consider changing this to be mutable: `mut s`
LL | to_fn_once(move|| { s.read_to_end(&mut Vec::new()); });
| ^ cannot borrow as mutable
|
help: consider changing this to be mutable
|
LL | let mut s = std::io::stdin();
| +++
error: aborting due to 2 previous errors

View File

@ -1,11 +1,13 @@
error[E0596]: cannot borrow `x[..]` as mutable, as `x` is not declared as mutable
--> $DIR/array_subslice.rs:7:21
|
LL | pub fn subslice_array(x: [u8; 3]) {
| - help: consider changing this to be mutable: `mut x`
...
LL | let [ref y, ref mut z @ ..] = x;
| ^^^^^^^^^ cannot borrow as mutable
|
help: consider changing this to be mutable
|
LL | pub fn subslice_array(mut x: [u8; 3]) {
| +++
error[E0596]: cannot borrow `f` as mutable, as it is not declared as mutable
--> $DIR/array_subslice.rs:10:5

View File

@ -1,20 +1,24 @@
error[E0594]: cannot assign to `z.0.0.0`, as it is not declared as mutable
--> $DIR/cant-mutate-imm.rs:12:9
|
LL | let z = (y, 10);
| - help: consider changing this to be mutable: `mut z`
...
LL | z.0.0.0 = 20;
| ^^^^^^^^^^^^ cannot assign
|
help: consider changing this to be mutable
|
LL | let mut z = (y, 10);
| +++
error[E0594]: cannot assign to `*bx.0`, as it is not declared as mutable
--> $DIR/cant-mutate-imm.rs:24:9
|
LL | let bx = Box::new(x);
| -- help: consider changing this to be mutable: `mut bx`
...
LL | bx.0 = 20;
| ^^^^^^^^^ cannot assign
|
help: consider changing this to be mutable
|
LL | let mut bx = Box::new(x);
| +++
error: aborting due to 2 previous errors

View File

@ -1,10 +1,13 @@
error[E0594]: cannot assign to `y`, as it is not declared as mutable
--> $DIR/closure-immutable-outer-variable.rs:11:26
|
LL | let y = true;
| - help: consider changing this to be mutable: `mut y`
LL | foo(Box::new(move || y = !y) as Box<_>);
| ^^^^^^ cannot assign
|
help: consider changing this to be mutable
|
LL | let mut y = true;
| +++
error: aborting due to 1 previous error

View File

@ -2,12 +2,14 @@ error[E0384]: cannot assign twice to immutable variable `x`
--> $DIR/command-line-diagnostics.rs:6:5
|
LL | let x = 42;
| -
| |
| first assignment to `x`
| help: consider making this binding mutable: `mut x`
| - first assignment to `x`
LL | x = 43;
| ^^^^^^ cannot assign twice to immutable variable
|
help: consider making this binding mutable
|
LL | let mut x = 42;
| +++
error: aborting due to 1 previous error

View File

@ -20,24 +20,32 @@ error[E0393]: the type parameter `Rhs` must be explicitly specified
--> $DIR/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.rs:16:27
|
LL | ) -> impl Iterator<Item = SubAssign> {
| ^^^^^^^^^ help: set the type parameter to the desired type: `SubAssign<Rhs>`
| ^^^^^^^^^
--> $SRC_DIR/core/src/ops/arith.rs:LL:COL
|
= note: type parameter `Rhs` must be specified for this
|
= note: because of the default `Self` reference, type parameters must be specified on object types
help: set the type parameter to the desired type
|
LL | ) -> impl Iterator<Item = SubAssign<Rhs>> {
| +++++
error[E0393]: the type parameter `Rhs` must be explicitly specified
--> $DIR/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.rs:16:27
|
LL | ) -> impl Iterator<Item = SubAssign> {
| ^^^^^^^^^ help: set the type parameter to the desired type: `SubAssign<Rhs>`
| ^^^^^^^^^
--> $SRC_DIR/core/src/ops/arith.rs:LL:COL
|
= note: type parameter `Rhs` must be specified for this
|
= note: because of the default `Self` reference, type parameters must be specified on object types
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: set the type parameter to the desired type
|
LL | ) -> impl Iterator<Item = SubAssign<Rhs>> {
| +++++
error[E0277]: `()` is not an iterator
--> $DIR/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.rs:16:6

View File

@ -2,10 +2,12 @@ error[E0308]: mismatched types
--> $DIR/issue-39974.rs:1:21
|
LL | const LENGTH: f64 = 2;
| ^
| |
| expected `f64`, found integer
| help: use a float literal: `2.0`
| ^ expected `f64`, found integer
|
help: use a float literal
|
LL | const LENGTH: f64 = 2.0;
| ++
error[E0308]: mismatched types
--> $DIR/issue-39974.rs:5:19

View File

@ -0,0 +1,4 @@
const FOO: &str = unsafe { &*(1_usize as *const [i64; 0] as *const [u8] as *const str) };
//~^ ERROR: cannot cast
fn main() {}

View File

@ -0,0 +1,9 @@
error[E0607]: cannot cast thin pointer `*const [i64; 0]` to fat pointer `*const [u8]`
--> $DIR/slice_elem_ty_mismatch_in_unsizing_cast.rs:1:31
|
LL | const FOO: &str = unsafe { &*(1_usize as *const [i64; 0] as *const [u8] as *const str) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0607`.

View File

@ -0,0 +1,45 @@
#![feature(derive_smart_pointer, arbitrary_self_types)]
use std::marker::SmartPointer;
#[derive(SmartPointer)]
//~^ ERROR: `SmartPointer` can only be derived on `struct`s with `#[repr(transparent)]`
enum NotStruct<'a, T: ?Sized> {
Variant(&'a T),
}
#[derive(SmartPointer)]
//~^ ERROR: At least one generic type should be designated as `#[pointee]` in order to derive `SmartPointer` traits
#[repr(transparent)]
struct NoPointee<'a, T: ?Sized> {
ptr: &'a T,
}
#[derive(SmartPointer)]
//~^ ERROR: `SmartPointer` can only be derived on `struct`s with at least one field
#[repr(transparent)]
struct NoField<'a, #[pointee] T: ?Sized> {}
//~^ ERROR: lifetime parameter `'a` is never used
//~| ERROR: type parameter `T` is never used
#[derive(SmartPointer)]
//~^ ERROR: `SmartPointer` can only be derived on `struct`s with at least one field
#[repr(transparent)]
struct NoFieldUnit<'a, #[pointee] T: ?Sized>();
//~^ ERROR: lifetime parameter `'a` is never used
//~| ERROR: type parameter `T` is never used
#[derive(SmartPointer)]
//~^ ERROR: `SmartPointer` can only be derived on `struct`s with `#[repr(transparent)]`
struct NotTransparent<'a, #[pointee] T: ?Sized> {
ptr: &'a T,
}
// However, reordering attributes should work nevertheless.
#[repr(transparent)]
#[derive(SmartPointer)]
struct ThisIsAPossibleSmartPointer<'a, #[pointee] T: ?Sized> {
ptr: &'a T,
}
fn main() {}

View File

@ -0,0 +1,75 @@
error: `SmartPointer` can only be derived on `struct`s with `#[repr(transparent)]`
--> $DIR/deriving-smart-pointer-neg.rs:5:10
|
LL | #[derive(SmartPointer)]
| ^^^^^^^^^^^^
|
= note: this error originates in the derive macro `SmartPointer` (in Nightly builds, run with -Z macro-backtrace for more info)
error: At least one generic type should be designated as `#[pointee]` in order to derive `SmartPointer` traits
--> $DIR/deriving-smart-pointer-neg.rs:11:10
|
LL | #[derive(SmartPointer)]
| ^^^^^^^^^^^^
|
= note: this error originates in the derive macro `SmartPointer` (in Nightly builds, run with -Z macro-backtrace for more info)
error: `SmartPointer` can only be derived on `struct`s with at least one field
--> $DIR/deriving-smart-pointer-neg.rs:18:10
|
LL | #[derive(SmartPointer)]
| ^^^^^^^^^^^^
|
= note: this error originates in the derive macro `SmartPointer` (in Nightly builds, run with -Z macro-backtrace for more info)
error: `SmartPointer` can only be derived on `struct`s with at least one field
--> $DIR/deriving-smart-pointer-neg.rs:25:10
|
LL | #[derive(SmartPointer)]
| ^^^^^^^^^^^^
|
= note: this error originates in the derive macro `SmartPointer` (in Nightly builds, run with -Z macro-backtrace for more info)
error: `SmartPointer` can only be derived on `struct`s with `#[repr(transparent)]`
--> $DIR/deriving-smart-pointer-neg.rs:32:10
|
LL | #[derive(SmartPointer)]
| ^^^^^^^^^^^^
|
= note: this error originates in the derive macro `SmartPointer` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0392]: lifetime parameter `'a` is never used
--> $DIR/deriving-smart-pointer-neg.rs:21:16
|
LL | struct NoField<'a, #[pointee] T: ?Sized> {}
| ^^ unused lifetime parameter
|
= help: consider removing `'a`, referring to it in a field, or using a marker such as `PhantomData`
error[E0392]: type parameter `T` is never used
--> $DIR/deriving-smart-pointer-neg.rs:21:31
|
LL | struct NoField<'a, #[pointee] T: ?Sized> {}
| ^ unused type parameter
|
= help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`
error[E0392]: lifetime parameter `'a` is never used
--> $DIR/deriving-smart-pointer-neg.rs:28:20
|
LL | struct NoFieldUnit<'a, #[pointee] T: ?Sized>();
| ^^ unused lifetime parameter
|
= help: consider removing `'a`, referring to it in a field, or using a marker such as `PhantomData`
error[E0392]: type parameter `T` is never used
--> $DIR/deriving-smart-pointer-neg.rs:28:35
|
LL | struct NoFieldUnit<'a, #[pointee] T: ?Sized>();
| ^ unused type parameter
|
= help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`
error: aborting due to 9 previous errors
For more information about this error, try `rustc --explain E0392`.

View File

@ -4,6 +4,7 @@
use std::marker::SmartPointer;
#[derive(SmartPointer)]
#[repr(transparent)]
struct MyPointer<'a, #[pointee] T: ?Sized> {
ptr: &'a T,
}

View File

@ -2,10 +2,13 @@ error[E0596]: cannot borrow `key` as mutable, as it is not declared as mutable
--> $DIR/issue-34337.rs:6:9
|
LL | get(&mut key);
| ^^^^^^^^
| |
| cannot borrow as mutable
| help: try removing `&mut` here
| ^^^^^^^^ cannot borrow as mutable
|
help: try removing `&mut` here
|
LL - get(&mut key);
LL + get(key);
|
error: aborting due to 1 previous error

View File

@ -2,10 +2,13 @@ error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
--> $DIR/issue-37139.rs:12:18
|
LL | test(&mut x);
| ^^^^^^
| |
| cannot borrow as mutable
| help: try removing `&mut` here
| ^^^^^^ cannot borrow as mutable
|
help: try removing `&mut` here
|
LL - test(&mut x);
LL + test(x);
|
error: aborting due to 1 previous error

View File

@ -2,31 +2,40 @@ error[E0308]: mismatched types
--> $DIR/issue-53280-expected-float-found-integer-literal.rs:2:24
|
LL | let sixteen: f32 = 16;
| --- ^^
| | |
| | expected `f32`, found integer
| | help: use a float literal: `16.0`
| --- ^^ expected `f32`, found integer
| |
| expected due to this
|
help: use a float literal
|
LL | let sixteen: f32 = 16.0;
| ++
error[E0308]: mismatched types
--> $DIR/issue-53280-expected-float-found-integer-literal.rs:5:38
|
LL | let a_million_and_seventy: f64 = 1_000_070;
| --- ^^^^^^^^^
| | |
| | expected `f64`, found integer
| | help: use a float literal: `1_000_070.0`
| --- ^^^^^^^^^ expected `f64`, found integer
| |
| expected due to this
|
help: use a float literal
|
LL | let a_million_and_seventy: f64 = 1_000_070.0;
| ++
error[E0308]: mismatched types
--> $DIR/issue-53280-expected-float-found-integer-literal.rs:8:30
|
LL | let negative_nine: f32 = -9;
| --- ^^
| | |
| | expected `f32`, found integer
| | help: use a float literal: `-9.0`
| --- ^^ expected `f32`, found integer
| |
| expected due to this
|
help: use a float literal
|
LL | let negative_nine: f32 = -9.0;
| ++
error[E0308]: mismatched types
--> $DIR/issue-53280-expected-float-found-integer-literal.rs:15:30

View File

@ -5,9 +5,13 @@ LL | trait A<T=Self> {}
| --------------- type parameter `T` must be specified for this
LL |
LL | fn together_we_will_rule_the_galaxy(son: &dyn A) {}
| ^ help: set the type parameter to the desired type: `A<T>`
| ^
|
= note: because of the default `Self` reference, type parameters must be specified on object types
help: set the type parameter to the desired type
|
LL | fn together_we_will_rule_the_galaxy(son: &dyn A<T>) {}
| +++
error: aborting due to 1 previous error

View File

@ -1,6 +1,7 @@
use std::marker::SmartPointer; //~ ERROR use of unstable library feature 'derive_smart_pointer'
#[derive(SmartPointer)] //~ ERROR use of unstable library feature 'derive_smart_pointer'
#[repr(transparent)]
struct MyPointer<'a, #[pointee] T: ?Sized> {
//~^ ERROR the `#[pointee]` attribute is an experimental feature
ptr: &'a T,

View File

@ -9,7 +9,7 @@ LL | #[derive(SmartPointer)]
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
error[E0658]: the `#[pointee]` attribute is an experimental feature
--> $DIR/feature-gate-derive-smart-pointer.rs:4:22
--> $DIR/feature-gate-derive-smart-pointer.rs:5:22
|
LL | struct MyPointer<'a, #[pointee] T: ?Sized> {
| ^^^^^^^^^^

View File

@ -34,11 +34,13 @@ LL | fn fun() -> _ {
error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
--> $DIR/suggest-return-closure.rs:23:9
|
LL | let x = String::new();
| - help: consider changing this to be mutable: `mut x`
...
LL | x.push(c);
| ^ cannot borrow as mutable
|
help: consider changing this to be mutable
|
LL | let mut x = String::new();
| +++
error[E0597]: `x` does not live long enough
--> $DIR/suggest-return-closure.rs:23:9

View File

@ -2,19 +2,23 @@ error[E0609]: no field `x` on type `*mut A`
--> $DIR/issue-11004.rs:7:21
|
LL | let x : i32 = n.x;
| --^
| | |
| | unknown field
| help: `n` is a raw pointer; try dereferencing it: `(*n).x`
| ^ unknown field
|
help: `n` is a raw pointer; try dereferencing it
|
LL | let x : i32 = (*n).x;
| ++ +
error[E0609]: no field `y` on type `*mut A`
--> $DIR/issue-11004.rs:8:21
|
LL | let y : f64 = n.y;
| --^
| | |
| | unknown field
| help: `n` is a raw pointer; try dereferencing it: `(*n).y`
| ^ unknown field
|
help: `n` is a raw pointer; try dereferencing it
|
LL | let y : f64 = (*n).y;
| ++ +
error: aborting due to 2 previous errors

View File

@ -14,9 +14,13 @@ LL | trait Add<Rhs=Self> {
| ------------------- type parameter `Rhs` must be specified for this
...
LL | let x = &10 as &dyn Add;
| ^^^ help: set the type parameter to the desired type: `Add<Rhs>`
| ^^^
|
= note: because of the default `Self` reference, type parameters must be specified on object types
help: set the type parameter to the desired type
|
LL | let x = &10 as &dyn Add<Rhs>;
| +++++
error: aborting due to 2 previous errors

View File

@ -5,9 +5,13 @@ LL | trait A<T=Self> {}
| --------------- type parameter `T` must be specified for this
LL |
LL | fn f(a: &dyn A) {}
| ^ help: set the type parameter to the desired type: `A<T>`
| ^
|
= note: because of the default `Self` reference, type parameters must be specified on object types
help: set the type parameter to the desired type
|
LL | fn f(a: &dyn A<T>) {}
| +++
error: aborting due to 1 previous error

View File

@ -2,9 +2,12 @@ error[E0529]: expected an array or slice, found `Vec<{integer}>`
--> $DIR/let-else-slicing-error.rs:6:9
|
LL | let [x, y] = nums else {
| ^^^^^^ ---- help: consider slicing here: `nums[..]`
| |
| pattern cannot match with input type `Vec<{integer}>`
| ^^^^^^ pattern cannot match with input type `Vec<{integer}>`
|
help: consider slicing here
|
LL | let [x, y] = nums[..] else {
| ++++
error: aborting due to 1 previous error

View File

@ -16,10 +16,13 @@ LL | fn foo<'a>(mut x: Ref<'a, 'a>, y: &'a u32) {
error[E0384]: cannot assign to immutable argument `y`
--> $DIR/ex3-both-anon-regions-one-is-struct-2.rs:4:5
|
LL | fn foo(mut x: Ref, y: &u32) {
| - help: consider making this binding mutable: `mut y`
LL | y = x.b;
| ^^^^^^^ cannot assign to immutable argument
|
help: consider making this binding mutable
|
LL | fn foo(mut x: Ref, mut y: &u32) {
| +++
error: aborting due to 2 previous errors

View File

@ -1,45 +1,53 @@
error[E0384]: cannot assign twice to immutable variable `x`
--> $DIR/liveness-assign-imm-local-notes.rs:10:9
|
LL | let x;
| - help: consider making this binding mutable: `mut x`
...
LL | x = 2;
| ----- first assignment to `x`
LL | x = 3;
| ^^^^^ cannot assign twice to immutable variable
|
help: consider making this binding mutable
|
LL | let mut x;
| +++
error[E0384]: cannot assign twice to immutable variable `x`
--> $DIR/liveness-assign-imm-local-notes.rs:21:13
|
LL | let x;
| - help: consider making this binding mutable: `mut x`
...
LL | x = 2;
| ----- first assignment to `x`
LL | x = 3;
| ^^^^^ cannot assign twice to immutable variable
|
help: consider making this binding mutable
|
LL | let mut x;
| +++
error[E0384]: cannot assign twice to immutable variable `x`
--> $DIR/liveness-assign-imm-local-notes.rs:30:13
|
LL | let x;
| - help: consider making this binding mutable: `mut x`
...
LL | x = 1;
| ^^^^^ cannot assign twice to immutable variable
|
help: consider making this binding mutable
|
LL | let mut x;
| +++
error[E0384]: cannot assign twice to immutable variable `x`
--> $DIR/liveness-assign-imm-local-notes.rs:32:13
|
LL | let x;
| - help: consider making this binding mutable: `mut x`
...
LL | x = 1;
| ----- first assignment to `x`
LL | } else {
LL | x = 2;
| ^^^^^ cannot assign twice to immutable variable
|
help: consider making this binding mutable
|
LL | let mut x;
| +++
error: aborting due to 4 previous errors

View File

@ -1,7 +1,7 @@
fn test() {
let v: isize;
//~^ HELP consider making this binding mutable
//~| SUGGESTION mut v
//~| SUGGESTION mut
loop {
v = 1; //~ ERROR cannot assign twice to immutable variable `v`
//~| NOTE cannot assign twice to immutable variable

View File

@ -1,11 +1,13 @@
error[E0384]: cannot assign twice to immutable variable `v`
--> $DIR/liveness-assign-imm-local-in-loop.rs:6:9
|
LL | let v: isize;
| - help: consider making this binding mutable: `mut v`
...
LL | v = 1;
| ^^^^^ cannot assign twice to immutable variable
|
help: consider making this binding mutable
|
LL | let mut v: isize;
| +++
error: aborting due to 1 previous error

View File

@ -1,7 +1,7 @@
fn test() {
let v: isize;
//~^ HELP consider making this binding mutable
//~| SUGGESTION mut v
//~| SUGGESTION mut
v = 2; //~ NOTE first assignment
v += 1; //~ ERROR cannot assign twice to immutable variable `v`
//~| NOTE cannot assign twice to immutable

View File

@ -1,13 +1,15 @@
error[E0384]: cannot assign twice to immutable variable `v`
--> $DIR/liveness-assign-imm-local-in-op-eq.rs:6:5
|
LL | let v: isize;
| - help: consider making this binding mutable: `mut v`
...
LL | v = 2;
| ----- first assignment to `v`
LL | v += 1;
| ^^^^^^ cannot assign twice to immutable variable
|
help: consider making this binding mutable
|
LL | let mut v: isize;
| +++
error: aborting due to 1 previous error

View File

@ -1,7 +1,7 @@
fn test() {
let b = Box::new(1); //~ NOTE first assignment
//~| HELP consider making this binding mutable
//~| SUGGESTION mut b
//~| SUGGESTION mut
drop(b);
b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b`
//~| NOTE cannot assign twice to immutable

View File

@ -2,13 +2,15 @@ error[E0384]: cannot assign twice to immutable variable `b`
--> $DIR/liveness-assign-imm-local-with-drop.rs:6:5
|
LL | let b = Box::new(1);
| -
| |
| first assignment to `b`
| help: consider making this binding mutable: `mut b`
| - first assignment to `b`
...
LL | b = Box::new(2);
| ^ cannot assign twice to immutable variable
|
help: consider making this binding mutable
|
LL | let mut b = Box::new(1);
| +++
error: aborting due to 1 previous error

View File

@ -1,7 +1,7 @@
fn test() {
let v: isize = 1; //~ NOTE first assignment
//~| HELP consider making this binding mutable
//~| SUGGESTION mut v
//~| SUGGESTION mut
v.clone();
v = 2; //~ ERROR cannot assign twice to immutable variable `v`
//~| NOTE cannot assign twice to immutable

View File

@ -2,13 +2,15 @@ error[E0384]: cannot assign twice to immutable variable `v`
--> $DIR/liveness-assign-imm-local-with-init.rs:6:5
|
LL | let v: isize = 1;
| -
| |
| first assignment to `v`
| help: consider making this binding mutable: `mut v`
| - first assignment to `v`
...
LL | v = 2;
| ^^^^^ cannot assign twice to immutable variable
|
help: consider making this binding mutable
|
LL | let mut v: isize = 1;
| +++
error: aborting due to 1 previous error

View File

@ -2,11 +2,14 @@ error[E0308]: mismatched types
--> $DIR/float-literal-inference-restrictions.rs:2:18
|
LL | let x: f32 = 1;
| --- ^
| | |
| | expected `f32`, found integer
| | help: use a float literal: `1.0`
| --- ^ expected `f32`, found integer
| |
| expected due to this
|
help: use a float literal
|
LL | let x: f32 = 1.0;
| ++
error[E0308]: mismatched types
--> $DIR/float-literal-inference-restrictions.rs:3:18

View File

@ -9,11 +9,11 @@ LL | x += 1;
help: consider making this binding mutable
|
LL | let &mut mut x = foo;
| ~~~~~
| +++
help: to modify the original value, take a borrow instead
|
LL | let &mut ref mut x = foo;
| ~~~~~~~~~
| +++++++
error[E0506]: cannot assign to `*foo` because it is borrowed
--> $DIR/mut-pattern-internal-mutability.rs:13:5

View File

@ -1,38 +1,46 @@
error[E0594]: cannot assign to `x`, as it is not declared as mutable
--> $DIR/closure-captures.rs:7:5
|
LL | fn one_closure(x: i32) {
| - help: consider changing this to be mutable: `mut x`
LL | ||
LL | x = 1;
| ^^^^^ cannot assign
|
help: consider changing this to be mutable
|
LL | fn one_closure(mut x: i32) {
| +++
error[E0594]: cannot assign to `x`, as it is not declared as mutable
--> $DIR/closure-captures.rs:9:5
|
LL | fn one_closure(x: i32) {
| - help: consider changing this to be mutable: `mut x`
...
LL | x = 1;
| ^^^^^ cannot assign
|
help: consider changing this to be mutable
|
LL | fn one_closure(mut x: i32) {
| +++
error[E0594]: cannot assign to `x`, as it is not declared as mutable
--> $DIR/closure-captures.rs:15:9
|
LL | fn two_closures(x: i32) {
| - help: consider changing this to be mutable: `mut x`
...
LL | x = 1;
| ^^^^^ cannot assign
|
help: consider changing this to be mutable
|
LL | fn two_closures(mut x: i32) {
| +++
error[E0594]: cannot assign to `x`, as it is not declared as mutable
--> $DIR/closure-captures.rs:19:9
|
LL | fn two_closures(x: i32) {
| - help: consider changing this to be mutable: `mut x`
...
LL | x = 1;
| ^^^^^ cannot assign
|
help: consider changing this to be mutable
|
LL | fn two_closures(mut x: i32) {
| +++
error[E0596]: cannot borrow `x` as mutable, as it is a captured variable in a `Fn` closure
--> $DIR/closure-captures.rs:27:9
@ -67,11 +75,13 @@ LL | x = 1;});
error[E0594]: cannot assign to `x`, as it is not declared as mutable
--> $DIR/closure-captures.rs:39:10
|
LL | fn two_closures_ref(x: i32) {
| - help: consider changing this to be mutable: `mut x`
...
LL | x = 1;}
| ^^^^^ cannot assign
|
help: consider changing this to be mutable
|
LL | fn two_closures_ref(mut x: i32) {
| +++
error[E0596]: cannot borrow `x` as mutable, as it is a captured variable in a `Fn` closure
--> $DIR/closure-captures.rs:38:9
@ -91,11 +101,13 @@ LL | x = 1;}
error[E0594]: cannot assign to `x`, as it is not declared as mutable
--> $DIR/closure-captures.rs:43:5
|
LL | fn two_closures_ref(x: i32) {
| - help: consider changing this to be mutable: `mut x`
...
LL | x = 1;});
| ^^^^^ cannot assign
|
help: consider changing this to be mutable
|
LL | fn two_closures_ref(mut x: i32) {
| +++
error[E0596]: cannot borrow `x` as mutable, as it is a captured variable in a `Fn` closure
--> $DIR/closure-captures.rs:42:9

View File

@ -1,11 +1,13 @@
error[E0594]: cannot assign to `x`, as it is not declared as mutable
--> $DIR/coroutine-upvar-mutability.rs:10:9
|
LL | let x = 0;
| - help: consider changing this to be mutable: `mut x`
...
LL | x = 1;
| ^^^^^ cannot assign
|
help: consider changing this to be mutable
|
LL | let mut x = 0;
| +++
error: aborting due to 1 previous error

View File

@ -1,11 +1,13 @@
error[E0594]: cannot assign to `x`, as it is not declared as mutable
--> $DIR/issue-46023.rs:5:9
|
LL | let x = 0;
| - help: consider changing this to be mutable: `mut x`
...
LL | x = 1;
| ^^^^^ cannot assign
|
help: consider changing this to be mutable
|
LL | let mut x = 0;
| +++
error: aborting due to 1 previous error

View File

@ -78,11 +78,11 @@ LL | | Err(a @ b @ a)
help: consider making this binding mutable
|
LL | Ok(a @ b @ mut a)
| ~~~~~
| +++
help: to modify the original value, take a borrow instead
|
LL | Ok(a @ b @ ref mut a)
| ~~~~~~~~~
| +++++++
error: aborting due to 12 previous errors

View File

@ -22,11 +22,11 @@ LL | _x1 = U;
help: consider making this binding mutable
|
LL | let [ref _x0_hold, mut _x1, ref xs_hold @ ..] = arr;
| ~~~~~~~
| +++
help: to modify the original value, take a borrow instead
|
LL | let [ref _x0_hold, ref mut _x1, ref xs_hold @ ..] = arr;
| ~~~~~~~~~~~
| +++++++
error[E0505]: cannot move out of `arr[..]` because it is borrowed
--> $DIR/borrowck-move-ref-pattern.rs:11:10
@ -86,11 +86,11 @@ LL | _x1 = U;
help: consider making this binding mutable
|
LL | let (ref _x0, mut _x1, ref _x2, ..) = tup;
| ~~~~~~~
| +++
help: to modify the original value, take a borrow instead
|
LL | let (ref _x0, ref mut _x1, ref _x2, ..) = tup;
| ~~~~~~~~~~~
| +++++++
error[E0502]: cannot borrow `tup.0` as mutable because it is also borrowed as immutable
--> $DIR/borrowck-move-ref-pattern.rs:24:20

View File

@ -9,11 +9,11 @@ LL | a = 42;
help: consider making this binding mutable
|
LL | let Foo(mut a) = Foo(0);
| ~~~~~
| +++
help: to modify the original value, take a borrow instead
|
LL | let Foo(ref mut a) = Foo(0);
| ~~~~~~~~~
| +++++++
error[E0384]: cannot assign twice to immutable variable `a`
--> $DIR/mut-ref-mut-2021.rs:15:5

View File

@ -1,10 +1,13 @@
error[E0596]: cannot borrow `b` as mutable, as it is not declared as mutable
--> $DIR/patkind-ref-binding-issue-114896.rs:7:9
|
LL | let &b = a;
| -- help: consider changing this to be mutable: `&(mut b)`
LL | b.make_ascii_uppercase();
| ^ cannot borrow as mutable
|
help: consider changing this to be mutable
|
LL | let &(mut b) = a;
| ~~~~~ +
error: aborting due to 1 previous error

View File

@ -1,10 +1,13 @@
error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
--> $DIR/patkind-ref-binding-issue-122415.rs:7:12
|
LL | fn foo(&x: &i32) {
| -- help: consider changing this to be mutable: `&(mut x)`
LL | mutate(&mut x);
| ^^^^^^ cannot borrow as mutable
|
help: consider changing this to be mutable
|
LL | fn foo(&(mut x): &i32) {
| ~~~~~ +
error: aborting due to 1 previous error

View File

@ -0,0 +1,288 @@
error: layout_of(Univariant) = Layout {
size: Size(4 bytes),
align: AbiAndPrefAlign {
abi: Align(4 bytes),
pref: $SOME_ALIGN,
},
abi: Uninhabited,
fields: Arbitrary {
offsets: [
Size(0 bytes),
],
memory_index: [
0,
],
},
largest_niche: Some(
Niche {
offset: Size(0 bytes),
value: Int(
I32,
false,
),
valid_range: 0..=0,
},
),
variants: Multiple {
tag: Initialized {
value: Int(
I32,
false,
),
valid_range: 0..=0,
},
tag_encoding: Direct,
tag_field: 0,
variants: [
Layout {
size: Size(4 bytes),
align: AbiAndPrefAlign {
abi: Align(4 bytes),
pref: $SOME_ALIGN,
},
abi: Uninhabited,
fields: Arbitrary {
offsets: [
Size(4 bytes),
],
memory_index: [
0,
],
},
largest_niche: None,
variants: Single {
index: 0,
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
}
--> $DIR/repr-c-dead-variants.rs:38:1
|
LL | enum Univariant {
| ^^^^^^^^^^^^^^^
error: layout_of(TwoVariants) = Layout {
size: Size(8 bytes),
align: AbiAndPrefAlign {
abi: Align(4 bytes),
pref: $SOME_ALIGN,
},
abi: ScalarPair(
Initialized {
value: Int(
I32,
false,
),
valid_range: 0..=1,
},
Union {
value: Int(
I8,
false,
),
},
),
fields: Arbitrary {
offsets: [
Size(0 bytes),
],
memory_index: [
0,
],
},
largest_niche: Some(
Niche {
offset: Size(0 bytes),
value: Int(
I32,
false,
),
valid_range: 0..=1,
},
),
variants: Multiple {
tag: Initialized {
value: Int(
I32,
false,
),
valid_range: 0..=1,
},
tag_encoding: Direct,
tag_field: 0,
variants: [
Layout {
size: Size(4 bytes),
align: AbiAndPrefAlign {
abi: Align(4 bytes),
pref: $SOME_ALIGN,
},
abi: Uninhabited,
fields: Arbitrary {
offsets: [
Size(4 bytes),
],
memory_index: [
0,
],
},
largest_niche: None,
variants: Single {
index: 0,
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
},
Layout {
size: Size(8 bytes),
align: AbiAndPrefAlign {
abi: Align(4 bytes),
pref: $SOME_ALIGN,
},
abi: ScalarPair(
Initialized {
value: Int(
I32,
false,
),
valid_range: 0..=1,
},
Union {
value: Int(
I8,
false,
),
},
),
fields: Arbitrary {
offsets: [
Size(4 bytes),
],
memory_index: [
0,
],
},
largest_niche: None,
variants: Single {
index: 1,
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
}
--> $DIR/repr-c-dead-variants.rs:45:1
|
LL | enum TwoVariants {
| ^^^^^^^^^^^^^^^^
error: layout_of(DeadBranchHasOtherField) = Layout {
size: Size(16 bytes),
align: AbiAndPrefAlign {
abi: Align(8 bytes),
pref: $SOME_ALIGN,
},
abi: Aggregate {
sized: true,
},
fields: Arbitrary {
offsets: [
Size(0 bytes),
],
memory_index: [
0,
],
},
largest_niche: Some(
Niche {
offset: Size(0 bytes),
value: Int(
I32,
false,
),
valid_range: 0..=1,
},
),
variants: Multiple {
tag: Initialized {
value: Int(
I32,
false,
),
valid_range: 0..=1,
},
tag_encoding: Direct,
tag_field: 0,
variants: [
Layout {
size: Size(16 bytes),
align: AbiAndPrefAlign {
abi: Align(8 bytes),
pref: $SOME_ALIGN,
},
abi: Uninhabited,
fields: Arbitrary {
offsets: [
Size(8 bytes),
Size(8 bytes),
],
memory_index: [
0,
1,
],
},
largest_niche: None,
variants: Single {
index: 0,
},
max_repr_align: Some(
Align(8 bytes),
),
unadjusted_abi_align: Align(8 bytes),
},
Layout {
size: Size(16 bytes),
align: AbiAndPrefAlign {
abi: Align(8 bytes),
pref: $SOME_ALIGN,
},
abi: Aggregate {
sized: true,
},
fields: Arbitrary {
offsets: [
Size(8 bytes),
],
memory_index: [
0,
],
},
largest_niche: None,
variants: Single {
index: 1,
},
max_repr_align: None,
unadjusted_abi_align: Align(8 bytes),
},
],
},
max_repr_align: Some(
Align(8 bytes),
),
unadjusted_abi_align: Align(8 bytes),
}
--> $DIR/repr-c-dead-variants.rs:57:1
|
LL | enum DeadBranchHasOtherField {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 3 previous errors

View File

@ -0,0 +1,288 @@
error: layout_of(Univariant) = Layout {
size: Size(1 bytes),
align: AbiAndPrefAlign {
abi: Align(1 bytes),
pref: $SOME_ALIGN,
},
abi: Uninhabited,
fields: Arbitrary {
offsets: [
Size(0 bytes),
],
memory_index: [
0,
],
},
largest_niche: Some(
Niche {
offset: Size(0 bytes),
value: Int(
I8,
false,
),
valid_range: 0..=0,
},
),
variants: Multiple {
tag: Initialized {
value: Int(
I8,
false,
),
valid_range: 0..=0,
},
tag_encoding: Direct,
tag_field: 0,
variants: [
Layout {
size: Size(1 bytes),
align: AbiAndPrefAlign {
abi: Align(1 bytes),
pref: $SOME_ALIGN,
},
abi: Uninhabited,
fields: Arbitrary {
offsets: [
Size(1 bytes),
],
memory_index: [
0,
],
},
largest_niche: None,
variants: Single {
index: 0,
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
}
--> $DIR/repr-c-dead-variants.rs:38:1
|
LL | enum Univariant {
| ^^^^^^^^^^^^^^^
error: layout_of(TwoVariants) = Layout {
size: Size(2 bytes),
align: AbiAndPrefAlign {
abi: Align(1 bytes),
pref: $SOME_ALIGN,
},
abi: ScalarPair(
Initialized {
value: Int(
I8,
false,
),
valid_range: 0..=1,
},
Union {
value: Int(
I8,
false,
),
},
),
fields: Arbitrary {
offsets: [
Size(0 bytes),
],
memory_index: [
0,
],
},
largest_niche: Some(
Niche {
offset: Size(0 bytes),
value: Int(
I8,
false,
),
valid_range: 0..=1,
},
),
variants: Multiple {
tag: Initialized {
value: Int(
I8,
false,
),
valid_range: 0..=1,
},
tag_encoding: Direct,
tag_field: 0,
variants: [
Layout {
size: Size(1 bytes),
align: AbiAndPrefAlign {
abi: Align(1 bytes),
pref: $SOME_ALIGN,
},
abi: Uninhabited,
fields: Arbitrary {
offsets: [
Size(1 bytes),
],
memory_index: [
0,
],
},
largest_niche: None,
variants: Single {
index: 0,
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
},
Layout {
size: Size(2 bytes),
align: AbiAndPrefAlign {
abi: Align(1 bytes),
pref: $SOME_ALIGN,
},
abi: ScalarPair(
Initialized {
value: Int(
I8,
false,
),
valid_range: 0..=1,
},
Union {
value: Int(
I8,
false,
),
},
),
fields: Arbitrary {
offsets: [
Size(1 bytes),
],
memory_index: [
0,
],
},
largest_niche: None,
variants: Single {
index: 1,
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
}
--> $DIR/repr-c-dead-variants.rs:45:1
|
LL | enum TwoVariants {
| ^^^^^^^^^^^^^^^^
error: layout_of(DeadBranchHasOtherField) = Layout {
size: Size(16 bytes),
align: AbiAndPrefAlign {
abi: Align(8 bytes),
pref: $SOME_ALIGN,
},
abi: Aggregate {
sized: true,
},
fields: Arbitrary {
offsets: [
Size(0 bytes),
],
memory_index: [
0,
],
},
largest_niche: Some(
Niche {
offset: Size(0 bytes),
value: Int(
I8,
false,
),
valid_range: 0..=1,
},
),
variants: Multiple {
tag: Initialized {
value: Int(
I8,
false,
),
valid_range: 0..=1,
},
tag_encoding: Direct,
tag_field: 0,
variants: [
Layout {
size: Size(16 bytes),
align: AbiAndPrefAlign {
abi: Align(8 bytes),
pref: $SOME_ALIGN,
},
abi: Uninhabited,
fields: Arbitrary {
offsets: [
Size(8 bytes),
Size(8 bytes),
],
memory_index: [
0,
1,
],
},
largest_niche: None,
variants: Single {
index: 0,
},
max_repr_align: Some(
Align(8 bytes),
),
unadjusted_abi_align: Align(8 bytes),
},
Layout {
size: Size(16 bytes),
align: AbiAndPrefAlign {
abi: Align(8 bytes),
pref: $SOME_ALIGN,
},
abi: Aggregate {
sized: true,
},
fields: Arbitrary {
offsets: [
Size(8 bytes),
],
memory_index: [
0,
],
},
largest_niche: None,
variants: Single {
index: 1,
},
max_repr_align: None,
unadjusted_abi_align: Align(8 bytes),
},
],
},
max_repr_align: Some(
Align(8 bytes),
),
unadjusted_abi_align: Align(8 bytes),
}
--> $DIR/repr-c-dead-variants.rs:57:1
|
LL | enum DeadBranchHasOtherField {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 3 previous errors

View File

@ -0,0 +1,288 @@
error: layout_of(Univariant) = Layout {
size: Size(4 bytes),
align: AbiAndPrefAlign {
abi: Align(4 bytes),
pref: $SOME_ALIGN,
},
abi: Uninhabited,
fields: Arbitrary {
offsets: [
Size(0 bytes),
],
memory_index: [
0,
],
},
largest_niche: Some(
Niche {
offset: Size(0 bytes),
value: Int(
I32,
false,
),
valid_range: 0..=0,
},
),
variants: Multiple {
tag: Initialized {
value: Int(
I32,
false,
),
valid_range: 0..=0,
},
tag_encoding: Direct,
tag_field: 0,
variants: [
Layout {
size: Size(4 bytes),
align: AbiAndPrefAlign {
abi: Align(4 bytes),
pref: $SOME_ALIGN,
},
abi: Uninhabited,
fields: Arbitrary {
offsets: [
Size(4 bytes),
],
memory_index: [
0,
],
},
largest_niche: None,
variants: Single {
index: 0,
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
}
--> $DIR/repr-c-dead-variants.rs:38:1
|
LL | enum Univariant {
| ^^^^^^^^^^^^^^^
error: layout_of(TwoVariants) = Layout {
size: Size(8 bytes),
align: AbiAndPrefAlign {
abi: Align(4 bytes),
pref: $SOME_ALIGN,
},
abi: ScalarPair(
Initialized {
value: Int(
I32,
false,
),
valid_range: 0..=1,
},
Union {
value: Int(
I8,
false,
),
},
),
fields: Arbitrary {
offsets: [
Size(0 bytes),
],
memory_index: [
0,
],
},
largest_niche: Some(
Niche {
offset: Size(0 bytes),
value: Int(
I32,
false,
),
valid_range: 0..=1,
},
),
variants: Multiple {
tag: Initialized {
value: Int(
I32,
false,
),
valid_range: 0..=1,
},
tag_encoding: Direct,
tag_field: 0,
variants: [
Layout {
size: Size(4 bytes),
align: AbiAndPrefAlign {
abi: Align(4 bytes),
pref: $SOME_ALIGN,
},
abi: Uninhabited,
fields: Arbitrary {
offsets: [
Size(4 bytes),
],
memory_index: [
0,
],
},
largest_niche: None,
variants: Single {
index: 0,
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
},
Layout {
size: Size(8 bytes),
align: AbiAndPrefAlign {
abi: Align(4 bytes),
pref: $SOME_ALIGN,
},
abi: ScalarPair(
Initialized {
value: Int(
I32,
false,
),
valid_range: 0..=1,
},
Union {
value: Int(
I8,
false,
),
},
),
fields: Arbitrary {
offsets: [
Size(4 bytes),
],
memory_index: [
0,
],
},
largest_niche: None,
variants: Single {
index: 1,
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
}
--> $DIR/repr-c-dead-variants.rs:45:1
|
LL | enum TwoVariants {
| ^^^^^^^^^^^^^^^^
error: layout_of(DeadBranchHasOtherField) = Layout {
size: Size(16 bytes),
align: AbiAndPrefAlign {
abi: Align(8 bytes),
pref: $SOME_ALIGN,
},
abi: Aggregate {
sized: true,
},
fields: Arbitrary {
offsets: [
Size(0 bytes),
],
memory_index: [
0,
],
},
largest_niche: Some(
Niche {
offset: Size(0 bytes),
value: Int(
I32,
false,
),
valid_range: 0..=1,
},
),
variants: Multiple {
tag: Initialized {
value: Int(
I32,
false,
),
valid_range: 0..=1,
},
tag_encoding: Direct,
tag_field: 0,
variants: [
Layout {
size: Size(16 bytes),
align: AbiAndPrefAlign {
abi: Align(8 bytes),
pref: $SOME_ALIGN,
},
abi: Uninhabited,
fields: Arbitrary {
offsets: [
Size(8 bytes),
Size(8 bytes),
],
memory_index: [
0,
1,
],
},
largest_niche: None,
variants: Single {
index: 0,
},
max_repr_align: Some(
Align(8 bytes),
),
unadjusted_abi_align: Align(8 bytes),
},
Layout {
size: Size(16 bytes),
align: AbiAndPrefAlign {
abi: Align(8 bytes),
pref: $SOME_ALIGN,
},
abi: Aggregate {
sized: true,
},
fields: Arbitrary {
offsets: [
Size(8 bytes),
],
memory_index: [
0,
],
},
largest_niche: None,
variants: Single {
index: 1,
},
max_repr_align: None,
unadjusted_abi_align: Align(8 bytes),
},
],
},
max_repr_align: Some(
Align(8 bytes),
),
unadjusted_abi_align: Align(8 bytes),
}
--> $DIR/repr-c-dead-variants.rs:57:1
|
LL | enum DeadBranchHasOtherField {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 3 previous errors

View File

@ -0,0 +1,63 @@
#![feature(no_core, rustc_attrs, lang_items)]
#![allow(dead_code)]
#![crate_type = "lib"]
#![no_std]
#![no_core]
// See also: repr-c-int-dead-variants.rs
//@ normalize-stderr-test "pref: Align\([1-8] bytes\)" -> "pref: $$SOME_ALIGN"
// This test depends on the value of the `c_enum_min_bits` target option.
// As there's no way to actually check it from UI test, we only run this test on a subset of archs.
// Four archs specifically are chosen: one for major architectures (x86_64, i686, aarch64)
// and `armebv7r-none-eabi` that has `c_enum_min_bits` set to 8.
//@ revisions: aarch64-unknown-linux-gnu
//@[aarch64-unknown-linux-gnu] compile-flags: --target aarch64-unknown-linux-gnu
//@[aarch64-unknown-linux-gnu] needs-llvm-components: aarch64
//@ revisions: i686-pc-windows-msvc
//@[i686-pc-windows-msvc] compile-flags: --target i686-pc-windows-gnu
//@[i686-pc-windows-msvc] needs-llvm-components: x86
//@ revisions: x86_64-unknown-linux-gnu
//@[x86_64-unknown-linux-gnu] compile-flags: --target x86_64-unknown-linux-gnu
//@[x86_64-unknown-linux-gnu] needs-llvm-components: x86
//
//@ revisions: armebv7r-none-eabi
//@[armebv7r-none-eabi] compile-flags: --target armebv7r-none-eabi
//@[armebv7r-none-eabi] needs-llvm-components: arm
// A simple uninhabited type.
enum Void {}
// Compiler must not remove dead variants of `#[repr(C, int)]` ADTs.
#[repr(C)]
#[rustc_layout(debug)]
enum Univariant { //~ ERROR layout_of
Variant(Void),
}
// ADTs with variants that have fields must have space allocated for those fields.
#[repr(C)]
#[rustc_layout(debug)]
enum TwoVariants { //~ ERROR layout_of
Variant1(Void),
Variant2(u8),
}
// Some targets have 4-byte-aligned u64, make it always 8-byte-aligned.
#[repr(C, align(8))]
struct Align8U64(u64);
// This one is 2 x u64: we reserve space for fields in a dead branch.
#[repr(C)]
#[rustc_layout(debug)]
enum DeadBranchHasOtherField { //~ ERROR layout_of
Variant1(Void, Align8U64),
Variant2(u8),
}
#[lang = "sized"]
trait Sized {}

View File

@ -0,0 +1,288 @@
error: layout_of(Univariant) = Layout {
size: Size(4 bytes),
align: AbiAndPrefAlign {
abi: Align(4 bytes),
pref: $SOME_ALIGN,
},
abi: Uninhabited,
fields: Arbitrary {
offsets: [
Size(0 bytes),
],
memory_index: [
0,
],
},
largest_niche: Some(
Niche {
offset: Size(0 bytes),
value: Int(
I32,
false,
),
valid_range: 0..=0,
},
),
variants: Multiple {
tag: Initialized {
value: Int(
I32,
false,
),
valid_range: 0..=0,
},
tag_encoding: Direct,
tag_field: 0,
variants: [
Layout {
size: Size(4 bytes),
align: AbiAndPrefAlign {
abi: Align(4 bytes),
pref: $SOME_ALIGN,
},
abi: Uninhabited,
fields: Arbitrary {
offsets: [
Size(4 bytes),
],
memory_index: [
0,
],
},
largest_niche: None,
variants: Single {
index: 0,
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
}
--> $DIR/repr-c-dead-variants.rs:38:1
|
LL | enum Univariant {
| ^^^^^^^^^^^^^^^
error: layout_of(TwoVariants) = Layout {
size: Size(8 bytes),
align: AbiAndPrefAlign {
abi: Align(4 bytes),
pref: $SOME_ALIGN,
},
abi: ScalarPair(
Initialized {
value: Int(
I32,
false,
),
valid_range: 0..=1,
},
Union {
value: Int(
I8,
false,
),
},
),
fields: Arbitrary {
offsets: [
Size(0 bytes),
],
memory_index: [
0,
],
},
largest_niche: Some(
Niche {
offset: Size(0 bytes),
value: Int(
I32,
false,
),
valid_range: 0..=1,
},
),
variants: Multiple {
tag: Initialized {
value: Int(
I32,
false,
),
valid_range: 0..=1,
},
tag_encoding: Direct,
tag_field: 0,
variants: [
Layout {
size: Size(4 bytes),
align: AbiAndPrefAlign {
abi: Align(4 bytes),
pref: $SOME_ALIGN,
},
abi: Uninhabited,
fields: Arbitrary {
offsets: [
Size(4 bytes),
],
memory_index: [
0,
],
},
largest_niche: None,
variants: Single {
index: 0,
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
},
Layout {
size: Size(8 bytes),
align: AbiAndPrefAlign {
abi: Align(4 bytes),
pref: $SOME_ALIGN,
},
abi: ScalarPair(
Initialized {
value: Int(
I32,
false,
),
valid_range: 0..=1,
},
Union {
value: Int(
I8,
false,
),
},
),
fields: Arbitrary {
offsets: [
Size(4 bytes),
],
memory_index: [
0,
],
},
largest_niche: None,
variants: Single {
index: 1,
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
}
--> $DIR/repr-c-dead-variants.rs:45:1
|
LL | enum TwoVariants {
| ^^^^^^^^^^^^^^^^
error: layout_of(DeadBranchHasOtherField) = Layout {
size: Size(16 bytes),
align: AbiAndPrefAlign {
abi: Align(8 bytes),
pref: $SOME_ALIGN,
},
abi: Aggregate {
sized: true,
},
fields: Arbitrary {
offsets: [
Size(0 bytes),
],
memory_index: [
0,
],
},
largest_niche: Some(
Niche {
offset: Size(0 bytes),
value: Int(
I32,
false,
),
valid_range: 0..=1,
},
),
variants: Multiple {
tag: Initialized {
value: Int(
I32,
false,
),
valid_range: 0..=1,
},
tag_encoding: Direct,
tag_field: 0,
variants: [
Layout {
size: Size(16 bytes),
align: AbiAndPrefAlign {
abi: Align(8 bytes),
pref: $SOME_ALIGN,
},
abi: Uninhabited,
fields: Arbitrary {
offsets: [
Size(8 bytes),
Size(8 bytes),
],
memory_index: [
0,
1,
],
},
largest_niche: None,
variants: Single {
index: 0,
},
max_repr_align: Some(
Align(8 bytes),
),
unadjusted_abi_align: Align(8 bytes),
},
Layout {
size: Size(16 bytes),
align: AbiAndPrefAlign {
abi: Align(8 bytes),
pref: $SOME_ALIGN,
},
abi: Aggregate {
sized: true,
},
fields: Arbitrary {
offsets: [
Size(8 bytes),
],
memory_index: [
0,
],
},
largest_niche: None,
variants: Single {
index: 1,
},
max_repr_align: None,
unadjusted_abi_align: Align(8 bytes),
},
],
},
max_repr_align: Some(
Align(8 bytes),
),
unadjusted_abi_align: Align(8 bytes),
}
--> $DIR/repr-c-dead-variants.rs:57:1
|
LL | enum DeadBranchHasOtherField {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 3 previous errors

View File

@ -0,0 +1,38 @@
#![feature(rustc_attrs)]
#![allow(dead_code)]
// See also: repr-c-dead-variants.rs
//@ normalize-stderr-test "pref: Align\([1-8] bytes\)" -> "pref: $$SOME_ALIGN"
// A simple uninhabited type.
enum Void {}
// Compiler must not remove dead variants of `#[repr(C, int)]` ADTs.
#[repr(C, u8)]
#[rustc_layout(debug)]
enum UnivariantU8 { //~ ERROR layout_of
Variant(Void),
}
// ADTs with variants that have fields must have space allocated for those fields.
#[repr(C, u8)]
#[rustc_layout(debug)]
enum TwoVariantsU8 { //~ ERROR layout_of
Variant1(Void),
Variant2(u8),
}
// Some targets have 4-byte-aligned u64, make it always 8-byte-aligned.
#[repr(C, align(8))]
struct Align8U64(u64);
// This one is 2 x u64: we reserve space for fields in a dead branch.
#[repr(C, u8)]
#[rustc_layout(debug)]
enum DeadBranchHasOtherFieldU8 { //~ ERROR layout_of
Variant1(Void, Align8U64),
Variant2(u8),
}
fn main() {}

View File

@ -0,0 +1,288 @@
error: layout_of(UnivariantU8) = Layout {
size: Size(1 bytes),
align: AbiAndPrefAlign {
abi: Align(1 bytes),
pref: $SOME_ALIGN,
},
abi: Uninhabited,
fields: Arbitrary {
offsets: [
Size(0 bytes),
],
memory_index: [
0,
],
},
largest_niche: Some(
Niche {
offset: Size(0 bytes),
value: Int(
I8,
false,
),
valid_range: 0..=0,
},
),
variants: Multiple {
tag: Initialized {
value: Int(
I8,
false,
),
valid_range: 0..=0,
},
tag_encoding: Direct,
tag_field: 0,
variants: [
Layout {
size: Size(1 bytes),
align: AbiAndPrefAlign {
abi: Align(1 bytes),
pref: $SOME_ALIGN,
},
abi: Uninhabited,
fields: Arbitrary {
offsets: [
Size(1 bytes),
],
memory_index: [
0,
],
},
largest_niche: None,
variants: Single {
index: 0,
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
}
--> $DIR/repr-c-int-dead-variants.rs:14:1
|
LL | enum UnivariantU8 {
| ^^^^^^^^^^^^^^^^^
error: layout_of(TwoVariantsU8) = Layout {
size: Size(2 bytes),
align: AbiAndPrefAlign {
abi: Align(1 bytes),
pref: $SOME_ALIGN,
},
abi: ScalarPair(
Initialized {
value: Int(
I8,
false,
),
valid_range: 0..=1,
},
Union {
value: Int(
I8,
false,
),
},
),
fields: Arbitrary {
offsets: [
Size(0 bytes),
],
memory_index: [
0,
],
},
largest_niche: Some(
Niche {
offset: Size(0 bytes),
value: Int(
I8,
false,
),
valid_range: 0..=1,
},
),
variants: Multiple {
tag: Initialized {
value: Int(
I8,
false,
),
valid_range: 0..=1,
},
tag_encoding: Direct,
tag_field: 0,
variants: [
Layout {
size: Size(1 bytes),
align: AbiAndPrefAlign {
abi: Align(1 bytes),
pref: $SOME_ALIGN,
},
abi: Uninhabited,
fields: Arbitrary {
offsets: [
Size(1 bytes),
],
memory_index: [
0,
],
},
largest_niche: None,
variants: Single {
index: 0,
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
},
Layout {
size: Size(2 bytes),
align: AbiAndPrefAlign {
abi: Align(1 bytes),
pref: $SOME_ALIGN,
},
abi: ScalarPair(
Initialized {
value: Int(
I8,
false,
),
valid_range: 0..=1,
},
Union {
value: Int(
I8,
false,
),
},
),
fields: Arbitrary {
offsets: [
Size(1 bytes),
],
memory_index: [
0,
],
},
largest_niche: None,
variants: Single {
index: 1,
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
}
--> $DIR/repr-c-int-dead-variants.rs:21:1
|
LL | enum TwoVariantsU8 {
| ^^^^^^^^^^^^^^^^^^
error: layout_of(DeadBranchHasOtherFieldU8) = Layout {
size: Size(16 bytes),
align: AbiAndPrefAlign {
abi: Align(8 bytes),
pref: $SOME_ALIGN,
},
abi: Aggregate {
sized: true,
},
fields: Arbitrary {
offsets: [
Size(0 bytes),
],
memory_index: [
0,
],
},
largest_niche: Some(
Niche {
offset: Size(0 bytes),
value: Int(
I8,
false,
),
valid_range: 0..=1,
},
),
variants: Multiple {
tag: Initialized {
value: Int(
I8,
false,
),
valid_range: 0..=1,
},
tag_encoding: Direct,
tag_field: 0,
variants: [
Layout {
size: Size(16 bytes),
align: AbiAndPrefAlign {
abi: Align(8 bytes),
pref: $SOME_ALIGN,
},
abi: Uninhabited,
fields: Arbitrary {
offsets: [
Size(8 bytes),
Size(8 bytes),
],
memory_index: [
0,
1,
],
},
largest_niche: None,
variants: Single {
index: 0,
},
max_repr_align: Some(
Align(8 bytes),
),
unadjusted_abi_align: Align(8 bytes),
},
Layout {
size: Size(16 bytes),
align: AbiAndPrefAlign {
abi: Align(8 bytes),
pref: $SOME_ALIGN,
},
abi: Aggregate {
sized: true,
},
fields: Arbitrary {
offsets: [
Size(8 bytes),
],
memory_index: [
0,
],
},
largest_niche: None,
variants: Single {
index: 1,
},
max_repr_align: None,
unadjusted_abi_align: Align(8 bytes),
},
],
},
max_repr_align: Some(
Align(8 bytes),
),
unadjusted_abi_align: Align(8 bytes),
}
--> $DIR/repr-c-int-dead-variants.rs:33:1
|
LL | enum DeadBranchHasOtherFieldU8 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 3 previous errors

Some files were not shown because too many files have changed in this diff Show More