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 10 pull requests #108904

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
52f7a21
Relax ordering rules for `asm!` operands
Amanieu Dec 16, 2022
40185db
Delete old re-exports from rustc_smir
celinval Mar 4, 2023
2c9b8c5
Implementing "<test_binary> --list --format json" #107307 #49359
parthopdas Feb 8, 2023
b66db7e
Create new rustc_smir struct to map future crates
celinval Mar 4, 2023
8d13454
Canonicalize the ROOT VAR
compiler-errors Mar 7, 2023
3bfcfd0
fix var equality issue with old canonicalizer
compiler-errors Mar 7, 2023
775bacd
Simplify `sort_by` calls
WaffleLapkin Mar 7, 2023
5eaeb71
Change item collection to be on demand
celinval Mar 7, 2023
a439c02
may not => cannot
compiler-errors Mar 7, 2023
0f4255e
Dedup copy field errors for identical types
compiler-errors Mar 8, 2023
8a99ffc
Suppress copy impl error when post-normalized type references errors
compiler-errors Mar 7, 2023
08e5a77
Don't report E0740 for type error
compiler-errors Mar 7, 2023
64eea3c
Tweak E0740
compiler-errors Mar 7, 2023
be60bcb
Rename `MapInPlace` as `FlatMapInPlace`.
nnethercote Mar 8, 2023
204ba32
fix: evaluate with wrong obligation stack
LYF1999 Mar 8, 2023
20a8119
Rollup merge of #105798 - Amanieu:relax-asm, r=joshtriplett
GuillaumeGomez Mar 8, 2023
d810534
Rollup merge of #108148 - parthopdas:master, r=oli-obk
GuillaumeGomez Mar 8, 2023
ae46eba
Rollup merge of #108839 - compiler-errors:canonicalize-the-root-var, …
GuillaumeGomez Mar 8, 2023
e4844a5
Rollup merge of #108846 - celinval:smir-poc, r=oli-obk
GuillaumeGomez Mar 8, 2023
292f553
Rollup merge of #108873 - WaffleLapkin:cmp, r=cjgillot
GuillaumeGomez Mar 8, 2023
780c2c1
Rollup merge of #108882 - compiler-errors:E0740, r=eholk
GuillaumeGomez Mar 8, 2023
5b7b922
Rollup merge of #108883 - compiler-errors:post-norm-copy-err, r=BoxyUwU
GuillaumeGomez Mar 8, 2023
62d18cb
Rollup merge of #108884 - compiler-errors:tweak-illegal-copy-impl-mes…
GuillaumeGomez Mar 8, 2023
ec7485c
Rollup merge of #108887 - nnethercote:rename-MapInPlace, r=lqd
GuillaumeGomez Mar 8, 2023
4b60218
Rollup merge of #108901 - LYF1999:yf/108897, r=lcnr
GuillaumeGomez Mar 8, 2023
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Session.vim
.project
.favorites.json
.settings/
.vs/

## Tool
.valgrindrc
Expand Down
10 changes: 2 additions & 8 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4669,15 +4669,9 @@ dependencies = [
name = "rustc_smir"
version = "0.0.0"
dependencies = [
"rustc_borrowck",
"rustc_driver",
"rustc_hir",
"rustc_interface",
"rustc_middle",
"rustc_mir_dataflow",
"rustc_mir_transform",
"rustc_serialize",
"rustc_trait_selection",
"rustc_span",
"tracing",
]

[[package]]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::ptr::P;
use crate::token::{self, Token};
use crate::tokenstream::*;

use rustc_data_structures::map_in_place::MapInPlace;
use rustc_data_structures::flat_map_in_place::FlatMapInPlace;
use rustc_data_structures::sync::Lrc;
use rustc_span::source_map::Spanned;
use rustc_span::symbol::Ident;
Expand Down
35 changes: 4 additions & 31 deletions compiler/rustc_builtin_macros/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,17 +203,6 @@ pub fn parse_asm_args<'a>(
// Validate the order of named, positional & explicit register operands and
// clobber_abi/options. We do this at the end once we have the full span
// of the argument available.
if !args.options_spans.is_empty() {
diag.struct_span_err(span, "arguments are not allowed after options")
.span_labels(args.options_spans.clone(), "previous options")
.span_label(span, "argument")
.emit();
} else if let Some((_, abi_span)) = args.clobber_abis.last() {
diag.struct_span_err(span, "arguments are not allowed after clobber_abi")
.span_label(*abi_span, "clobber_abi")
.span_label(span, "argument")
.emit();
}
if explicit_reg {
if name.is_some() {
diag.struct_span_err(span, "explicit register arguments cannot have names").emit();
Expand All @@ -227,17 +216,6 @@ pub fn parse_asm_args<'a>(
.emit();
continue;
}
if !args.reg_args.is_empty() {
let mut err = diag.struct_span_err(
span,
"named arguments cannot follow explicit register arguments",
);
err.span_label(span, "named argument");
for pos in &args.reg_args {
err.span_label(args.operands[*pos].1, "explicit register argument");
}
err.emit();
}
args.named_args.insert(name, slot);
} else {
if !args.named_args.is_empty() || !args.reg_args.is_empty() {
Expand Down Expand Up @@ -478,15 +456,6 @@ fn parse_clobber_abi<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> PResult<'a,

let full_span = span_start.to(p.prev_token.span);

if !args.options_spans.is_empty() {
let mut err = p
.sess
.span_diagnostic
.struct_span_err(full_span, "clobber_abi is not allowed after options");
err.span_labels(args.options_spans.clone(), "options");
return Err(err);
}

match &new_abis[..] {
// should have errored above during parsing
[] => unreachable!(),
Expand Down Expand Up @@ -699,6 +668,10 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
args.operands[idx].1,
"explicit register arguments cannot be used in the asm template",
);
err.span_help(
args.operands[idx].1,
"use the register name directly in the assembly code",
);
}
err.emit();
None
Expand Down
27 changes: 26 additions & 1 deletion compiler/rustc_builtin_macros/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_errors::Applicability;
use rustc_expand::base::*;
use rustc_session::Session;
use rustc_span::symbol::{sym, Ident, Symbol};
use rustc_span::Span;
use rustc_span::{FileNameDisplayPreference, Span};
use std::iter;
use thin_vec::{thin_vec, ThinVec};

Expand Down Expand Up @@ -231,6 +231,8 @@ pub fn expand_test_or_bench(
&item.ident,
));

let location_info = get_location_info(cx, &item);

let mut test_const = cx.item(
sp,
Ident::new(item.ident.name, sp),
Expand Down Expand Up @@ -280,6 +282,16 @@ pub fn expand_test_or_bench(
cx.expr_none(sp)
},
),
// source_file: <relative_path_of_source_file>
field("source_file", cx.expr_str(sp, location_info.0)),
// start_line: start line of the test fn identifier.
field("start_line", cx.expr_usize(sp, location_info.1)),
// start_col: start column of the test fn identifier.
field("start_col", cx.expr_usize(sp, location_info.2)),
// end_line: end line of the test fn identifier.
field("end_line", cx.expr_usize(sp, location_info.3)),
// end_col: end column of the test fn identifier.
field("end_col", cx.expr_usize(sp, location_info.4)),
// compile_fail: true | false
field("compile_fail", cx.expr_bool(sp, false)),
// no_run: true | false
Expand Down Expand Up @@ -364,6 +376,19 @@ pub fn expand_test_or_bench(
}
}

fn get_location_info(cx: &ExtCtxt<'_>, item: &ast::Item) -> (Symbol, usize, usize, usize, usize) {
let span = item.ident.span;
let (source_file, lo_line, lo_col, hi_line, hi_col) =
cx.sess.source_map().span_to_location_info(span);

let file_name = match source_file {
Some(sf) => sf.name.display(FileNameDisplayPreference::Local).to_string(),
None => "no-location".to_string(),
};

(Symbol::intern(&file_name), lo_line, lo_col, hi_line, hi_col)
}

fn item_path(mod_path: &[Ident], item_ident: &Ident) -> String {
mod_path
.iter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@ use smallvec::{Array, SmallVec};
use std::ptr;
use thin_vec::ThinVec;

pub trait MapInPlace<T>: Sized {
fn map_in_place<F>(&mut self, mut f: F)
where
F: FnMut(T) -> T,
{
self.flat_map_in_place(|e| Some(f(e)))
}

pub trait FlatMapInPlace<T>: Sized {
fn flat_map_in_place<F, I>(&mut self, f: F)
where
F: FnMut(T) -> I,
Expand Down Expand Up @@ -66,14 +59,14 @@ macro_rules! flat_map_in_place {
};
}

impl<T> MapInPlace<T> for Vec<T> {
impl<T> FlatMapInPlace<T> for Vec<T> {
flat_map_in_place!();
}

impl<T, A: Array<Item = T>> MapInPlace<T> for SmallVec<A> {
impl<T, A: Array<Item = T>> FlatMapInPlace<T> for SmallVec<A> {
flat_map_in_place!();
}

impl<T> MapInPlace<T> for ThinVec<T> {
impl<T> FlatMapInPlace<T> for ThinVec<T> {
flat_map_in_place!();
}
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ pub fn cold_path<F: FnOnce() -> R, R>(f: F) -> R {
pub mod base_n;
pub mod binary_search_util;
pub mod captures;
pub mod flat_map_in_place;
pub mod flock;
pub mod functor;
pub mod fx;
pub mod graph;
pub mod intern;
pub mod jobserver;
pub mod macros;
pub mod map_in_place;
pub mod obligation_forest;
pub mod owning_ref;
pub mod sip128;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use rustc_ast::tokenstream::{LazyAttrTokenStream, TokenTree};
use rustc_ast::NodeId;
use rustc_ast::{self as ast, AttrStyle, Attribute, HasAttrs, HasTokens, MetaItem};
use rustc_attr as attr;
use rustc_data_structures::flat_map_in_place::FlatMapInPlace;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::map_in_place::MapInPlace;
use rustc_feature::{Feature, Features, State as FeatureState};
use rustc_feature::{
ACCEPTED_FEATURES, ACTIVE_FEATURES, REMOVED_FEATURES, STABLE_REMOVED_FEATURES,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use rustc_ast::{ForeignItemKind, HasAttrs, HasNodeId};
use rustc_ast::{Inline, ItemKind, MacStmtStyle, MetaItemKind, ModKind};
use rustc_ast::{NestedMetaItem, NodeId, PatKind, StmtKind, TyKind};
use rustc_ast_pretty::pprust;
use rustc_data_structures::map_in_place::MapInPlace;
use rustc_data_structures::flat_map_in_place::FlatMapInPlace;
use rustc_data_structures::sync::Lrc;
use rustc_errors::PResult;
use rustc_feature::Features;
Expand Down
11 changes: 9 additions & 2 deletions compiler/rustc_hir_analysis/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ hir_analysis_missing_type_params =
.note = because of the default `Self` reference, type parameters must be specified on object types

hir_analysis_copy_impl_on_type_with_dtor =
the trait `Copy` may not be implemented for this type; the type has a destructor
the trait `Copy` cannot be implemented for this type; the type has a destructor
.label = `Copy` not allowed on types with destructors

hir_analysis_multiple_relaxed_default_bounds =
type parameter has more than one relaxed default bound, only one is supported

hir_analysis_copy_impl_on_non_adt =
the trait `Copy` may not be implemented for this type
the trait `Copy` cannot be implemented for this type
.label = type is not a structure or enumeration

hir_analysis_const_impl_for_non_const_trait =
Expand Down Expand Up @@ -163,3 +163,10 @@ hir_analysis_pass_to_variadic_function = can't pass `{$ty}` to variadic function
.help = cast the value to `{$cast_ty}`

hir_analysis_cast_thin_pointer_to_fat_pointer = cannot cast thin pointer `{$expr_ty}` to fat pointer `{$cast_ty}`

hir_analysis_invalid_union_field =
field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union
.note = union fields must not have drop side-effects, which is currently enforced via either `Copy` or `ManuallyDrop<...>`

hir_analysis_invalid_union_field_sugg =
wrap the field type in `ManuallyDrop<...>`
32 changes: 11 additions & 21 deletions compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::check::intrinsicck::InlineAsmCtxt;
use crate::errors::LinkageType;
use crate::errors::{self, LinkageType};

use super::compare_impl_item::check_type_bounds;
use super::compare_impl_item::{compare_impl_method, compare_impl_ty};
Expand Down Expand Up @@ -114,9 +114,11 @@ fn check_union_fields(tcx: TyCtxt<'_>, span: Span, item_def_id: LocalDefId) -> b
allowed_union_field(*elem, tcx, param_env)
}
_ => {
// Fallback case: allow `ManuallyDrop` and things that are `Copy`.
// Fallback case: allow `ManuallyDrop` and things that are `Copy`,
// also no need to report an error if the type is unresolved.
ty.ty_adt_def().is_some_and(|adt_def| adt_def.is_manually_drop())
|| ty.is_copy_modulo_regions(tcx, param_env)
|| ty.references_error()
}
}
}
Expand All @@ -131,26 +133,14 @@ fn check_union_fields(tcx: TyCtxt<'_>, span: Span, item_def_id: LocalDefId) -> b
Some(Node::Field(field)) => (field.span, field.ty.span),
_ => unreachable!("mir field has to correspond to hir field"),
};
struct_span_err!(
tcx.sess,
tcx.sess.emit_err(errors::InvalidUnionField {
field_span,
E0740,
"unions cannot contain fields that may need dropping"
)
.note(
"a type is guaranteed not to need dropping \
when it implements `Copy`, or when it is the special `ManuallyDrop<_>` type",
)
.multipart_suggestion_verbose(
"when the type does not implement `Copy`, \
wrap it inside a `ManuallyDrop<_>` and ensure it is manually dropped",
vec![
(ty_span.shrink_to_lo(), "std::mem::ManuallyDrop<".into()),
(ty_span.shrink_to_hi(), ">".into()),
],
Applicability::MaybeIncorrect,
)
.emit();
sugg: errors::InvalidUnionFieldSuggestion {
lo: ty_span.shrink_to_lo(),
hi: ty_span.shrink_to_hi(),
},
note: (),
});
return false;
} else if field_ty.needs_drop(tcx, param_env) {
// This should never happen. But we can get here e.g. in case of name resolution errors.
Expand Down
10 changes: 9 additions & 1 deletion compiler/rustc_hir_analysis/src/coherence/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! up data structures required by type-checking/codegen.

use crate::errors::{CopyImplOnNonAdt, CopyImplOnTypeWithDtor, DropImplOnWrongItem};
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{struct_span_err, MultiSpan};
use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LocalDefId};
Expand Down Expand Up @@ -86,15 +87,22 @@ fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
tcx.sess,
span,
E0204,
"the trait `Copy` may not be implemented for this type"
"the trait `Copy` cannot be implemented for this type"
);

// We'll try to suggest constraining type parameters to fulfill the requirements of
// their `Copy` implementation.
let mut errors: BTreeMap<_, Vec<_>> = Default::default();
let mut bounds = vec![];

let mut seen_tys = FxHashSet::default();

for (field, ty, reason) in fields {
// Only report an error once per type.
if !seen_tys.insert(ty) {
continue;
}

let field_span = tcx.def_span(field.did);
err.span_label(field_span, "this field does not implement `Copy`");

Expand Down
22 changes: 21 additions & 1 deletion compiler/rustc_hir_analysis/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rustc_errors::{
error_code, Applicability, DiagnosticBuilder, ErrorGuaranteed, Handler, IntoDiagnostic,
MultiSpan,
};
use rustc_macros::Diagnostic;
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_middle::ty::Ty;
use rustc_span::{symbol::Ident, Span, Symbol};

Expand Down Expand Up @@ -430,3 +430,23 @@ pub(crate) struct CastThinPointerToFatPointer<'tcx> {
pub expr_ty: Ty<'tcx>,
pub cast_ty: String,
}

#[derive(Diagnostic)]
#[diag(hir_analysis_invalid_union_field, code = "E0740")]
pub(crate) struct InvalidUnionField {
#[primary_span]
pub field_span: Span,
#[subdiagnostic]
pub sugg: InvalidUnionFieldSuggestion,
#[note]
pub note: (),
}

#[derive(Subdiagnostic)]
#[multipart_suggestion(hir_analysis_invalid_union_field_sugg, applicability = "machine-applicable")]
pub(crate) struct InvalidUnionFieldSuggestion {
#[suggestion_part(code = "std::mem::ManuallyDrop<")]
pub lo: Span,
#[suggestion_part(code = ">")]
pub hi: Span,
}
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ hir_typeck_field_multiply_specified_in_initializer =
.previous_use_label = first use of `{$ident}`

hir_typeck_copy_impl_on_type_with_dtor =
the trait `Copy` may not be implemented for this type; the type has a destructor
the trait `Copy` cannot be implemented for this type; the type has a destructor
.label = `Copy` not allowed on types with destructors

hir_typeck_multiple_relaxed_default_bounds =
type parameter has more than one relaxed default bound, only one is supported

hir_typeck_copy_impl_on_non_adt =
the trait `Copy` may not be implemented for this type
the trait `Copy` cannot be implemented for this type
.label = type is not a structure or enumeration

hir_typeck_trait_object_declared_with_no_traits =
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
.collect();

// Sort them by the name so we have a stable result.
names.sort_by(|a, b| a.as_str().partial_cmp(b.as_str()).unwrap());
names.sort_by(|a, b| a.as_str().cmp(b.as_str()));
names
}

Expand Down
Loading