Skip to content

Commit 23744c8

Browse files
committed
Auto merge of rust-lang#74342 - Manishearth:rollup-l63pesj, r=Manishearth
Rollup of 11 pull requests Successful merges: - rust-lang#73759 (Add missing Stdin and StdinLock examples) - rust-lang#74211 (Structured suggestion when not using struct pattern) - rust-lang#74228 (Provide structured suggestion on unsized fields and fn params) - rust-lang#74252 (Don't allow `DESTDIR` to influence LLVM builds) - rust-lang#74263 (Slight reorganization of sys/(fast_)thread_local) - rust-lang#74271 (process_unix: prefer i32::*_be_bytes over manually shifting bytes) - rust-lang#74272 (pprust: support multiline comments within lines) - rust-lang#74332 (Update cargo) - rust-lang#74334 (bootstrap: Improve wording on docs for `verbose-tests`) - rust-lang#74336 (typeck: use `item_name` in cross-crate packed diag) - rust-lang#74340 (lint: use `transparent_newtype_field` to avoid ICE) Failed merges: r? @ghost
2 parents 2002eba + dbe7ed3 commit 23744c8

File tree

189 files changed

+1068
-703
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

189 files changed

+1068
-703
lines changed

config.toml.example

+1-2
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,7 @@
391391
# desired in distributions, for example.
392392
#rpath = true
393393

394-
# Emits extraneous output from tests to ensure that failures of the test
395-
# harness are debuggable just from logfiles.
394+
# Emits extra output from tests so test failures are debuggable just from logfiles.
396395
#verbose-tests = false
397396

398397
# Flag indicating whether tests are compiled with optimizations (the -O flag).

src/bootstrap/native.rs

+5
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,11 @@ fn configure_cmake(
347347
// LLVM and LLD builds can produce a lot of those and hit CI limits on log size.
348348
cfg.define("CMAKE_INSTALL_MESSAGE", "LAZY");
349349

350+
// Do not allow the user's value of DESTDIR to influence where
351+
// LLVM will install itself. LLVM must always be installed in our
352+
// own build directories.
353+
cfg.env("DESTDIR", "");
354+
350355
if builder.config.ninja {
351356
cfg.generator("Ninja");
352357
}

src/libcore/marker.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,8 @@ impl<T: ?Sized> !Send for *mut T {}
8484
#[stable(feature = "rust1", since = "1.0.0")]
8585
#[lang = "sized"]
8686
#[rustc_on_unimplemented(
87-
on(parent_trait = "std::path::Path", label = "borrow the `Path` instead"),
8887
message = "the size for values of type `{Self}` cannot be known at compilation time",
89-
label = "doesn't have a size known at compile-time",
90-
note = "to learn more, visit <https://doc.rust-lang.org/book/\
91-
ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>"
88+
label = "doesn't have a size known at compile-time"
9289
)]
9390
#[fundamental] // for Default, for example, which requires that `[T]: !Default` be evaluatable
9491
#[rustc_specialization_trait]

src/librustc_ast_lowering/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
526526
Ident::with_dummy_span(sym::_task_context),
527527
hir::BindingAnnotation::Mutable,
528528
);
529-
let param = hir::Param { attrs: &[], hir_id: self.next_id(), pat, span };
529+
let param = hir::Param { attrs: &[], hir_id: self.next_id(), pat, ty_span: span, span };
530530
let params = arena_vec![self; param];
531531

532532
let body_id = self.lower_body(move |this| {

src/librustc_ast_lowering/item.rs

+2
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
972972
attrs: self.lower_attrs(&param.attrs),
973973
hir_id: self.lower_node_id(param.id),
974974
pat: self.lower_pat(&param.pat),
975+
ty_span: param.ty.span,
975976
span: param.span,
976977
}
977978
}
@@ -1098,6 +1099,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10981099
attrs: parameter.attrs,
10991100
hir_id: parameter.hir_id,
11001101
pat: new_parameter_pat,
1102+
ty_span: parameter.ty_span,
11011103
span: parameter.span,
11021104
};
11031105

src/librustc_ast_pretty/pprust.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,20 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
450450
fn print_comment(&mut self, cmnt: &comments::Comment) {
451451
match cmnt.style {
452452
comments::Mixed => {
453-
assert_eq!(cmnt.lines.len(), 1);
454453
self.zerobreak();
455-
self.word(cmnt.lines[0].clone());
454+
if let Some((last, lines)) = cmnt.lines.split_last() {
455+
self.ibox(0);
456+
457+
for line in lines {
458+
self.word(line.clone());
459+
self.hardbreak()
460+
}
461+
462+
self.word(last.clone());
463+
self.space();
464+
465+
self.end();
466+
}
456467
self.zerobreak()
457468
}
458469
comments::Isolated => {

src/librustc_hir/hir.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2148,6 +2148,7 @@ pub struct Param<'hir> {
21482148
pub attrs: &'hir [Attribute],
21492149
pub hir_id: HirId,
21502150
pub pat: &'hir Pat<'hir>,
2151+
pub ty_span: Span,
21512152
pub span: Span,
21522153
}
21532154

src/librustc_lint/types.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -531,23 +531,23 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
531531
match ty.kind {
532532
ty::FnPtr(_) => true,
533533
ty::Ref(..) => true,
534-
ty::Adt(field_def, substs) if field_def.repr.transparent() && !field_def.is_union() => {
535-
for field in field_def.all_fields() {
536-
let field_ty = self.cx.tcx.normalize_erasing_regions(
537-
self.cx.param_env,
538-
field.ty(self.cx.tcx, substs),
539-
);
540-
if field_ty.is_zst(self.cx.tcx, field.did) {
541-
continue;
542-
}
534+
ty::Adt(def, substs) if def.repr.transparent() && !def.is_union() => {
535+
let guaranteed_nonnull_optimization = self
536+
.cx
537+
.tcx
538+
.get_attrs(def.did)
539+
.iter()
540+
.any(|a| a.check_name(sym::rustc_nonnull_optimization_guaranteed));
541+
542+
if guaranteed_nonnull_optimization {
543+
return true;
544+
}
543545

544-
let attrs = self.cx.tcx.get_attrs(field_def.did);
545-
if attrs
546-
.iter()
547-
.any(|a| a.check_name(sym::rustc_nonnull_optimization_guaranteed))
548-
|| self.ty_is_known_nonnull(field_ty)
549-
{
550-
return true;
546+
for variant in &def.variants {
547+
if let Some(field) = variant.transparent_newtype_field(self.cx.tcx) {
548+
if self.ty_is_known_nonnull(field.ty(self.cx.tcx, substs)) {
549+
return true;
550+
}
551551
}
552552
}
553553

src/librustc_middle/traits/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ pub enum ObligationCauseCode<'tcx> {
215215
/// Type of each variable must be `Sized`.
216216
VariableType(hir::HirId),
217217
/// Argument type must be `Sized`.
218-
SizedArgumentType,
218+
SizedArgumentType(Option<Span>),
219219
/// Return type must be `Sized`.
220220
SizedReturnType,
221221
/// Yield type must be `Sized`.
@@ -229,6 +229,7 @@ pub enum ObligationCauseCode<'tcx> {
229229
/// Types of fields (other than the last, except for packed structs) in a struct must be sized.
230230
FieldSized {
231231
adt_kind: AdtKind,
232+
span: Span,
232233
last: bool,
233234
},
234235

src/librustc_middle/traits/structural_impls.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,14 @@ impl<'a, 'tcx> Lift<'tcx> for traits::ObligationCauseCode<'a> {
151151
super::VariableType(id) => Some(super::VariableType(id)),
152152
super::ReturnValue(id) => Some(super::ReturnValue(id)),
153153
super::ReturnType => Some(super::ReturnType),
154-
super::SizedArgumentType => Some(super::SizedArgumentType),
154+
super::SizedArgumentType(sp) => Some(super::SizedArgumentType(sp)),
155155
super::SizedReturnType => Some(super::SizedReturnType),
156156
super::SizedYieldType => Some(super::SizedYieldType),
157157
super::InlineAsmSized => Some(super::InlineAsmSized),
158158
super::RepeatVec(suggest_flag) => Some(super::RepeatVec(suggest_flag)),
159-
super::FieldSized { adt_kind, last } => Some(super::FieldSized { adt_kind, last }),
159+
super::FieldSized { adt_kind, span, last } => {
160+
Some(super::FieldSized { adt_kind, span, last })
161+
}
160162
super::ConstSized => Some(super::ConstSized),
161163
super::ConstPatternStructural => Some(super::ConstPatternStructural),
162164
super::SharedStatic => Some(super::SharedStatic),

src/librustc_resolve/build_reduced_graph.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
300300
}
301301

302302
fn insert_field_names(&mut self, def_id: DefId, field_names: Vec<Spanned<Symbol>>) {
303-
if !field_names.is_empty() {
304-
self.r.field_names.insert(def_id, field_names);
305-
}
303+
self.r.field_names.insert(def_id, field_names);
306304
}
307305

308306
fn block_needs_anonymous_module(&mut self, block: &Block) -> bool {
@@ -1428,6 +1426,8 @@ impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> {
14281426
let ctor_kind = CtorKind::from_ast(&variant.data);
14291427
let ctor_res = Res::Def(DefKind::Ctor(CtorOf::Variant, ctor_kind), ctor_def_id);
14301428
self.r.define(parent, ident, ValueNS, (ctor_res, ctor_vis, variant.span, expn_id));
1429+
// Record field names for error reporting.
1430+
self.insert_field_names_local(ctor_def_id, &variant.data);
14311431

14321432
visit::walk_variant(self, variant);
14331433
}

src/librustc_resolve/late.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ crate enum PathSource<'a> {
184184
// Paths in struct expressions and patterns `Path { .. }`.
185185
Struct,
186186
// Paths in tuple struct patterns `Path(..)`.
187-
TupleStruct,
187+
TupleStruct(Span),
188188
// `m::A::B` in `<T as m::A>::B::C`.
189189
TraitItem(Namespace),
190190
}
@@ -193,7 +193,7 @@ impl<'a> PathSource<'a> {
193193
fn namespace(self) -> Namespace {
194194
match self {
195195
PathSource::Type | PathSource::Trait(_) | PathSource::Struct => TypeNS,
196-
PathSource::Expr(..) | PathSource::Pat | PathSource::TupleStruct => ValueNS,
196+
PathSource::Expr(..) | PathSource::Pat | PathSource::TupleStruct(_) => ValueNS,
197197
PathSource::TraitItem(ns) => ns,
198198
}
199199
}
@@ -204,7 +204,7 @@ impl<'a> PathSource<'a> {
204204
| PathSource::Expr(..)
205205
| PathSource::Pat
206206
| PathSource::Struct
207-
| PathSource::TupleStruct => true,
207+
| PathSource::TupleStruct(_) => true,
208208
PathSource::Trait(_) | PathSource::TraitItem(..) => false,
209209
}
210210
}
@@ -215,7 +215,7 @@ impl<'a> PathSource<'a> {
215215
PathSource::Trait(_) => "trait",
216216
PathSource::Pat => "unit struct, unit variant or constant",
217217
PathSource::Struct => "struct, variant or union type",
218-
PathSource::TupleStruct => "tuple struct or tuple variant",
218+
PathSource::TupleStruct(_) => "tuple struct or tuple variant",
219219
PathSource::TraitItem(ns) => match ns {
220220
TypeNS => "associated type",
221221
ValueNS => "method or associated constant",
@@ -301,7 +301,7 @@ impl<'a> PathSource<'a> {
301301
| Res::SelfCtor(..) => true,
302302
_ => false,
303303
},
304-
PathSource::TupleStruct => match res {
304+
PathSource::TupleStruct(_) => match res {
305305
Res::Def(DefKind::Ctor(_, CtorKind::Fn), _) | Res::SelfCtor(..) => true,
306306
_ => false,
307307
},
@@ -336,8 +336,8 @@ impl<'a> PathSource<'a> {
336336
(PathSource::Struct, false) => error_code!(E0422),
337337
(PathSource::Expr(..), true) => error_code!(E0423),
338338
(PathSource::Expr(..), false) => error_code!(E0425),
339-
(PathSource::Pat | PathSource::TupleStruct, true) => error_code!(E0532),
340-
(PathSource::Pat | PathSource::TupleStruct, false) => error_code!(E0531),
339+
(PathSource::Pat | PathSource::TupleStruct(_), true) => error_code!(E0532),
340+
(PathSource::Pat | PathSource::TupleStruct(_), false) => error_code!(E0531),
341341
(PathSource::TraitItem(..), true) => error_code!(E0575),
342342
(PathSource::TraitItem(..), false) => error_code!(E0576),
343343
}
@@ -1483,7 +1483,7 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
14831483
self.r.record_partial_res(pat.id, PartialRes::new(res));
14841484
}
14851485
PatKind::TupleStruct(ref path, ..) => {
1486-
self.smart_resolve_path(pat.id, None, path, PathSource::TupleStruct);
1486+
self.smart_resolve_path(pat.id, None, path, PathSource::TupleStruct(pat.span));
14871487
}
14881488
PatKind::Path(ref qself, ref path) => {
14891489
self.smart_resolve_path(pat.id, qself.as_ref(), path, PathSource::Pat);

src/librustc_resolve/late/diagnostics.rs

+57-11
Original file line numberDiff line numberDiff line change
@@ -480,10 +480,12 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
480480

481481
let mut bad_struct_syntax_suggestion = |def_id: DefId| {
482482
let (followed_by_brace, closing_brace) = self.followed_by_brace(span);
483-
let mut suggested = false;
483+
484484
match source {
485-
PathSource::Expr(Some(parent)) => {
486-
suggested = path_sep(err, &parent);
485+
PathSource::Expr(Some(
486+
parent @ Expr { kind: ExprKind::Field(..) | ExprKind::MethodCall(..), .. },
487+
)) => {
488+
path_sep(err, &parent);
487489
}
488490
PathSource::Expr(None) if followed_by_brace => {
489491
if let Some(sp) = closing_brace {
@@ -505,15 +507,56 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
505507
),
506508
);
507509
}
508-
suggested = true;
509510
}
510-
_ => {}
511-
}
512-
if !suggested {
513-
if let Some(span) = self.r.opt_span(def_id) {
514-
err.span_label(span, &format!("`{}` defined here", path_str));
511+
PathSource::Expr(
512+
None | Some(Expr { kind: ExprKind::Call(..) | ExprKind::Path(..), .. }),
513+
)
514+
| PathSource::TupleStruct(_)
515+
| PathSource::Pat => {
516+
let span = match &source {
517+
PathSource::Expr(Some(Expr {
518+
span, kind: ExprKind::Call(_, _), ..
519+
}))
520+
| PathSource::TupleStruct(span) => {
521+
// We want the main underline to cover the suggested code as well for
522+
// cleaner output.
523+
err.set_span(*span);
524+
*span
525+
}
526+
_ => span,
527+
};
528+
if let Some(span) = self.r.opt_span(def_id) {
529+
err.span_label(span, &format!("`{}` defined here", path_str));
530+
}
531+
let (tail, descr, applicability) = match source {
532+
PathSource::Pat | PathSource::TupleStruct(_) => {
533+
("", "pattern", Applicability::MachineApplicable)
534+
}
535+
_ => (": val", "literal", Applicability::HasPlaceholders),
536+
};
537+
let (fields, applicability) = match self.r.field_names.get(&def_id) {
538+
Some(fields) => (
539+
fields
540+
.iter()
541+
.map(|f| format!("{}{}", f.node, tail))
542+
.collect::<Vec<String>>()
543+
.join(", "),
544+
applicability,
545+
),
546+
None => ("/* fields */".to_string(), Applicability::HasPlaceholders),
547+
};
548+
let pad = match self.r.field_names.get(&def_id) {
549+
Some(fields) if fields.is_empty() => "",
550+
_ => " ",
551+
};
552+
err.span_suggestion(
553+
span,
554+
&format!("use struct {} syntax instead", descr),
555+
format!("{} {{{pad}{}{pad}}}", path_str, fields, pad = pad),
556+
applicability,
557+
);
515558
}
516-
err.span_label(span, format!("did you mean `{} {{ /* fields */ }}`?", path_str));
559+
_ => {}
517560
}
518561
};
519562

@@ -546,7 +589,10 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
546589
return false;
547590
}
548591
}
549-
(Res::Def(DefKind::Enum, def_id), PathSource::TupleStruct | PathSource::Expr(..)) => {
592+
(
593+
Res::Def(DefKind::Enum, def_id),
594+
PathSource::TupleStruct(_) | PathSource::Expr(..),
595+
) => {
550596
if let Some(variants) = self.collect_enum_variants(def_id) {
551597
if !variants.is_empty() {
552598
let msg = if variants.len() == 1 {

src/librustc_trait_selection/traits/error_reporting/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,12 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
376376
// If it has a custom `#[rustc_on_unimplemented]`
377377
// error message, let's display it as the label!
378378
err.span_label(span, s.as_str());
379-
err.help(&explanation);
379+
if !matches!(trait_ref.skip_binder().self_ty().kind, ty::Param(_)) {
380+
// When the self type is a type param We don't need to "the trait
381+
// `std::marker::Sized` is not implemented for `T`" as we will point
382+
// at the type param with a label to suggest constraining it.
383+
err.help(&explanation);
384+
}
380385
} else {
381386
err.span_label(span, explanation);
382387
}
@@ -403,7 +408,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
403408
}
404409

405410
self.suggest_dereferences(&obligation, &mut err, &trait_ref, points_at_arg);
406-
self.suggest_borrow_on_unsized_slice(&obligation.cause.code, &mut err);
407411
self.suggest_fn_call(&obligation, &mut err, &trait_ref, points_at_arg);
408412
self.suggest_remove_reference(&obligation, &mut err, &trait_ref);
409413
self.suggest_semicolon_removal(&obligation, &mut err, span, &trait_ref);

0 commit comments

Comments
 (0)