Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 9 pull requests #127326

Merged
merged 28 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a82f70e
Migrate some rustc_builtin_macros to SessionDiagnostic
He1pa Jun 25, 2024
cf9bcb2
Remove duplicate of tests/ui/impl-trait/nested-return-type2.rs
oli-obk Jun 27, 2024
10a513b
Remove duplicate of tests/ui/impl-trait/nested-return-type2-tait2.rs
oli-obk Jun 27, 2024
71dfbea
Disable dead variant removal for `#[repr(C)]` enums.
GoldsteinE Mar 25, 2024
8a3c07a
Clarify guarantees about ABI compatibility
GoldsteinE May 5, 2024
140392b
Adjust rustdoc automatic link suggestion
estebank Jul 3, 2024
89ecae5
Better span for "make binding mutable" suggestion
estebank Jul 3, 2024
f63d2bc
Better suggestion span for missing type parameter
estebank Jul 3, 2024
9344779
Fix `&mut` removal suggestion
estebank Jul 3, 2024
a06a18a
Properly handle removal suggestion rendering
estebank Jul 3, 2024
2699d81
Use shorter span for float literal suggestion
estebank Jul 3, 2024
ff92ab0
More accurate mutability suggestion
estebank Jul 3, 2024
8ea1066
Tweak slice and as_deref suggestion span
estebank Jul 4, 2024
a5e7da0
Tweak raw-pointer field access and array indexing suggestions
estebank Jul 4, 2024
0b4edb2
reject SmartPointer constructions not serving the purpose
dingxiangfei2009 Jul 3, 2024
1471532
Allow to have different types for arguments of `Rustc::remap_path_pre…
GuillaumeGomez Jul 4, 2024
12f29e9
added built-in var to jsondocck
its-the-shrimp Jul 4, 2024
87b7415
trivial update on tidy bless note
chenyukang Jul 4, 2024
0d54fe0
Remove a use of `StructuredDiag`, which is incompatible with automati…
oli-obk Jul 4, 2024
f0a0f8f
Rollup merge of #123043 - GoldsteinE:fix/repr-c-dead-branches, r=oli-obk
matthiaskrgr Jul 4, 2024
b16a711
Rollup merge of #126405 - He1pa:translate_builtin_macro_diag, r=david…
matthiaskrgr Jul 4, 2024
e62956d
Rollup merge of #127037 - oli-obk:define_opaque_types18, r=davidtwco
matthiaskrgr Jul 4, 2024
d27136f
Rollup merge of #127283 - dingxiangfei2009:check-repr-transparent, r=…
matthiaskrgr Jul 4, 2024
54bd3a7
Rollup merge of #127301 - estebank:fix-suggestions, r=Urgau
matthiaskrgr Jul 4, 2024
c091d09
Rollup merge of #127307 - GuillaumeGomez:different-types-remap_path_p…
matthiaskrgr Jul 4, 2024
6f43a02
Rollup merge of #127309 - its-the-shrimp:jsondocck_add_file_var, r=aD…
matthiaskrgr Jul 4, 2024
1652721
Rollup merge of #127314 - chenyukang:yukang-fix-bless-note, r=albertl…
matthiaskrgr Jul 4, 2024
dd42f7a
Rollup merge of #127319 - oli-obk:fail2taint, r=compiler-errors
matthiaskrgr Jul 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_abi/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 11 additions & 14 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
);
}
Expand Down
29 changes: 16 additions & 13 deletions compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,21 +408,21 @@ 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;
}
}
}
} 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,
);
}
Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions compiler/rustc_builtin_macros/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 5 additions & 8 deletions compiler/rustc_builtin_macros/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
}
};

Expand Down Expand Up @@ -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
}
Expand Down
39 changes: 36 additions & 3 deletions compiler/rustc_builtin_macros/src/deriving/smart_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
};

Expand Down
40 changes: 40 additions & 0 deletions compiler/rustc_builtin_macros/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
}
24 changes: 12 additions & 12 deletions compiler/rustc_builtin_macros/src/proc_macro_harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
11 changes: 8 additions & 3 deletions compiler/rustc_builtin_macros/src/source_util.rs
Original file line number Diff line number Diff line change
@@ -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,
};
Expand Down Expand Up @@ -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;
Expand Down
Loading
Loading