to_string(NO_ANN, |s| s.print_path(segment, false))
}
+pub fn qpath_to_string(segment: &hir::QPath<'_>) -> String {
+ to_string(NO_ANN, |s| s.print_qpath(segment, false))
+}
+
pub fn fn_to_string(
decl: &hir::FnDecl<'_>,
header: hir::FnHeader,
= self.typeck_results.borrow().qpath_res(qpath, callee_expr.hir_id)
// Only suggest removing parens if there are no arguments
&& arg_exprs.is_empty()
- && let Ok(path) = self.tcx.sess.source_map().span_to_snippet(callee_expr.span)
{
let descr = match kind {
def::CtorOf::Struct => "struct",
let removal_span =
callee_expr.span.shrink_to_hi().to(call_expr.span.shrink_to_hi());
unit_variant =
- Some((removal_span, descr, path));
+ Some((removal_span, descr, rustc_hir_pretty::qpath_to_string(qpath)));
}
let callee_ty = self.resolve_vars_if_possible(callee_ty);
tcx.ty_error()
}
Res::Def(DefKind::Ctor(_, CtorKind::Fictive), _) => {
- report_unexpected_variant_res(tcx, res, expr.span);
+ report_unexpected_variant_res(tcx, res, qpath, expr.span);
tcx.ty_error()
}
_ => self.instantiate_value_path(segs, opt_ty, res, expr.span, expr.hir_id).0,
err.emit();
}
-fn report_unexpected_variant_res(tcx: TyCtxt<'_>, res: Res, span: Span) {
+fn report_unexpected_variant_res(tcx: TyCtxt<'_>, res: Res, qpath: &hir::QPath<'_>, span: Span) {
struct_span_err!(
tcx.sess,
span,
E0533,
- "expected unit struct, unit variant or constant, found {}{}",
+ "expected unit struct, unit variant or constant, found {} `{}`",
res.descr(),
- tcx.sess
- .source_map()
- .span_to_snippet(span)
- .map_or_else(|_| String::new(), |s| format!(" `{s}`",)),
+ rustc_hir_pretty::qpath_to_string(qpath),
)
.emit();
}
PatKind::TupleStruct(ref qpath, subpats, ddpos) => {
self.check_pat_tuple_struct(pat, qpath, subpats, ddpos, expected, def_bm, ti)
}
- PatKind::Path(_) => self.check_pat_path(pat, path_res.unwrap(), expected, ti),
+ PatKind::Path(ref qpath) => {
+ self.check_pat_path(pat, qpath, path_res.unwrap(), expected, ti)
+ }
PatKind::Struct(ref qpath, fields, has_rest_pat) => {
self.check_pat_struct(pat, qpath, fields, has_rest_pat, expected, def_bm, ti)
}
fn check_pat_path<'b>(
&self,
pat: &Pat<'_>,
+ qpath: &hir::QPath<'_>,
path_resolution: (Res, Option<Ty<'tcx>>, &'b [hir::PathSegment<'b>]),
expected: Ty<'tcx>,
ti: TopInfo<'tcx>,
return tcx.ty_error();
}
Res::Def(DefKind::AssocFn | DefKind::Ctor(_, CtorKind::Fictive | CtorKind::Fn), _) => {
- report_unexpected_variant_res(tcx, res, pat.span);
+ report_unexpected_variant_res(tcx, res, qpath, pat.span);
return tcx.ty_error();
}
Res::SelfCtor(..)
LL | Foo::bar => {}
| ^^^^^^^^
-error[E0533]: expected unit struct, unit variant or constant, found associated function `<Foo>::bar`
+error[E0533]: expected unit struct, unit variant or constant, found associated function `Foo::bar`
--> $DIR/method-path-in-pattern.rs:19:9
|
LL | <Foo>::bar => {}
| ^^^^^^^^^^
-error[E0533]: expected unit struct, unit variant or constant, found associated function `<Foo>::trait_bar`
+error[E0533]: expected unit struct, unit variant or constant, found associated function `Foo::trait_bar`
--> $DIR/method-path-in-pattern.rs:23:9
|
LL | <Foo>::trait_bar => {}
LL | if let Foo::bar = 0u32 {}
| ^^^^^^^^
-error[E0533]: expected unit struct, unit variant or constant, found associated function `<Foo>::bar`
+error[E0533]: expected unit struct, unit variant or constant, found associated function `Foo::bar`
--> $DIR/method-path-in-pattern.rs:28:12
|
LL | if let <Foo>::bar = 0u32 {}
-error[E0533]: expected unit struct, unit variant or constant, found associated function `<S as Tr>::A::f::<u8>`
+error[E0533]: expected unit struct, unit variant or constant, found associated function `<<S as Tr>::A>::f<u8>`
--> $DIR/qualified-path-params.rs:20:9
|
LL | <S as Tr>::A::f::<u8> => {}
--- /dev/null
+enum Enum {
+ Unit,
+}
+type Alias = Enum;
+
+fn main() {
+ Alias::
+ Unit();
+ //~^^ ERROR expected function, found enum variant `Alias::Unit`
+}
--- /dev/null
+error[E0618]: expected function, found enum variant `Alias::Unit`
+ --> $DIR/issue-99240-2.rs:7:5
+ |
+LL | Unit,
+ | ---- enum variant `Alias::Unit` defined here
+...
+LL | Alias::
+ | _____^
+ | |_____|
+ | ||
+LL | || Unit();
+ | ||________^_- call expression requires function
+ | |_________|
+ |
+ |
+help: `Alias::Unit` is a unit enum variant, and does not take parentheses to be constructed
+ |
+LL - Unit();
+LL + Unit;
+ |
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0618`.