Skip to content

Commit 9b56c87

Browse files
committed
Rollup merge of rust-lang#54604 - alexreg:self_in_typedefs-help, r=estebank
Added help message for `self_in_typedefs` feature gate Fixes rust-lang#54563. CC @Centril @estebank @leonardo-m
2 parents 420ddf1 + 4151de4 commit 9b56c87

File tree

5 files changed

+38
-15
lines changed

5 files changed

+38
-15
lines changed

src/librustc_mir/hair/pattern/check_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ fn check_legality_of_move_bindings(cx: &MatchVisitor,
539539
.emit();
540540
} else if has_guard && !cx.tcx.allow_bind_by_move_patterns_with_guards() {
541541
let mut err = struct_span_err!(cx.tcx.sess, p.span, E0008,
542-
"cannot bind by-move into a pattern guard");
542+
"cannot bind by-move into a pattern guard");
543543
err.span_label(p.span, "moves value into pattern guard");
544544
if cx.tcx.sess.opts.unstable_features.is_nightly_build() && cx.tcx.use_mir_borrowck() {
545545
err.help("add #![feature(bind_by_move_pattern_guards)] to the \

src/librustc_resolve/lib.rs

+29-9
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ use rustc::lint;
4242
use rustc::hir::def::*;
4343
use rustc::hir::def::Namespace::*;
4444
use rustc::hir::def_id::{CRATE_DEF_INDEX, LOCAL_CRATE, DefId};
45-
use rustc::ty;
4645
use rustc::hir::{Freevar, FreevarMap, TraitCandidate, TraitMap, GlobMap};
46+
use rustc::session::config::nightly_options;
47+
use rustc::ty;
4748
use rustc::util::nodemap::{NodeMap, NodeSet, FxHashMap, FxHashSet, DefIdMap};
4849

4950
use rustc_metadata::creader::CrateLoader;
@@ -1381,6 +1382,9 @@ pub struct Resolver<'a, 'b: 'a> {
13811382
/// The current self type if inside an impl (used for better errors).
13821383
current_self_type: Option<Ty>,
13831384

1385+
/// The current self item if inside an ADT (used for better errors).
1386+
current_self_item: Option<NodeId>,
1387+
13841388
/// The idents for the primitive types.
13851389
primitive_type_table: PrimitiveTypeTable,
13861390

@@ -1710,6 +1714,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
17101714

17111715
current_trait_ref: None,
17121716
current_self_type: None,
1717+
current_self_item: None,
17131718

17141719
primitive_type_table: PrimitiveTypeTable::new(),
17151720

@@ -2186,15 +2191,17 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
21862191
}
21872192

21882193
fn resolve_adt(&mut self, item: &Item, generics: &Generics) {
2189-
self.with_type_parameter_rib(HasTypeParameters(generics, ItemRibKind), |this| {
2190-
let item_def_id = this.definitions.local_def_id(item.id);
2191-
if this.session.features_untracked().self_in_typedefs {
2192-
this.with_self_rib(Def::SelfTy(None, Some(item_def_id)), |this| {
2194+
self.with_current_self_item(item, |this| {
2195+
this.with_type_parameter_rib(HasTypeParameters(generics, ItemRibKind), |this| {
2196+
let item_def_id = this.definitions.local_def_id(item.id);
2197+
if this.session.features_untracked().self_in_typedefs {
2198+
this.with_self_rib(Def::SelfTy(None, Some(item_def_id)), |this| {
2199+
visit::walk_item(this, item);
2200+
});
2201+
} else {
21932202
visit::walk_item(this, item);
2194-
});
2195-
} else {
2196-
visit::walk_item(this, item);
2197-
}
2203+
}
2204+
});
21982205
});
21992206
}
22002207

@@ -2435,6 +2442,15 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
24352442
result
24362443
}
24372444

2445+
fn with_current_self_item<T, F>(&mut self, self_item: &Item, f: F) -> T
2446+
where F: FnOnce(&mut Resolver) -> T
2447+
{
2448+
let previous_value = replace(&mut self.current_self_item, Some(self_item.id));
2449+
let result = f(self);
2450+
self.current_self_item = previous_value;
2451+
result
2452+
}
2453+
24382454
/// This is called to resolve a trait reference from an `impl` (i.e. `impl Trait for Foo`)
24392455
fn with_optional_trait_ref<T, F>(&mut self, opt_trait_ref: Option<&TraitRef>, f: F) -> T
24402456
where F: FnOnce(&mut Resolver, Option<DefId>) -> T
@@ -3004,6 +3020,10 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
30043020
"traits and impls"
30053021
};
30063022
err.span_label(span, format!("`Self` is only available in {}", available_in));
3023+
if this.current_self_item.is_some() && nightly_options::is_nightly_build() {
3024+
err.help("add #![feature(self_in_typedefs)] to the crate attributes \
3025+
to enable");
3026+
}
30073027
return (err, Vec::new());
30083028
}
30093029
if is_self_value(path, ns) {

src/librustc_typeck/check/method/probe.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ use check::FnCtxt;
1717
use hir::def_id::DefId;
1818
use hir::def::Def;
1919
use namespace::Namespace;
20+
use rustc::hir;
21+
use rustc::lint;
22+
use rustc::session::config::nightly_options;
2023
use rustc::ty::subst::{Subst, Substs};
2124
use rustc::traits::{self, ObligationCause};
2225
use rustc::ty::{self, Ty, ToPolyTraitRef, ToPredicate, TraitRef, TypeFoldable};
@@ -28,8 +31,6 @@ use rustc::middle::stability;
2831
use syntax::ast;
2932
use syntax::util::lev_distance::{lev_distance, find_best_match_for_name};
3033
use syntax_pos::{Span, symbol::Symbol};
31-
use rustc::hir;
32-
use rustc::lint;
3334
use std::mem;
3435
use std::ops::Deref;
3536
use std::rc::Rc;
@@ -1073,9 +1074,9 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
10731074
self.tcx.item_path_str(stable_pick.item.def_id),
10741075
));
10751076

1076-
if ::rustc::session::config::nightly_options::is_nightly_build() {
1077+
if nightly_options::is_nightly_build() {
10771078
for (candidate, feature) in unstable_candidates {
1078-
diag.note(&format!(
1079+
diag.help(&format!(
10791080
"add #![feature({})] to the crate attributes to enable `{}`",
10801081
feature,
10811082
self.tcx.item_path_str(candidate.item.def_id),

src/test/ui/feature-gates/feature-gate-self_in_typedefs.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error[E0411]: cannot find type `Self` in this scope
33
|
44
LL | Cons(T, &'a Self)
55
| ^^^^ `Self` is only available in traits and impls
6+
|
7+
= help: add #![feature(self_in_typedefs)] to the crate attributes to enable
68

79
error: aborting due to previous error
810

src/test/ui/inference/inference_unstable.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ LL | assert_eq!('x'.ipu_flatten(), 1);
88
= warning: once this method is added to the standard library, the ambiguity may cause an error or change in behavior!
99
= note: for more information, see issue #48919 <https://github.com/rust-lang/rust/issues/48919>
1010
= help: call with fully qualified syntax `inference_unstable_itertools::IpuItertools::ipu_flatten(...)` to keep using the current method
11-
= note: add #![feature(ipu_flatten)] to the crate attributes to enable `inference_unstable_iterator::IpuIterator::ipu_flatten`
11+
= help: add #![feature(ipu_flatten)] to the crate attributes to enable `inference_unstable_iterator::IpuIterator::ipu_flatten`
1212

0 commit comments

Comments
 (0)