Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit affe0d3

Browse files
committedAug 5, 2022
Auto merge of rust-lang#100174 - Dylan-DPC:rollup-wnskbk6, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - rust-lang#99835 (Suggest adding/removing `ref` for binding patterns) - rust-lang#100155 (Use `node_type_opt` to skip over generics that were not expected) - rust-lang#100157 (rustdoc: use `collect()` instead of repeatedly pushing) - rust-lang#100158 (kmc-solid: Add a stub implementation of rust-lang#98246 (`File::set_times`)) - rust-lang#100166 (Remove more Clean trait implementations) - rust-lang#100168 (Improve diagnostics for `const a: = expr;`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents d77da9d + e7ed844 commit affe0d3

30 files changed

+414
-162
lines changed
 

‎compiler/rustc_parse/src/parser/item.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,39 +1179,47 @@ impl<'a> Parser<'a> {
11791179

11801180
// Parse the type of a `const` or `static mut?` item.
11811181
// That is, the `":" $ty` fragment.
1182-
let ty = if self.eat(&token::Colon) {
1183-
self.parse_ty()?
1184-
} else {
1185-
self.recover_missing_const_type(id, m)
1182+
let ty = match (self.eat(&token::Colon), self.check(&token::Eq) | self.check(&token::Semi))
1183+
{
1184+
// If there wasn't a `:` or the colon was followed by a `=` or `;` recover a missing type.
1185+
(true, false) => self.parse_ty()?,
1186+
(colon, _) => self.recover_missing_const_type(colon, m),
11861187
};
11871188

11881189
let expr = if self.eat(&token::Eq) { Some(self.parse_expr()?) } else { None };
11891190
self.expect_semi()?;
11901191
Ok((id, ty, expr))
11911192
}
11921193

1193-
/// We were supposed to parse `:` but the `:` was missing.
1194+
/// We were supposed to parse `":" $ty` but the `:` or the type was missing.
11941195
/// This means that the type is missing.
1195-
fn recover_missing_const_type(&mut self, id: Ident, m: Option<Mutability>) -> P<Ty> {
1196+
fn recover_missing_const_type(&mut self, colon_present: bool, m: Option<Mutability>) -> P<Ty> {
11961197
// Construct the error and stash it away with the hope
11971198
// that typeck will later enrich the error with a type.
11981199
let kind = match m {
11991200
Some(Mutability::Mut) => "static mut",
12001201
Some(Mutability::Not) => "static",
12011202
None => "const",
12021203
};
1203-
let mut err = self.struct_span_err(id.span, &format!("missing type for `{kind}` item"));
1204+
1205+
let colon = match colon_present {
1206+
true => "",
1207+
false => ":",
1208+
};
1209+
1210+
let span = self.prev_token.span.shrink_to_hi();
1211+
let mut err = self.struct_span_err(span, &format!("missing type for `{kind}` item"));
12041212
err.span_suggestion(
1205-
id.span,
1213+
span,
12061214
"provide a type for the item",
1207-
format!("{id}: <type>"),
1215+
format!("{colon} <type>"),
12081216
Applicability::HasPlaceholders,
12091217
);
1210-
err.stash(id.span, StashKey::ItemNoType);
1218+
err.stash(span, StashKey::ItemNoType);
12111219

12121220
// The user intended that the type be inferred,
12131221
// so treat this as if the user wrote e.g. `const A: _ = expr;`.
1214-
P(Ty { kind: TyKind::Infer, span: id.span, id: ast::DUMMY_NODE_ID, tokens: None })
1222+
P(Ty { kind: TyKind::Infer, span, id: ast::DUMMY_NODE_ID, tokens: None })
12151223
}
12161224

12171225
/// Parses an enum declaration.

‎compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,13 +1761,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17611761
.filter_map(|seg| seg.args.as_ref())
17621762
.flat_map(|a| a.args.iter())
17631763
{
1764-
if let hir::GenericArg::Type(hir_ty) = &arg {
1765-
let ty = self.resolve_vars_if_possible(
1766-
self.typeck_results.borrow().node_type(hir_ty.hir_id),
1767-
);
1768-
if ty == predicate.self_ty() {
1769-
error.obligation.cause.span = hir_ty.span;
1770-
}
1764+
if let hir::GenericArg::Type(hir_ty) = &arg
1765+
&& let Some(ty) =
1766+
self.typeck_results.borrow().node_type_opt(hir_ty.hir_id)
1767+
&& self.resolve_vars_if_possible(ty) == predicate.self_ty()
1768+
{
1769+
error.obligation.cause.span = hir_ty.span;
1770+
break;
17711771
}
17721772
}
17731773
}

‎compiler/rustc_typeck/src/check/pat.rs

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
600600
// If there are multiple arms, make sure they all agree on
601601
// what the type of the binding `x` ought to be.
602602
if var_id != pat.hir_id {
603-
self.check_binding_alt_eq_ty(pat.span, var_id, local_ty, ti);
603+
self.check_binding_alt_eq_ty(ba, pat.span, var_id, local_ty, ti);
604604
}
605605

606606
if let Some(p) = sub {
@@ -610,7 +610,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
610610
local_ty
611611
}
612612

613-
fn check_binding_alt_eq_ty(&self, span: Span, var_id: HirId, ty: Ty<'tcx>, ti: TopInfo<'tcx>) {
613+
fn check_binding_alt_eq_ty(
614+
&self,
615+
ba: hir::BindingAnnotation,
616+
span: Span,
617+
var_id: HirId,
618+
ty: Ty<'tcx>,
619+
ti: TopInfo<'tcx>,
620+
) {
614621
let var_ty = self.local_ty(span, var_id).decl_ty;
615622
if let Some(mut err) = self.demand_eqtype_pat_diag(span, var_ty, ty, ti) {
616623
let hir = self.tcx.hir();
@@ -628,12 +635,50 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
628635
});
629636
let pre = if in_match { "in the same arm, " } else { "" };
630637
err.note(&format!("{}a binding must have the same type in all alternatives", pre));
631-
// FIXME: check if `var_ty` and `ty` can be made the same type by adding or removing
632-
// `ref` or `&` to the pattern.
638+
self.suggest_adding_missing_ref_or_removing_ref(
639+
&mut err,
640+
span,
641+
var_ty,
642+
self.resolve_vars_with_obligations(ty),
643+
ba,
644+
);
633645
err.emit();
634646
}
635647
}
636648

649+
fn suggest_adding_missing_ref_or_removing_ref(
650+
&self,
651+
err: &mut Diagnostic,
652+
span: Span,
653+
expected: Ty<'tcx>,
654+
actual: Ty<'tcx>,
655+
ba: hir::BindingAnnotation,
656+
) {
657+
match (expected.kind(), actual.kind(), ba) {
658+
(ty::Ref(_, inner_ty, _), _, hir::BindingAnnotation::Unannotated)
659+
if self.can_eq(self.param_env, *inner_ty, actual).is_ok() =>
660+
{
661+
err.span_suggestion_verbose(
662+
span.shrink_to_lo(),
663+
"consider adding `ref`",
664+
"ref ",
665+
Applicability::MaybeIncorrect,
666+
);
667+
}
668+
(_, ty::Ref(_, inner_ty, _), hir::BindingAnnotation::Ref)
669+
if self.can_eq(self.param_env, expected, *inner_ty).is_ok() =>
670+
{
671+
err.span_suggestion_verbose(
672+
span.with_hi(span.lo() + BytePos(4)),
673+
"consider removing `ref`",
674+
"",
675+
Applicability::MaybeIncorrect,
676+
);
677+
}
678+
_ => (),
679+
}
680+
}
681+
637682
// Precondition: pat is a Ref(_) pattern
638683
fn borrow_pat_suggestion(&self, err: &mut Diagnostic, pat: &Pat<'_>) {
639684
let tcx = self.tcx;

‎compiler/rustc_typeck/src/collect/type_of.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,9 @@ fn infer_placeholder_type<'a>(
801801
match tcx.sess.diagnostic().steal_diagnostic(span, StashKey::ItemNoType) {
802802
Some(mut err) => {
803803
if !ty.references_error() {
804+
// Only suggest adding `:` if it was missing (and suggested by parsing diagnostic)
805+
let colon = if span == item_ident.span.shrink_to_hi() { ":" } else { "" };
806+
804807
// The parser provided a sub-optimal `HasPlaceholders` suggestion for the type.
805808
// We are typeck and have the real type, so remove that and suggest the actual type.
806809
// FIXME(eddyb) this looks like it should be functionality on `Diagnostic`.
@@ -816,7 +819,7 @@ fn infer_placeholder_type<'a>(
816819
err.span_suggestion(
817820
span,
818821
&format!("provide a type for the {item}", item = kind),
819-
format!("{}: {}", item_ident, sugg_ty),
822+
format!("{colon} {sugg_ty}"),
820823
Applicability::MachineApplicable,
821824
);
822825
} else {

‎library/std/src/sys/solid/fs.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ pub struct OpenOptions {
7777
custom_flags: i32,
7878
}
7979

80+
#[derive(Copy, Clone, Debug, Default)]
81+
pub struct FileTimes {}
82+
8083
#[derive(Clone, PartialEq, Eq, Debug)]
8184
pub struct FilePermissions(c_short);
8285

@@ -126,6 +129,11 @@ impl FilePermissions {
126129
}
127130
}
128131

132+
impl FileTimes {
133+
pub fn set_accessed(&mut self, _t: SystemTime) {}
134+
pub fn set_modified(&mut self, _t: SystemTime) {}
135+
}
136+
129137
impl FileType {
130138
pub fn is_dir(&self) -> bool {
131139
self.is(abi::S_IFDIR)
@@ -452,6 +460,10 @@ impl File {
452460
pub fn set_permissions(&self, _perm: FilePermissions) -> io::Result<()> {
453461
unsupported()
454462
}
463+
464+
pub fn set_times(&self, _times: FileTimes) -> io::Result<()> {
465+
unsupported()
466+
}
455467
}
456468

457469
impl Drop for File {

‎src/librustdoc/clean/mod.rs

Lines changed: 82 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ impl<'tcx> Clean<'tcx, Option<GenericBound>> for hir::GenericBound<'tcx> {
156156
return None;
157157
}
158158

159-
GenericBound::TraitBound(t.clean(cx), modifier)
159+
GenericBound::TraitBound(clean_poly_trait_ref(t, cx), modifier)
160160
}
161161
})
162162
}
@@ -1001,69 +1001,68 @@ fn clean_trait_ref<'tcx>(trait_ref: &hir::TraitRef<'tcx>, cx: &mut DocContext<'t
10011001
path
10021002
}
10031003

1004-
impl<'tcx> Clean<'tcx, PolyTrait> for hir::PolyTraitRef<'tcx> {
1005-
fn clean(&self, cx: &mut DocContext<'tcx>) -> PolyTrait {
1006-
PolyTrait {
1007-
trait_: clean_trait_ref(&self.trait_ref, cx),
1008-
generic_params: self
1009-
.bound_generic_params
1010-
.iter()
1011-
.filter(|p| !is_elided_lifetime(p))
1012-
.map(|x| clean_generic_param(cx, None, x))
1013-
.collect(),
1014-
}
1004+
fn clean_poly_trait_ref<'tcx>(
1005+
poly_trait_ref: &hir::PolyTraitRef<'tcx>,
1006+
cx: &mut DocContext<'tcx>,
1007+
) -> PolyTrait {
1008+
PolyTrait {
1009+
trait_: clean_trait_ref(&poly_trait_ref.trait_ref, cx),
1010+
generic_params: poly_trait_ref
1011+
.bound_generic_params
1012+
.iter()
1013+
.filter(|p| !is_elided_lifetime(p))
1014+
.map(|x| clean_generic_param(cx, None, x))
1015+
.collect(),
10151016
}
10161017
}
10171018

1018-
impl<'tcx> Clean<'tcx, Item> for hir::TraitItem<'tcx> {
1019-
fn clean(&self, cx: &mut DocContext<'tcx>) -> Item {
1020-
let local_did = self.def_id.to_def_id();
1021-
cx.with_param_env(local_did, |cx| {
1022-
let inner = match self.kind {
1023-
hir::TraitItemKind::Const(ty, Some(default)) => AssocConstItem(
1024-
clean_ty(ty, cx),
1025-
ConstantKind::Local { def_id: local_did, body: default },
1026-
),
1027-
hir::TraitItemKind::Const(ty, None) => TyAssocConstItem(clean_ty(ty, cx)),
1028-
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(body)) => {
1029-
let m = clean_function(cx, sig, self.generics, body);
1030-
MethodItem(m, None)
1031-
}
1032-
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Required(names)) => {
1033-
let (generics, decl) = enter_impl_trait(cx, |cx| {
1034-
// NOTE: generics must be cleaned before args
1035-
let generics = self.generics.clean(cx);
1036-
let args = clean_args_from_types_and_names(cx, sig.decl.inputs, names);
1037-
let decl = clean_fn_decl_with_args(cx, sig.decl, args);
1038-
(generics, decl)
1039-
});
1040-
TyMethodItem(Box::new(Function { decl, generics }))
1041-
}
1042-
hir::TraitItemKind::Type(bounds, Some(default)) => {
1043-
let generics = enter_impl_trait(cx, |cx| self.generics.clean(cx));
1044-
let bounds = bounds.iter().filter_map(|x| x.clean(cx)).collect();
1045-
let item_type = clean_middle_ty(hir_ty_to_ty(cx.tcx, default), cx, None);
1046-
AssocTypeItem(
1047-
Box::new(Typedef {
1048-
type_: clean_ty(default, cx),
1049-
generics,
1050-
item_type: Some(item_type),
1051-
}),
1052-
bounds,
1053-
)
1054-
}
1055-
hir::TraitItemKind::Type(bounds, None) => {
1056-
let generics = enter_impl_trait(cx, |cx| self.generics.clean(cx));
1057-
let bounds = bounds.iter().filter_map(|x| x.clean(cx)).collect();
1058-
TyAssocTypeItem(Box::new(generics), bounds)
1059-
}
1060-
};
1061-
let what_rustc_thinks =
1062-
Item::from_def_id_and_parts(local_did, Some(self.ident.name), inner, cx);
1063-
// Trait items always inherit the trait's visibility -- we don't want to show `pub`.
1064-
Item { visibility: Inherited, ..what_rustc_thinks }
1065-
})
1066-
}
1019+
fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext<'tcx>) -> Item {
1020+
let local_did = trait_item.def_id.to_def_id();
1021+
cx.with_param_env(local_did, |cx| {
1022+
let inner = match trait_item.kind {
1023+
hir::TraitItemKind::Const(ty, Some(default)) => AssocConstItem(
1024+
clean_ty(ty, cx),
1025+
ConstantKind::Local { def_id: local_did, body: default },
1026+
),
1027+
hir::TraitItemKind::Const(ty, None) => TyAssocConstItem(clean_ty(ty, cx)),
1028+
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(body)) => {
1029+
let m = clean_function(cx, sig, trait_item.generics, body);
1030+
MethodItem(m, None)
1031+
}
1032+
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Required(names)) => {
1033+
let (generics, decl) = enter_impl_trait(cx, |cx| {
1034+
// NOTE: generics must be cleaned before args
1035+
let generics = trait_item.generics.clean(cx);
1036+
let args = clean_args_from_types_and_names(cx, sig.decl.inputs, names);
1037+
let decl = clean_fn_decl_with_args(cx, sig.decl, args);
1038+
(generics, decl)
1039+
});
1040+
TyMethodItem(Box::new(Function { decl, generics }))
1041+
}
1042+
hir::TraitItemKind::Type(bounds, Some(default)) => {
1043+
let generics = enter_impl_trait(cx, |cx| trait_item.generics.clean(cx));
1044+
let bounds = bounds.iter().filter_map(|x| x.clean(cx)).collect();
1045+
let item_type = clean_middle_ty(hir_ty_to_ty(cx.tcx, default), cx, None);
1046+
AssocTypeItem(
1047+
Box::new(Typedef {
1048+
type_: clean_ty(default, cx),
1049+
generics,
1050+
item_type: Some(item_type),
1051+
}),
1052+
bounds,
1053+
)
1054+
}
1055+
hir::TraitItemKind::Type(bounds, None) => {
1056+
let generics = enter_impl_trait(cx, |cx| trait_item.generics.clean(cx));
1057+
let bounds = bounds.iter().filter_map(|x| x.clean(cx)).collect();
1058+
TyAssocTypeItem(Box::new(generics), bounds)
1059+
}
1060+
};
1061+
let what_rustc_thinks =
1062+
Item::from_def_id_and_parts(local_did, Some(trait_item.ident.name), inner, cx);
1063+
// Trait items always inherit the trait's visibility -- we don't want to show `pub`.
1064+
Item { visibility: Inherited, ..what_rustc_thinks }
1065+
})
10671066
}
10681067

10691068
impl<'tcx> Clean<'tcx, Item> for hir::ImplItem<'tcx> {
@@ -1515,7 +1514,7 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
15151514
}
15161515
TyKind::Path(_) => clean_qpath(ty, cx),
15171516
TyKind::TraitObject(bounds, ref lifetime, _) => {
1518-
let bounds = bounds.iter().map(|bound| bound.clean(cx)).collect();
1517+
let bounds = bounds.iter().map(|bound| clean_poly_trait_ref(bound, cx)).collect();
15191518
let lifetime =
15201519
if !lifetime.is_elided() { Some(clean_lifetime(*lifetime, cx)) } else { None };
15211520
DynTrait(bounds, lifetime)
@@ -1617,9 +1616,10 @@ pub(crate) fn clean_middle_ty<'tcx>(
16171616
// HACK: pick the first `did` as the `did` of the trait object. Someone
16181617
// might want to implement "native" support for marker-trait-only
16191618
// trait objects.
1620-
let mut dids = obj.principal_def_id().into_iter().chain(obj.auto_traits());
1621-
let did = dids
1622-
.next()
1619+
let mut dids = obj.auto_traits();
1620+
let did = obj
1621+
.principal_def_id()
1622+
.or_else(|| dids.next())
16231623
.unwrap_or_else(|| panic!("found trait object `{:?}` with no traits?", this));
16241624
let substs = match obj.principal() {
16251625
Some(principal) => principal.skip_binder().substs,
@@ -1630,19 +1630,18 @@ pub(crate) fn clean_middle_ty<'tcx>(
16301630
inline::record_extern_fqn(cx, did, ItemType::Trait);
16311631

16321632
let lifetime = clean_middle_region(*reg);
1633-
let mut bounds = vec![];
1634-
1635-
for did in dids {
1636-
let empty = cx.tcx.intern_substs(&[]);
1637-
let path = external_path(cx, did, false, vec![], empty);
1638-
inline::record_extern_fqn(cx, did, ItemType::Trait);
1639-
let bound = PolyTrait { trait_: path, generic_params: Vec::new() };
1640-
bounds.push(bound);
1641-
}
1633+
let mut bounds = dids
1634+
.map(|did| {
1635+
let empty = cx.tcx.intern_substs(&[]);
1636+
let path = external_path(cx, did, false, vec![], empty);
1637+
inline::record_extern_fqn(cx, did, ItemType::Trait);
1638+
PolyTrait { trait_: path, generic_params: Vec::new() }
1639+
})
1640+
.collect::<Vec<_>>();
16421641

1643-
let mut bindings = vec![];
1644-
for pb in obj.projection_bounds() {
1645-
bindings.push(TypeBinding {
1642+
let bindings = obj
1643+
.projection_bounds()
1644+
.map(|pb| TypeBinding {
16461645
assoc: projection_to_path_segment(
16471646
pb.skip_binder()
16481647
.lift_to_tcx(cx.tcx)
@@ -1656,8 +1655,8 @@ pub(crate) fn clean_middle_ty<'tcx>(
16561655
kind: TypeBindingKind::Equality {
16571656
term: clean_middle_term(pb.skip_binder().term, cx),
16581657
},
1659-
});
1660-
}
1658+
})
1659+
.collect();
16611660

16621661
let path = external_path(cx, did, false, bindings, substs);
16631662
bounds.insert(0, PolyTrait { trait_: path, generic_params: Vec::new() });
@@ -1953,8 +1952,10 @@ fn clean_maybe_renamed_item<'tcx>(
19531952
})
19541953
}
19551954
ItemKind::Trait(_, _, generics, bounds, item_ids) => {
1956-
let items =
1957-
item_ids.iter().map(|ti| cx.tcx.hir().trait_item(ti.id).clean(cx)).collect();
1955+
let items = item_ids
1956+
.iter()
1957+
.map(|ti| clean_trait_item(cx.tcx.hir().trait_item(ti.id), cx))
1958+
.collect();
19581959

19591960
TraitItem(Trait {
19601961
def_id,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn foo(i: impl std::fmt::Display) {}
2+
3+
fn main() {
4+
foo::<()>(());
5+
//~^ ERROR this function takes 0 generic arguments but 1 generic argument was supplied
6+
//~| ERROR `()` doesn't implement `std::fmt::Display`
7+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
error[E0107]: this function takes 0 generic arguments but 1 generic argument was supplied
2+
--> $DIR/issue-100154.rs:4:5
3+
|
4+
LL | foo::<()>(());
5+
| ^^^------ help: remove these generics
6+
| |
7+
| expected 0 generic arguments
8+
|
9+
note: function defined here, with 0 generic parameters
10+
--> $DIR/issue-100154.rs:1:4
11+
|
12+
LL | fn foo(i: impl std::fmt::Display) {}
13+
| ^^^
14+
= note: `impl Trait` cannot be explicitly specified as a generic argument
15+
16+
error[E0277]: `()` doesn't implement `std::fmt::Display`
17+
--> $DIR/issue-100154.rs:4:15
18+
|
19+
LL | foo::<()>(());
20+
| --------- ^^ `()` cannot be formatted with the default formatter
21+
| |
22+
| required by a bound introduced by this call
23+
|
24+
= help: the trait `std::fmt::Display` is not implemented for `()`
25+
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
26+
note: required by a bound in `foo`
27+
--> $DIR/issue-100154.rs:1:16
28+
|
29+
LL | fn foo(i: impl std::fmt::Display) {}
30+
| ^^^^^^^^^^^^^^^^^ required by this bound in `foo`
31+
32+
error: aborting due to 2 previous errors
33+
34+
Some errors have detailed explanations: E0107, E0277.
35+
For more information about an error, try `rustc --explain E0107`.

‎src/test/ui/attributes/issue-90873.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ LL | #![a={impl std::ops::Neg for i8 {}}]
3434
| ^ consider adding a `main` function to `$DIR/issue-90873.rs`
3535

3636
error: missing type for `static` item
37-
--> $DIR/issue-90873.rs:1:16
37+
--> $DIR/issue-90873.rs:1:17
3838
|
3939
LL | #![u=||{static d=||1;}]
40-
| ^ help: provide a type for the item: `d: <type>`
40+
| ^ help: provide a type for the item: `: <type>`
4141

4242
error: aborting due to 6 previous errors
4343

‎src/test/ui/issues/issue-69396-const-no-type-in-macro.stderr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ LL | | }
1717
= note: this error originates in the macro `suite` (in Nightly builds, run with -Z macro-backtrace for more info)
1818

1919
error: missing type for `const` item
20-
--> $DIR/issue-69396-const-no-type-in-macro.rs:4:19
20+
--> $DIR/issue-69396-const-no-type-in-macro.rs:4:20
2121
|
2222
LL | const A = "A".$fn();
23-
| ^ help: provide a type for the constant: `A: usize`
23+
| ^ help: provide a type for the constant: `: usize`
2424
...
2525
LL | / suite! {
2626
LL | | len;
@@ -31,13 +31,13 @@ LL | | }
3131
= note: this error originates in the macro `suite` (in Nightly builds, run with -Z macro-backtrace for more info)
3232

3333
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
34-
--> $DIR/issue-69396-const-no-type-in-macro.rs:4:19
34+
--> $DIR/issue-69396-const-no-type-in-macro.rs:4:20
3535
|
3636
LL | const A = "A".$fn();
37-
| ^
38-
| |
39-
| not allowed in type signatures
40-
| help: replace with the correct type: `bool`
37+
| ^
38+
| |
39+
| not allowed in type signatures
40+
| help: replace with the correct type: `bool`
4141
...
4242
LL | / suite! {
4343
LL | | len;

‎src/test/ui/mismatched_types/E0409.stderr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ LL | (0, ref y) | (y, 0) => {}
1717
| first introduced with type `&{integer}` here
1818
|
1919
= note: in the same arm, a binding must have the same type in all alternatives
20+
help: consider adding `ref`
21+
|
22+
LL | (0, ref y) | (ref y, 0) => {}
23+
| +++
2024

2125
error: aborting due to 2 previous errors
2226

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// run-rustfix
2+
#![allow(dead_code, unused_variables)]
3+
4+
fn main() {
5+
enum Blah {
6+
A(isize, isize, usize),
7+
B(isize, usize),
8+
}
9+
10+
match Blah::A(1, 1, 2) {
11+
Blah::A(_, x, ref y) | Blah::B(x, ref y) => {}
12+
//~^ ERROR mismatched types
13+
//~| ERROR variable `y` is bound inconsistently across alternatives separated by `|`
14+
}
15+
16+
match Blah::A(1, 1, 2) {
17+
Blah::A(_, x, y) | Blah::B(x, y) => {}
18+
//~^ ERROR mismatched types
19+
//~| variable `y` is bound inconsistently across alternatives separated by `|`
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// run-rustfix
2+
#![allow(dead_code, unused_variables)]
3+
4+
fn main() {
5+
enum Blah {
6+
A(isize, isize, usize),
7+
B(isize, usize),
8+
}
9+
10+
match Blah::A(1, 1, 2) {
11+
Blah::A(_, x, ref y) | Blah::B(x, y) => {}
12+
//~^ ERROR mismatched types
13+
//~| ERROR variable `y` is bound inconsistently across alternatives separated by `|`
14+
}
15+
16+
match Blah::A(1, 1, 2) {
17+
Blah::A(_, x, y) | Blah::B(x, ref y) => {}
18+
//~^ ERROR mismatched types
19+
//~| variable `y` is bound inconsistently across alternatives separated by `|`
20+
}
21+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
error[E0409]: variable `y` is bound inconsistently across alternatives separated by `|`
2+
--> $DIR/suggest-adding-or-removing-ref-for-binding-pattern.rs:11:43
3+
|
4+
LL | Blah::A(_, x, ref y) | Blah::B(x, y) => {}
5+
| - first binding ^ bound in different ways
6+
7+
error[E0409]: variable `y` is bound inconsistently across alternatives separated by `|`
8+
--> $DIR/suggest-adding-or-removing-ref-for-binding-pattern.rs:17:43
9+
|
10+
LL | Blah::A(_, x, y) | Blah::B(x, ref y) => {}
11+
| - first binding ^ bound in different ways
12+
13+
error[E0308]: mismatched types
14+
--> $DIR/suggest-adding-or-removing-ref-for-binding-pattern.rs:11:43
15+
|
16+
LL | match Blah::A(1, 1, 2) {
17+
| ---------------- this expression has type `Blah`
18+
LL | Blah::A(_, x, ref y) | Blah::B(x, y) => {}
19+
| ----- ^ expected `&usize`, found `usize`
20+
| |
21+
| first introduced with type `&usize` here
22+
|
23+
= note: in the same arm, a binding must have the same type in all alternatives
24+
help: consider adding `ref`
25+
|
26+
LL | Blah::A(_, x, ref y) | Blah::B(x, ref y) => {}
27+
| +++
28+
29+
error[E0308]: mismatched types
30+
--> $DIR/suggest-adding-or-removing-ref-for-binding-pattern.rs:17:39
31+
|
32+
LL | match Blah::A(1, 1, 2) {
33+
| ---------------- this expression has type `Blah`
34+
LL | Blah::A(_, x, y) | Blah::B(x, ref y) => {}
35+
| - ^^^^^ expected `usize`, found `&usize`
36+
| |
37+
| first introduced with type `usize` here
38+
|
39+
= note: in the same arm, a binding must have the same type in all alternatives
40+
help: consider removing `ref`
41+
|
42+
LL - Blah::A(_, x, y) | Blah::B(x, ref y) => {}
43+
LL + Blah::A(_, x, y) | Blah::B(x, y) => {}
44+
|
45+
46+
error: aborting due to 4 previous errors
47+
48+
Some errors have detailed explanations: E0308, E0409.
49+
For more information about an error, try `rustc --explain E0308`.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: missing type for `const` item
2-
--> $DIR/issue-89574.rs:2:11
2+
--> $DIR/issue-89574.rs:2:22
33
|
44
LL | const EMPTY_ARRAY = [];
5-
| ^^^^^^^^^^^ help: provide a type for the item: `EMPTY_ARRAY: <type>`
5+
| ^ help: provide a type for the item: `: <type>`
66

77
error: aborting due to previous error
88

‎src/test/ui/parser/item-free-const-no-body-semantic-fail.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ LL | const B;
1515
| help: provide a definition for the constant: `= <expr>;`
1616

1717
error: missing type for `const` item
18-
--> $DIR/item-free-const-no-body-semantic-fail.rs:6:7
18+
--> $DIR/item-free-const-no-body-semantic-fail.rs:6:8
1919
|
2020
LL | const B;
21-
| ^ help: provide a type for the item: `B: <type>`
21+
| ^ help: provide a type for the item: `: <type>`
2222

2323
error: aborting due to 3 previous errors
2424

‎src/test/ui/parser/item-free-static-no-body-semantic-fail.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ LL | static mut D;
3131
| help: provide a definition for the static: `= <expr>;`
3232

3333
error: missing type for `static` item
34-
--> $DIR/item-free-static-no-body-semantic-fail.rs:6:8
34+
--> $DIR/item-free-static-no-body-semantic-fail.rs:6:9
3535
|
3636
LL | static B;
37-
| ^ help: provide a type for the item: `B: <type>`
37+
| ^ help: provide a type for the item: `: <type>`
3838

3939
error: missing type for `static mut` item
40-
--> $DIR/item-free-static-no-body-semantic-fail.rs:10:12
40+
--> $DIR/item-free-static-no-body-semantic-fail.rs:10:13
4141
|
4242
LL | static mut D;
43-
| ^ help: provide a type for the item: `D: <type>`
43+
| ^ help: provide a type for the item: `: <type>`
4444

4545
error: aborting due to 6 previous errors
4646

‎src/test/ui/parser/removed-syntax-static-fn.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ LL | }
1616
| - the item list ends here
1717

1818
error: missing type for `static` item
19-
--> $DIR/removed-syntax-static-fn.rs:4:12
19+
--> $DIR/removed-syntax-static-fn.rs:4:14
2020
|
2121
LL | static fn f() {}
22-
| ^^ help: provide a type for the item: `r#fn: <type>`
22+
| ^ help: provide a type for the item: `: <type>`
2323

2424
error: aborting due to 3 previous errors
2525

‎src/test/ui/resolve/resolve-inconsistent-binding-mode.stderr

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ LL | Opts::A(ref i) | Opts::B(i) => {}
3131
| first introduced with type `&isize` here
3232
|
3333
= note: in the same arm, a binding must have the same type in all alternatives
34+
help: consider adding `ref`
35+
|
36+
LL | Opts::A(ref i) | Opts::B(ref i) => {}
37+
| +++
3438

3539
error[E0308]: mismatched types
3640
--> $DIR/resolve-inconsistent-binding-mode.rs:18:34
@@ -43,6 +47,10 @@ LL | Opts::A(ref i) | Opts::B(i) => {}
4347
| first introduced with type `&isize` here
4448
|
4549
= note: in the same arm, a binding must have the same type in all alternatives
50+
help: consider adding `ref`
51+
|
52+
LL | Opts::A(ref i) | Opts::B(ref i) => {}
53+
| +++
4654

4755
error[E0308]: mismatched types
4856
--> $DIR/resolve-inconsistent-binding-mode.rs:27:38

‎src/test/ui/resolve/resolve-inconsistent-names.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ fn main() {
2323
//~| ERROR mismatched types
2424
//~| ERROR variable `c` is not bound in all patterns
2525
//~| HELP if you meant to match on unit variant `E::A`, use the full path in the pattern
26+
//~| HELP consider removing `ref`
2627
}
2728

2829
let z = (10, 20);

‎src/test/ui/resolve/resolve-inconsistent-names.stderr

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ LL | (A, B) | (ref B, c) | (c, A) => ()
5555
| first binding
5656

5757
error[E0408]: variable `CONST1` is not bound in all patterns
58-
--> $DIR/resolve-inconsistent-names.rs:30:23
58+
--> $DIR/resolve-inconsistent-names.rs:31:23
5959
|
6060
LL | (CONST1, _) | (_, Const2) => ()
6161
| ------ ^^^^^^^^^^^ pattern doesn't bind `CONST1`
@@ -69,7 +69,7 @@ LL | const CONST1: usize = 10;
6969
| ^^^^^^^^^^^^^^^^^^^^^^^^^ not accessible
7070

7171
error[E0408]: variable `Const2` is not bound in all patterns
72-
--> $DIR/resolve-inconsistent-names.rs:30:9
72+
--> $DIR/resolve-inconsistent-names.rs:31:9
7373
|
7474
LL | (CONST1, _) | (_, Const2) => ()
7575
| ^^^^^^^^^^^ ------ variable not in all patterns
@@ -92,6 +92,11 @@ LL | (A, B) | (ref B, c) | (c, A) => ()
9292
| first introduced with type `E` here
9393
|
9494
= note: in the same arm, a binding must have the same type in all alternatives
95+
help: consider removing `ref`
96+
|
97+
LL - (A, B) | (ref B, c) | (c, A) => ()
98+
LL + (A, B) | (B, c) | (c, A) => ()
99+
|
95100

96101
error: aborting due to 9 previous errors
97102

‎src/test/ui/suggestions/const-no-type.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,38 @@ fn main() {}
1414
const C2 = 42;
1515
//~^ ERROR missing type for `const` item
1616
//~| HELP provide a type for the item
17-
//~| SUGGESTION C2: <type>
17+
//~| SUGGESTION : <type>
1818

1919
#[cfg(FALSE)]
2020
static S2 = "abc";
2121
//~^ ERROR missing type for `static` item
2222
//~| HELP provide a type for the item
23-
//~| SUGGESTION S2: <type>
23+
//~| SUGGESTION : <type>
2424

2525
#[cfg(FALSE)]
2626
static mut SM2 = "abc";
2727
//~^ ERROR missing type for `static mut` item
2828
//~| HELP provide a type for the item
29-
//~| SUGGESTION SM2: <type>
29+
//~| SUGGESTION : <type>
3030

3131
// These will, so the diagnostics should be stolen by typeck:
3232

3333
const C = 42;
3434
//~^ ERROR missing type for `const` item
3535
//~| HELP provide a type for the constant
36-
//~| SUGGESTION C: i32
36+
//~| SUGGESTION : i32
3737

3838
const D = &&42;
3939
//~^ ERROR missing type for `const` item
4040
//~| HELP provide a type for the constant
41-
//~| SUGGESTION D: &&i32
41+
//~| SUGGESTION : &&i32
4242

4343
static S = Vec::<String>::new();
4444
//~^ ERROR missing type for `static` item
4545
//~| HELP provide a type for the static variable
46-
//~| SUGGESTION S: Vec<String>
46+
//~| SUGGESTION : Vec<String>
4747

4848
static mut SM = "abc";
4949
//~^ ERROR missing type for `static mut` item
5050
//~| HELP provide a type for the static variable
51-
//~| SUGGESTION &str
51+
//~| SUGGESTION : &str
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
11
error: missing type for `const` item
2-
--> $DIR/const-no-type.rs:33:7
2+
--> $DIR/const-no-type.rs:33:8
33
|
44
LL | const C = 42;
5-
| ^ help: provide a type for the constant: `C: i32`
5+
| ^ help: provide a type for the constant: `: i32`
66

77
error: missing type for `const` item
8-
--> $DIR/const-no-type.rs:38:7
8+
--> $DIR/const-no-type.rs:38:8
99
|
1010
LL | const D = &&42;
11-
| ^ help: provide a type for the constant: `D: &&i32`
11+
| ^ help: provide a type for the constant: `: &&i32`
1212

1313
error: missing type for `static` item
14-
--> $DIR/const-no-type.rs:43:8
14+
--> $DIR/const-no-type.rs:43:9
1515
|
1616
LL | static S = Vec::<String>::new();
17-
| ^ help: provide a type for the static variable: `S: Vec<String>`
17+
| ^ help: provide a type for the static variable: `: Vec<String>`
1818

1919
error: missing type for `static mut` item
20-
--> $DIR/const-no-type.rs:48:12
20+
--> $DIR/const-no-type.rs:48:14
2121
|
2222
LL | static mut SM = "abc";
23-
| ^^ help: provide a type for the static variable: `SM: &str`
23+
| ^ help: provide a type for the static variable: `: &str`
2424

2525
error: missing type for `const` item
26-
--> $DIR/const-no-type.rs:14:7
26+
--> $DIR/const-no-type.rs:14:9
2727
|
2828
LL | const C2 = 42;
29-
| ^^ help: provide a type for the item: `C2: <type>`
29+
| ^ help: provide a type for the item: `: <type>`
3030

3131
error: missing type for `static` item
32-
--> $DIR/const-no-type.rs:20:8
32+
--> $DIR/const-no-type.rs:20:10
3333
|
3434
LL | static S2 = "abc";
35-
| ^^ help: provide a type for the item: `S2: <type>`
35+
| ^ help: provide a type for the item: `: <type>`
3636

3737
error: missing type for `static mut` item
38-
--> $DIR/const-no-type.rs:26:12
38+
--> $DIR/const-no-type.rs:26:15
3939
|
4040
LL | static mut SM2 = "abc";
41-
| ^^^ help: provide a type for the item: `SM2: <type>`
41+
| ^ help: provide a type for the item: `: <type>`
4242

4343
error: aborting due to 7 previous errors
4444

‎src/test/ui/suggestions/unnamable-types.stderr

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: missing type for `const` item
2-
--> $DIR/unnamable-types.rs:6:7
2+
--> $DIR/unnamable-types.rs:6:8
33
|
44
LL | const A = 5;
5-
| ^ help: provide a type for the constant: `A: i32`
5+
| ^ help: provide a type for the constant: `: i32`
66

77
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
88
--> $DIR/unnamable-types.rs:10:11
@@ -26,10 +26,10 @@ LL | const C: _ = || 42;
2626
| ^^^^^
2727

2828
error: missing type for `const` item
29-
--> $DIR/unnamable-types.rs:23:7
29+
--> $DIR/unnamable-types.rs:23:8
3030
|
3131
LL | const D = S { t: { let i = 0; move || -> i32 { i } } };
32-
| ^
32+
| ^
3333
|
3434
note: however, the inferred type `S<[closure@$DIR/unnamable-types.rs:23:31: 23:45]>` cannot be named
3535
--> $DIR/unnamable-types.rs:23:11
@@ -38,22 +38,22 @@ LL | const D = S { t: { let i = 0; move || -> i32 { i } } };
3838
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3939

4040
error: missing type for `const` item
41-
--> $DIR/unnamable-types.rs:29:7
41+
--> $DIR/unnamable-types.rs:29:8
4242
|
4343
LL | const E = foo;
44-
| ^ help: provide a type for the constant: `E: fn() -> i32`
44+
| ^ help: provide a type for the constant: `: fn() -> i32`
4545

4646
error: missing type for `const` item
47-
--> $DIR/unnamable-types.rs:32:7
47+
--> $DIR/unnamable-types.rs:32:8
4848
|
4949
LL | const F = S { t: foo };
50-
| ^ help: provide a type for the constant: `F: S<fn() -> i32>`
50+
| ^ help: provide a type for the constant: `: S<fn() -> i32>`
5151

5252
error: missing type for `const` item
53-
--> $DIR/unnamable-types.rs:37:7
53+
--> $DIR/unnamable-types.rs:37:8
5454
|
5555
LL | const G = || -> i32 { yield 0; return 1; };
56-
| ^
56+
| ^
5757
|
5858
note: however, the inferred type `[generator@$DIR/unnamable-types.rs:37:11: 37:20]` cannot be named
5959
--> $DIR/unnamable-types.rs:37:11

‎src/test/ui/transmutability/references.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0277]: `&'static Unit` cannot be safely transmuted into `&'static Unit` in the defining scope of `assert::Context`.
2-
--> $DIR/references.rs:19:52
2+
--> $DIR/references.rs:19:37
33
|
44
LL | assert::is_maybe_transmutable::<&'static Unit, &'static Unit>();
5-
| ^^^^^^^^^^^^^ `&'static Unit` cannot be safely transmuted into `&'static Unit` in the defining scope of `assert::Context`.
5+
| ^^^^^^^^^^^^^ `&'static Unit` cannot be safely transmuted into `&'static Unit` in the defining scope of `assert::Context`.
66
|
77
= help: the trait `BikeshedIntrinsicFrom<&'static Unit, assert::Context, true, true, true, true>` is not implemented for `&'static Unit`
88
note: required by a bound in `is_maybe_transmutable`

‎src/test/ui/typeck/issue-100164.fixed

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// run-rustfix
2+
3+
const _A: i32 = 123;
4+
//~^ ERROR: missing type for `const` item
5+
6+
fn main() {
7+
const _B: i32 = 123;
8+
//~^ ERROR: missing type for `const` item
9+
}

‎src/test/ui/typeck/issue-100164.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// run-rustfix
2+
3+
const _A: = 123;
4+
//~^ ERROR: missing type for `const` item
5+
6+
fn main() {
7+
const _B: = 123;
8+
//~^ ERROR: missing type for `const` item
9+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: missing type for `const` item
2+
--> $DIR/issue-100164.rs:3:10
3+
|
4+
LL | const _A: = 123;
5+
| ^ help: provide a type for the constant: `i32`
6+
7+
error: missing type for `const` item
8+
--> $DIR/issue-100164.rs:7:14
9+
|
10+
LL | const _B: = 123;
11+
| ^ help: provide a type for the constant: `i32`
12+
13+
error: aborting due to 2 previous errors
14+

‎src/test/ui/typeck/issue-79040.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ LL | const FOO = "hello" + 1;
77
| &str
88

99
error: missing type for `const` item
10-
--> $DIR/issue-79040.rs:2:11
10+
--> $DIR/issue-79040.rs:2:14
1111
|
1212
LL | const FOO = "hello" + 1;
13-
| ^^^ help: provide a type for the item: `FOO: <type>`
13+
| ^ help: provide a type for the item: `: <type>`
1414

1515
error: aborting due to 2 previous errors
1616

‎src/test/ui/typeck/typeck_type_placeholder_item.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,10 @@ LL ~ b: (T, T),
189189
|
190190

191191
error: missing type for `static` item
192-
--> $DIR/typeck_type_placeholder_item.rs:73:12
192+
--> $DIR/typeck_type_placeholder_item.rs:73:13
193193
|
194194
LL | static A = 42;
195-
| ^ help: provide a type for the static variable: `A: i32`
195+
| ^ help: provide a type for the static variable: `: i32`
196196

197197
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
198198
--> $DIR/typeck_type_placeholder_item.rs:75:15

0 commit comments

Comments
 (0)
This repository has been archived.