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 #88940

Closed
wants to merge 43 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
3caf0bc
Accept `m!{ .. }.method()` and `m!{ .. }?` statements.
m-ou-se Sep 6, 2021
ebf1252
Add test for braced-macro followed by `.` or `?`.
m-ou-se Sep 6, 2021
ce35f8e
remap-cwd-prefix
danakj Jul 22, 2021
2a687de
Move documentation to the unstable book
danakj Sep 7, 2021
2691a39
Revert "Allow formatting `Anonymous{Struct, Union}` declarations"
pnkfelix Sep 8, 2021
2041fb1
Revert "Add test for pretty printing anonymous types"
pnkfelix Sep 8, 2021
5560f6d
Revert "Fix ast expanded printing for anonymous types"
pnkfelix Sep 8, 2021
f38ec9c
Revert "Add test for restriction of anonymous types on validation"
pnkfelix Sep 8, 2021
b6aa7e3
Manually crafted revert of d4ad050ce5778a09566f6f9ec172565815d54604 .
pnkfelix Sep 8, 2021
91feb76
Revert "Implement Anonymous{Struct, Union} in the AST"
pnkfelix Sep 8, 2021
f26f1ed
Re-add 71a7f8f1884b2c83eeb4a545eef16df1f2ea6476 post-revert.
pnkfelix Sep 8, 2021
35370a7
regression test for issue #88583.
pnkfelix Sep 9, 2021
5dab3c5
feat(rustc_typeck): suggest removing bad parens in `(recv.method)()`
notriddle Sep 11, 2021
e5c2412
Add the corrections stuff to the 88803 test case
notriddle Sep 11, 2021
d98892b
Make sure the call span parens check only fires on the callee, not args
notriddle Sep 11, 2021
40f2a3b
Move object safety suggestions to the end of the error
estebank Sep 12, 2021
8be729c
chore: convert to a multi-part suggestion
notriddle Sep 13, 2021
7d8d7a0
Add negative test in macro-braces-dot-question.rs.
m-ou-se Sep 13, 2021
8d879aa
Simplify std::os module reexports to fix rustdoc linking issues
GuillaumeGomez Sep 3, 2021
1c4873c
Remove usage of cfg_if in std/src/os/mod.rs
GuillaumeGomez Sep 3, 2021
7965a9f
Move fortanix module position in std::os reexports for alpha sort
GuillaumeGomez Sep 7, 2021
9a3b1cf
Update permissions path for clippy lint
GuillaumeGomez Sep 13, 2021
1053a5b
`Wrapping<T>` has the same layout and ABI as `T`
joshlf Sep 13, 2021
ae2cda6
Tokenize emoji as if they were valid indentifiers
estebank Aug 29, 2021
f61ae01
Replace ZWJ with nothing in terminal output
estebank Sep 9, 2021
8b65c79
Fix RustDoc
estebank Sep 9, 2021
b43ac6e
Add `unic-emoji-char` and its dependencies to the allow list
estebank Sep 9, 2021
411d643
fix fmt
estebank Sep 9, 2021
4c71eec
Account for confusable codepoints when recovering emoji identifiers
estebank Sep 9, 2021
3750cc6
review comment: plural of emoji is emoji
estebank Sep 10, 2021
109ebdf
`replace_tabs` -> `normalize_whitespace`
estebank Sep 10, 2021
76713c9
udpate comment to be more accurate
estebank Sep 10, 2021
30f9807
Sort `FxHashSet`'s contents before emitting errors for consistent output
estebank Sep 14, 2021
f9b8191
Remove implementation of `min_align_of` intrinsic
tmiasko Sep 14, 2021
8580e54
Rollup merge of #87320 - danakj:debug-compilation-dir, r=michaelwoeri…
Manishearth Sep 14, 2021
8be84a9
Rollup merge of #88619 - GuillaumeGomez:simplify-std-os-reexports, r=…
Manishearth Sep 14, 2021
d8d2681
Rollup merge of #88690 - m-ou-se:macro-braces-dot-question-expr-parse…
Manishearth Sep 14, 2021
8417ac5
Rollup merge of #88775 - pnkfelix:revert-anon-union-parsing, r=davidtwco
Manishearth Sep 14, 2021
46373af
Rollup merge of #88781 - estebank:emoji-idents, r=oli-obk
Manishearth Sep 14, 2021
6e041ee
Rollup merge of #88841 - notriddle:notriddle/method-parens, r=estebank
Manishearth Sep 14, 2021
7195c8d
Rollup merge of #88892 - estebank:trait-objects, r=petrochenkov
Manishearth Sep 14, 2021
0c3a7d0
Rollup merge of #88915 - joshlf:patch-4, r=kennytm
Manishearth Sep 14, 2021
d675005
Rollup merge of #88933 - tmiasko:remove-min-align-of, r=oli-obk
Manishearth Sep 14, 2021
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
42 changes: 42 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3980,6 +3980,7 @@ name = "rustc_lexer"
version = "0.1.0"
dependencies = [
"expect-test",
"unic-emoji-char",
"unicode-xid",
]

Expand Down Expand Up @@ -5443,6 +5444,47 @@ version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c"

[[package]]
name = "unic-char-property"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8c57a407d9b6fa02b4795eb81c5b6652060a15a7903ea981f3d723e6c0be221"
dependencies = [
"unic-char-range",
]

[[package]]
name = "unic-char-range"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0398022d5f700414f6b899e10b8348231abf9173fa93144cbc1a43b9793c1fbc"

[[package]]
name = "unic-common"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80d7ff825a6a654ee85a63e80f92f054f904f21e7d12da4e22f9834a4aaa35bc"

[[package]]
name = "unic-emoji-char"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b07221e68897210270a38bde4babb655869637af0f69407f96053a34f76494d"
dependencies = [
"unic-char-property",
"unic-char-range",
"unic-ucd-version",
]

[[package]]
name = "unic-ucd-version"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96bd2f2237fe450fcd0a1d2f5f4e91711124f7857ba2e964247776ebeeb7b0c4"
dependencies = [
"unic-common",
]

[[package]]
name = "unicase"
version = "2.6.0"
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1902,10 +1902,6 @@ pub enum TyKind {
Never,
/// A tuple (`(A, B, C, D,...)`).
Tup(Vec<P<Ty>>),
/// An anonymous struct type i.e. `struct { foo: Type }`
AnonymousStruct(Vec<FieldDef>, bool),
/// An anonymous union type i.e. `union { bar: Type }`
AnonymousUnion(Vec<FieldDef>, bool),
/// A path (`module::module::...::Type`), optionally
/// "qualified", e.g., `<Vec<T> as SomeTrait>::SomeType`.
///
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_ast/src/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,9 +484,6 @@ pub fn noop_visit_ty<T: MutVisitor>(ty: &mut P<Ty>, vis: &mut T) {
visit_vec(bounds, |bound| vis.visit_param_bound(bound));
}
TyKind::MacCall(mac) => vis.visit_mac_call(mac),
TyKind::AnonymousStruct(fields, ..) | TyKind::AnonymousUnion(fields, ..) => {
fields.flat_map_in_place(|field| vis.flat_map_field_def(field));
}
}
vis.visit_span(span);
visit_lazy_tts(tokens, vis);
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,6 @@ pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) {
TyKind::Typeof(ref expression) => visitor.visit_anon_const(expression),
TyKind::Infer | TyKind::ImplicitSelf | TyKind::Err => {}
TyKind::MacCall(ref mac) => visitor.visit_mac_call(mac),
TyKind::AnonymousStruct(ref fields, ..) | TyKind::AnonymousUnion(ref fields, ..) => {
walk_list!(visitor, visit_field_def, fields)
}
TyKind::Never | TyKind::CVarArgs => {}
}
}
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,10 +748,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
}

pub(super) fn lower_field_def(
&mut self,
(index, f): (usize, &FieldDef),
) -> hir::FieldDef<'hir> {
fn lower_field_def(&mut self, (index, f): (usize, &FieldDef)) -> hir::FieldDef<'hir> {
let ty = if let TyKind::Path(ref qself, ref path) = f.ty.kind {
let t = self.lower_path_ty(
&f.ty,
Expand Down
9 changes: 0 additions & 9 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1301,15 +1301,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let kind = match t.kind {
TyKind::Infer => hir::TyKind::Infer,
TyKind::Err => hir::TyKind::Err,
// FIXME(unnamed_fields): IMPLEMENTATION IN PROGRESS
TyKind::AnonymousStruct(ref _fields, _recovered) => {
self.sess.struct_span_err(t.span, "anonymous structs are unimplemented").emit();
hir::TyKind::Err
}
TyKind::AnonymousUnion(ref _fields, _recovered) => {
self.sess.struct_span_err(t.span, "anonymous unions are unimplemented").emit();
hir::TyKind::Err
}
TyKind::Slice(ref ty) => hir::TyKind::Slice(self.lower_ty(ty, itctx)),
TyKind::Ptr(ref mt) => hir::TyKind::Ptr(self.lower_mt(mt, itctx)),
TyKind::Rptr(ref region, ref mt) => {
Expand Down
68 changes: 0 additions & 68 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,19 +193,13 @@ impl<'a> AstValidator<'a> {
}
}
}
TyKind::AnonymousStruct(ref fields, ..) | TyKind::AnonymousUnion(ref fields, ..) => {
self.with_banned_assoc_ty_bound(|this| {
walk_list!(this, visit_struct_field_def, fields)
});
}
_ => visit::walk_ty(self, t),
}
}

fn visit_struct_field_def(&mut self, field: &'a FieldDef) {
if let Some(ident) = field.ident {
if ident.name == kw::Underscore {
self.check_anonymous_field(field);
self.visit_vis(&field.vis);
self.visit_ident(ident);
self.visit_ty_common(&field.ty);
Expand Down Expand Up @@ -251,66 +245,6 @@ impl<'a> AstValidator<'a> {
err.emit();
}

fn check_anonymous_field(&self, field: &FieldDef) {
let FieldDef { ty, .. } = field;
match &ty.kind {
TyKind::AnonymousStruct(..) | TyKind::AnonymousUnion(..) => {
// We already checked for `kw::Underscore` before calling this function,
// so skip the check
}
TyKind::Path(..) => {
// If the anonymous field contains a Path as type, we can't determine
// if the path is a valid struct or union, so skip the check
}
_ => {
let msg = "unnamed fields can only have struct or union types";
let label = "not a struct or union";
self.err_handler()
.struct_span_err(field.span, msg)
.span_label(ty.span, label)
.emit();
}
}
}

fn deny_anonymous_struct(&self, ty: &Ty) {
match &ty.kind {
TyKind::AnonymousStruct(..) => {
self.err_handler()
.struct_span_err(
ty.span,
"anonymous structs are not allowed outside of unnamed struct or union fields",
)
.span_label(ty.span, "anonymous struct declared here")
.emit();
}
TyKind::AnonymousUnion(..) => {
self.err_handler()
.struct_span_err(
ty.span,
"anonymous unions are not allowed outside of unnamed struct or union fields",
)
.span_label(ty.span, "anonymous union declared here")
.emit();
}
_ => {}
}
}

fn deny_anonymous_field(&self, field: &FieldDef) {
if let Some(ident) = field.ident {
if ident.name == kw::Underscore {
self.err_handler()
.struct_span_err(
field.span,
"anonymous fields are not allowed outside of structs or unions",
)
.span_label(ident.span, "anonymous field declared here")
.emit()
}
}
}

fn check_decl_no_pat(decl: &FnDecl, mut report_err: impl FnMut(Span, Option<Ident>, bool)) {
for Param { pat, .. } in &decl.inputs {
match pat.kind {
Expand Down Expand Up @@ -1081,7 +1015,6 @@ impl<'a> Visitor<'a> for AstValidator<'a> {

fn visit_ty(&mut self, ty: &'a Ty) {
self.visit_ty_common(ty);
self.deny_anonymous_struct(ty);
self.walk_ty(ty)
}

Expand All @@ -1096,7 +1029,6 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
}

fn visit_field_def(&mut self, s: &'a FieldDef) {
self.deny_anonymous_field(s);
visit::walk_field_def(self, s)
}

Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
// involved, so we only emit errors where there are no other parsing errors.
gate_all!(destructuring_assignment, "destructuring assignments are unstable");
}
gate_all!(unnamed_fields, "unnamed fields are not yet fully implemented");

// All uses of `gate_all!` below this point were added in #65742,
// and subsequently disabled (with the non-early gating readded).
Expand Down
16 changes: 6 additions & 10 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -985,14 +985,6 @@ impl<'a> State<'a> {
}
self.pclose();
}
ast::TyKind::AnonymousStruct(ref fields, ..) => {
self.head("struct");
self.print_record_struct_body(&fields, ty.span);
}
ast::TyKind::AnonymousUnion(ref fields, ..) => {
self.head("union");
self.print_record_struct_body(&fields, ty.span);
}
ast::TyKind::Paren(ref typ) => {
self.popen();
self.print_type(typ);
Expand Down Expand Up @@ -1413,7 +1405,12 @@ impl<'a> State<'a> {
}
}

crate fn print_record_struct_body(&mut self, fields: &[ast::FieldDef], span: rustc_span::Span) {
crate fn print_record_struct_body(
&mut self,
fields: &Vec<ast::FieldDef>,
span: rustc_span::Span,
) {
self.nbsp();
self.bopen();
self.hardbreak_if_not_bol();

Expand Down Expand Up @@ -1462,7 +1459,6 @@ impl<'a> State<'a> {
}
ast::VariantData::Struct(ref fields, ..) => {
self.print_where_clause(&generics.where_clause);
self.nbsp();
self.print_record_struct_body(fields, span);
}
}
Expand Down
9 changes: 2 additions & 7 deletions compiler/rustc_const_eval/src/interpret/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,10 @@ crate fn eval_nullary_intrinsic<'tcx>(
ensure_monomorphic_enough(tcx, tp_ty)?;
ConstValue::from_bool(tp_ty.needs_drop(tcx, param_env))
}
sym::min_align_of | sym::pref_align_of => {
sym::pref_align_of => {
// Correctly handles non-monomorphic calls, so there is no need for ensure_monomorphic_enough.
let layout = tcx.layout_of(param_env.and(tp_ty)).map_err(|e| err_inval!(Layout(e)))?;
let n = match name {
sym::pref_align_of => layout.align.pref.bytes(),
sym::min_align_of => layout.align.abi.bytes(),
_ => bug!(),
};
ConstValue::from_machine_usize(n, &tcx)
ConstValue::from_machine_usize(layout.align.pref.bytes(), &tcx)
}
sym::type_id => {
ensure_monomorphic_enough(tcx, tp_ty)?;
Expand Down
23 changes: 16 additions & 7 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ impl EmitterWriter {
}

let source_string = match file.get_line(line.line_index - 1) {
Some(s) => replace_tabs(&*s),
Some(s) => normalize_whitespace(&*s),
None => return Vec::new(),
};

Expand Down Expand Up @@ -1272,7 +1272,7 @@ impl EmitterWriter {
buffer.append(0, ": ", header_style);
}
for &(ref text, _) in msg.iter() {
buffer.append(0, &replace_tabs(text), header_style);
buffer.append(0, &normalize_whitespace(text), header_style);
}
}

Expand Down Expand Up @@ -1526,7 +1526,7 @@ impl EmitterWriter {

self.draw_line(
&mut buffer,
&replace_tabs(&unannotated_line),
&normalize_whitespace(&unannotated_line),
annotated_file.lines[line_idx + 1].line_index - 1,
last_buffer_line_num,
width_offset,
Expand Down Expand Up @@ -1648,7 +1648,7 @@ impl EmitterWriter {
buffer.puts(
row_num - 1,
max_line_num_len + 3,
&replace_tabs(
&normalize_whitespace(
&*file_lines
.file
.get_line(file_lines.lines[line_pos].line_index)
Expand All @@ -1674,7 +1674,7 @@ impl EmitterWriter {
}

// print the suggestion
buffer.append(row_num, &replace_tabs(line), Style::NoStyle);
buffer.append(row_num, &normalize_whitespace(line), Style::NoStyle);

// Colorize addition/replacements with green.
for &SubstitutionHighlight { start, end } in highlight_parts {
Expand Down Expand Up @@ -2054,8 +2054,17 @@ fn num_decimal_digits(num: usize) -> usize {
MAX_DIGITS
}

fn replace_tabs(str: &str) -> String {
str.replace('\t', " ")
const REPLACEMENTS: &[(char, &str)] = &[
('\t', " "),
('\u{200D}', ""), // Replace ZWJ with nothing for consistent terminal output of grapheme clusters.
];

fn normalize_whitespace(str: &str) -> String {
let mut output = str.to_string();
for (c, replacement) in REPLACEMENTS {
output = output.replace(*c, replacement);
}
output
}

fn draw_col_separator(buffer: &mut StyledBuffer, line: usize, col: usize) {
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,9 +638,6 @@ declare_features! (
/// Allows specifying the as-needed link modifier
(active, native_link_modifiers_as_needed, "1.53.0", Some(81490), None),

/// Allows unnamed fields of struct and union type
(incomplete, unnamed_fields, "1.53.0", Some(49804), None),

/// Allows qualified paths in struct expressions, struct patterns and tuple struct patterns.
(active, more_qualified_paths, "1.54.0", Some(86935), None),

Expand Down
10 changes: 6 additions & 4 deletions compiler/rustc_infer/src/traits/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ pub fn report_object_safety_error(
messages.push(msg.clone());
}
}
if trait_span.is_some() {
// Only provide the help if its a local trait, otherwise it's not actionable.
violation.solution(&mut err);
}
}
}
let has_multi_span = !multi_span.is_empty();
Expand All @@ -104,5 +100,11 @@ pub fn report_object_safety_error(
to be resolvable dynamically; for more information visit \
<https://doc.rust-lang.org/reference/items/traits.html#object-safety>",
);
if trait_span.is_some() {
for violation in reported_violations {
// Only provide the help if its a local trait, otherwise it's not actionable.
violation.solution(&mut err);
}
}
err
}
Loading